1
- # Copyright (c) 2021, 2022 , Oracle and/or its affiliates.
1
+ # Copyright (c) 2021, 2023 , Oracle and/or its affiliates.
2
2
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
3
3
#
4
4
# ------------
7
7
# WDT filters to prepare a model for use a target environment, using the createDomain or prepareModel tools.
8
8
# These operations can be invoked as a single call, or independently of each other.
9
9
from oracle .weblogic .deploy .util import PyRealBoolean
10
+ from oracle .weblogic .deploy .util import PyOrderedDict
10
11
from wlsdeploy .aliases import alias_utils
12
+ from wlsdeploy .aliases .model_constants import ADMIN_SERVER_NAME
11
13
from wlsdeploy .aliases .model_constants import AUTO_MIGRATION_ENABLED
12
14
from wlsdeploy .aliases .model_constants import CALCULATED_LISTEN_PORTS
13
15
from wlsdeploy .aliases .model_constants import CANDIDATE_MACHINE
14
16
from wlsdeploy .aliases .model_constants import CANDIDATE_MACHINES_FOR_MIGRATABLE_SERVER
15
17
from wlsdeploy .aliases .model_constants import CLUSTER
16
18
from wlsdeploy .aliases .model_constants import CLUSTER_MESSAGING_MODE
17
19
from wlsdeploy .aliases .model_constants import DATABASE_LESS_LEASING_BASIS
20
+ from wlsdeploy .aliases .model_constants import DEFAULT_ADMIN_SERVER_NAME
18
21
from wlsdeploy .aliases .model_constants import DYNAMIC_SERVERS
19
22
from wlsdeploy .aliases .model_constants import LISTEN_PORT
20
23
from wlsdeploy .aliases .model_constants import MACHINE
31
34
from wlsdeploy .aliases .model_constants import RESOURCE_MANAGER
32
35
from wlsdeploy .aliases .model_constants import SECURITY_CONFIGURATION
33
36
from wlsdeploy .aliases .model_constants import SERVER
37
+ from wlsdeploy .aliases .model_constants import SERVER_NAME_PREFIX
34
38
from wlsdeploy .aliases .model_constants import SERVER_START
35
39
from wlsdeploy .aliases .model_constants import SERVER_TEMPLATE
36
40
from wlsdeploy .aliases .model_constants import TOPOLOGY
45
49
from wlsdeploy .util import dictionary_utils
46
50
import wlsdeploy .util .unicode_helper as str_helper
47
51
52
+ FIX_PREFIX_TEMPLATE = '-- FIX PREFIX %s --'
53
+
48
54
_class_name = 'wko_filter'
49
55
_logger = PlatformLogger ('wlsdeploy.tool.util' )
50
56
@@ -61,6 +67,7 @@ def filter_model(model, model_context):
61
67
filter_resources (model , model_context )
62
68
filter_online_attributes (model , model_context )
63
69
check_clustered_server_ports (model , model_context )
70
+ check_dynamic_cluster_prefixes (model , model_context )
64
71
65
72
66
73
def filter_model_for_wko (model , model_context ):
@@ -73,6 +80,17 @@ def filter_model_for_wko(model, model_context):
73
80
filter_model (model , model_context )
74
81
75
82
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
+
76
94
def filter_model_for_vz (model , model_context ):
77
95
"""
78
96
Perform filtering operations on the specified model to prepare for Verrazzano deployment.
@@ -143,6 +161,71 @@ def check_clustered_server_ports(model, _model_context):
143
161
server_port_map [server_cluster ] = {"firstServer" : server_name , "serverPort" : server_port_text }
144
162
145
163
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
+
146
229
def filter_topology (model , _model_context ):
147
230
"""
148
231
Remove elements from the topology section of the model that are not relevant in a Kubernetes environment.
@@ -201,6 +284,18 @@ def filter_resources(model, _model_context):
201
284
del resources [delete_key ]
202
285
203
286
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
+
204
299
class OnlineAttributeFilter (ModelTraverse ):
205
300
"""
206
301
Traverse the model and remove any online-only attributes.
0 commit comments