Skip to content

Set domain type in domain resource templates #1135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions core/src/main/python/extract_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ def __process_args(args):
"""
_method_name = '__process_args'

# if no target type was specified, use wko
if CommandLineArgUtil.TARGET_SWITCH not in args:
args.append(CommandLineArgUtil.TARGET_SWITCH)
args.append('wko')

cla_util = CommandLineArgUtil(_program_name, __required_arguments, __optional_arguments)
cla_util.set_allow_multiple_models(True)
argument_map = cla_util.process_args(args, TOOL_TYPE_EXTRACT)
Expand All @@ -76,10 +81,6 @@ def __process_args(args):
# allow unresolved tokens and archive entries
argument_map[CommandLineArgUtil.VALIDATION_METHOD] = validate_configuration.LAX_METHOD

# if no target type was specified, use wko
if CommandLineArgUtil.TARGET_SWITCH not in argument_map:
argument_map[CommandLineArgUtil.TARGET_SWITCH] = 'wko'

# warn about deprecated -domain_resource_file argument.
# not needed once -domain_resource_file is removed and -output_dir moves to __required_arguments.
if CommandLineArgUtil.DOMAIN_RESOURCE_FILE_SWITCH in argument_map:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
DATASOURCES = 'datasources'
DATASOURCE_NAME = 'datasourceName'
DATASOURCE_URL = 'url'
DOMAIN_HOME_SOURCE_TYPE = 'domainHomeSourceType'
DOMAIN_NAME = 'domainName'
DOMAIN_PREFIX = 'domainPrefix'
DOMAIN_TYPE = 'domainType'
Expand All @@ -49,6 +50,7 @@
HAS_APPLICATIONS = 'hasApplications'
HAS_CLUSTERS = 'hasClusters'
HAS_DATASOURCES = 'hasDatasources'
HAS_MODEL = 'hasModel'
NAMESPACE = 'namespace'
REPLICAS = 'replicas'
RUNTIME_ENCRYPTION_SECRET = "runtimeEncryptionSecret"
Expand Down Expand Up @@ -154,6 +156,10 @@ def _build_template_hash(model, model_context, aliases, credential_injector):
template_hash[DOMAIN_PREFIX] = domain_uid
template_hash[NAMESPACE] = domain_uid

# domain home source type
template_hash[DOMAIN_HOME_SOURCE_TYPE] = target_configuration.get_domain_home_source_name()
template_hash[HAS_MODEL] = target_configuration.uses_wdt_model()

# secrets that should not be included in secrets section
declared_secrets = []

Expand Down
26 changes: 1 addition & 25 deletions core/src/main/python/wlsdeploy/util/cla_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@
from wlsdeploy.json.json_translator import JsonToPython
from wlsdeploy.logging.platform_logger import PlatformLogger
from wlsdeploy.util import path_utils
from wlsdeploy.util import validate_configuration
from wlsdeploy.util.target_configuration import CREDENTIALS_METHOD
from wlsdeploy.util.target_configuration import CREDENTIALS_METHODS
from wlsdeploy.util.target_configuration import TargetConfiguration
from wlsdeploy.util.target_configuration import VALIDATION_METHOD
from wlsdeploy.util.validate_configuration import VALIDATION_METHODS

# tool type may indicate variations in argument processing
Expand Down Expand Up @@ -1115,29 +1111,9 @@ def _validate_target_arg(self, value):
else:
try:
# verify the file is in proper format
# file_handle = open(target_configuration_file)
# config_dictionary = eval(file_handle.read())
config_dictionary = JsonToPython(target_configuration_file).parse()
target_configuration = TargetConfiguration(config_dictionary)
validation_method = target_configuration.get_validation_method()
if (validation_method is not None) and \
(validation_method not in validate_configuration.VALIDATION_METHODS):
ex = exception_helper.create_cla_exception(self.ARG_VALIDATION_ERROR_EXIT_CODE,
'WLSDPLY-01648', target_configuration_file,
validation_method, VALIDATION_METHOD,
', '.join(validate_configuration.VALIDATION_METHODS))
self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
raise ex

credentials_method = target_configuration.get_credentials_method()
if (credentials_method is not None) and (credentials_method not in CREDENTIALS_METHODS):
ex = exception_helper.create_cla_exception(self.ARG_VALIDATION_ERROR_EXIT_CODE,
'WLSDPLY-01648', target_configuration_file,
credentials_method, CREDENTIALS_METHOD,
', '.join(CREDENTIALS_METHODS))
self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
raise ex

target_configuration.validate_configuration(self.ARG_VALIDATION_ERROR_EXIT_CODE, target_configuration_file)
except SyntaxError, se:
ex = exception_helper.create_cla_exception(self.ARG_VALIDATION_ERROR_EXIT_CODE,
'WLSDPLY-01644', target_configuration_file, se)
Expand Down
71 changes: 69 additions & 2 deletions core/src/main/python/wlsdeploy/util/target_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
Copyright (c) 2020, 2022, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
"""

from wlsdeploy.exception import exception_helper
from wlsdeploy.logging.platform_logger import PlatformLogger
from wlsdeploy.util import dictionary_utils
from wlsdeploy.util.validate_configuration import VALIDATION_METHODS

# types for credential method
CREDENTIALS_METHOD = "credentials_method"
Expand All @@ -21,6 +23,9 @@
# Determines whether a persistent volume is used
USE_PERSISTENT_VOLUME = "use_persistent_volume"

# Determines the type of domain used
DOMAIN_HOME_SOURCE_TYPE = "domain_home_source_type"

# put secret tokens in the model, and build a script to create the secrets.
SECRETS_METHOD = 'secrets'

Expand All @@ -32,12 +37,24 @@
CONFIG_OVERRIDES_SECRETS_METHOD
]

# domain home source types and names
DOMAIN_IN_IMAGE_SOURCE_TYPE = 'dii'
MODEL_IN_IMAGE_SOURCE_TYPE = 'mii'
PERSISTENT_VOLUME_SOURCE_TYPE = 'pv'

SOURCE_TYPE_NAMES = {
DOMAIN_IN_IMAGE_SOURCE_TYPE: 'Image',
MODEL_IN_IMAGE_SOURCE_TYPE: 'FromModel',
PERSISTENT_VOLUME_SOURCE_TYPE: 'PersistentVolume'
}


class TargetConfiguration(object):
"""
Provide access to fields in the target.json JSON file of a target environment.
"""
_class_name = 'TargetEnvironment'
_class_name = 'TargetConfiguration'
_logger = PlatformLogger('wlsdeploy.util')

def __init__(self, config_dictionary):
"""
Expand Down Expand Up @@ -162,3 +179,53 @@ def use_persistent_volume(self):
if result is None:
result = False
return result

def uses_wdt_model(self):
"""
Determine if this configuration will include WDT model content in the output file.
WKO builds the domain using this model content for the model-in-image source type.
:return: True if a model is included, False otherwise
"""
source_type = self._get_domain_home_source_type()
return source_type == MODEL_IN_IMAGE_SOURCE_TYPE

def get_domain_home_source_name(self):
"""
Return the name associated with the domain home source type key.
:return: the domain home source name
"""
source_type = self._get_domain_home_source_type()
return SOURCE_TYPE_NAMES[source_type]

def validate_configuration(self, exit_code, target_configuration_file):
validation_method = self.get_validation_method()
self._validate_enumerated_field(VALIDATION_METHOD, validation_method, VALIDATION_METHODS, exit_code,
target_configuration_file)

credentials_method = self.get_credentials_method()
self._validate_enumerated_field(CREDENTIALS_METHOD, credentials_method, CREDENTIALS_METHODS, exit_code,
target_configuration_file)

source_type = self._get_domain_home_source_type()
self._validate_enumerated_field(DOMAIN_HOME_SOURCE_TYPE, source_type, SOURCE_TYPE_NAMES.keys(), exit_code,
target_configuration_file)

###################
# Private methods #
###################

def _get_domain_home_source_type(self):
"""
Get the domain home source type (private method).
:return: the domain home source type key, or the default MODEL_IN_IMAGE_SOURCE_TYPE
"""
source_type = dictionary_utils.get_element(self.config_dictionary, DOMAIN_HOME_SOURCE_TYPE)
return source_type or MODEL_IN_IMAGE_SOURCE_TYPE

def _validate_enumerated_field(self, key, value, valid_values, exit_code, target_configuration_file):
method_name = '_validate_enumerated_field'
if (value is not None) and (value not in valid_values):
ex = exception_helper.create_cla_exception(exit_code, 'WLSDPLY-01648', target_configuration_file,
value, key, ', '.join(valid_values))
self._logger.throwing(ex, class_name=self._class_name, method_name=method_name)
raise ex
4 changes: 3 additions & 1 deletion core/src/main/targetconfigs/templates/vz-application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ spec:

# WebLogic Image Tool provides domainHome, domainHomeSourceType, and imageName
domainHome: '{{{domainHome}}}'
domainHomeSourceType: '{{{domainHomeSourceType}}}'
domainHomeSourceType: {{{domainHomeSourceType}}}
image: '{{{imageName}}}'

imagePullSecrets:
Expand All @@ -62,6 +62,7 @@ spec:
name: {{{webLogicCredentialsSecret}}}
configuration:
introspectorJobActiveDeadlineSeconds: 900
{{#hasModel}}
model:
configMap: {{{domainPrefix}}}-configmap
domainType: {{{domainType}}}
Expand All @@ -74,6 +75,7 @@ spec:
# used only for model-in-image deployment, can be removed for other types.
runtimeEncryptionSecret: {{{runtimeEncryptionSecret}}}
{{/runtimeEncryptionSecret}}
{{/hasModel}}
{{#hasAdditionalSecrets}}

secrets:
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/targetconfigs/templates/wko-domain.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spec:

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

# The WebLogic Server Docker image that the Operator uses to start the domain
image: '{{{imageName}}}'
Expand Down Expand Up @@ -77,6 +77,7 @@ spec:
istio:
enabled: false
introspectorJobActiveDeadlineSeconds: 900
{{#hasModel}}
model:
domainType: {{{domainType}}}

Expand All @@ -88,6 +89,7 @@ spec:
# used only for model-in-image deployment, can be removed for other types.
runtimeEncryptionSecret: {{{runtimeEncryptionSecret}}}
{{/runtimeEncryptionSecret}}
{{/hasModel}}
{{#hasAdditionalSecrets}}

# Secrets that are referenced by model yaml macros
Expand Down
1 change: 1 addition & 0 deletions core/src/main/targetconfigs/vz-dii/target.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"variable_injectors" : {"PORT": {},"HOST": {},"URL": {}},
"validation_method" : "lax",
"domain_home_source_type" : "dii",
"credentials_output_method" : "script",
"exclude_domain_bin_contents": true,
"additional_output" : "vz-application.yaml"
Expand Down
1 change: 1 addition & 0 deletions core/src/main/targetconfigs/vz-pv/target.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"variable_injectors" : {"PORT": {},"HOST": {},"URL": {}},
"validation_method" : "lax",
"domain_home_source_type" : "pv",
"credentials_output_method" : "script",
"exclude_domain_bin_contents": true,
"use_persistent_volume" : true,
Expand Down
1 change: 1 addition & 0 deletions core/src/main/targetconfigs/vz/target.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"variable_injectors" : {"PORT": {},"HOST": {},"URL": {}},
"validation_method" : "lax",
"domain_home_source_type" : "mii",
"credentials_method" : "secrets",
"credentials_output_method" : "script",
"exclude_domain_bin_contents": true,
Expand Down
1 change: 1 addition & 0 deletions core/src/main/targetconfigs/wko-dii/target.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"variable_injectors" : {"PORT": {},"HOST": {},"URL": {}},
"validation_method" : "lax",
"domain_home_source_type" : "dii",
"credentials_output_method" : "script",
"exclude_domain_bin_contents": true,
"additional_output" : "wko-domain.yaml"
Expand Down
1 change: 1 addition & 0 deletions core/src/main/targetconfigs/wko-pv/target.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"variable_injectors" : {"PORT": {},"HOST": {},"URL": {}},
"validation_method" : "lax",
"domain_home_source_type" : "pv",
"credentials_output_method" : "script",
"exclude_domain_bin_contents": true,
"use_persistent_volume" : true,
Expand Down
1 change: 1 addition & 0 deletions core/src/main/targetconfigs/wko/target.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
},
"variable_injectors" : {"PORT": {},"HOST": {},"URL": {}},
"validation_method" : "lax",
"domain_home_source_type" : "mii",
"credentials_method" : "secrets",
"credentials_output_method" : "script",
"exclude_domain_bin_contents": true,
Expand Down