77import javaos as os
88import sys
99
10- from java .io import IOException
10+ from java .io import IOException , PrintStream
1111from java .lang import IllegalArgumentException
12- from java .lang import String
12+ from java .lang import String , System
1313
1414from oracle .weblogic .deploy .deploy import DeployException
1515from oracle .weblogic .deploy .exception import BundleAwareException
3636from wlsdeploy .tool .validate .validator import Validator
3737from wlsdeploy .tool .util import filter_helper
3838from wlsdeploy .tool .util .wlst_helper import WlstHelper
39+ from wlsdeploy .tool .util .string_output_stream import StringOutputStream
3940from wlsdeploy .util import cla_helper
4041from wlsdeploy .util import dictionary_utils
4142from wlsdeploy .util import getcreds
4546from wlsdeploy .util .cla_utils import CommandLineArgUtil
4647from wlsdeploy .util .model import Model
4748from wlsdeploy .util .model_context import ModelContext
48- from wlsdeploy .util .model_translator import FileToPython
4949from wlsdeploy .util .weblogic_helper import WebLogicHelper
5050from wlsdeploy .util import model as model_helper
5151
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
238239def __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
292311def __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
328347def __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 )
0 commit comments