Skip to content

Commit 440c98c

Browse files
authored
Fix deletetarget and nontargetupdate (#1156)
1 parent 737ea19 commit 440c98c

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

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

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,6 @@ def __get_existing_apps(self, base_location):
405405
absolute_planpath = attributes_map['AbsolutePlanPath']
406406
config_targets = self.__get_config_targets()
407407

408-
# AppRuntimeStateRuntime/AppRuntimeStateRuntime always return the app even if not targeted
409-
# skip as if it is not there
410-
if len(config_targets) == 0:
411-
continue
412-
# There are case in application where absolute source path is not set but sourepath is
413-
# if source path is not absolute then we need to add the domain path
414-
415408
if absolute_planpath is None:
416409
absolute_planpath = attributes_map['PlanPath']
417410

@@ -607,6 +600,14 @@ def __build_library_deploy_strategy(self, location, model_libs, existing_lib_ref
607600
if lib_dict['SourcePath'] is None and existing_src_path is not None:
608601
lib_dict['SourcePath'] = existing_src_path
609602

603+
def __shouldCheckForTargetChange(self, src_path, model_src_path):
604+
# If the existing running app's source path (always absolute from runtime mbean) = the model's source path.
605+
# or if the model sourcepath + domain home is exactly equal to the running's app source path.
606+
# return True otherwise return False
607+
if not os.path.isabs(model_src_path):
608+
return self.model_context.get_domain_home() + '/' + model_src_path == src_path
609+
else:
610+
return FileUtils.getCanonicalPath(src_path) == FileUtils.getCanonicalPath(model_src_path)
610611

611612
def __build_app_deploy_strategy(self, location, model_apps, existing_app_refs, stop_and_undeploy_app_list):
612613
"""
@@ -666,8 +667,8 @@ def __build_app_deploy_strategy(self, location, model_apps, existing_app_refs, s
666667
existing_plan_hash = self.__get_file_hash(plan_path)
667668
if model_src_hash == existing_src_hash:
668669
if model_plan_hash == existing_plan_hash:
669-
if not (os.path.isabs(src_path) and os.path.isabs(model_src_path) and
670-
FileUtils.getCanonicalPath(src_path) == FileUtils.getCanonicalPath(model_src_path)):
670+
if self.__shouldCheckForTargetChange(src_path, model_src_path):
671+
671672
# If model hashes match existing hashes, the application did not change.
672673
# Unless targets were added, there's no need to redeploy.
673674
# If it is an absolute path, there is nothing to compare so assume redeploy
@@ -678,8 +679,16 @@ def __build_app_deploy_strategy(self, location, model_apps, existing_app_refs, s
678679
existing_app_targets = dictionary_utils.get_element(existing_app_ref, 'target')
679680
existing_app_targets_set = Set(existing_app_targets)
680681

681-
if existing_app_targets_set.issuperset(model_targets_set):
682-
self.__remove_app_from_deployment(model_apps, app)
682+
if existing_app_targets_set == model_targets_set and len(existing_app_targets_set) > 0:
683+
# redeploy the app if everything is the same
684+
self.logger.info('WLSDPLY-09336', src_path,
685+
class_name=self._class_name, method_name=_method_name)
686+
if versioned_name not in stop_and_undeploy_app_list:
687+
stop_and_undeploy_app_list.append(versioned_name)
688+
elif len(existing_app_targets_set) == 0 and len(model_targets_set) == 0:
689+
self.__remove_app_from_deployment(model_apps, app, "emptyset")
690+
elif existing_app_targets_set.issuperset(model_targets_set):
691+
self.__remove_app_from_deployment(model_apps, app, "superset")
683692
else:
684693
# Adjust the targets to only the new targets so that existing apps on
685694
# already targeted servers are not impacted.
@@ -692,8 +701,7 @@ def __build_app_deploy_strategy(self, location, model_apps, existing_app_refs, s
692701
if app_dict['SourcePath'] is None and src_path is not None:
693702
app_dict['SourcePath'] = src_path
694703
else:
695-
self.logger.info('WLSDPLY-09336', src_path,
696-
class_name=self._class_name, method_name=_method_name)
704+
# same hash but different path, so redeploy it
697705
if versioned_name not in stop_and_undeploy_app_list:
698706
stop_and_undeploy_app_list.append(versioned_name)
699707
else:
@@ -833,9 +841,17 @@ def __handle_builtin_libraries(self, targets_not_changed, model_libs, lib,
833841
adjusted_targets = ','.join(adjusted_set)
834842
model_libs[lib][TARGET] = adjusted_targets
835843

836-
def __remove_app_from_deployment(self, model_dict, app_name):
837-
self.logger.info('WLSDPLY-09337', app_name,
838-
class_name=self._class_name, method_name='remove_app_from_deployment')
844+
def __remove_app_from_deployment(self, model_dict, app_name, reason="delete"):
845+
if "superset" == reason:
846+
self.logger.info('WLSDPLY-09338', app_name,
847+
class_name=self._class_name, method_name='remove_app_from_deployment')
848+
elif "emptyset" == reason:
849+
self.logger.info('WLSDPLY-09339', app_name,
850+
class_name=self._class_name, method_name='remove_app_from_deployment')
851+
else:
852+
self.logger.info('WLSDPLY-09337', app_name,
853+
class_name=self._class_name, method_name='remove_app_from_deployment')
854+
839855
model_dict.pop(app_name)
840856

841857
def __remove_lib_from_deployment(self, model_dict, lib_name):

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
@@ -1151,6 +1151,10 @@ WLSDPLY-09334=Application {0} not found. Please specify a valid application for
11511151
WLSDPLY-09335=Undeploying {0} {1} from targets: {2}
11521152
WLSDPLY-09336=Redeployed application {0} because the old and the new binary have the same path.
11531153
WLSDPLY-09337=Removing {0} from model deployment because it is started with a delete notation. It will be undeployed.
1154+
WLSDPLY-09338=Removing {0} from model deployment because the running application's targets are a superset of \
1155+
the targets in the model.
1156+
WLSDPLY-09339=Removing {0} from model deployment because the running application's has no target and \
1157+
also no targets in the model.
11541158

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

0 commit comments

Comments
 (0)