Skip to content

Commit 6d65f4b

Browse files
authored
Model undeploy (#608)
* add support for app/lib deletion based on the exclamation notation * Fix online undeploy lib * add detection for expanded names when deleting library and application * add detection for expanded names when deleting library and application * refactor code
1 parent e349793 commit 6d65f4b

File tree

2 files changed

+80
-3
lines changed

2 files changed

+80
-3
lines changed

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

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
import copy
6-
import os
6+
import os, re
77
from java.io import ByteArrayOutputStream
88
from java.io import File
99
from java.io import FileInputStream
@@ -36,6 +36,9 @@
3636
from wlsdeploy.tool.deploy.deployer import Deployer
3737
from wlsdeploy.util import dictionary_utils
3838
from wlsdeploy.util import string_utils
39+
from wlsdeploy.util import model_helper
40+
from wlsdeploy.aliases import model_constants
41+
3942

4043
import oracle.weblogic.deploy.util.FileUtils as FileUtils
4144
import oracle.weblogic.deploy.util.PyOrderedDict as OrderedDict
@@ -93,6 +96,17 @@ def __add_shared_libraries(self):
9396
for shared_library_name in shared_libraries:
9497
self.logger.info('WLSDPLY-09608', LIBRARY, shared_library_name, self._parent_type, self._parent_name,
9598
class_name=self._class_name, method_name=_method_name)
99+
100+
if model_helper.is_delete_name(shared_library_name):
101+
102+
self.__verify_delete_versioned_app(shared_library_name, existing_shared_libraries, type='lib')
103+
104+
location = LocationContext()
105+
location.append_location(model_constants.LIBRARY)
106+
existing_names = deployer_utils.get_existing_object_list(location, self.alias_helper)
107+
deployer_utils.delete_named_element(location, shared_library_name, existing_names, self.alias_helper)
108+
continue
109+
96110
#
97111
# In WLST offline mode, the shared library name must match the fully qualified name, including
98112
# the spec and implementation versions from the deployment descriptor. Since we want to allow
@@ -155,6 +169,16 @@ def __add_applications(self):
155169
self.logger.info('WLSDPLY-09301', APPLICATION, application_name, self._parent_type, self._parent_name,
156170
class_name=self._class_name, method_name=_method_name)
157171

172+
if model_helper.is_delete_name(application_name):
173+
174+
self.__verify_delete_versioned_app(application_name, existing_applications, type='app')
175+
176+
location = LocationContext()
177+
location.append_location(model_constants.APPLICATION)
178+
existing_names = deployer_utils.get_existing_object_list(location, self.alias_helper)
179+
deployer_utils.delete_named_element(location, application_name, existing_names, self.alias_helper)
180+
continue
181+
158182
application = \
159183
copy.deepcopy(dictionary_utils.get_dictionary_element(applications, application_name))
160184

@@ -228,7 +252,7 @@ def __online_deploy_apps_and_libs(self, base_location):
228252
# Go through the model libraries and find existing libraries that are referenced
229253
# by applications and compute a processing strategy for each library.
230254
self.__build_library_deploy_strategy(lib_location, model_shared_libraries, existing_libs, existing_lib_refs,
231-
stop_app_list, update_library_list)
255+
stop_app_list, update_library_list, stop_and_undeploy_app_list)
232256

233257
# Go through the model applications and compute the processing strategy for each application.
234258
app_location = LocationContext(base_location).append_location(APPLICATION)
@@ -494,7 +518,10 @@ def __get_library_references(self, base_location):
494518
return existing_libraries
495519

496520
def __build_library_deploy_strategy(self, location, model_libs, existing_libs, existing_lib_refs,
497-
stop_app_list, update_library_list):
521+
stop_app_list, update_library_list, stop_and_undeploy_app_list):
522+
523+
_method_name = '__build_library_deploy_strategy'
524+
498525
if model_libs is not None:
499526
uses_path_tokens_model_attribute_names = self.__get_uses_path_tokens_attribute_names(location)
500527

@@ -504,6 +531,19 @@ def __build_library_deploy_strategy(self, location, model_libs, existing_libs, e
504531
if param in lib_dict:
505532
self.model_context.replace_tokens(LIBRARY, lib, param, lib_dict)
506533

534+
if model_helper.is_delete_name(lib):
535+
536+
self.__verify_delete_versioned_app(lib, existing_libs, 'lib')
537+
538+
if lib[1:] in existing_libs:
539+
model_libs.pop(lib)
540+
_add_ref_apps_to_stoplist(stop_app_list, existing_lib_refs, lib[1:])
541+
stop_and_undeploy_app_list.append(lib[1:])
542+
else:
543+
model_libs.pop(lib)
544+
stop_and_undeploy_app_list.append(lib[1:])
545+
continue
546+
507547
if lib in existing_libs:
508548
existing_lib_ref = dictionary_utils.get_dictionary_element(existing_lib_refs, lib)
509549

@@ -568,6 +608,16 @@ def __build_app_deploy_strategy(self, location, model_apps, existing_apps, exist
568608
if param in app_dict:
569609
self.model_context.replace_tokens(APPLICATION, app, param, app_dict)
570610

611+
if model_helper.is_delete_name(app):
612+
613+
self.__verify_delete_versioned_app(app, existing_apps, 'app')
614+
615+
# remove the !app from the model
616+
self.__remove_app_from_deployment(model_apps, app)
617+
# undeploy the app (without !)
618+
stop_and_undeploy_app_list.append(app[1:])
619+
continue
620+
571621
if app in existing_apps:
572622
# Compare the hashes of the domain's existing apps to the model's apps.
573623
# If they match, remove them from the list to be deployed.
@@ -600,6 +650,29 @@ def __build_app_deploy_strategy(self, location, model_apps, existing_apps, exist
600650
stop_and_undeploy_app_list.append(app)
601651
return
602652

653+
def __verify_delete_versioned_app(self, app, existing_apps, type='app'):
654+
655+
_method_name = '__verify_delete_versioned_app'
656+
657+
if type == 'app':
658+
err_key_list = 'WLSDPLY-09332'
659+
err_key = 'WLSDPLY-09334'
660+
else:
661+
err_key_list = 'WLSDPLY-09331'
662+
err_key = 'WLSDPLY-09333'
663+
664+
if not app[1:] in existing_apps:
665+
tokens = re.split(r'[\#*\@*]', app[1:])
666+
re_expr = tokens[0] + '[\#*\@*]'
667+
r = re.compile(re_expr)
668+
matched_list = filter(r.match, existing_apps)
669+
if len(matched_list) > 0:
670+
ex = exception_helper.create_deploy_exception(err_key_list, app[1:], matched_list)
671+
else:
672+
ex = exception_helper.create_deploy_exception(err_key, app[1:])
673+
self.logger.throwing(ex, class_name=self._class_name, method_name=_method_name)
674+
raise ex
675+
603676
def __get_uses_path_tokens_attribute_names(self, app_location):
604677
location = LocationContext(app_location)
605678
token_name = self.alias_helper.get_name_token(location)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,10 @@ WLSDPLY-09327=Failed to stop application {0}: {1}
996996
WLSDPLY-09328=Application {0} name has been updated to {1} to match the application version in the MANIFEST.MF file
997997
WLSDPLY-09329=Failed to compute name for application {0} from archive at {1}: {2}
998998
WLSDPLY-09330=Source path for {0} {1} not found in any archive: {2}
999+
WLSDPLY-09331=Library {0} not found, found similar names {1}. For deleting library, specify the exact name
1000+
WLSDPLY-09332=Application {0} not found, found similar names {1}. For deleting application, specify the exact name
1001+
WLSDPLY-09333=Library {0} not found. Please specify a valid library for deletion
1002+
WLSDPLY-09334=Application {0} not found. Please specify a valid application for deletion
9991003

10001004
# wlsdeploy/tool/deploy/common_resources_deployer.py
10011005
WLSDPLY-09400=ResourceGroup was specified in the test file but are not supported in WebLogic Server version {0}

0 commit comments

Comments
 (0)