Skip to content

Commit 231c0be

Browse files
authored
JIRA WDT-534 - Remove app/library targets during edit session; factor out online_check_save_activate() (#816)
1 parent f1ea9f8 commit 231c0be

File tree

5 files changed

+144
-157
lines changed

5 files changed

+144
-157
lines changed

core/src/main/python/deploy.py

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
import os
88
import sys
99

10-
from java.io import PrintStream
11-
from java.lang import System
12-
13-
1410
from oracle.weblogic.deploy.deploy import DeployException
1511
from oracle.weblogic.deploy.exception import BundleAwareException
1612
from oracle.weblogic.deploy.util import CLAException
@@ -26,7 +22,6 @@
2622
from wlsdeploy.tool.deploy import deployer_utils
2723
from wlsdeploy.tool.deploy import model_deployer
2824
from wlsdeploy.tool.util import model_context_helper
29-
from wlsdeploy.tool.util.string_output_stream import StringOutputStream
3025
from wlsdeploy.tool.util import wlst_helper
3126
from wlsdeploy.tool.util.wlst_helper import WlstHelper
3227
from wlsdeploy.util import cla_helper
@@ -136,39 +131,15 @@ def __deploy_online(model, model_context, aliases):
136131

137132
try:
138133
model_deployer.deploy_resources(model, model_context, aliases, wlst_mode=__wlst_mode)
134+
deployer_utils.delete_online_deployment_targets(model, aliases, __wlst_mode)
139135
except DeployException, de:
140-
__release_edit_session_and_disconnect()
136+
deployer_utils.release_edit_session_and_disconnect()
141137
raise de
142138

143-
exit_code = 0
139+
exit_code = deployer_utils.online_check_save_activate(model_context)
144140

145-
try:
146-
# First we enable the stdout again and then redirect the stdoout to a string output stream
147-
# call isRestartRequired to get the output, capture the string and then silence wlst output again
148-
#
149-
__wlst_helper.enable_stdout()
150-
sostream = StringOutputStream()
151-
System.setOut(PrintStream(sostream))
152-
restart_required = __wlst_helper.is_restart_required()
153-
is_restartreq_output = sostream.get_string()
154-
__wlst_helper.silence()
155-
if model_context.is_cancel_changes_if_restart_required() and restart_required:
156-
__wlst_helper.cancel_edit()
157-
__logger.warning('WLSDPLY_09015', is_restartreq_output)
158-
exit_code = CommandLineArgUtil.PROG_CANCEL_CHANGES_IF_RESTART_EXIT_CODE
159-
deployer_utils.list_non_dynamic_changes(model_context, is_restartreq_output)
160-
else:
161-
__wlst_helper.save()
162-
__wlst_helper.activate(model_context.get_model_config().get_activate_timeout())
163-
if restart_required:
164-
deployer_utils.list_non_dynamic_changes(model_context, is_restartreq_output)
165-
exit_code = CommandLineArgUtil.PROG_RESTART_REQUIRED
166-
exit_code = deployer_utils.list_restarts(model_context, exit_code)
167-
except BundleAwareException, ex:
168-
__release_edit_session_and_disconnect()
169-
raise ex
170-
171-
model_deployer.deploy_applications(model, model_context, aliases, wlst_mode=__wlst_mode)
141+
if exit_code != CommandLineArgUtil.PROG_CANCEL_CHANGES_IF_RESTART_EXIT_CODE:
142+
model_deployer.deploy_applications(model, model_context, aliases, wlst_mode=__wlst_mode)
172143

173144
try:
174145
__wlst_helper.disconnect()
@@ -215,23 +186,6 @@ def __deploy_offline(model, model_context, aliases):
215186
return 0
216187

217188

218-
def __release_edit_session_and_disconnect():
219-
"""
220-
An online error recovery method.
221-
"""
222-
_method_name = '__release_edit_session_and_disconnect'
223-
try:
224-
__wlst_helper.undo()
225-
__wlst_helper.stop_edit()
226-
__wlst_helper.disconnect()
227-
except BundleAwareException, ex:
228-
# This method is only used for cleanup after an error so don't mask
229-
# the original problem by throwing yet another exception...
230-
__logger.warning('WLSDPLY-09012', ex.getLocalizedMessage(), error=ex,
231-
class_name=_class_name, method_name=_method_name)
232-
return
233-
234-
235189
def __close_domain_on_error():
236190
"""
237191
An offline error recovery method.

core/src/main/python/update.py

Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
import os
88
import sys
99

10-
from java.io import PrintStream
11-
from java.lang import System
12-
1310
from oracle.weblogic.deploy.deploy import DeployException
1411
from oracle.weblogic.deploy.exception import BundleAwareException
1512
from oracle.weblogic.deploy.util import CLAException
@@ -30,7 +27,6 @@
3027
from wlsdeploy.tool.util import wlst_helper
3128
from wlsdeploy.tool.util.wlst_helper import WlstHelper
3229
from wlsdeploy.tool.util.rcu_helper import RCUHelper
33-
from wlsdeploy.tool.util.string_output_stream import StringOutputStream
3430
from wlsdeploy.util import cla_helper
3531
from wlsdeploy.util import tool_exit
3632
from wlsdeploy.util.cla_utils import CommandLineArgUtil
@@ -143,7 +139,7 @@ def __update_online(model, model_context, aliases):
143139
topology_updater.update_machines_clusters_and_servers(delete_now=False)
144140
topology_updater.warn_set_server_groups()
145141
except DeployException, de:
146-
__release_edit_session_and_disconnect()
142+
deployer_utils.release_edit_session_and_disconnect()
147143
raise de
148144

149145
# Server or Cluster may be added, this is to make sure they are targeted properly
@@ -163,11 +159,12 @@ def __update_online(model, model_context, aliases):
163159
try:
164160
topology_updater.update()
165161
model_deployer.deploy_resources(model, model_context, aliases, wlst_mode=__wlst_mode)
162+
deployer_utils.delete_online_deployment_targets(model, aliases, __wlst_mode)
166163
except DeployException, de:
167-
__release_edit_session_and_disconnect()
164+
deployer_utils.release_edit_session_and_disconnect()
168165
raise de
169166

170-
exit_code = __check_update_require_domain_restart(model_context)
167+
exit_code = deployer_utils.online_check_save_activate(model_context)
171168
# if user requested cancel changes if restart required stops
172169

173170
if exit_code != CommandLineArgUtil.PROG_CANCEL_CHANGES_IF_RESTART_EXIT_CODE:
@@ -183,40 +180,6 @@ def __update_online(model, model_context, aliases):
183180
return exit_code
184181

185182

186-
def __check_update_require_domain_restart(model_context):
187-
_method_name = '__check_update_require_domain_restart'
188-
exit_code = 0
189-
try:
190-
# First we enable the stdout again and then redirect the stdoout to a string output stream
191-
# call isRestartRequired to get the output, capture the string and then silence wlst output again
192-
#
193-
194-
__wlst_helper.enable_stdout()
195-
sostream = StringOutputStream()
196-
System.setOut(PrintStream(sostream))
197-
restart_required = __wlst_helper.is_restart_required()
198-
is_restartreq_output = sostream.get_string()
199-
__wlst_helper.silence()
200-
if model_context.is_cancel_changes_if_restart_required() and restart_required:
201-
__wlst_helper.cancel_edit()
202-
__logger.warning('WLSDPLY_09015', is_restartreq_output)
203-
exit_code = CommandLineArgUtil.PROG_CANCEL_CHANGES_IF_RESTART_EXIT_CODE
204-
deployer_utils.list_non_dynamic_changes(model_context, is_restartreq_output)
205-
else:
206-
__wlst_helper.save()
207-
__wlst_helper.activate(model_context.get_model_config().get_activate_timeout())
208-
if restart_required:
209-
exit_code = CommandLineArgUtil.PROG_RESTART_REQUIRED
210-
deployer_utils.list_non_dynamic_changes(model_context, is_restartreq_output)
211-
exit_code = deployer_utils.list_restarts(model_context, exit_code)
212-
213-
except BundleAwareException, ex:
214-
__release_edit_session_and_disconnect()
215-
raise ex
216-
217-
return exit_code
218-
219-
220183
def __update_offline(model, model_context, aliases):
221184
"""
222185
Offline update orchestration
@@ -271,23 +234,6 @@ def __update_offline_domain():
271234
raise ex
272235

273236

274-
def __release_edit_session_and_disconnect():
275-
"""
276-
An online error recovery method.
277-
"""
278-
_method_name = '__release_edit_session_and_disconnect'
279-
try:
280-
__wlst_helper.undo()
281-
__wlst_helper.stop_edit()
282-
__wlst_helper.disconnect()
283-
except BundleAwareException, ex:
284-
# This method is only used for cleanup after an error so don't mask
285-
# the original problem by throwing yet another exception...
286-
__logger.warning('WLSDPLY-09012', ex.getLocalizedMessage(), error=ex,
287-
class_name=_class_name, method_name=_method_name)
288-
return
289-
290-
291237
def __close_domain_on_error():
292238
"""
293239
An offline error recovery method.

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

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -232,23 +232,16 @@ def __online_deploy_apps_and_libs(self, base_location):
232232
# libraries to be undeployed
233233
update_library_list = list()
234234

235-
# app targets to be deleted
236-
app_delete_targets = dict()
237-
238-
# library targets to be deleted
239-
lib_delete_targets = dict()
240-
241235
lib_location = LocationContext(base_location).append_location(LIBRARY)
242236
# Go through the model libraries and find existing libraries that are referenced
243237
# by applications and compute a processing strategy for each library.
244238
self.__build_library_deploy_strategy(lib_location, model_shared_libraries, existing_lib_refs,
245-
stop_app_list, update_library_list, stop_and_undeploy_app_list,
246-
lib_delete_targets)
239+
stop_app_list, update_library_list, stop_and_undeploy_app_list)
247240

248241
# Go through the model applications and compute the processing strategy for each application.
249242
app_location = LocationContext(base_location).append_location(APPLICATION)
250243
self.__build_app_deploy_strategy(app_location, model_applications, existing_app_refs,
251-
stop_and_undeploy_app_list, app_delete_targets)
244+
stop_and_undeploy_app_list)
252245

253246
# deployed_app_list is list of apps that has been deployed and stareted again
254247
# redeploy_app_list is list of apps that needs to be redeplyed
@@ -268,18 +261,6 @@ def __online_deploy_apps_and_libs(self, base_location):
268261
self.__stop_app(app)
269262
self.__undeploy_app(app)
270263

271-
# targets were deleted from an app, so undeploy for those specific targets
272-
for app in app_delete_targets:
273-
delete_targets = app_delete_targets[app]
274-
if delete_targets:
275-
self.__undeploy_app(app, targets=delete_targets)
276-
277-
# targets were deleted from a library, so undeploy for those specific targets
278-
for lib in lib_delete_targets:
279-
delete_targets = lib_delete_targets[lib]
280-
if delete_targets:
281-
self.__undeploy_app(lib, library_module='true', targets=delete_targets)
282-
283264
# library is updated, it must be undeployed first
284265
for lib in update_library_list:
285266
self.__undeploy_app(lib, library_module='true')
@@ -521,7 +502,7 @@ def __get_library_references(self, base_location):
521502
return existing_libraries
522503

523504
def __build_library_deploy_strategy(self, location, model_libs, existing_lib_refs, stop_app_list,
524-
update_library_list, stop_and_undeploy_app_list, lib_delete_targets):
505+
update_library_list, stop_and_undeploy_app_list):
525506
"""
526507
Update maps and lists to control re-deployment processing.
527508
:param location: the location of the libraries
@@ -530,7 +511,6 @@ def __build_library_deploy_strategy(self, location, model_libs, existing_lib_ref
530511
:param stop_app_list: a list to update with dependent apps to be stopped and undeployed
531512
:param update_library_list: a list to update with libraries to be stopped before deploying
532513
:param stop_and_undeploy_app_list: a list to update with libraries to be stopped and undeployed
533-
:param lib_delete_targets: a map to update with delete targets for libraries
534514
"""
535515
_method_name = '__build_library_deploy_strategy'
536516

@@ -563,9 +543,8 @@ def __build_library_deploy_strategy(self, location, model_libs, existing_lib_ref
563543

564544
existing_lib_ref = dictionary_utils.get_dictionary_element(existing_lib_refs, versioned_name)
565545

566-
# collect the delete targets, and remove them from the model and existing targets
567-
lib_delete_targets[versioned_name] = \
568-
self.__extract_delete_targets(lib_dict, existing_lib_ref, location, lib)
546+
# remove deleted targets from the model and the existing library targets
547+
self.__remove_delete_targets(lib_dict, existing_lib_ref)
569548

570549
if versioned_name in existing_libs:
571550
# skipping absolute path libraries if they are the same
@@ -628,15 +607,13 @@ def __build_library_deploy_strategy(self, location, model_libs, existing_lib_ref
628607
lib_dict['SourcePath'] = existing_src_path
629608
return
630609

631-
def __build_app_deploy_strategy(self, location, model_apps, existing_app_refs, stop_and_undeploy_app_list,
632-
app_delete_targets):
610+
def __build_app_deploy_strategy(self, location, model_apps, existing_app_refs, stop_and_undeploy_app_list):
633611
"""
634612
Update maps and lists to control re-deployment processing.
635613
:param location: the location of the applications
636614
:param model_apps: a copy of applications from the model, attributes may be revised
637615
:param existing_app_refs: map of information about each existing app
638616
:param stop_and_undeploy_app_list: a list to update with apps to be stopped and undeployed
639-
:param app_delete_targets: a map to update with delete targets for applications
640617
"""
641618
_method_name = '__build_app_deploy_strategy'
642619

@@ -665,9 +642,8 @@ def __build_app_deploy_strategy(self, location, model_apps, existing_app_refs, s
665642

666643
existing_app_ref = dictionary_utils.get_dictionary_element(existing_app_refs, versioned_name)
667644

668-
# collect the delete targets, and remove them from the model and existing targets
669-
app_delete_targets[versioned_name] = \
670-
self.__extract_delete_targets(app_dict, existing_app_ref, location, app)
645+
# remove deleted targets from the model and the existing app targets
646+
self.__remove_delete_targets(app_dict, existing_app_ref)
671647

672648
if versioned_name in existing_apps:
673649
# Compare the hashes of the domain's existing apps to the model's apps.
@@ -719,17 +695,13 @@ def __build_app_deploy_strategy(self, location, model_apps, existing_app_refs, s
719695
stop_and_undeploy_app_list.append(versioned_name)
720696
return
721697

722-
def __extract_delete_targets(self, model_dict, existing_ref, location, name):
698+
def __remove_delete_targets(self, model_dict, existing_ref):
723699
"""
724-
Create a comma-separated list of targets to be deleted for an app or library.
725-
Remove those targets from the model and existing target dictionaries.
700+
Remove deleted targets from the model and existing target dictionaries.
726701
:param model_dict: the model dictionary for the app or library, may be modified
727702
:param existing_ref: the existing dictionary for the app or library, may be modified
728-
:param location: the location of the app or library, for logging
729-
:param name: the name of the app or library, for logging
730-
:return: a comma-separated list of targets to be removed, empty string for no targets
731703
"""
732-
_method_name = '__extract_delete_targets'
704+
_method_name = '__remove_delete_targets'
733705

734706
model_targets = dictionary_utils.get_element(model_dict, TARGET)
735707
model_targets = alias_utils.create_list(model_targets, 'WLSDPLY-08000')
@@ -738,23 +710,15 @@ def __extract_delete_targets(self, model_dict, existing_ref, location, name):
738710
if not existing_targets:
739711
existing_targets = list()
740712

741-
delete_targets = []
742713
model_targets_iterator = list(model_targets)
743714
for model_target in model_targets_iterator:
744715
if model_helper.is_delete_name(model_target):
745716
model_targets.remove(model_target)
746717
target_name = model_helper.get_delete_item_name(model_target)
747718
if target_name in existing_targets:
748719
existing_targets.remove(target_name)
749-
delete_targets.append(target_name)
750-
else:
751-
location.add_name_token(self.aliases.get_name_token(location), name)
752-
location_path = self.aliases.get_model_folder_path(location)
753-
self.logger.warning('WLSDPLY-08022', model_target, TARGET, location_path,
754-
class_name=self._class_name, method_name=_method_name)
755720

756721
model_dict[TARGET] = ",".join(model_targets)
757-
return ",".join(delete_targets)
758722

759723
def __verify_delete_versioned_app(self, app, existing_apps, type='app'):
760724
"""

0 commit comments

Comments
 (0)