Skip to content

Commit e7b980a

Browse files
committed
Merge branch 'jira-wdt-846-deployment-validation' into 'develop-4.0'
Additional validation for appDeployments section See merge request weblogic-cloud/weblogic-deploy-tooling!1644
2 parents cf14a9a + 7773a62 commit e7b980a

File tree

5 files changed

+994
-771
lines changed

5 files changed

+994
-771
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
"""
2+
Copyright (c) 2024, Oracle and/or its affiliates.
3+
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
"""
5+
6+
from oracle.weblogic.deploy.util import WLSDeployArchive
7+
8+
from wlsdeploy.aliases.model_constants import APPLICATION
9+
from wlsdeploy.aliases.model_constants import APP_DEPLOYMENTS
10+
from wlsdeploy.aliases.model_constants import LIBRARY
11+
from wlsdeploy.aliases.model_constants import PLAN_DIR
12+
from wlsdeploy.aliases.model_constants import PLAN_PATH
13+
from wlsdeploy.aliases.model_constants import SOURCE_PATH
14+
from wlsdeploy.logging.platform_logger import PlatformLogger
15+
from wlsdeploy.tool.validate.model_validator import ModelValidator
16+
from wlsdeploy.util import dictionary_utils
17+
from wlsdeploy.util import variables
18+
19+
_class_name = 'DeploymentsValidator'
20+
_logger = PlatformLogger('wlsdeploy.validate')
21+
22+
ARCHIVE_APPS_PREFIX = WLSDeployArchive.ARCHIVE_APPS_TARGET_DIR + WLSDeployArchive.ZIP_SEP
23+
ARCHIVE_SHLIBS_PREFIX = WLSDeployArchive.ARCHIVE_SHLIBS_TARGET_DIR + WLSDeployArchive.ZIP_SEP
24+
ARCHIVE_STRUCT_APPS_PREFIX = WLSDeployArchive.ARCHIVE_STRUCT_APPS_TARGET_DIR + WLSDeployArchive.ZIP_SEP
25+
26+
27+
class DeploymentsValidator(ModelValidator):
28+
"""
29+
Class for validating the appDeployments section of a model file
30+
"""
31+
32+
def __init__(self, variables_map, archive_helper, validation_mode, model_context, aliases,
33+
wlst_mode):
34+
"""
35+
Create a validator instance.
36+
:param variables_map: map of variables used in the model
37+
:param archive_helper: used to validate archive paths
38+
:param model_context: used to get command-line options
39+
:param aliases: used to validate folders, attributes. also determines exception type
40+
:param wlst_mode: online or offline mode
41+
"""
42+
ModelValidator.__init__(self, variables_map, archive_helper, validation_mode, model_context, aliases,
43+
wlst_mode)
44+
45+
def validate(self, model_dict):
46+
"""
47+
Validate the app deployments section of the model.
48+
:param model_dict: the top-level model dictionary
49+
:param model_dict:
50+
"""
51+
self.validate_model_section(APP_DEPLOYMENTS, model_dict,
52+
self._aliases.get_model_app_deployments_top_level_folder_names())
53+
54+
# Override
55+
def _process_model_node(self, model_node, validation_location):
56+
"""
57+
Override this method to validate combined PlanDir and PlanPath, if both are present.
58+
"""
59+
ModelValidator._process_model_node(self, model_node, validation_location)
60+
61+
plan_path = dictionary_utils.get_element(model_node, PLAN_PATH)
62+
if plan_path:
63+
plan_path = variables.substitute_key(plan_path, self._variable_properties)
64+
model_folder_path = self._aliases.get_model_folder_path(validation_location)
65+
66+
plan_dir = dictionary_utils.get_element(model_node, PLAN_DIR)
67+
if plan_dir:
68+
plan_dir = variables.substitute_key(plan_dir, self._variable_properties)
69+
combined_path = '%s/%s' % (plan_dir, plan_path)
70+
combined_name = '%s+%s' % (PLAN_DIR, PLAN_PATH) # attribute name for logging
71+
self._validate_single_path_in_archive(combined_path, combined_name, model_folder_path)
72+
self.__validate_deployment_path(combined_path, combined_name, validation_location)
73+
else:
74+
# call the superclass method, method in this class intentionally skips this attribute
75+
ModelValidator._validate_single_path_in_archive(self, plan_path, PLAN_PATH, model_folder_path)
76+
self.__validate_deployment_path(plan_path, PLAN_PATH, validation_location)
77+
78+
# Override
79+
def _validate_attribute(self, attribute_name, attribute_value, valid_attr_infos, path_tokens_attr_keys,
80+
model_folder_path, validation_location):
81+
"""
82+
Extend this method to verify that archive source paths have prescribed directory names.
83+
"""
84+
ModelValidator._validate_attribute(self, attribute_name, attribute_value, valid_attr_infos,
85+
path_tokens_attr_keys, model_folder_path, validation_location)
86+
87+
if attribute_name == SOURCE_PATH:
88+
source_path = variables.substitute_key(attribute_value, self._variable_properties)
89+
self.__validate_deployment_path(source_path, SOURCE_PATH, validation_location)
90+
91+
# Override
92+
def _validate_single_path_in_archive(self, path, attribute_name, model_folder_path):
93+
"""
94+
Override superclass method exclude PlanPath from validation.
95+
This is handled in tandem with optional PlanDir in _process_model_node.
96+
:param path: the path to be checked
97+
:param attribute_name: the name of the attribute to be checked
98+
:param model_folder_path: the model folder path, used for logging
99+
"""
100+
if attribute_name != PLAN_PATH:
101+
ModelValidator._validate_single_path_in_archive(self, path, attribute_name, model_folder_path)
102+
103+
def __validate_deployment_path(self, deployment_path, attribute_name, location):
104+
"""
105+
Verify that an archive source or plan path has a prescribed directory name.
106+
:param deployment_path: the path to be validated
107+
:param attribute_name: the attribute name, for logging only
108+
:param location: the model location, for logging
109+
"""
110+
if WLSDeployArchive.isPathIntoArchive(deployment_path):
111+
deployment_type = location.get_current_model_folder()
112+
model_folder_path = self._aliases.get_model_folder_path(location)
113+
114+
if deployment_type == APPLICATION:
115+
if not deployment_path.startswith(ARCHIVE_APPS_PREFIX) and \
116+
not deployment_path.startswith(ARCHIVE_STRUCT_APPS_PREFIX):
117+
self._logger.severe('WLSDPLY-05241', attribute_name, deployment_path, model_folder_path,
118+
ARCHIVE_APPS_PREFIX, ARCHIVE_STRUCT_APPS_PREFIX)
119+
120+
if deployment_type == LIBRARY:
121+
if not deployment_path.startswith(ARCHIVE_SHLIBS_PREFIX):
122+
self._logger.severe('WLSDPLY-05240', attribute_name, deployment_path, model_folder_path,
123+
ARCHIVE_SHLIBS_PREFIX)

0 commit comments

Comments
 (0)