From be65289197823e94bb053284761277d99d405cab Mon Sep 17 00:00:00 2001 From: Richard Killen Date: Wed, 29 Mar 2023 12:41:56 -0500 Subject: [PATCH 1/2] Write restart and non-dynamic information to results.json for update and deploy --- core/src/main/python/deploy.py | 4 + core/src/main/python/update.py | 3 + .../wlsdeploy/tool/deploy/deployer_utils.py | 30 +++++-- .../wlsdeploy/tool/util/results_file.py | 85 +++++++++++++++++++ 4 files changed, 116 insertions(+), 6 deletions(-) create mode 100644 core/src/main/python/wlsdeploy/tool/util/results_file.py diff --git a/core/src/main/python/deploy.py b/core/src/main/python/deploy.py index 6faf4516e2..dcc3a69607 100644 --- a/core/src/main/python/deploy.py +++ b/core/src/main/python/deploy.py @@ -23,6 +23,7 @@ from wlsdeploy.tool.util import wlst_helper from wlsdeploy.tool.util.wlst_helper import WlstHelper from wlsdeploy.util import cla_helper +from wlsdeploy.tool.util import results_file from wlsdeploy.util import tool_main from wlsdeploy.util.cla_utils import CommandLineArgUtil from wlsdeploy.util.exit_code import ExitCode @@ -102,6 +103,9 @@ def __deploy(model, model_context, aliases): ret_code = __deploy_online(model, model_context, aliases) else: ret_code = __deploy_offline(model, model_context, aliases) + + results_file.check_and_write(model_context, ExceptionType.DEPLOY) + return ret_code diff --git a/core/src/main/python/update.py b/core/src/main/python/update.py index 04e070397a..ae111258cb 100644 --- a/core/src/main/python/update.py +++ b/core/src/main/python/update.py @@ -22,6 +22,7 @@ from wlsdeploy.tool.deploy import model_deployer from wlsdeploy.tool.deploy.topology_updater import TopologyUpdater from wlsdeploy.tool.util import model_context_helper +from wlsdeploy.tool.util import results_file from wlsdeploy.tool.util import wlst_helper from wlsdeploy.tool.util.wlst_helper import WlstHelper from wlsdeploy.tool.util.rcu_helper import RCUHelper @@ -109,6 +110,8 @@ def __update(model, model_context, aliases): else: ret_code = __update_offline(model, model_context, aliases) + results_file.check_and_write(model_context, ExceptionType.DEPLOY) + return ret_code diff --git a/core/src/main/python/wlsdeploy/tool/deploy/deployer_utils.py b/core/src/main/python/wlsdeploy/tool/deploy/deployer_utils.py index 8e8ff186db..792a9c27db 100644 --- a/core/src/main/python/wlsdeploy/tool/deploy/deployer_utils.py +++ b/core/src/main/python/wlsdeploy/tool/deploy/deployer_utils.py @@ -1,5 +1,5 @@ """ -Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates. +Copyright (c) 2017, 2023, Oracle Corporation and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. """ import os @@ -48,6 +48,7 @@ from wlsdeploy.exception import exception_helper from wlsdeploy.exception.expection_types import ExceptionType from wlsdeploy.logging import platform_logger +from wlsdeploy.tool.util import results_file from wlsdeploy.tool.util.string_output_stream import StringOutputStream from wlsdeploy.tool.util.wlst_helper import WlstHelper from wlsdeploy.util import dictionary_utils @@ -503,16 +504,20 @@ def list_restarts(model_context, exit_code): line = '%s:%s:%s:%s' % (entry[0], entry[1], entry[2], entry[3]) _logger.finer('WLSDPLY-09208', line, class_name=_class_name, method_name=_method_name) pw.println(line) + + results_file.add_restart_entry(entry[0], entry[1], entry[2], entry[3]) pw.close() _logger.exiting(class_name=_class_name, method_name=_method_name, result=result) return result -def list_non_dynamic_changes(model_context, non_dynamic_changes_string): +def list_non_dynamic_changes(unactivated_changes, non_dynamic_changes_string, model_context): """ If output dir is present in the model context, write the restart data to the output dir as non_dynamic_changes.file. - :param model_context: Current context with the run parameters. - :param non_dynamic_changes_string: java.lang.String of changes that were non dynamic + Add unactivated changes that are not dynamic to the results file. + :param unactivated_changes: a list of unactivated changes for WLST + :param non_dynamic_changes_string: java.lang.String of changes that were non-dynamic + :param model_context: used to get the output directory """ _method_name = 'list_non_dynamic_changes' _logger.entering(class_name=_class_name, method_name=_method_name) @@ -523,6 +528,14 @@ def list_non_dynamic_changes(model_context, non_dynamic_changes_string): pw.println(non_dynamic_changes_string) pw.close() + for change in unactivated_changes: + if change.isRestartRequired() and not change.getAffectedBean(): + bean_name = str(change.getBean()) + attribute_name = change.getAttributeName() + results_file.add_non_dynamic_change(bean_name, attribute_name) + + results_file.add_non_dynamic_changes_text(str_helper.to_string(non_dynamic_changes_string)) + def get_list_of_restarts(): """ @@ -589,17 +602,22 @@ def online_check_save_activate(model_context): restart_required = _wlst_helper.is_restart_required() is_restartreq_output = sostream.get_string() _wlst_helper.silence() + + # get unactivated changes before cancel or save + config_manager = _wlst_helper.get_config_manager() + unactivated_changes = config_manager.getUnactivatedChanges() + if model_context.is_cancel_changes_if_restart_required() and restart_required: _wlst_helper.cancel_edit() _logger.warning('WLSDPLY-09018', is_restartreq_output) exit_code = ExitCode.CANCEL_CHANGES_IF_RESTART - list_non_dynamic_changes(model_context, is_restartreq_output) + list_non_dynamic_changes(unactivated_changes, is_restartreq_output, model_context) else: _wlst_helper.save() _wlst_helper.activate(model_context.get_model_config().get_activate_timeout()) if restart_required: exit_code = ExitCode.RESTART_REQUIRED - list_non_dynamic_changes(model_context, is_restartreq_output) + list_non_dynamic_changes(unactivated_changes, is_restartreq_output, model_context) exit_code = list_restarts(model_context, exit_code) except BundleAwareException, ex: diff --git a/core/src/main/python/wlsdeploy/tool/util/results_file.py b/core/src/main/python/wlsdeploy/tool/util/results_file.py new file mode 100644 index 0000000000..f44c338cb9 --- /dev/null +++ b/core/src/main/python/wlsdeploy/tool/util/results_file.py @@ -0,0 +1,85 @@ +""" +Copyright (c) 2023, Oracle and/or its affiliates. +Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. +""" +import os + +from oracle.weblogic.deploy.json import JsonException +from oracle.weblogic.deploy.util import PyOrderedDict + +from wlsdeploy.exception import exception_helper +from wlsdeploy.json.json_translator import PythonToJson + +""" +This module acts as a singleton to collect results for the duration of a tool's execution, +without having to be passed to individual methods and classes. +""" + +RESULTS_FILE_NAME = 'results.json' + +NON_DYNAMIC_CHANGES_FOLDER = 'nonDynamicChanges' +RESTARTS_FOLDER = 'restarts' + +CLUSTER_KEY = 'cluster' +NON_DYNAMIC_CHANGES_TEXT_KEY = 'nonDynamicChangesText' +RESOURCE_NAME_KEY = 'resourceName' +RESOURCE_TYPE_KEY = 'resourceType' +SERVER_KEY = 'server' +TEXT_KEY = 'text' + +_results_dict = PyOrderedDict() + + +def check_and_write(model_context, exception_type): + """ + Write the results file to the output directory, if output directory was specified. + :param model_context: used to determine output directory + :param exception_type: the exception type to be thrown on failure + """ + output_dir = model_context.get_output_dir() + if output_dir: + results_file = os.path.join(output_dir, RESULTS_FILE_NAME) + json_object = PythonToJson(_results_dict) + + try: + json_object.write_to_json_file(results_file) + except JsonException, ex: + raise exception_helper.create_exception(exception_type, 'WLSDPLY-01681', results_file, + ex.getLocalizedMessage(), error=ex) + + +def add_restart_entry(cluster, server, resource_name, resource_type): + restart = PyOrderedDict() + if cluster: + restart[CLUSTER_KEY] = cluster + if server: + restart[SERVER_KEY] = server + if resource_name: + restart[RESOURCE_NAME_KEY] = resource_name + if resource_type: + restart[RESOURCE_TYPE_KEY] = resource_type + restarts = _add_or_create_array(_results_dict, RESTARTS_FOLDER) + restarts.append(restart) + + +def add_non_dynamic_change(bean_name, attribute_name): + non_dynamic_changes = _add_or_create_folder(_results_dict, NON_DYNAMIC_CHANGES_FOLDER) + bean_array = _add_or_create_array(non_dynamic_changes, bean_name) + bean_array.append(attribute_name) + + +def add_non_dynamic_changes_text(non_dynamic_changes_text): + lines = non_dynamic_changes_text.splitlines() + _results_dict[NON_DYNAMIC_CHANGES_TEXT_KEY] = lines + + +def _add_or_create_folder(parent_folder, folder_name): + if folder_name not in parent_folder: + parent_folder[folder_name] = PyOrderedDict() + return parent_folder[folder_name] + + +def _add_or_create_array(parent_folder, folder_name): + if folder_name not in parent_folder: + parent_folder[folder_name] = [] + return parent_folder[folder_name] From 16d6ccdf5332947d3cec569e5a9d7455596b74ae Mon Sep 17 00:00:00 2001 From: Richard Killen Date: Wed, 29 Mar 2023 12:43:19 -0500 Subject: [PATCH 2/2] Update description of -output_dir argument for update and deploy --- documentation/3.0/content/userguide/tools/deploy.md | 2 +- documentation/3.0/content/userguide/tools/update.md | 2 +- installer/src/main/bin/deployApps.cmd | 9 ++++----- installer/src/main/bin/deployApps.sh | 9 ++++----- installer/src/main/bin/updateDomain.cmd | 9 ++++----- installer/src/main/bin/updateDomain.sh | 9 ++++----- 6 files changed, 18 insertions(+), 22 deletions(-) diff --git a/documentation/3.0/content/userguide/tools/deploy.md b/documentation/3.0/content/userguide/tools/deploy.md index 6e983984c2..e6075c6b0b 100644 --- a/documentation/3.0/content/userguide/tools/deploy.md +++ b/documentation/3.0/content/userguide/tools/deploy.md @@ -71,7 +71,7 @@ The Deploy Applications Tool supports the use of multiple models, as described i | `-domain_type` | The type of domain. (for example, `WLS`, `JRF`) | `WLS` | | `-model_file` | The location of the model file. This can also be specified as a comma-separated list of model locations, where each successive model layers on top of the previous ones. | | | `-oracle_home` | Home directory of the Oracle WebLogic installation. Required if the `ORACLE_HOME` environment variable is not set.| | -| `-output_dir` | If present, write restart information to this directory as `restart.file`, or, if `cancel_changes_if_restart_required` used, write non-dynamic changes information to file. | | +| `-output_dir` | If specified, files containing restart information are written to this directory, including `restart.file`, `non_dynamic_changes.file`, and `results.json`. | | | `-passphrase_env` | An alternative to entering the encryption passphrase at a prompt. The value is an environment variable name that WDT will use to retrieve the passphrase. | | | `-passphrase_file` | An alternative to entering the encryption passphrase at a prompt. The value is the name of a file with a string value which WDT will read to retrieve the passphrase. | | | `-use_encryption` | One or more of the passwords in the model or variables file(s) are encrypted and must be decrypted. Java 8 or later is required for this feature. | | diff --git a/documentation/3.0/content/userguide/tools/update.md b/documentation/3.0/content/userguide/tools/update.md index c0637b1f5a..c4f12cf0e3 100644 --- a/documentation/3.0/content/userguide/tools/update.md +++ b/documentation/3.0/content/userguide/tools/update.md @@ -83,7 +83,7 @@ The Update Domain Tool supports the use of multiple models, as described in [Usi | `-oracle_home` | Home directory of the Oracle WebLogic installation. Required if the `ORACLE_HOME` environment variable is not set. | | | `-passphrase_env` | An alternative to entering the encryption passphrase at a prompt. The value is an environment variable name that WDT will use to retrieve the passphrase. | | | `-passphrase_file` | An alternative to entering the encryption passphrase at a prompt. The value is a the name of a file with a string value which WDT will read to retrieve the passphrase. | | -| `-update_dir` | If present, write restart information to this directory as `restart.file`, or if `cancel_changes_if_restart_required` used, write non-dynamic changes information to `non_dynamic_changes` file. | | +| `-update_dir` | If specified, files containing restart information are written to this directory, including `restart.file`, `non_dynamic_changes.file`, and `results.json`. | | | `-use_encryption` | One or more of the passwords in the model or variables file(s) are encrypted and must be decrypted. Java 8 or later required for this feature. | | | `-variable_home` | The location of the property file containing the values for variables used in the model. This can also be specified as a comma-separated list of property files, where each successive set of properties layers on top of the previous ones. | | | `-wait_for_edit_lock` | Skip checks for active edit sessions and pending changes before trying to acquire the WLST online edit lock to modify domain configuration. | | diff --git a/installer/src/main/bin/deployApps.cmd b/installer/src/main/bin/deployApps.cmd index 724a291795..7d3ca3263a 100644 --- a/installer/src/main/bin/deployApps.cmd +++ b/installer/src/main/bin/deployApps.cmd @@ -128,11 +128,10 @@ ECHO. ECHO wlst_path - the Oracle Home subdirectory of the wlst.cmd ECHO script to use (e.g., ^\soa) ECHO. -ECHO output_dir - if present, write restart information to this -ECHO directory as restart.file, or, if -ECHO cancel_changes_if_restart_required is used, -ECHO write non dynamic changes information to -ECHO non_dynamic_changes.file. +ECHO output_dir - if specified, files containing restart information +ECHO are written to this directory, including +ECHO restart.file, non_dynamic_changes.file, and +ECHO results.json. ECHO. ECHO admin_url - the admin server URL (used for online deploy) ECHO. diff --git a/installer/src/main/bin/deployApps.sh b/installer/src/main/bin/deployApps.sh index d67e4e76bd..bde458709a 100644 --- a/installer/src/main/bin/deployApps.sh +++ b/installer/src/main/bin/deployApps.sh @@ -89,11 +89,10 @@ usage() { echo " wlst_path - the Oracle Home subdirectory of the wlst.cmd" echo " script to use (e.g., /soa)." echo "" - echo " output_dir - if present, write restart information to this" - echo " directory in restart.file, or, if" - echo " cancel_changes_if_restart_required is used," - echo " write non-dynamic changes information to" - echo " non_dynamic_changes.file." + echo " output_dir - if specified, files containing restart information" + echo " are written to this directory, including" + echo " restart.file, non_dynamic_changes.file, and" + echo " results.json." echo "" echo " admin_url - the admin server URL (used for online deploy)." echo "" diff --git a/installer/src/main/bin/updateDomain.cmd b/installer/src/main/bin/updateDomain.cmd index d3ce3e8d43..71e0ba0e17 100644 --- a/installer/src/main/bin/updateDomain.cmd +++ b/installer/src/main/bin/updateDomain.cmd @@ -127,11 +127,10 @@ ECHO. ECHO wlst_path - the Oracle Home subdirectory of the wlst.cmd ECHO script to use (e.g., ^\soa) ECHO. -ECHO output_dir - if present, write restart information to this -ECHO directory as restart.file, or, if -ECHO cancel_changes_if_restart_required is used, -ECHO write non dynamic changes information to -ECHO non_dynamic_changes.file. +ECHO output_dir - if specified, files containing restart information +ECHO are written to this directory, including +ECHO restart.file, non_dynamic_changes.file, and +ECHO results.json. ECHO. ECHO admin_url - the admin server URL (used for online deploy) ECHO. diff --git a/installer/src/main/bin/updateDomain.sh b/installer/src/main/bin/updateDomain.sh index 7627fcb26e..039243ab8d 100644 --- a/installer/src/main/bin/updateDomain.sh +++ b/installer/src/main/bin/updateDomain.sh @@ -89,11 +89,10 @@ usage() { echo " wlst_path - the Oracle Home subdirectory of the wlst.cmd" echo " script to use (e.g., /soa)." echo "" - echo " output_dir - if present, write restart information to this" - echo " directory in restart.file, or, if" - echo " cancel_changes_if_restart_required is used," - echo " write non-dynamic changes information to" - echo " non_dynamic_changes.file." + echo " output_dir - if specified, files containing restart information" + echo " are written to this directory, including" + echo " restart.file, non_dynamic_changes.file, and" + echo " results.json." echo "" echo " admin_url - the admin server URL (used for online deploy)." echo ""