Skip to content

Commit cd39570

Browse files
authored
Write restart and non-dynamic information to results.json for update and deploy (#1434)
* Write restart and non-dynamic information to results.json for update and deploy * Update description of -output_dir argument for update and deploy
1 parent 6d336ba commit cd39570

File tree

10 files changed

+134
-28
lines changed

10 files changed

+134
-28
lines changed

core/src/main/python/deploy.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from wlsdeploy.tool.util import wlst_helper
2424
from wlsdeploy.tool.util.wlst_helper import WlstHelper
2525
from wlsdeploy.util import cla_helper
26+
from wlsdeploy.tool.util import results_file
2627
from wlsdeploy.util import tool_main
2728
from wlsdeploy.util.cla_utils import CommandLineArgUtil
2829
from wlsdeploy.util.exit_code import ExitCode
@@ -102,6 +103,9 @@ def __deploy(model, model_context, aliases):
102103
ret_code = __deploy_online(model, model_context, aliases)
103104
else:
104105
ret_code = __deploy_offline(model, model_context, aliases)
106+
107+
results_file.check_and_write(model_context, ExceptionType.DEPLOY)
108+
105109
return ret_code
106110

107111

core/src/main/python/update.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from wlsdeploy.tool.deploy import model_deployer
2323
from wlsdeploy.tool.deploy.topology_updater import TopologyUpdater
2424
from wlsdeploy.tool.util import model_context_helper
25+
from wlsdeploy.tool.util import results_file
2526
from wlsdeploy.tool.util import wlst_helper
2627
from wlsdeploy.tool.util.wlst_helper import WlstHelper
2728
from wlsdeploy.tool.util.rcu_helper import RCUHelper
@@ -109,6 +110,8 @@ def __update(model, model_context, aliases):
109110
else:
110111
ret_code = __update_offline(model, model_context, aliases)
111112

113+
results_file.check_and_write(model_context, ExceptionType.DEPLOY)
114+
112115
return ret_code
113116

114117

core/src/main/python/wlsdeploy/tool/deploy/deployer_utils.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2022, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2023, Oracle Corporation and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
import os
@@ -48,6 +48,7 @@
4848
from wlsdeploy.exception import exception_helper
4949
from wlsdeploy.exception.expection_types import ExceptionType
5050
from wlsdeploy.logging import platform_logger
51+
from wlsdeploy.tool.util import results_file
5152
from wlsdeploy.tool.util.string_output_stream import StringOutputStream
5253
from wlsdeploy.tool.util.wlst_helper import WlstHelper
5354
from wlsdeploy.util import dictionary_utils
@@ -503,16 +504,20 @@ def list_restarts(model_context, exit_code):
503504
line = '%s:%s:%s:%s' % (entry[0], entry[1], entry[2], entry[3])
504505
_logger.finer('WLSDPLY-09208', line, class_name=_class_name, method_name=_method_name)
505506
pw.println(line)
507+
508+
results_file.add_restart_entry(entry[0], entry[1], entry[2], entry[3])
506509
pw.close()
507510
_logger.exiting(class_name=_class_name, method_name=_method_name, result=result)
508511
return result
509512

510513

511-
def list_non_dynamic_changes(model_context, non_dynamic_changes_string):
514+
def list_non_dynamic_changes(unactivated_changes, non_dynamic_changes_string, model_context):
512515
"""
513516
If output dir is present in the model context, write the restart data to the output dir as non_dynamic_changes.file.
514-
:param model_context: Current context with the run parameters.
515-
:param non_dynamic_changes_string: java.lang.String of changes that were non dynamic
517+
Add unactivated changes that are not dynamic to the results file.
518+
:param unactivated_changes: a list of unactivated changes for WLST
519+
:param non_dynamic_changes_string: java.lang.String of changes that were non-dynamic
520+
:param model_context: used to get the output directory
516521
"""
517522
_method_name = 'list_non_dynamic_changes'
518523
_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):
523528
pw.println(non_dynamic_changes_string)
524529
pw.close()
525530

531+
for change in unactivated_changes:
532+
if change.isRestartRequired() and not change.getAffectedBean():
533+
bean_name = str(change.getBean())
534+
attribute_name = change.getAttributeName()
535+
results_file.add_non_dynamic_change(bean_name, attribute_name)
536+
537+
results_file.add_non_dynamic_changes_text(str_helper.to_string(non_dynamic_changes_string))
538+
526539

527540
def get_list_of_restarts():
528541
"""
@@ -589,17 +602,22 @@ def online_check_save_activate(model_context):
589602
restart_required = _wlst_helper.is_restart_required()
590603
is_restartreq_output = sostream.get_string()
591604
_wlst_helper.silence()
605+
606+
# get unactivated changes before cancel or save
607+
config_manager = _wlst_helper.get_config_manager()
608+
unactivated_changes = config_manager.getUnactivatedChanges()
609+
592610
if model_context.is_cancel_changes_if_restart_required() and restart_required:
593611
_wlst_helper.cancel_edit()
594612
_logger.warning('WLSDPLY-09018', is_restartreq_output)
595613
exit_code = ExitCode.CANCEL_CHANGES_IF_RESTART
596-
list_non_dynamic_changes(model_context, is_restartreq_output)
614+
list_non_dynamic_changes(unactivated_changes, is_restartreq_output, model_context)
597615
else:
598616
_wlst_helper.save()
599617
_wlst_helper.activate(model_context.get_model_config().get_activate_timeout())
600618
if restart_required:
601619
exit_code = ExitCode.RESTART_REQUIRED
602-
list_non_dynamic_changes(model_context, is_restartreq_output)
620+
list_non_dynamic_changes(unactivated_changes, is_restartreq_output, model_context)
603621
exit_code = list_restarts(model_context, exit_code)
604622

605623
except BundleAwareException, ex:
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
"""
2+
Copyright (c) 2023, Oracle and/or its affiliates.
3+
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
"""
5+
import os
6+
7+
from oracle.weblogic.deploy.json import JsonException
8+
from oracle.weblogic.deploy.util import PyOrderedDict
9+
10+
from wlsdeploy.exception import exception_helper
11+
from wlsdeploy.json.json_translator import PythonToJson
12+
13+
"""
14+
This module acts as a singleton to collect results for the duration of a tool's execution,
15+
without having to be passed to individual methods and classes.
16+
"""
17+
18+
RESULTS_FILE_NAME = 'results.json'
19+
20+
NON_DYNAMIC_CHANGES_FOLDER = 'nonDynamicChanges'
21+
RESTARTS_FOLDER = 'restarts'
22+
23+
CLUSTER_KEY = 'cluster'
24+
NON_DYNAMIC_CHANGES_TEXT_KEY = 'nonDynamicChangesText'
25+
RESOURCE_NAME_KEY = 'resourceName'
26+
RESOURCE_TYPE_KEY = 'resourceType'
27+
SERVER_KEY = 'server'
28+
TEXT_KEY = 'text'
29+
30+
_results_dict = PyOrderedDict()
31+
32+
33+
def check_and_write(model_context, exception_type):
34+
"""
35+
Write the results file to the output directory, if output directory was specified.
36+
:param model_context: used to determine output directory
37+
:param exception_type: the exception type to be thrown on failure
38+
"""
39+
output_dir = model_context.get_output_dir()
40+
if output_dir:
41+
results_file = os.path.join(output_dir, RESULTS_FILE_NAME)
42+
json_object = PythonToJson(_results_dict)
43+
44+
try:
45+
json_object.write_to_json_file(results_file)
46+
except JsonException, ex:
47+
raise exception_helper.create_exception(exception_type, 'WLSDPLY-01681', results_file,
48+
ex.getLocalizedMessage(), error=ex)
49+
50+
51+
def add_restart_entry(cluster, server, resource_name, resource_type):
52+
restart = PyOrderedDict()
53+
if cluster:
54+
restart[CLUSTER_KEY] = cluster
55+
if server:
56+
restart[SERVER_KEY] = server
57+
if resource_name:
58+
restart[RESOURCE_NAME_KEY] = resource_name
59+
if resource_type:
60+
restart[RESOURCE_TYPE_KEY] = resource_type
61+
restarts = _add_or_create_array(_results_dict, RESTARTS_FOLDER)
62+
restarts.append(restart)
63+
64+
65+
def add_non_dynamic_change(bean_name, attribute_name):
66+
non_dynamic_changes = _add_or_create_folder(_results_dict, NON_DYNAMIC_CHANGES_FOLDER)
67+
bean_array = _add_or_create_array(non_dynamic_changes, bean_name)
68+
bean_array.append(attribute_name)
69+
70+
71+
def add_non_dynamic_changes_text(non_dynamic_changes_text):
72+
lines = non_dynamic_changes_text.splitlines()
73+
_results_dict[NON_DYNAMIC_CHANGES_TEXT_KEY] = lines
74+
75+
76+
def _add_or_create_folder(parent_folder, folder_name):
77+
if folder_name not in parent_folder:
78+
parent_folder[folder_name] = PyOrderedDict()
79+
return parent_folder[folder_name]
80+
81+
82+
def _add_or_create_array(parent_folder, folder_name):
83+
if folder_name not in parent_folder:
84+
parent_folder[folder_name] = []
85+
return parent_folder[folder_name]

documentation/3.0/content/userguide/tools/deploy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ The Deploy Applications Tool supports the use of multiple models, as described i
7171
| `-domain_type` | The type of domain. (for example, `WLS`, `JRF`) | `WLS` |
7272
| `-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. | |
7373
| `-oracle_home` | Home directory of the Oracle WebLogic installation. Required if the `ORACLE_HOME` environment variable is not set.| |
74-
| `-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. | |
74+
| `-output_dir` | If specified, files containing restart information are written to this directory, including `restart.file`, `non_dynamic_changes.file`, and `results.json`. | |
7575
| `-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. | |
7676
| `-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. | |
7777
| `-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. | |

documentation/3.0/content/userguide/tools/update.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ The Update Domain Tool supports the use of multiple models, as described in [Usi
8383
| `-oracle_home` | Home directory of the Oracle WebLogic installation. Required if the `ORACLE_HOME` environment variable is not set. | |
8484
| `-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. | |
8585
| `-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. | |
86-
| `-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. | |
86+
| `-update_dir` | If specified, files containing restart information are written to this directory, including `restart.file`, `non_dynamic_changes.file`, and `results.json`. | |
8787
| `-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. | |
8888
| `-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. | |
8989
| `-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. | |

installer/src/main/bin/deployApps.cmd

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,10 @@ ECHO.
128128
ECHO wlst_path - the Oracle Home subdirectory of the wlst.cmd
129129
ECHO script to use (e.g., ^<ORACLE_HOME^>\soa)
130130
ECHO.
131-
ECHO output_dir - if present, write restart information to this
132-
ECHO directory as restart.file, or, if
133-
ECHO cancel_changes_if_restart_required is used,
134-
ECHO write non dynamic changes information to
135-
ECHO non_dynamic_changes.file.
131+
ECHO output_dir - if specified, files containing restart information
132+
ECHO are written to this directory, including
133+
ECHO restart.file, non_dynamic_changes.file, and
134+
ECHO results.json.
136135
ECHO.
137136
ECHO admin_url - the admin server URL (used for online deploy)
138137
ECHO.

installer/src/main/bin/deployApps.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,10 @@ usage() {
8989
echo " wlst_path - the Oracle Home subdirectory of the wlst.cmd"
9090
echo " script to use (e.g., <ORACLE_HOME>/soa)."
9191
echo ""
92-
echo " output_dir - if present, write restart information to this"
93-
echo " directory in restart.file, or, if"
94-
echo " cancel_changes_if_restart_required is used,"
95-
echo " write non-dynamic changes information to"
96-
echo " non_dynamic_changes.file."
92+
echo " output_dir - if specified, files containing restart information"
93+
echo " are written to this directory, including"
94+
echo " restart.file, non_dynamic_changes.file, and"
95+
echo " results.json."
9796
echo ""
9897
echo " admin_url - the admin server URL (used for online deploy)."
9998
echo ""

installer/src/main/bin/updateDomain.cmd

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,10 @@ ECHO.
127127
ECHO wlst_path - the Oracle Home subdirectory of the wlst.cmd
128128
ECHO script to use (e.g., ^<ORACLE_HOME^>\soa)
129129
ECHO.
130-
ECHO output_dir - if present, write restart information to this
131-
ECHO directory as restart.file, or, if
132-
ECHO cancel_changes_if_restart_required is used,
133-
ECHO write non dynamic changes information to
134-
ECHO non_dynamic_changes.file.
130+
ECHO output_dir - if specified, files containing restart information
131+
ECHO are written to this directory, including
132+
ECHO restart.file, non_dynamic_changes.file, and
133+
ECHO results.json.
135134
ECHO.
136135
ECHO admin_url - the admin server URL (used for online deploy)
137136
ECHO.

installer/src/main/bin/updateDomain.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,10 @@ usage() {
8989
echo " wlst_path - the Oracle Home subdirectory of the wlst.cmd"
9090
echo " script to use (e.g., <ORACLE_HOME>/soa)."
9191
echo ""
92-
echo " output_dir - if present, write restart information to this"
93-
echo " directory in restart.file, or, if"
94-
echo " cancel_changes_if_restart_required is used,"
95-
echo " write non-dynamic changes information to"
96-
echo " non_dynamic_changes.file."
92+
echo " output_dir - if specified, files containing restart information"
93+
echo " are written to this directory, including"
94+
echo " restart.file, non_dynamic_changes.file, and"
95+
echo " results.json."
9796
echo ""
9897
echo " admin_url - the admin server URL (used for online deploy)."
9998
echo ""

0 commit comments

Comments
 (0)