2
2
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
3
3
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4
4
"""
5
+ import os
6
+
5
7
from java .io import File
6
8
from java .lang import IllegalArgumentException
7
9
@@ -241,6 +243,10 @@ def _add_application_to_archive(self, application_name, application_dict):
241
243
_logger .entering (application_name , class_name = _class_name , method_name = _method_name )
242
244
archive_file = self ._model_context .get_archive_file ()
243
245
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 )
244
250
file_name = application_dict [model_constants .SOURCE_PATH ]
245
251
if file_name :
246
252
file_name_path = file_name
@@ -260,14 +266,7 @@ def _add_application_to_archive(self, application_name, application_dict):
260
266
try :
261
267
new_source_name = archive_file .addApplication (file_name_path )
262
268
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 ())
271
270
except WLSDeployArchiveIOException , wioe :
272
271
de = exception_helper .create_discover_exception ('WLSDPLY-06397' , application_name ,
273
272
file_name_path , wioe .getLocalizedMessage ())
@@ -310,14 +309,107 @@ def add_application_plan_to_archive(self, application_name, application_dict):
310
309
_logger .exiting (class_name = _class_name , method_name = _method_name )
311
310
return
312
311
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
+
313
401
def _get_plan_path (self , plan_path , archive_file , app_source_name , application_name , application_dict ):
402
+ _method_name = '_get_plan_path'
314
403
plan_dir = None
315
404
if model_constants .PLAN_DIR in application_dict :
316
405
plan_dir = application_dict [model_constants .PLAN_DIR ]
317
406
del application_dict [model_constants .PLAN_DIR ]
318
407
plan_file_name = self ._resolve_deployment_plan_path (plan_dir , plan_path )
319
408
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 )
321
413
self .add_to_remote_map (plan_path , new_plan_name ,
322
414
WLSDeployArchive .ArchiveEntryType .APPLICATION_PLAN .name ())
323
415
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
338
430
raise de
339
431
340
432
return new_plan_name
433
+
341
434
def _resolve_deployment_plan_path (self , plan_dir , plan_path ):
342
435
"""
343
436
Find the deployment plan absolute file path.
0 commit comments