Skip to content

Commit 4c1c7d5

Browse files
authored
Perform final filtering on full, merged model (#1398)
* Validate server template settings for create and prepare tools, with complete model * Added final filters to check dynamic servers and admin server for targets
1 parent e8fe3b3 commit 4c1c7d5

File tree

21 files changed

+280
-118
lines changed

21 files changed

+280
-118
lines changed

core/src/main/python/create.py

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from wlsdeploy.tool.util.archive_helper import ArchiveHelper
3636
from wlsdeploy.tool.util.wlst_helper import WlstHelper
3737
from wlsdeploy.tool.util import wlst_helper
38+
from wlsdeploy.tool.validate.content_validator import ContentValidator
3839
from wlsdeploy.util import cla_helper
3940
from wlsdeploy.util import getcreds
4041
from wlsdeploy.util import tool_main
@@ -313,6 +314,10 @@ def main(model_context):
313314
model_dictionary = cla_helper.load_model(_program_name, model_context, aliases, "create", __wlst_mode,
314315
validate_crd_sections=False)
315316

317+
# check for any content problems in the merged, substituted model
318+
content_validator = ContentValidator(model_context)
319+
content_validator.validate_model(model_dictionary)
320+
316321
archive_helper = None
317322
archive_file_name = model_context.get_archive_file_name()
318323
if archive_file_name:

core/src/main/python/discover.py

+2
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,8 @@ def __check_and_customize_model(model, model_context, aliases, credential_inject
498498
if filter_helper.apply_filters(model.get_model(), "discover", model_context):
499499
__logger.info('WLSDPLY-06014', _class_name=_class_name, method_name=_method_name)
500500

501+
filter_helper.apply_final_filters(model.get_model(), model.get_model(), model_context)
502+
501503
# target config always present in model context, default config if not declared
502504
target_configuration = model_context.get_target_configuration()
503505

core/src/main/python/wlsdeploy/tool/prepare/model_preparer.py

+23
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from wlsdeploy.tool.util.credential_injector import CredentialInjector
2424
from wlsdeploy.tool.util.variable_injector import VARIABLE_FILE_UPDATE
2525
from wlsdeploy.tool.util.variable_injector import VariableInjector
26+
from wlsdeploy.tool.validate.content_validator import ContentValidator
2627
from wlsdeploy.tool.validate.validator import Validator
2728
from wlsdeploy.util import cla_helper
2829
from wlsdeploy.util import model
@@ -271,6 +272,21 @@ def _clean_archive_files(self):
271272
if self.model_context.get_target_configuration().exclude_domain_bin_contents():
272273
archive_helper.remove_domain_scripts()
273274

275+
def _apply_final_filters(self, model_dictionary):
276+
"""
277+
Apply final filters to the merged model dictionary,
278+
and apply any updates to the last model in the command-line list.
279+
"""
280+
model_file_list = self.model_files.split(',')
281+
last_file = model_file_list[-1]
282+
update_file = os.path.join(self.output_dir, os.path.basename(last_file))
283+
284+
update_model_dict = FileToPython(update_file, True).parse()
285+
filter_helper.apply_final_filters(model_dictionary, update_model_dict, self.model_context)
286+
287+
pty = PythonToYaml(update_model_dict)
288+
pty.write_to_yaml_file(update_file)
289+
274290
def prepare_models(self):
275291
"""
276292
Replace password attributes in each model file with secret tokens, and write each model.
@@ -367,6 +383,13 @@ def prepare_models(self):
367383
# correct any secret values that point to @@PROP values
368384
self.fix_property_secrets(variable_map)
369385

386+
# apply final filter changes for the merged model to the last source model
387+
self._apply_final_filters(merged_model_dictionary)
388+
389+
# check for any content problems in the merged, substituted model
390+
content_validator = ContentValidator(self.model_context)
391+
content_validator.validate_model(merged_model_dictionary)
392+
370393
target_configuration_helper.generate_all_output_files(Model(merged_model_dictionary), self._aliases,
371394
self.credential_injector, self.model_context,
372395
ExceptionType.PREPARE)

core/src/main/python/wlsdeploy/tool/util/filter_helper.py

+43-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from wlsdeploy.logging.platform_logger import PlatformLogger
1010
from wlsdeploy.tool.util.filters import wko_filter
11+
from wlsdeploy.tool.util.filters import wko_final_filter
1112
from wlsdeploy.util import dictionary_utils
1213
from wlsdeploy.util import path_utils
1314
from wlsdeploy.util.model_translator import FileToPython
@@ -23,7 +24,6 @@
2324
'k8s_filter': wko_filter.filter_model,
2425
'vz_filter': wko_filter.filter_model_for_vz,
2526
'wko_filter': wko_filter.filter_model_for_wko,
26-
'wko3_filter': wko_filter.filter_model_for_wko3,
2727

2828
# individual filters for custom target environments
2929
'online_attributes_filter': wko_filter.filter_online_attributes,
@@ -32,6 +32,15 @@
3232
'server_ports_filter': wko_filter.check_clustered_server_ports
3333
}
3434

35+
# final filters run against the merged, substituted model.
36+
__final_filter_map = {
37+
# groups that execute multiple filters
38+
'k8s_final_filter': wko_final_filter.filter_final_model,
39+
'vz_final_filter': wko_final_filter.filter_final_model_for_vz,
40+
'wko_final_filter': wko_final_filter.filter_final_model_for_wko,
41+
'wko3_final_filter': wko_final_filter.filter_final_model_for_wko3,
42+
}
43+
3544

3645
def apply_filters(model, tool_type, model_context):
3746
"""
@@ -87,6 +96,39 @@ def apply_filters(model, tool_type, model_context):
8796
return filter_applied
8897

8998

99+
def apply_final_filters(model, update_model, model_context):
100+
"""
101+
Apply any final filters configured to the specified model.
102+
:param model: the model to be filtered
103+
:param update_model: the model to be updated with any changes
104+
:param model_context: used to find target filters
105+
:return: True if any filter was applied, False otherwise
106+
:raises: BundleAwareException of the specified type: if an error occurs
107+
"""
108+
_method_name = 'apply_final_filters'
109+
110+
filter_applied = False
111+
112+
try:
113+
final_filters = model_context.get_target_configuration().get_final_model_filters()
114+
for final_filter in final_filters:
115+
filter_id = dictionary_utils.get_element(final_filter, 'id')
116+
filter_method = dictionary_utils.get_element(__final_filter_map, filter_id)
117+
if filter_method is None:
118+
__logger.severe('WLSDPLY-20037', str_helper.to_string(filter_id), class_name=__class_name,
119+
method_name=_method_name)
120+
return False
121+
else:
122+
filter_method(model, update_model, model_context)
123+
return True
124+
125+
except Exception, ex:
126+
__logger.severe('WLSDPLY-20038', str_helper.to_string(ex), error=ex, class_name=__class_name,
127+
method_name=_method_name)
128+
129+
return filter_applied
130+
131+
90132
def _apply_filter(model, the_filter, model_context, filter_file_location):
91133
"""
92134
Apply the specified filter to the specified model.

core/src/main/python/wlsdeploy/tool/util/filters/wko_filter.py

-95
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,14 @@
77
# WDT filters to prepare a model for use a target environment, using the createDomain or prepareModel tools.
88
# These operations can be invoked as a single call, or independently of each other.
99
from oracle.weblogic.deploy.util import PyRealBoolean
10-
from oracle.weblogic.deploy.util import PyOrderedDict
1110
from wlsdeploy.aliases import alias_utils
12-
from wlsdeploy.aliases.model_constants import ADMIN_SERVER_NAME
1311
from wlsdeploy.aliases.model_constants import AUTO_MIGRATION_ENABLED
1412
from wlsdeploy.aliases.model_constants import CALCULATED_LISTEN_PORTS
1513
from wlsdeploy.aliases.model_constants import CANDIDATE_MACHINE
1614
from wlsdeploy.aliases.model_constants import CANDIDATE_MACHINES_FOR_MIGRATABLE_SERVER
1715
from wlsdeploy.aliases.model_constants import CLUSTER
1816
from wlsdeploy.aliases.model_constants import CLUSTER_MESSAGING_MODE
1917
from wlsdeploy.aliases.model_constants import DATABASE_LESS_LEASING_BASIS
20-
from wlsdeploy.aliases.model_constants import DEFAULT_ADMIN_SERVER_NAME
2118
from wlsdeploy.aliases.model_constants import DYNAMIC_SERVERS
2219
from wlsdeploy.aliases.model_constants import LISTEN_PORT
2320
from wlsdeploy.aliases.model_constants import MACHINE
@@ -34,7 +31,6 @@
3431
from wlsdeploy.aliases.model_constants import RESOURCE_MANAGER
3532
from wlsdeploy.aliases.model_constants import SECURITY_CONFIGURATION
3633
from wlsdeploy.aliases.model_constants import SERVER
37-
from wlsdeploy.aliases.model_constants import SERVER_NAME_PREFIX
3834
from wlsdeploy.aliases.model_constants import SERVER_START
3935
from wlsdeploy.aliases.model_constants import SERVER_TEMPLATE
4036
from wlsdeploy.aliases.model_constants import TOPOLOGY
@@ -49,8 +45,6 @@
4945
from wlsdeploy.util import dictionary_utils
5046
import wlsdeploy.util.unicode_helper as str_helper
5147

52-
FIX_PREFIX_TEMPLATE = '-- FIX PREFIX %s --'
53-
5448
_class_name = 'wko_filter'
5549
_logger = PlatformLogger('wlsdeploy.tool.util')
5650

@@ -67,7 +61,6 @@ def filter_model(model, model_context):
6761
filter_resources(model, model_context)
6862
filter_online_attributes(model, model_context)
6963
check_clustered_server_ports(model, model_context)
70-
check_dynamic_cluster_prefixes(model, model_context)
7164

7265

7366
def filter_model_for_wko(model, model_context):
@@ -80,17 +73,6 @@ def filter_model_for_wko(model, model_context):
8073
filter_model(model, model_context)
8174

8275

83-
def filter_model_for_wko3(model, model_context):
84-
"""
85-
Perform filtering operations on the specified model to prepare for WKO deployment.
86-
Currently matches the general k8s target filtering.
87-
:param model: the model to be filtered
88-
:param model_context: used by nested filters
89-
"""
90-
filter_model(model, model_context)
91-
check_admin_server_defined(model, model_context)
92-
93-
9476
def filter_model_for_vz(model, model_context):
9577
"""
9678
Perform filtering operations on the specified model to prepare for Verrazzano deployment.
@@ -161,71 +143,6 @@ def check_clustered_server_ports(model, _model_context):
161143
server_port_map[server_cluster] = {"firstServer": server_name, "serverPort": server_port_text}
162144

163145

164-
def check_dynamic_cluster_prefixes(model, _model_context):
165-
"""
166-
All Dynamic Clusters must have a DynamicServers section with the ServerNamePrefix field explicitly declared.
167-
Ensure each cluster uses a unique value for this field.
168-
:param model: the model to be updated
169-
:param _model_context: unused, passed by filter_helper if called independently
170-
:return:
171-
"""
172-
_method_name = 'check_dynamic_cluster_prefixes'
173-
174-
server_name_prefixes = []
175-
topology_folder = dictionary_utils.get_dictionary_element(model, TOPOLOGY)
176-
clusters_folder = dictionary_utils.get_dictionary_element(topology_folder, CLUSTER)
177-
for cluster_name, cluster_fields in clusters_folder.items():
178-
dynamic_folder = dictionary_utils.get_element(cluster_fields, DYNAMIC_SERVERS)
179-
if dynamic_folder:
180-
server_name_prefix = dictionary_utils.get_element(dynamic_folder, SERVER_NAME_PREFIX)
181-
182-
if not server_name_prefix:
183-
_logger.warning('WLSDPLY-20204', cluster_name, SERVER_NAME_PREFIX, class_name=_class_name,
184-
method_name=_method_name)
185-
server_name_prefix = _get_unused_prefix(server_name_prefixes)
186-
dynamic_folder[SERVER_NAME_PREFIX] = server_name_prefix
187-
188-
elif server_name_prefix in server_name_prefixes:
189-
_logger.warning('WLSDPLY-20205', SERVER_NAME_PREFIX, server_name_prefix, class_name=_class_name,
190-
method_name=_method_name)
191-
server_name_prefix = _get_unused_prefix(server_name_prefixes)
192-
dynamic_folder[SERVER_NAME_PREFIX] = server_name_prefix
193-
194-
server_name_prefixes.append(server_name_prefix)
195-
196-
197-
def check_admin_server_defined(model, _model_context):
198-
"""
199-
Ensure that the AdminServerName attribute is set, and that the server is defined.
200-
This is required by WKO 3.0, and not by 4.0 and later.
201-
:param model: the model to be filtered
202-
:param _model_context: unused, passed by filter_helper if called independently
203-
"""
204-
_method_name = 'check_admin_server_defined'
205-
206-
topology_folder = dictionary_utils.get_element(model, TOPOLOGY)
207-
if topology_folder is None:
208-
# for cases with multiple models, avoid adding topology and admin server for
209-
# models with only resources, applications, etc.
210-
return
211-
212-
admin_server_name = dictionary_utils.get_element(topology_folder, ADMIN_SERVER_NAME)
213-
if not admin_server_name:
214-
admin_server_name = DEFAULT_ADMIN_SERVER_NAME
215-
_logger.info('WLSDPLY-20206', ADMIN_SERVER_NAME, admin_server_name, class_name=_class_name,
216-
method_name=_method_name)
217-
topology_folder[ADMIN_SERVER_NAME] = admin_server_name
218-
219-
servers_folder = dictionary_utils.get_element(topology_folder, SERVER)
220-
if servers_folder is None:
221-
servers_folder = PyOrderedDict()
222-
topology_folder[SERVER] = servers_folder
223-
224-
if admin_server_name not in servers_folder:
225-
_logger.info('WLSDPLY-20207', SERVER, admin_server_name, class_name=_class_name, method_name=_method_name)
226-
servers_folder[admin_server_name] = PyOrderedDict()
227-
228-
229146
def filter_topology(model, _model_context):
230147
"""
231148
Remove elements from the topology section of the model that are not relevant in a Kubernetes environment.
@@ -284,18 +201,6 @@ def filter_resources(model, _model_context):
284201
del resources[delete_key]
285202

286203

287-
def _get_unused_prefix(used_prefixes):
288-
"""
289-
Find a recognizable, unused prefix that can be used in the filtered model.
290-
:param used_prefixes: prefixes that have already been used in the model
291-
:return: an unused prefix
292-
"""
293-
i = 1
294-
while FIX_PREFIX_TEMPLATE % i in used_prefixes:
295-
i += 1
296-
return FIX_PREFIX_TEMPLATE % i
297-
298-
299204
class OnlineAttributeFilter(ModelTraverse):
300205
"""
301206
Traverse the model and remove any online-only attributes.

0 commit comments

Comments
 (0)