22Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
33Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44"""
5+ import os
6+
57from java .io import File
68from java .lang import IllegalArgumentException
79
@@ -241,6 +243,10 @@ def _add_application_to_archive(self, application_name, application_dict):
241243 _logger .entering (application_name , class_name = _class_name , method_name = _method_name )
242244 archive_file = self ._model_context .get_archive_file ()
243245 if model_constants .SOURCE_PATH in application_dict :
246+ if model_constants .PLAN_DIR in application_dict and \
247+ self ._test_app_folder (application_dict [model_constants .SOURCE_PATH ],
248+ application_dict [model_constants .PLAN_DIR ]):
249+ return self ._create_app_folder (application_name , application_dict )
244250 file_name = application_dict [model_constants .SOURCE_PATH ]
245251 if file_name :
246252 file_name_path = file_name
@@ -260,14 +266,7 @@ def _add_application_to_archive(self, application_name, application_dict):
260266 try :
261267 new_source_name = archive_file .addApplication (file_name_path )
262268 except IllegalArgumentException , iae :
263- if model_constants .TARGET in application_dict :
264- target = application_dict [model_constants .TARGET ]
265- del application_dict [model_constants .TARGET ]
266- _logger .warning ('WLSDPLY-06395' , application_name , target , iae .getLocalizedMessage (),
267- class_name = _class_name , method_name = _method_name )
268- else :
269- _logger .warning ('WLSDPLY-06396' , application_name , iae .getLocalizedMessage (),
270- class_name = _class_name , method_name = _method_name )
269+ self ._disconnect_target (application_name , application_dict , iae .getLocalizedMessage ())
271270 except WLSDeployArchiveIOException , wioe :
272271 de = exception_helper .create_discover_exception ('WLSDPLY-06397' , application_name ,
273272 file_name_path , wioe .getLocalizedMessage ())
@@ -310,14 +309,107 @@ def add_application_plan_to_archive(self, application_name, application_dict):
310309 _logger .exiting (class_name = _class_name , method_name = _method_name )
311310 return
312311
312+ def _create_app_folder (self , application_name , application_dict ):
313+ """
314+ Create a well-formed application and plan directory
315+ :param application_name: name of application
316+ :param application_dict: model dictionary with application parameters
317+ :return: newly constructed source name
318+ """
319+ _method_name = '_create_app_folder'
320+
321+ _logger .entering (application_name , class_name = _class_name , method_name = _method_name )
322+
323+ self ._create_application_directory (application_name , application_dict )
324+ self ._create_plan_directory (application_name , application_dict )
325+
326+ _logger .exiting (class_name = _class_name , method_name = _method_name )
327+
328+ def _test_app_folder (self , source_path , plan_dir ):
329+ app_folder = False
330+ app_dir = File (source_path ).getParent ()
331+ if app_dir .endswith ('app' ) and plan_dir .endswith ('plan' ):
332+ app_folder = True
333+ return app_folder
334+
335+ def _disconnect_target (self , application_name , application_dict , message ):
336+ _method_name = '_disconnect_target'
337+ if model_constants .TARGET in application_dict :
338+ target = application_dict [model_constants .TARGET ]
339+ del application_dict [model_constants .TARGET ]
340+ _logger .warning ('WLSDPLY-06395' , application_name , target , message ,
341+ class_name = _class_name , method_name = _method_name )
342+ else :
343+ _logger .warning ('WLSDPLY-06396' , application_name , iae .getLocalizedMessage (),
344+ class_name = _class_name , method_name = _method_name )
345+ def _create_application_directory (self , application_name , application_dict ):
346+ _method_name = '_create_application_directory'
347+ new_source_name = None
348+ app_dir = application_dict [model_constants .SOURCE_PATH ]
349+ archive_file = self ._model_context .get_archive_file ()
350+ if self ._model_context .is_remote ():
351+ new_source_name = archive_file .getApplicationDirectoryArchivePath (application_name , app_dir )
352+
353+ self .add_to_remote_map (app_dir , new_source_name ,
354+ WLSDeployArchive .ArchiveEntryType .APPLICATIONS .name ())
355+ elif not self ._model_context .skip_archive ():
356+ if not os .path .abspath (app_dir ):
357+ app_dir = os .path .join (self ._model_context .get_domain_home (), app_dir )
358+ try :
359+ new_source_name = archive_file .addApplicationFolder (application_name , app_dir )
360+ except IllegalArgumentException , iae :
361+ self ._disconnect_target (application_name , application_dict , iae .getLocalizedMessage ())
362+ except WLSDeployArchiveIOException , wioe :
363+ de = exception_helper .create_discover_exception ('WLSDPLY-06403' , application_name ,
364+ file_name_path , wioe .getLocalizedMessage ())
365+ _logger .throwing (class_name = _class_name , method_name = _method_name , error = de )
366+ raise de
367+ if new_source_name is not None :
368+ _logger .finer ('WLSDPLY-06398' , application_name , new_source_name , class_name = _class_name ,
369+ method_name = _method_name )
370+ application_dict [model_constants .SOURCE_PATH ] = new_source_name
371+
372+ def _create_plan_directory (self , application_name , application_dict ):
373+ _method_name = '_create_plan_directory'
374+ new_source_name = None
375+ plan_dir = application_dict [model_constants .PLAN_DIR ]
376+ archive_file = self ._model_context .get_archive_file ()
377+ if not os .path .abspath (plan_dir ):
378+ plan_dir = os .path .join (self ._model_context .get_domain_home (), plan_dir )
379+ if self ._model_context .is_remote ():
380+ new_source_name = archive_file .getApplicationPlanDirArchivePath (application_name , plan_dir )
381+ self .add_to_remote_map (plan_dir , new_source_name ,
382+ WLSDeployArchive .ArchiveEntryType .APPLICATION_PLAN .name ())
383+ elif not self ._model_context .skip_archive ():
384+ try :
385+ new_source_name = archive_file .addApplicationPlanFolder (application_name , plan_dir )
386+ except IllegalArgumentException , iae :
387+ _logger .warning ('WLSDPLY-06395' , application_name , plan_dir ,
388+ iae .getLocalizedMessage (), class_name = _class_name ,
389+ method_name = _method_name )
390+ new_source_name = None
391+ except WLSDeployArchiveIOException , wioe :
392+ de = exception_helper .create_discover_exception ('WLSDPLY-06397' , application_dict , plan_dir ,
393+ wioe .getLocalizedMessage ())
394+ _logger .throwing (class_name = _class_name , method_name = _method_name , error = de )
395+ raise de
396+ if new_source_name is not None :
397+ _logger .finer ('WLSDPLY-06398' , application_name , new_source_name , class_name = _class_name ,
398+ method_name = _method_name )
399+ application_dict [model_constants .PLAN_DIR ] = new_source_name
400+
313401 def _get_plan_path (self , plan_path , archive_file , app_source_name , application_name , application_dict ):
402+ _method_name = '_get_plan_path'
314403 plan_dir = None
315404 if model_constants .PLAN_DIR in application_dict :
316405 plan_dir = application_dict [model_constants .PLAN_DIR ]
317406 del application_dict [model_constants .PLAN_DIR ]
318407 plan_file_name = self ._resolve_deployment_plan_path (plan_dir , plan_path )
319408 if self ._model_context .is_remote ():
320- new_plan_name = archive_file .getApplicationPlanArchivePath (plan_file_name )
409+ if plan_file_name .endswith ('plan' ):
410+ new_plan_name = archive_file .getApplicationPlanDirArchivePath (plan_file_name )
411+ else :
412+ new_plan_name = archive_file .getApplicationPlanArchivePath (plan_file_name )
321413 self .add_to_remote_map (plan_path , new_plan_name ,
322414 WLSDeployArchive .ArchiveEntryType .APPLICATION_PLAN .name ())
323415 elif not self ._model_context .skip_archive ():
@@ -338,6 +430,7 @@ def _get_plan_path(self, plan_path, archive_file, app_source_name, application_n
338430 raise de
339431
340432 return new_plan_name
433+
341434 def _resolve_deployment_plan_path (self , plan_dir , plan_path ):
342435 """
343436 Find the deployment plan absolute file path.
0 commit comments