Skip to content

Commit 78de94d

Browse files
jshum2479ddsharpe
authored andcommitted
add option to control whether to activate or cancel the online update (#456)
1 parent a24247c commit 78de94d

File tree

8 files changed

+151
-27
lines changed

8 files changed

+151
-27
lines changed

core/src/main/python/deploy.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import javaos as os
88
import sys
99

10-
from java.io import IOException
10+
from java.io import IOException, PrintStream
1111
from java.lang import IllegalArgumentException
12-
from java.lang import IllegalStateException
13-
from java.lang import String
12+
from java.lang import String, System
13+
1414

1515
from oracle.weblogic.deploy.deploy import DeployException
1616
from oracle.weblogic.deploy.exception import BundleAwareException
@@ -35,6 +35,7 @@
3535
from wlsdeploy.tool.deploy import model_deployer
3636
from wlsdeploy.tool.validate.validator import Validator
3737
from wlsdeploy.tool.util import filter_helper
38+
from wlsdeploy.tool.util.string_output_stream import StringOutputStream
3839
from wlsdeploy.tool.util.wlst_helper import WlstHelper
3940
from wlsdeploy.util import cla_helper
4041
from wlsdeploy.util import getcreds
@@ -73,7 +74,8 @@
7374
CommandLineArgUtil.ADMIN_USER_SWITCH,
7475
CommandLineArgUtil.ADMIN_PASS_SWITCH,
7576
CommandLineArgUtil.USE_ENCRYPTION_SWITCH,
76-
CommandLineArgUtil.PASSPHRASE_SWITCH
77+
CommandLineArgUtil.PASSPHRASE_SWITCH,
78+
CommandLineArgUtil.ROLLBACK_IF_RESTART_REQ_SWITCH
7779
]
7880

7981

@@ -216,13 +218,13 @@ def __deploy(model, model_context, aliases):
216218
:raises DeployException: if an error occurs
217219
"""
218220
if __wlst_mode == WlstModes.ONLINE:
219-
__deploy_online(model, model_context, aliases)
221+
ret_code = __deploy_online(model, model_context, aliases)
220222
else:
221-
__deploy_offline(model, model_context, aliases)
222-
return
223+
ret_code = __deploy_offline(model, model_context, aliases)
224+
return ret_code =
223225

224226

225-
def __deploy_online(model, model_context, aliases):
227+
def __deploy_online(model, model_context, aliases):
226228
"""
227229
Online deployment orchestration
228230
:param model: the model
@@ -254,9 +256,27 @@ def __deploy_online(model, model_context, aliases):
254256
__release_edit_session_and_disconnect()
255257
raise de
256258

259+
exit_code = 0
260+
257261
try:
258-
__wlst_helper.save()
259-
__wlst_helper.activate()
262+
# First we enable the stdout again and then redirect the stdoout to a string output stream
263+
# call isRestartRequired to get the output, capture the string and then silence wlst output again
264+
#
265+
__wlst_helper.enable_stdout()
266+
sostream = StringOutputStream()
267+
System.setOut(PrintStream(sostream))
268+
restart_required = __wlst_helper.is_restart_required()
269+
is_restartreq_output = sostream.get_string()
270+
__wlst_helper.silence()
271+
if model_context.is_rollback_if_restart_required() and restart_required:
272+
__wlst_helper.cancel_edit()
273+
__logger.severe('WLSDPLY_09015', is_restartreq_output)
274+
exit_code = CommandLineArgUtil.PROG_ROLLBACK_IF_RESTART_EXIT_CODE
275+
else:
276+
__wlst_helper.save()
277+
__wlst_helper.activate()
278+
if restart_required:
279+
exit_code = CommandLineArgUtil.PROG_RESTART_REQUIRED
260280
except BundleAwareException, ex:
261281
__release_edit_session_and_disconnect()
262282
raise ex
@@ -270,7 +290,7 @@ def __deploy_online(model, model_context, aliases):
270290
# to indicate a failure...just log the error since the process is going to exit anyway.
271291
__logger.warning('WLSDPLY-09009', _program_name, ex.getLocalizedMessage(), error=ex,
272292
class_name=_class_name, method_name=_method_name)
273-
return
293+
return exit_code
274294

275295

276296
def __deploy_offline(model, model_context, aliases):
@@ -303,7 +323,7 @@ def __deploy_offline(model, model_context, aliases):
303323
# a failure...just log the error since the process is going to exit anyway.
304324
__logger.warning('WLSDPLY-09011', _program_name, ex.getLocalizedMessage(), error=ex,
305325
class_name=_class_name, method_name=_method_name)
306-
return
326+
return 0
307327

308328

309329
def __release_edit_session_and_disconnect():
@@ -418,7 +438,7 @@ def main(args):
418438

419439
try:
420440
model = Model(model_dictionary)
421-
__deploy(model, model_context, aliases)
441+
exit_code = __deploy(model, model_context, aliases)
422442
except DeployException, ex:
423443
__logger.severe('WLSDPLY-09015', _program_name, ex.getLocalizedMessage(), error=ex,
424444
class_name=_class_name, method_name=_method_name)

core/src/main/python/update.py

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
import javaos as os
88
import sys
99

10-
from java.io import IOException
10+
from java.io import IOException, PrintStream
1111
from java.lang import IllegalArgumentException
12-
from java.lang import String
12+
from java.lang import String, System
1313

1414
from oracle.weblogic.deploy.deploy import DeployException
1515
from oracle.weblogic.deploy.exception import BundleAwareException
@@ -36,6 +36,7 @@
3636
from wlsdeploy.tool.validate.validator import Validator
3737
from wlsdeploy.tool.util import filter_helper
3838
from wlsdeploy.tool.util.wlst_helper import WlstHelper
39+
from wlsdeploy.tool.util.string_output_stream import StringOutputStream
3940
from wlsdeploy.util import cla_helper
4041
from wlsdeploy.util import dictionary_utils
4142
from wlsdeploy.util import getcreds
@@ -45,7 +46,6 @@
4546
from wlsdeploy.util.cla_utils import CommandLineArgUtil
4647
from wlsdeploy.util.model import Model
4748
from wlsdeploy.util.model_context import ModelContext
48-
from wlsdeploy.util.model_translator import FileToPython
4949
from wlsdeploy.util.weblogic_helper import WebLogicHelper
5050
from wlsdeploy.util import model as model_helper
5151

@@ -74,7 +74,8 @@
7474
CommandLineArgUtil.ADMIN_USER_SWITCH,
7575
CommandLineArgUtil.ADMIN_PASS_SWITCH,
7676
CommandLineArgUtil.USE_ENCRYPTION_SWITCH,
77-
CommandLineArgUtil.PASSPHRASE_SWITCH
77+
CommandLineArgUtil.PASSPHRASE_SWITCH,
78+
CommandLineArgUtil.ROLLBACK_IF_RESTART_REQ_SWITCH
7879
]
7980

8081

@@ -226,14 +227,14 @@ def __update(model, model_context, aliases):
226227
:raises DeployException: if an error occurs
227228
"""
228229
if __wlst_mode == WlstModes.ONLINE:
229-
__update_online(model, model_context, aliases)
230+
ret_code = __update_online(model, model_context, aliases)
230231
else:
231-
__update_offline(model, model_context, aliases)
232+
ret_code = __update_offline(model, model_context, aliases)
232233

233234
if os.environ.has_key('__WLSDEPLOY_STORE_MODEL__'):
234235
model_helper.persist_model(model_context, model)
235-
return
236236

237+
return ret_code
237238

238239
def __update_online(model, model_context, aliases):
239240
"""
@@ -264,15 +265,33 @@ def __update_online(model, model_context, aliases):
264265
try:
265266
topology_updater = TopologyUpdater(model, model_context, aliases, wlst_mode=WlstModes.ONLINE)
266267
topology_updater.update()
267-
268268
model_deployer.deploy_resources(model, model_context, aliases, wlst_mode=__wlst_mode)
269269
except DeployException, de:
270270
__release_edit_session_and_disconnect()
271271
raise de
272272

273+
exit_code = 0
274+
273275
try:
274-
__wlst_helper.save()
275-
__wlst_helper.activate()
276+
# First we enable the stdout again and then redirect the stdoout to a string output stream
277+
# call isRestartRequired to get the output, capture the string and then silence wlst output again
278+
#
279+
280+
__wlst_helper.enable_stdout()
281+
sostream = StringOutputStream()
282+
System.setOut(PrintStream(sostream))
283+
restart_required = __wlst_helper.is_restart_required()
284+
is_restartreq_output = sostream.get_string()
285+
__wlst_helper.silence()
286+
if model_context.is_rollback_if_restart_required() and restart_required:
287+
__wlst_helper.cancel_edit()
288+
__logger.severe('WLSDPLY_09015', is_restartreq_output)
289+
exit_code = CommandLineArgUtil.PROG_ROLLBACK_IF_RESTART_EXIT_CODE
290+
else:
291+
__wlst_helper.save()
292+
__wlst_helper.activate()
293+
if restart_required:
294+
exit_code = CommandLineArgUtil.PROG_RESTART_REQUIRED
276295
except BundleAwareException, ex:
277296
__release_edit_session_and_disconnect()
278297
raise ex
@@ -286,7 +305,7 @@ def __update_online(model, model_context, aliases):
286305
# to indicate a failure...just log the error since the process is going to exit anyway.
287306
__logger.warning('WLSDPLY-09009', _program_name, ex.getLocalizedMessage(), error=ex,
288307
class_name=_class_name, method_name=_method_name)
289-
return
308+
return exit_code
290309

291310

292311
def __update_offline(model, model_context, aliases):
@@ -322,7 +341,7 @@ def __update_offline(model, model_context, aliases):
322341
# a failure...just log the error since the process is going to exit anyway.
323342
__logger.warning('WLSDPLY-09011', _program_name, ex.getLocalizedMessage(), error=ex,
324343
class_name=_class_name, method_name=_method_name)
325-
return
344+
return 0
326345

327346

328347
def __release_edit_session_and_disconnect():
@@ -437,7 +456,7 @@ def main(args):
437456

438457
try:
439458
model = Model(model_dictionary)
440-
__update(model, model_context, aliases)
459+
exit_code = __update(model, model_context, aliases)
441460
except DeployException, ex:
442461
__logger.severe('WLSDPLY-09015', _program_name, ex.getLocalizedMessage(), error=ex,
443462
class_name=_class_name, method_name=_method_name)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
Copyright (c) 2017, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
3+
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
"""
5+
6+
from java.io import OutputStream, ByteArrayOutputStream
7+
from java.lang import String
8+
9+
"""
10+
This class allows redirecting the stdout to a string array for wlst.
11+
"""
12+
class StringOutputStream(OutputStream):
13+
14+
def __init__(self):
15+
self.stream = ByteArrayOutputStream()
16+
17+
def write(self,b,off,len):
18+
self.stream.write(b,off,len)
19+
20+
def get_string(self):
21+
output = String(self.stream.toByteArray())
22+
if self.stream is not None:
23+
self.stream.close()
24+
return output
25+

core/src/main/python/wlsdeploy/tool/util/wlst_helper.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,9 @@ def undo(self):
654654
raise ex
655655
return
656656

657+
def cancel_edit(self):
658+
wlst_helper.cancel_edit()
659+
657660
def save(self):
658661
"""
659662
Save the outstanding Weblogic Server configuration changes for the current edit session.
@@ -711,6 +714,15 @@ def silence(self):
711714
wlst_helper.silence()
712715
return
713716

717+
def enable_stdout(self):
718+
"""
719+
Performs the wlst commands to enable stdout
720+
"""
721+
_method_name = 'enable_stdout'
722+
self.__logger.entering(class_name=self.__class_name, method_name=_method_name)
723+
wlst_helper.enable_stdout()
724+
return
725+
714726
def set_if_needed(self, wlst_name, wlst_value, model_type, model_name, masked=False):
715727
"""
716728
Set the WLST attribute to the specified value if the name and value are not None.
@@ -975,6 +987,13 @@ def domain_runtime(self):
975987
raise ex
976988
return
977989

990+
def is_restart_required(self):
991+
"""
992+
Return if the update changes require restart of the domain or servers.
993+
:return: true if the changes require restart
994+
"""
995+
return wlst_helper.is_restart_required()
996+
978997
def is_connected(self):
979998
"""
980999
Determine if the wlst session is currently connected to the admin server.

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class CommandLineArgUtil(object):
5757
ENCRYPT_MANUAL_SWITCH = '-manual'
5858
# phony arg used as a key to store the password
5959
ONE_PASS_SWITCH = '-password'
60+
ROLLBACK_IF_RESTART_REQ_SWITCH = '-rollback_if_require_restart'
6061
USE_ENCRYPTION_SWITCH = '-use_encryption'
6162
RUN_RCU_SWITCH = '-run_rcu'
6263
TARGET_VERSION_SWITCH = '-target_version'
@@ -80,6 +81,8 @@ class CommandLineArgUtil(object):
8081
HELP_EXIT_CODE = 100
8182
USAGE_ERROR_EXIT_CODE = 99
8283
ARG_VALIDATION_ERROR_EXIT_CODE = 98
84+
PROG_RESTART_REQUIRED = 103
85+
PROG_ROLLBACK_IF_RESTART_EXIT_CODE = 3
8386
PROG_ERROR_EXIT_CODE = 2
8487
PROG_WARNING_EXIT_CODE = 1
8588
PROG_OK_EXIT_CODE = 0
@@ -410,6 +413,8 @@ def process_args(self, args, for_domain_create=False):
410413
ex = self._get_out_of_args_exception(key)
411414
self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
412415
raise ex
416+
elif self.is_rollback_if_restart_required_key(key):
417+
self._add_arg(key, True)
413418
else:
414419
ex = exception_helper.create_cla_exception('WLSDPLY-01601', self._program_name, key)
415420
ex.setExitCode(self.USAGE_ERROR_EXIT_CODE)
@@ -1073,6 +1078,9 @@ def _validate_variable_properties_file_arg(self, value):
10731078
raise ex
10741079
return variables.getAbsolutePath()
10751080

1081+
def is_rollback_if_restart_required_key(self, key):
1082+
return self.ROLLBACK_IF_RESTART_REQ_SWITCH == key
1083+
10761084
###########################################################################
10771085
# Helper methods #
10781086
###########################################################################

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(self, program_name, arg_map):
6464
self._opss_wallet_passphrase = None
6565
self._opss_wallet = None
6666
self._validation_method = None
67+
self._rollback_if_restart_required = None
6768

6869
if CommandLineArgUtil.ORACLE_HOME_SWITCH in arg_map:
6970
self._oracle_home = arg_map[CommandLineArgUtil.ORACLE_HOME_SWITCH]
@@ -142,6 +143,9 @@ def __init__(self, program_name, arg_map):
142143
if CommandLineArgUtil.ONE_PASS_SWITCH in arg_map:
143144
self._encrypt_one_pass = arg_map[CommandLineArgUtil.ONE_PASS_SWITCH]
144145

146+
if CommandLineArgUtil.ROLLBACK_IF_RESTART_REQ_SWITCH in arg_map:
147+
self._rollback_if_restart_required = arg_map[CommandLineArgUtil.ROLLBACK_IF_RESTART_REQ_SWITCH]
148+
145149
if CommandLineArgUtil.USE_ENCRYPTION_SWITCH in arg_map:
146150
self._use_encryption = arg_map[CommandLineArgUtil.USE_ENCRYPTION_SWITCH]
147151

@@ -277,6 +281,13 @@ def get_archive_file_name(self):
277281
"""
278282
return self._archive_file_name
279283

284+
def is_rollback_if_restart_required(self):
285+
"""
286+
Get the rollback if restart required
287+
:return: true or false
288+
"""
289+
return self._rollback_if_restart_required
290+
280291
def get_opss_wallet(self):
281292
"""
282293
Get the opss wallet.

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,18 @@ def get_cmo():
440440
_logger.exiting(class_name=_class_name, method_name=_method_name, result=wlst.cmo)
441441
return wlst.cmo
442442

443+
def is_restart_required():
444+
"""
445+
Return if the update changes require restart of the domain or servers.
446+
:return: true if the changes require restart
447+
"""
448+
return wlst.isRestartRequired()
449+
450+
def cancel_edit():
451+
"""
452+
Cancel current edit session
453+
"""
454+
wlst.cancelEdit('y')
443455

444456
def is_connected():
445457
"""
@@ -694,6 +706,15 @@ def silence():
694706
wlst.WLS.getCommandExceptionHandler().setSilent(True)
695707

696708

709+
def enable_stdout():
710+
"""
711+
Performs the wlst commands to enable stdout
712+
"""
713+
wlst.WLS.setLogToStdOut(True)
714+
wlst.WLS.setShowLSResult(True)
715+
wlst.WLS_ON.setlogToStandardOut(True)
716+
717+
697718
def connect(username, password, url):
698719
"""
699720
Connect WLST to a Weblogic Server instance at the provided url with the provided credentials.

0 commit comments

Comments
 (0)