Skip to content

Commit 39b2b69

Browse files
authored
Set domain type in domain resource templates (#1135)
* Assign default extract target type before processing arguments * Set domain type in domain resource templates; validate target configuration in class * Clarified comment about model content inclusion
1 parent 0d3941f commit 39b2b69

File tree

12 files changed

+93
-33
lines changed

12 files changed

+93
-33
lines changed

core/src/main/python/extract_resource.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ def __process_args(args):
6262
"""
6363
_method_name = '__process_args'
6464

65+
# if no target type was specified, use wko
66+
if CommandLineArgUtil.TARGET_SWITCH not in args:
67+
args.append(CommandLineArgUtil.TARGET_SWITCH)
68+
args.append('wko')
69+
6570
cla_util = CommandLineArgUtil(_program_name, __required_arguments, __optional_arguments)
6671
cla_util.set_allow_multiple_models(True)
6772
argument_map = cla_util.process_args(args, TOOL_TYPE_EXTRACT)
@@ -76,10 +81,6 @@ def __process_args(args):
7681
# allow unresolved tokens and archive entries
7782
argument_map[CommandLineArgUtil.VALIDATION_METHOD] = validate_configuration.LAX_METHOD
7883

79-
# if no target type was specified, use wko
80-
if CommandLineArgUtil.TARGET_SWITCH not in argument_map:
81-
argument_map[CommandLineArgUtil.TARGET_SWITCH] = 'wko'
82-
8384
# warn about deprecated -domain_resource_file argument.
8485
# not needed once -domain_resource_file is removed and -output_dir moves to __required_arguments.
8586
if CommandLineArgUtil.DOMAIN_RESOURCE_FILE_SWITCH in argument_map:

core/src/main/python/wlsdeploy/tool/util/targets/additional_output_helper.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
DATASOURCES = 'datasources'
4242
DATASOURCE_NAME = 'datasourceName'
4343
DATASOURCE_URL = 'url'
44+
DOMAIN_HOME_SOURCE_TYPE = 'domainHomeSourceType'
4445
DOMAIN_NAME = 'domainName'
4546
DOMAIN_PREFIX = 'domainPrefix'
4647
DOMAIN_TYPE = 'domainType'
@@ -49,6 +50,7 @@
4950
HAS_APPLICATIONS = 'hasApplications'
5051
HAS_CLUSTERS = 'hasClusters'
5152
HAS_DATASOURCES = 'hasDatasources'
53+
HAS_MODEL = 'hasModel'
5254
NAMESPACE = 'namespace'
5355
REPLICAS = 'replicas'
5456
RUNTIME_ENCRYPTION_SECRET = "runtimeEncryptionSecret"
@@ -154,6 +156,10 @@ def _build_template_hash(model, model_context, aliases, credential_injector):
154156
template_hash[DOMAIN_PREFIX] = domain_uid
155157
template_hash[NAMESPACE] = domain_uid
156158

159+
# domain home source type
160+
template_hash[DOMAIN_HOME_SOURCE_TYPE] = target_configuration.get_domain_home_source_name()
161+
template_hash[HAS_MODEL] = target_configuration.uses_wdt_model()
162+
157163
# secrets that should not be included in secrets section
158164
declared_secrets = []
159165

core/src/main/python/wlsdeploy/util/cla_utils.py

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@
2121
from wlsdeploy.json.json_translator import JsonToPython
2222
from wlsdeploy.logging.platform_logger import PlatformLogger
2323
from wlsdeploy.util import path_utils
24-
from wlsdeploy.util import validate_configuration
25-
from wlsdeploy.util.target_configuration import CREDENTIALS_METHOD
26-
from wlsdeploy.util.target_configuration import CREDENTIALS_METHODS
2724
from wlsdeploy.util.target_configuration import TargetConfiguration
28-
from wlsdeploy.util.target_configuration import VALIDATION_METHOD
2925
from wlsdeploy.util.validate_configuration import VALIDATION_METHODS
3026

3127
# tool type may indicate variations in argument processing
@@ -1115,29 +1111,9 @@ def _validate_target_arg(self, value):
11151111
else:
11161112
try:
11171113
# verify the file is in proper format
1118-
# file_handle = open(target_configuration_file)
1119-
# config_dictionary = eval(file_handle.read())
11201114
config_dictionary = JsonToPython(target_configuration_file).parse()
11211115
target_configuration = TargetConfiguration(config_dictionary)
1122-
validation_method = target_configuration.get_validation_method()
1123-
if (validation_method is not None) and \
1124-
(validation_method not in validate_configuration.VALIDATION_METHODS):
1125-
ex = exception_helper.create_cla_exception(self.ARG_VALIDATION_ERROR_EXIT_CODE,
1126-
'WLSDPLY-01648', target_configuration_file,
1127-
validation_method, VALIDATION_METHOD,
1128-
', '.join(validate_configuration.VALIDATION_METHODS))
1129-
self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
1130-
raise ex
1131-
1132-
credentials_method = target_configuration.get_credentials_method()
1133-
if (credentials_method is not None) and (credentials_method not in CREDENTIALS_METHODS):
1134-
ex = exception_helper.create_cla_exception(self.ARG_VALIDATION_ERROR_EXIT_CODE,
1135-
'WLSDPLY-01648', target_configuration_file,
1136-
credentials_method, CREDENTIALS_METHOD,
1137-
', '.join(CREDENTIALS_METHODS))
1138-
self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
1139-
raise ex
1140-
1116+
target_configuration.validate_configuration(self.ARG_VALIDATION_ERROR_EXIT_CODE, target_configuration_file)
11411117
except SyntaxError, se:
11421118
ex = exception_helper.create_cla_exception(self.ARG_VALIDATION_ERROR_EXIT_CODE,
11431119
'WLSDPLY-01644', target_configuration_file, se)

core/src/main/python/wlsdeploy/util/target_configuration.py

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
Copyright (c) 2020, 2022, Oracle and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
5-
5+
from wlsdeploy.exception import exception_helper
6+
from wlsdeploy.logging.platform_logger import PlatformLogger
67
from wlsdeploy.util import dictionary_utils
8+
from wlsdeploy.util.validate_configuration import VALIDATION_METHODS
79

810
# types for credential method
911
CREDENTIALS_METHOD = "credentials_method"
@@ -21,6 +23,9 @@
2123
# Determines whether a persistent volume is used
2224
USE_PERSISTENT_VOLUME = "use_persistent_volume"
2325

26+
# Determines the type of domain used
27+
DOMAIN_HOME_SOURCE_TYPE = "domain_home_source_type"
28+
2429
# put secret tokens in the model, and build a script to create the secrets.
2530
SECRETS_METHOD = 'secrets'
2631

@@ -32,12 +37,24 @@
3237
CONFIG_OVERRIDES_SECRETS_METHOD
3338
]
3439

40+
# domain home source types and names
41+
DOMAIN_IN_IMAGE_SOURCE_TYPE = 'dii'
42+
MODEL_IN_IMAGE_SOURCE_TYPE = 'mii'
43+
PERSISTENT_VOLUME_SOURCE_TYPE = 'pv'
44+
45+
SOURCE_TYPE_NAMES = {
46+
DOMAIN_IN_IMAGE_SOURCE_TYPE: 'Image',
47+
MODEL_IN_IMAGE_SOURCE_TYPE: 'FromModel',
48+
PERSISTENT_VOLUME_SOURCE_TYPE: 'PersistentVolume'
49+
}
50+
3551

3652
class TargetConfiguration(object):
3753
"""
3854
Provide access to fields in the target.json JSON file of a target environment.
3955
"""
40-
_class_name = 'TargetEnvironment'
56+
_class_name = 'TargetConfiguration'
57+
_logger = PlatformLogger('wlsdeploy.util')
4158

4259
def __init__(self, config_dictionary):
4360
"""
@@ -162,3 +179,53 @@ def use_persistent_volume(self):
162179
if result is None:
163180
result = False
164181
return result
182+
183+
def uses_wdt_model(self):
184+
"""
185+
Determine if this configuration will include WDT model content in the output file.
186+
WKO builds the domain using this model content for the model-in-image source type.
187+
:return: True if a model is included, False otherwise
188+
"""
189+
source_type = self._get_domain_home_source_type()
190+
return source_type == MODEL_IN_IMAGE_SOURCE_TYPE
191+
192+
def get_domain_home_source_name(self):
193+
"""
194+
Return the name associated with the domain home source type key.
195+
:return: the domain home source name
196+
"""
197+
source_type = self._get_domain_home_source_type()
198+
return SOURCE_TYPE_NAMES[source_type]
199+
200+
def validate_configuration(self, exit_code, target_configuration_file):
201+
validation_method = self.get_validation_method()
202+
self._validate_enumerated_field(VALIDATION_METHOD, validation_method, VALIDATION_METHODS, exit_code,
203+
target_configuration_file)
204+
205+
credentials_method = self.get_credentials_method()
206+
self._validate_enumerated_field(CREDENTIALS_METHOD, credentials_method, CREDENTIALS_METHODS, exit_code,
207+
target_configuration_file)
208+
209+
source_type = self._get_domain_home_source_type()
210+
self._validate_enumerated_field(DOMAIN_HOME_SOURCE_TYPE, source_type, SOURCE_TYPE_NAMES.keys(), exit_code,
211+
target_configuration_file)
212+
213+
###################
214+
# Private methods #
215+
###################
216+
217+
def _get_domain_home_source_type(self):
218+
"""
219+
Get the domain home source type (private method).
220+
:return: the domain home source type key, or the default MODEL_IN_IMAGE_SOURCE_TYPE
221+
"""
222+
source_type = dictionary_utils.get_element(self.config_dictionary, DOMAIN_HOME_SOURCE_TYPE)
223+
return source_type or MODEL_IN_IMAGE_SOURCE_TYPE
224+
225+
def _validate_enumerated_field(self, key, value, valid_values, exit_code, target_configuration_file):
226+
method_name = '_validate_enumerated_field'
227+
if (value is not None) and (value not in valid_values):
228+
ex = exception_helper.create_cla_exception(exit_code, 'WLSDPLY-01648', target_configuration_file,
229+
value, key, ', '.join(valid_values))
230+
self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
231+
raise ex

core/src/main/targetconfigs/templates/vz-application.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ spec:
5252

5353
# WebLogic Image Tool provides domainHome, domainHomeSourceType, and imageName
5454
domainHome: '{{{domainHome}}}'
55-
domainHomeSourceType: '{{{domainHomeSourceType}}}'
55+
domainHomeSourceType: {{{domainHomeSourceType}}}
5656
image: '{{{imageName}}}'
5757

5858
imagePullSecrets:
@@ -62,6 +62,7 @@ spec:
6262
name: {{{webLogicCredentialsSecret}}}
6363
configuration:
6464
introspectorJobActiveDeadlineSeconds: 900
65+
{{#hasModel}}
6566
model:
6667
configMap: {{{domainPrefix}}}-configmap
6768
domainType: {{{domainType}}}
@@ -74,6 +75,7 @@ spec:
7475
# used only for model-in-image deployment, can be removed for other types.
7576
runtimeEncryptionSecret: {{{runtimeEncryptionSecret}}}
7677
{{/runtimeEncryptionSecret}}
78+
{{/hasModel}}
7779
{{#hasAdditionalSecrets}}
7880

7981
secrets:

core/src/main/targetconfigs/templates/wko-domain.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ spec:
1414

1515
# The domain home source type
1616
# Set to PersistentVolume for domain-in-pv, Image for domain-in-image, or FromModel for model-in-image
17-
domainHomeSourceType: '{{{domainHomeSourceType}}}'
17+
domainHomeSourceType: {{{domainHomeSourceType}}}
1818

1919
# The WebLogic Server Docker image that the Operator uses to start the domain
2020
image: '{{{imageName}}}'
@@ -77,6 +77,7 @@ spec:
7777
istio:
7878
enabled: false
7979
introspectorJobActiveDeadlineSeconds: 900
80+
{{#hasModel}}
8081
model:
8182
domainType: {{{domainType}}}
8283

@@ -88,6 +89,7 @@ spec:
8889
# used only for model-in-image deployment, can be removed for other types.
8990
runtimeEncryptionSecret: {{{runtimeEncryptionSecret}}}
9091
{{/runtimeEncryptionSecret}}
92+
{{/hasModel}}
9193
{{#hasAdditionalSecrets}}
9294

9395
# Secrets that are referenced by model yaml macros

core/src/main/targetconfigs/vz-dii/target.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
},
77
"variable_injectors" : {"PORT": {},"HOST": {},"URL": {}},
88
"validation_method" : "lax",
9+
"domain_home_source_type" : "dii",
910
"credentials_output_method" : "script",
1011
"exclude_domain_bin_contents": true,
1112
"additional_output" : "vz-application.yaml"

core/src/main/targetconfigs/vz-pv/target.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
},
77
"variable_injectors" : {"PORT": {},"HOST": {},"URL": {}},
88
"validation_method" : "lax",
9+
"domain_home_source_type" : "pv",
910
"credentials_output_method" : "script",
1011
"exclude_domain_bin_contents": true,
1112
"use_persistent_volume" : true,

core/src/main/targetconfigs/vz/target.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
},
88
"variable_injectors" : {"PORT": {},"HOST": {},"URL": {}},
99
"validation_method" : "lax",
10+
"domain_home_source_type" : "mii",
1011
"credentials_method" : "secrets",
1112
"credentials_output_method" : "script",
1213
"exclude_domain_bin_contents": true,

core/src/main/targetconfigs/wko-dii/target.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
},
77
"variable_injectors" : {"PORT": {},"HOST": {},"URL": {}},
88
"validation_method" : "lax",
9+
"domain_home_source_type" : "dii",
910
"credentials_output_method" : "script",
1011
"exclude_domain_bin_contents": true,
1112
"additional_output" : "wko-domain.yaml"

0 commit comments

Comments
 (0)