Skip to content

Write restart and non-dynamic information to results.json for update and deploy #1434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/src/main/python/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
3 changes: 3 additions & 0 deletions core/src/main/python/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
30 changes: 24 additions & 6 deletions core/src/main/python/wlsdeploy/tool/deploy/deployer_utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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():
"""
Expand Down Expand Up @@ -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:
Expand Down
85 changes: 85 additions & 0 deletions core/src/main/python/wlsdeploy/tool/util/results_file.py
Original file line number Diff line number Diff line change
@@ -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]
2 changes: 1 addition & 1 deletion documentation/3.0/content/userguide/tools/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. | |
Expand Down
2 changes: 1 addition & 1 deletion documentation/3.0/content/userguide/tools/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. | |
Expand Down
9 changes: 4 additions & 5 deletions installer/src/main/bin/deployApps.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,10 @@ ECHO.
ECHO wlst_path - the Oracle Home subdirectory of the wlst.cmd
ECHO script to use (e.g., ^<ORACLE_HOME^>\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.
Expand Down
9 changes: 4 additions & 5 deletions installer/src/main/bin/deployApps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,10 @@ usage() {
echo " wlst_path - the Oracle Home subdirectory of the wlst.cmd"
echo " script to use (e.g., <ORACLE_HOME>/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 ""
Expand Down
9 changes: 4 additions & 5 deletions installer/src/main/bin/updateDomain.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,10 @@ ECHO.
ECHO wlst_path - the Oracle Home subdirectory of the wlst.cmd
ECHO script to use (e.g., ^<ORACLE_HOME^>\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.
Expand Down
9 changes: 4 additions & 5 deletions installer/src/main/bin/updateDomain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,10 @@ usage() {
echo " wlst_path - the Oracle Home subdirectory of the wlst.cmd"
echo " script to use (e.g., <ORACLE_HOME>/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 ""
Expand Down