|
2 | 2 | Copyright (c) 2020, 2022, Oracle and/or its affiliates. |
3 | 3 | Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. |
4 | 4 | """ |
5 | | - |
| 5 | +from wlsdeploy.exception import exception_helper |
| 6 | +from wlsdeploy.logging.platform_logger import PlatformLogger |
6 | 7 | from wlsdeploy.util import dictionary_utils |
| 8 | +from wlsdeploy.util.validate_configuration import VALIDATION_METHODS |
7 | 9 |
|
8 | 10 | # types for credential method |
9 | 11 | CREDENTIALS_METHOD = "credentials_method" |
|
21 | 23 | # Determines whether a persistent volume is used |
22 | 24 | USE_PERSISTENT_VOLUME = "use_persistent_volume" |
23 | 25 |
|
| 26 | +# Determines the type of domain used |
| 27 | +DOMAIN_HOME_SOURCE_TYPE = "domain_home_source_type" |
| 28 | + |
24 | 29 | # put secret tokens in the model, and build a script to create the secrets. |
25 | 30 | SECRETS_METHOD = 'secrets' |
26 | 31 |
|
|
32 | 37 | CONFIG_OVERRIDES_SECRETS_METHOD |
33 | 38 | ] |
34 | 39 |
|
| 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 | + |
35 | 51 |
|
36 | 52 | class TargetConfiguration(object): |
37 | 53 | """ |
38 | 54 | Provide access to fields in the target.json JSON file of a target environment. |
39 | 55 | """ |
40 | | - _class_name = 'TargetEnvironment' |
| 56 | + _class_name = 'TargetConfiguration' |
| 57 | + _logger = PlatformLogger('wlsdeploy.util') |
41 | 58 |
|
42 | 59 | def __init__(self, config_dictionary): |
43 | 60 | """ |
@@ -162,3 +179,53 @@ def use_persistent_volume(self): |
162 | 179 | if result is None: |
163 | 180 | result = False |
164 | 181 | 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 |
0 commit comments