Skip to content

Commit 39d6592

Browse files
authored
Allow user to undo any current edit session (#731)
* Add option to undo existing edit session * update shell script for undo current edit * Add info message if there are outstanding edit but undo by -undo_current_edit * undo edit also for deploy * rename undo_current_edit to discard_current_edit
1 parent 706af02 commit 39d6592

File tree

11 files changed

+65
-8
lines changed

11 files changed

+65
-8
lines changed

core/src/main/python/deploy.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
CommandLineArgUtil.ADMIN_PASS_SWITCH,
6363
CommandLineArgUtil.USE_ENCRYPTION_SWITCH,
6464
CommandLineArgUtil.PASSPHRASE_SWITCH,
65+
CommandLineArgUtil.DISCARD_CURRENT_EDIT_SWITCH,
6566
CommandLineArgUtil.ROLLBACK_IF_RESTART_REQ_SWITCH
6667
]
6768

@@ -121,9 +122,11 @@ def __deploy_online(model, model_context, aliases):
121122

122123
try:
123124
__wlst_helper.connect(admin_user, admin_pwd, admin_url)
124-
deployer_utils.ensure_no_uncommitted_changes_or_edit_sessions()
125+
deployer_utils.ensure_no_uncommitted_changes_or_edit_sessions(model_context.is_discard_current_edit())
125126
__wlst_helper.edit()
126127
__wlst_helper.start_edit()
128+
if model_context.is_discard_current_edit():
129+
deployer_utils.discard_current_edit()
127130
except BundleAwareException, ex:
128131
raise ex
129132

core/src/main/python/update.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@
6565
CommandLineArgUtil.USE_ENCRYPTION_SWITCH,
6666
CommandLineArgUtil.PASSPHRASE_SWITCH,
6767
CommandLineArgUtil.ROLLBACK_IF_RESTART_REQ_SWITCH,
68-
CommandLineArgUtil.UPDATE_RCU_SCHEMA_PASS_SWITCH
68+
CommandLineArgUtil.UPDATE_RCU_SCHEMA_PASS_SWITCH,
69+
CommandLineArgUtil.DISCARD_CURRENT_EDIT_SWITCH
6970
]
7071

7172

@@ -125,9 +126,11 @@ def __update_online(model, model_context, aliases):
125126

126127
try:
127128
__wlst_helper.connect(admin_user, admin_pwd, admin_url)
128-
deployer_utils.ensure_no_uncommitted_changes_or_edit_sessions()
129+
deployer_utils.ensure_no_uncommitted_changes_or_edit_sessions(model_context.is_discard_current_edit())
129130
__wlst_helper.edit()
130131
__wlst_helper.start_edit()
132+
if model_context.is_discard_current_edit():
133+
deployer_utils.discard_current_edit()
131134
except BundleAwareException, ex:
132135
raise ex
133136

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def deploy(self):
7171
self.__add_shared_libraries()
7272
self.__add_applications()
7373
else:
74-
deployer_utils.ensure_no_uncommitted_changes_or_edit_sessions()
74+
deployer_utils.ensure_no_uncommitted_changes_or_edit_sessions(self.model_context.is_discard_current_edit())
7575
self.__online_deploy_apps_and_libs(self._base_location)
7676
return
7777

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def delete_named_element(location, delete_name, existing_names, aliases):
258258
_wlst_helper.delete(name, type_name)
259259

260260

261-
def ensure_no_uncommitted_changes_or_edit_sessions():
261+
def ensure_no_uncommitted_changes_or_edit_sessions(ignoreEditSessionCheck=False):
262262
"""
263263
Ensure that the domain does not contain any uncommitted changes and there is no existing edit session.
264264
:raises: DeployException: if there are any uncommitted changes, existing edit sessions, or a WLST error occurs
@@ -277,12 +277,12 @@ def ensure_no_uncommitted_changes_or_edit_sessions():
277277
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
278278
raise ex
279279

280-
if unactivated_changes:
280+
if unactivated_changes and not ignoreEditSessionCheck:
281281
ex = exception_helper.create_deploy_exception('WLSDPLY-09103')
282282
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
283283
raise ex
284284

285-
if current_editor is not None:
285+
if current_editor is not None and not ignoreEditSessionCheck:
286286
ex = exception_helper.create_deploy_exception('WLSDPLY-09104', str(current_editor))
287287
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
288288
raise ex
@@ -293,6 +293,28 @@ def ensure_no_uncommitted_changes_or_edit_sessions():
293293
_logger.exiting(class_name=_class_name, method_name=_method_name)
294294
return
295295

296+
def discard_current_edit():
297+
"""
298+
Undo any current edit that may have left.
299+
:raises: DeployException: if there are any wlst errors
300+
"""
301+
_method_name = 'discard_current_edit'
302+
303+
_logger.entering(class_name=_class_name, method_name=_method_name)
304+
try:
305+
cmgr = _wlst_helper.get_config_manager()
306+
unactivated_changes = _wlst_helper.have_unactivated_changes(cmgr)
307+
308+
if unactivated_changes:
309+
_logger.info("WLSDPLY-09016")
310+
cmgr.undoUnactivatedChanges()
311+
312+
except PyWLSTException, e:
313+
ex = exception_helper.create_deploy_exception('WLSDPLY-09112', e.getLocalizedMessage(), error=e)
314+
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
315+
raise ex
316+
_logger.exiting(class_name=_class_name, method_name=_method_name)
317+
return
296318

297319
def extract_from_uri(model_context, path_value):
298320
"""

core/src/main/python/wlsdeploy/util/cla_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class CommandLineArgUtil(object):
4747
ADMIN_PASS_SWITCH = '-admin_pass'
4848
ARCHIVE_FILE_SWITCH = '-archive_file'
4949
MODEL_FILE_SWITCH = '-model_file'
50+
DISCARD_CURRENT_EDIT_SWITCH = '-discard_current_edit'
5051
OPSS_WALLET_SWITCH = '-opss_wallet'
5152
OPSS_WALLET_PASSPHRASE = '-opss_wallet_passphrase'
5253
PREVIOUS_MODEL_FILE_SWITCH = '-prev_model_file'
@@ -97,6 +98,7 @@ class CommandLineArgUtil(object):
9798
ROLLBACK_IF_RESTART_REQ_SWITCH,
9899
RUN_RCU_SWITCH,
99100
UPDATE_RCU_SCHEMA_PASS_SWITCH,
101+
DISCARD_CURRENT_EDIT_SWITCH,
100102
USE_ENCRYPTION_SWITCH
101103
]
102104

core/src/main/python/wlsdeploy/util/model_context.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def __init__(self, program_name, arg_map):
8787
self._variable_keywords_file = None
8888
self._variable_properties_file = None
8989
self._rcu_db_user = 'SYS'
90+
self._discard_current_edit = False
9091

9192
self._trailing_args = []
9293

@@ -133,6 +134,9 @@ def __copy_from_args(self, arg_map):
133134
if CommandLineArgUtil.MODEL_FILE_SWITCH in arg_map:
134135
self._model_file = arg_map[CommandLineArgUtil.MODEL_FILE_SWITCH]
135136

137+
if CommandLineArgUtil.DISCARD_CURRENT_EDIT_SWITCH in arg_map:
138+
self._discard_current_edit = arg_map[CommandLineArgUtil.DISCARD_CURRENT_EDIT_SWITCH]
139+
136140
if CommandLineArgUtil.PREVIOUS_MODEL_FILE_SWITCH in arg_map:
137141
self._previous_model_file = arg_map[CommandLineArgUtil.PREVIOUS_MODEL_FILE_SWITCH]
138142

@@ -267,6 +271,8 @@ def __copy__(self):
267271
arg_map[CommandLineArgUtil.VARIABLE_FILE_SWITCH] = self._variable_file_name
268272
if self._run_rcu is not None:
269273
arg_map[CommandLineArgUtil.RUN_RCU_SWITCH]= self._run_rcu
274+
if self._discard_current_edit is not None:
275+
arg_map[CommandLineArgUtil.DISCARD_CURRENT_EDIT_SWITCH]= self._discard_current_edit
270276
if self._rcu_database is not None:
271277
arg_map[CommandLineArgUtil.RCU_DB_SWITCH] = self._rcu_database
272278
if self._rcu_prefix is not None:
@@ -435,6 +441,13 @@ def is_rollback_if_restart_required(self):
435441
"""
436442
return self._rollback_if_restart_required
437443

444+
def is_discard_current_edit(self):
445+
"""
446+
Get the discard current edit value.
447+
:return: true or false
448+
"""
449+
return self._discard_current_edit
450+
438451
def get_opss_wallet(self):
439452
"""
440453
Get the opss wallet.

core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,8 @@ WLSDPLY-09014={0} was unable to load the model from {1} due to a translation err
994994
WLSDPLY-09015={0} deployment failed: {1}
995995
WLSDPLY_09015=Online update has been rollback because the flag rollback_if_require_restart is set and the update requires \
996996
restart: {0}
997+
WLSDPLY-09016=There are outstanding changes but -discard_current_edit has been specified, all changes have been \
998+
discarded before processing update.
997999
# wlsdeploy/tool/deploy/deployer_utils.py
9981000
WLSDPLY-09100=Existing object names are {0}
9991001
WLSDPLY-09101=Creating MBean type {1} with name {0}
@@ -1008,7 +1010,7 @@ WLSDPLY-09108=Model attribute {0} at model location {1} with value {2} reference
10081010
WLSDPLY-09109=Unable to delete {0} {1}, name does not exist
10091011
WLSDPLY-09110=Deleting {0} {1}
10101012
WLSDPLY-09111=Unable to get delete item name for {0}
1011-
1013+
WLSDPLY-09112=Failed to discard current edit session: {0}
10121014
# wlsdeploy/tool/deploy/deployer.py
10131015
WLSDPLY-09200=Error setting attribute {0} for {1} {2}: {3}
10141016
WLSDPLY-09201=Failed to get existing WLST value for model attribute {0} at location {1} because the \

installer/src/main/bin/deployApps.cmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ ECHO [-variable_file ^<variable_file^>]
7878
ECHO [-domain_type ^<domain_type^>]
7979
ECHO [-wlst_path ^<wlst_path^>]
8080
ECHO [-rollback_if_require_restart]
81+
ECHO [-discard_current_edit]
8182
ECHO [-admin_url ^<admin_url^>
8283
ECHO -admin_user ^<admin_user^>
8384
ECHO ]
@@ -115,6 +116,8 @@ ECHO admin_user - the admin username (used for online deploy)
115116
ECHO.
116117
ECHO rollback_if_require_restart - rollback the changes if the update requires domain restart
117118
ECHO.
119+
ECHO discard_current_edit - discard all existing changes before starting update
120+
ECHO.
118121
ECHO The -use_encryption switch tells the program that one or more of the
119122
ECHO passwords in the model or variables files are encrypted. The program will
120123
ECHO prompt for the decryption passphrase to use to decrypt the passwords.

installer/src/main/bin/deployApps.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ usage() {
3939
echo " [-domain_type <domain_type>]"
4040
echo " [-wlst_path <wlst_path>]"
4141
echo " [-rollback_if_require_restart]"
42+
echo " [-discard_current_edit]"
4243
echo " [-admin_url <admin_url>"
4344
echo " -admin_user <admin_user>"
4445
echo " ]"
@@ -76,6 +77,8 @@ usage() {
7677
echo ""
7778
echo " rollback_if_require_restart - rollback the changes if the update requires domain restart"
7879
echo ""
80+
echo " discard_current_edit - discard all existing changes before starting update"
81+
echo ""
7982
echo " The -use_encryption switch tells the program that one or more of the"
8083
echo " passwords in the model or variables files are encrypted. The program will"
8184
echo " prompt for the decryption passphrase to use to decrypt the passwords."

installer/src/main/bin/updateDomain.cmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ ECHO [-variable_file ^<variable_file^>]
7878
ECHO [-domain_type ^<domain_type^>]
7979
ECHO [-wlst_path ^<wlst_path^>]
8080
ECHO [-rollback_if_require_restart]
81+
ECHO [-discard_current_edit]
8182
ECHO [-admin_url ^<admin_url^>
8283
ECHO -admin_user ^<admin_user^>
8384
ECHO ]
@@ -115,6 +116,8 @@ ECHO admin_user - the admin username (used for online deploy)
115116
ECHO.
116117
ECHO rollback_if_require_restart - rollback the changes if the update requires domain restart
117118
ECHO.
119+
ECHO discard_current_edit - discard all existing changes before starting update
120+
ECHO.
118121
ECHO The -use_encryption switch tells the program that one or more of the
119122
ECHO passwords in the model or variables files are encrypted. The program will
120123
ECHO prompt for the decryption passphrase to use to decrypt the passwords.

0 commit comments

Comments
 (0)