44"""
55import copy
66import os , re
7- from java .io import ByteArrayOutputStream
87from java .io import File
98from java .io import FileInputStream
109from java .io import FileNotFoundException
1514from java .util .jar import Manifest
1615from java .util .zip import ZipException
1716from sets import Set
17+
18+ from oracle .weblogic .deploy .aliases import TypeUtils
1819from wlsdeploy .aliases .location_context import LocationContext
1920from wlsdeploy .aliases .model_constants import ABSOLUTE_SOURCE_PATH
2021from wlsdeploy .aliases .model_constants import APPLICATION
@@ -418,6 +419,7 @@ def __get_existing_apps(self, base_location):
418419 attributes_map = self .wlst_helper .lsa ()
419420 absolute_sourcepath = attributes_map ['AbsoluteSourcePath' ]
420421 absolute_planpath = attributes_map ['AbsolutePlanPath' ]
422+ config_targets = self .__get_config_targets ()
421423
422424 # There are case in application where absolute source path is not set but sourepath is
423425 # if source path is not absolute then we need to add the domain path
@@ -442,7 +444,7 @@ def __get_existing_apps(self, base_location):
442444 else :
443445 plan_hash = None
444446
445- _update_ref_dictionary (ref_dictionary , app , absolute_sourcepath , app_hash , None ,
447+ _update_ref_dictionary (ref_dictionary , app , absolute_sourcepath , app_hash , config_targets ,
446448 absolute_plan_path = absolute_planpath , deploy_order = deployment_order ,
447449 plan_hash = plan_hash )
448450 return ref_dictionary
@@ -641,7 +643,23 @@ def __build_app_deploy_strategy(self, location, model_apps, existing_apps, exist
641643 existing_plan_hash = self .__get_file_hash (plan_path )
642644 if model_src_hash == existing_src_hash :
643645 if model_plan_hash == existing_plan_hash :
644- self .__remove_app_from_deployment (model_apps , app )
646+ # If model hashes match existing hashes, the application did not change.
647+ # Unless targets were added, there's no need to redeploy.
648+ model_targets = dictionary_utils .get_element (app_dict , TARGET )
649+ model_targets_list = TypeUtils .convertToType (list , model_targets )
650+ model_targets_set = Set (model_targets_list )
651+
652+ existing_app_targets = dictionary_utils .get_element (existing_app_ref , 'target' )
653+ existing_app_targets_set = Set (existing_app_targets )
654+
655+ if existing_app_targets_set .issuperset (model_targets_set ):
656+ self .__remove_app_from_deployment (model_apps , app )
657+ else :
658+ # Adjust the targets to only the new targets so that existing apps on
659+ # already targeted servers are not impacted.
660+ adjusted_set = model_targets_set .difference (existing_app_targets_set )
661+ adjusted_targets = ',' .join (adjusted_set )
662+ app_dict ['Target' ] = adjusted_targets
645663 else :
646664 # updated deployment plan
647665 stop_and_undeploy_app_list .append (app )
0 commit comments