Skip to content

Commit 6a35278

Browse files
committed
Adding common code to detect the structured app install root directory
1 parent 6dc2160 commit 6a35278

File tree

7 files changed

+257
-80
lines changed

7 files changed

+257
-80
lines changed

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

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@
2727
from wlsdeploy.aliases.model_constants import SOURCE_PATH
2828
from wlsdeploy.aliases.wlst_modes import WlstModes
2929
from wlsdeploy.exception import exception_helper
30+
from wlsdeploy.exception.exception_types import ExceptionType
3031
from wlsdeploy.tool.deploy import deployer_utils
3132
from wlsdeploy.tool.deploy.applications_version_helper import ApplicationsVersionHelper
3233
from wlsdeploy.tool.deploy.deployer import Deployer
3334
from wlsdeploy.tool.util import appmodule_helper
35+
from wlsdeploy.tool.util import structured_apps_helper
3436
from wlsdeploy.util import dictionary_utils
3537
from wlsdeploy.util import model_helper
3638
from wlsdeploy.util import string_utils
@@ -182,16 +184,17 @@ def _fixup_structured_app_plan_file_config_root(self, structured_app_dict):
182184
# best effort only...
183185
pass
184186

185-
def _is_structured_app(self, app_dict):
187+
def _is_structured_app(self, app_name, app_dict):
186188
"""
187189
Is the application represented by the dictionary a structured application? It is the caller's responsibility
188190
to only call this method for applications and not shared libraries!
189191
192+
:param app_name: the application name
190193
:param app_dict: the model dictionary representing the application
191194
:return: True, structured_app_dir if the application is a structured application; False, None otherwise
192195
"""
193196
_method_name = 'is_structured_app'
194-
self.logger.entering(app_dict, class_name=self._class_name, method_name=_method_name)
197+
self.logger.entering(app_name, app_dict, class_name=self._class_name, method_name=_method_name)
195198

196199
result = False
197200
structured_app_dir = None
@@ -203,7 +206,7 @@ def _is_structured_app(self, app_dict):
203206

204207
if not result:
205208
result, structured_app_dir = \
206-
self.__is_external_structured_app(model_source_path, combined_plan_path)
209+
self.__is_external_structured_app(app_name, model_source_path, combined_plan_path)
207210

208211
self.logger.exiting(class_name=self._class_name, method_name=_method_name, result=[result, structured_app_dir])
209212
return result, structured_app_dir
@@ -328,7 +331,7 @@ def _extract_deployment_from_archive(self, deployment_name, deployment_type, dep
328331
is_structured_app = False
329332
structured_app_dir = None
330333
if deployment_type == APPLICATION:
331-
is_structured_app, structured_app_dir = self._is_structured_app(deployment_dict)
334+
is_structured_app, structured_app_dir = self._is_structured_app(deployment_name, deployment_dict)
332335

333336
if is_structured_app:
334337
# is_structured_app() only returns true if both the app and the plan have similar paths.
@@ -515,33 +518,18 @@ def __is_archived_structured_app(self, model_source_path, combined_plan_path):
515518
self.logger.exiting(class_name=self._class_name, method_name=_method_name, result=[result, structured_app_dir])
516519
return result, structured_app_dir
517520

518-
def __is_external_structured_app(self, model_source_path, combined_plan_path):
521+
def __is_external_structured_app(self, app_name, model_source_path, combined_plan_path):
519522
_method_name = '__is_external_structured_app'
520-
self.logger.entering(model_source_path, combined_plan_path,
523+
self.logger.entering(app_name, model_source_path, combined_plan_path,
521524
class_name=self._class_name, method_name=_method_name)
522525

523-
result = False
524526
structured_app_dir = None
525527
if not string_utils.is_empty(model_source_path) and not string_utils.is_empty(combined_plan_path) \
526528
and not WLSDeployArchive.isPathIntoArchive(model_source_path):
527-
528-
source_path_to_compare = model_source_path.replace('\\', '/')
529-
plan_path_to_compare = combined_plan_path.replace('\\', '/')
530-
531-
# Try to determine the structured application_directory as best we can.
532-
source_path_elements = source_path_to_compare.split('/')
533-
app_dir_index = -1
534-
for idx, source_path_element in enumerate(source_path_elements):
535-
# Search the entire list since the path could include multiple directories named 'app'
536-
# and we always want the last one.
537-
if source_path_element.lower() == 'app':
538-
app_dir_index = idx
539-
540-
if app_dir_index > 0:
541-
fake_str_app_dir = '/'.join(source_path_elements[0:app_dir_index])
542-
if plan_path_to_compare.startswith(fake_str_app_dir + '/'):
543-
result = True
544-
structured_app_dir = model_source_path[0:len(fake_str_app_dir)]
529+
structured_app_dir = \
530+
structured_apps_helper.get_structured_app_install_root(app_name, model_source_path, combined_plan_path,
531+
ExceptionType.DEPLOY)
532+
result = not string_utils.is_empty(structured_app_dir)
545533

546534
self.logger.exiting(class_name=self._class_name, method_name=_method_name, result=[result, structured_app_dir])
547535
return result, structured_app_dir

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def __deploy_applications(self):
128128
self._set_attributes_and_add_subfolders(application_location, application)
129129

130130
self._substitute_appmodule_token(app_source_path, module_type)
131-
is_structured_app, __ = self._is_structured_app(application)
131+
is_structured_app, __ = self._is_structured_app(application_name, application)
132132
if is_structured_app:
133133
self._fixup_structured_app_plan_file_config_root(application)
134134

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ def __deploy_model_deployments(self, deployments, deployments_location, deployme
824824
self._extract_deployment_from_archive(deployment_name, deployment_type, deployment_dict)
825825

826826
if deployment_type == APPLICATION:
827-
is_structured_app, _ = self._is_structured_app(deployment_dict)
827+
is_structured_app, _ = self._is_structured_app(deployment_name, deployment_dict)
828828
if is_structured_app:
829829
self._fixup_structured_app_plan_file_config_root(deployment_dict)
830830

core/src/main/python/wlsdeploy/tool/discover/deployments_discoverer.py

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@
2626
from wlsdeploy.aliases.model_constants import SOURCE_PATH
2727
from wlsdeploy.aliases.wlst_modes import WlstModes
2828
from wlsdeploy.exception import exception_helper
29+
from wlsdeploy.exception.exception_types import ExceptionType
2930
from wlsdeploy.logging.platform_logger import PlatformLogger
3031
from wlsdeploy.tool.discover import discoverer
3132
from wlsdeploy.tool.discover.discoverer import Discoverer
33+
from wlsdeploy.tool.util import structured_apps_helper
3234
from wlsdeploy.util import dictionary_utils
3335
from wlsdeploy.util import path_helper
36+
from wlsdeploy.util import string_utils
3437

3538
_class_name = 'DeploymentsDiscoverer'
3639
_logger = PlatformLogger(discoverer.get_discover_logger_name())
@@ -442,45 +445,17 @@ def _is_structured_app(self, application_name, application_dict):
442445
_logger.finer('WLSDPLY-06405', application_name, source_path, plan_dir, plan_path,
443446
class_name=_class_name, method_name=_method_name)
444447

445-
if source_path is None:
448+
if string_utils.is_empty(source_path):
446449
de = exception_helper.create_discover_exception('WLSDPLY-06404', application_name)
447450
_logger.throwing(class_name=_class_name, method_name=_method_name, error=de)
448451
raise de
449-
if plan_path is None:
452+
if string_utils.is_empty(plan_path):
450453
_logger.exiting(class_name=_class_name, method_name=_method_name, result=[False, None])
451454
return False, None
452455

453-
if self.path_helper.is_relative_path(source_path):
454-
source_path = self.path_helper.join(self._model_context.get_domain_home(), source_path)
455-
source_path = self.path_helper.get_canonical_path(source_path)
456-
457-
source_path_parent = self.path_helper.get_parent_directory(source_path)
458-
_logger.finer('WLSDPLY-06406', application_name, source_path_parent,
459-
class_name=_class_name, method_name=_method_name)
460-
if source_path_parent is None or \
461-
self.path_helper.basename(source_path_parent) != 'app' or \
462-
self.path_helper.get_parent_directory(source_path_parent) == source_path_parent:
463-
_logger.exiting(class_name=_class_name, method_name=_method_name, result=[False, None])
464-
return False, None
465-
466-
# _get_app_install_root() only needs a path to either the PlanDir or the PlanPath to determine
467-
# if this application is a structured app.
468-
#
469-
if plan_dir is None:
470-
if self.path_helper.is_relative_path(plan_path):
471-
plan_path = self.path_helper.join(self._model_context.get_domain_home(), plan_path)
472-
plan_path = self.path_helper.get_canonical_path(plan_path)
473-
effective_plan = plan_path
474-
else:
475-
if self.path_helper.is_relative_path(plan_dir):
476-
plan_dir = self.path_helper.join(self._model_context.get_domain_home(), plan_dir)
477-
plan_dir = self.path_helper.get_canonical_path(plan_dir)
478-
effective_plan = plan_dir
479-
480-
install_root_dir = self._get_app_install_root(source_path_parent, effective_plan)
456+
install_root_dir = self._get_structured_app_install_root(application_name, source_path, plan_dir, plan_path)
481457
if install_root_dir is not None:
482-
_logger.exiting(class_name=_class_name, method_name=_method_name,
483-
result=[True, install_root_dir])
458+
_logger.exiting(class_name=_class_name, method_name=_method_name, result=[True, install_root_dir])
484459
return True, install_root_dir
485460

486461
_logger.exiting(class_name=_class_name, method_name=_method_name, result=[False, None])
@@ -671,15 +646,39 @@ def _resolve_deployment_plan_path(self, plan_dir, plan_path):
671646
return self.path_helper.get_canonical_path(plan_path, relative_to=relative_to)
672647
return plan_path
673648

674-
def _get_app_install_root(self, app_dir, plan_dir):
675-
_method_name = '_get_app_install_root'
676-
_logger.entering(app_dir, plan_dir, class_name=_class_name, method_name=_method_name)
649+
def _get_structured_app_install_root(self, app_name, source_path, plan_dir, plan_path):
650+
"""
651+
This method tries to determine if this is a structured application and if so, returns the
652+
install root directory.
653+
654+
:param app_name: The application name
655+
:param source_path: The application source path (already validated as not None)
656+
:param plan_dir: The application plan directory, if set
657+
:param plan_path: The application plan path (already validated as not None)
658+
:return: The structured application install root directory or None, if it is not a structured application
659+
"""
660+
_method_name = '_get_structured_app_install_root'
661+
_logger.entering(app_name, source_path, plan_dir, plan_path,
662+
class_name=_class_name, method_name=_method_name)
663+
664+
full_source_path = source_path
665+
if self.path_helper.is_relative_path(source_path):
666+
full_source_path = self.path_helper.join(self._model_context.get_domain_home(), source_path)
667+
full_source_path = self.path_helper.get_canonical_path(full_source_path)
677668

678-
app_install_root = self.path_helper.get_parent_directory(app_dir)
679-
if plan_dir.startswith(app_install_root):
680-
install_root = app_install_root
669+
full_plan_path = plan_path
670+
if string_utils.is_empty(plan_dir):
671+
if self.path_helper.is_relative_path(plan_path):
672+
full_plan_path = self.path_helper.join(self._model_context.get_domain_home(), plan_path)
673+
full_plan_path = self.path_helper.get_canonical_path(full_plan_path)
681674
else:
682-
install_root = None
675+
full_plan_path = self.path_helper.join(plan_dir, plan_path)
676+
if self.path_helper.is_relative_path(full_plan_path):
677+
full_plan_path = self.path_helper.join(self._model_context.get_domain_home(), full_plan_path)
678+
full_plan_path = self.path_helper.get_canonical_path(full_plan_path)
679+
680+
install_root = structured_apps_helper.get_structured_app_install_root(app_name, full_source_path,
681+
full_plan_path, ExceptionType.DISCOVER)
683682

684683
_logger.exiting(class_name=_class_name, method_name=_method_name, result=install_root)
685684
return install_root
@@ -695,6 +694,7 @@ def _get_dictionary_attribute_with_path_tokens_replaced(self, model_dict, attrib
695694
_logger.exiting(class_name=_class_name, method_name=_method_name, result=result)
696695
return result
697696

697+
698698
def _generate_new_plan_name(binary_path, plan_path):
699699
"""
700700
Generate a new plan name from the plan path and binary path.

0 commit comments

Comments
 (0)