3
3
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
4
"""
5
5
import copy
6
- import os
6
+ import os , re
7
7
from java .io import ByteArrayOutputStream
8
8
from java .io import File
9
9
from java .io import FileInputStream
36
36
from wlsdeploy .tool .deploy .deployer import Deployer
37
37
from wlsdeploy .util import dictionary_utils
38
38
from wlsdeploy .util import string_utils
39
+ from wlsdeploy .util import model_helper
40
+ from wlsdeploy .aliases import model_constants
41
+
39
42
40
43
import oracle .weblogic .deploy .util .FileUtils as FileUtils
41
44
import oracle .weblogic .deploy .util .PyOrderedDict as OrderedDict
@@ -93,6 +96,17 @@ def __add_shared_libraries(self):
93
96
for shared_library_name in shared_libraries :
94
97
self .logger .info ('WLSDPLY-09608' , LIBRARY , shared_library_name , self ._parent_type , self ._parent_name ,
95
98
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
+
96
110
#
97
111
# In WLST offline mode, the shared library name must match the fully qualified name, including
98
112
# the spec and implementation versions from the deployment descriptor. Since we want to allow
@@ -155,6 +169,16 @@ def __add_applications(self):
155
169
self .logger .info ('WLSDPLY-09301' , APPLICATION , application_name , self ._parent_type , self ._parent_name ,
156
170
class_name = self ._class_name , method_name = _method_name )
157
171
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
+
158
182
application = \
159
183
copy .deepcopy (dictionary_utils .get_dictionary_element (applications , application_name ))
160
184
@@ -228,7 +252,7 @@ def __online_deploy_apps_and_libs(self, base_location):
228
252
# Go through the model libraries and find existing libraries that are referenced
229
253
# by applications and compute a processing strategy for each library.
230
254
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 )
232
256
233
257
# Go through the model applications and compute the processing strategy for each application.
234
258
app_location = LocationContext (base_location ).append_location (APPLICATION )
@@ -494,7 +518,10 @@ def __get_library_references(self, base_location):
494
518
return existing_libraries
495
519
496
520
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
+
498
525
if model_libs is not None :
499
526
uses_path_tokens_model_attribute_names = self .__get_uses_path_tokens_attribute_names (location )
500
527
@@ -504,6 +531,19 @@ def __build_library_deploy_strategy(self, location, model_libs, existing_libs, e
504
531
if param in lib_dict :
505
532
self .model_context .replace_tokens (LIBRARY , lib , param , lib_dict )
506
533
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
+
507
547
if lib in existing_libs :
508
548
existing_lib_ref = dictionary_utils .get_dictionary_element (existing_lib_refs , lib )
509
549
@@ -568,6 +608,16 @@ def __build_app_deploy_strategy(self, location, model_apps, existing_apps, exist
568
608
if param in app_dict :
569
609
self .model_context .replace_tokens (APPLICATION , app , param , app_dict )
570
610
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
+
571
621
if app in existing_apps :
572
622
# Compare the hashes of the domain's existing apps to the model's apps.
573
623
# 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
600
650
stop_and_undeploy_app_list .append (app )
601
651
return
602
652
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
+
603
676
def __get_uses_path_tokens_attribute_names (self , app_location ):
604
677
location = LocationContext (app_location )
605
678
token_name = self .alias_helper .get_name_token (location )
0 commit comments