Skip to content

Commit 29c956f

Browse files
committed
Use hyphenated lists when extracting domain resource from model
1 parent ba06653 commit 29c956f

File tree

7 files changed

+47
-62
lines changed

7 files changed

+47
-62
lines changed

core/src/main/python/wlsdeploy/json/json_translator.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2017, 2021, Oracle Corporation and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
55
This model provider translation classes that convert between JSON and Python Dictionaries.
@@ -18,6 +18,7 @@
1818
import oracle.weblogic.deploy.json.JsonTranslator as JJsonTranslator
1919

2020
from wlsdeploy.logging.platform_logger import PlatformLogger
21+
from wlsdeploy.util.boolean_value import BooleanValue
2122
import wlsdeploy.exception.exception_helper as exception_helper
2223

2324
# Unlike with yaml files, JSON files do not allow comments. remove from file
@@ -202,7 +203,7 @@ def _write_list_to_json_file(self, alist, writer, indent=''):
202203
writer.println()
203204
if isinstance(value, dict):
204205
writer.write(list_indent)
205-
self._write_dictionary_to_json_file(value, writer, indent)
206+
self._write_dictionary_to_json_file(value, writer, list_indent)
206207
else:
207208
writer.write(list_indent)
208209
writer.write(_format_json_value(value))
@@ -239,6 +240,8 @@ def _format_json_value(value):
239240
builder = StringBuilder()
240241
if type(value) == bool:
241242
builder.append(JBoolean.toString(value))
243+
elif isinstance(value, BooleanValue):
244+
builder.append(value.get_string_value())
242245
elif isinstance(value, types.StringTypes):
243246
builder.append('"').append(_escape_text(value.strip())).append('"')
244247
else:

core/src/main/python/wlsdeploy/tool/extract/domain_resource_extractor.py

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
from wlsdeploy.aliases.alias_constants import PASSWORD_TOKEN
1212
from wlsdeploy.aliases.model_constants import CLUSTER
1313
from wlsdeploy.aliases.model_constants import DEFAULT_WLS_DOMAIN_NAME
14-
from wlsdeploy.aliases.model_constants import KUBERNETES
1514
from wlsdeploy.aliases.model_constants import MODEL_LIST_DELIMITER
1615
from wlsdeploy.aliases.model_constants import NAME
1716
from wlsdeploy.exception import exception_helper
1817
from wlsdeploy.exception.expection_types import ExceptionType
1918
from wlsdeploy.tool.extract import wko_schema_helper
2019
from wlsdeploy.tool.util import k8s_helper
2120
from wlsdeploy.util import dictionary_utils
21+
from wlsdeploy.util.boolean_value import BooleanValue
2222
from wlsdeploy.util.model_translator import PythonToFile
2323

2424
API_VERSION = 'apiVersion'
@@ -93,7 +93,6 @@ def extract(self):
9393

9494
# write the resource file structure to the output file
9595
writer = PythonToFile(resource_dict)
96-
writer.set_yaml_hyphenate_yaml_lists(True)
9796
writer.write_to_file(resource_file)
9897
return
9998

@@ -108,18 +107,16 @@ def _create_domain_resource_dictionary(self):
108107

109108
schema = wko_schema_helper.get_domain_resource_schema(ExceptionType.DEPLOY)
110109

111-
model_path = KUBERNETES + ":"
112-
self._process_folder(kubernetes_map, schema, resource_dict, None, model_path)
110+
self._process_folder(kubernetes_map, schema, resource_dict, None)
113111
return resource_dict
114112

115-
def _process_folder(self, model_dict, schema_folder, target_dict, schema_path, model_path):
113+
def _process_folder(self, model_dict, schema_folder, target_dict, schema_path):
116114
"""
117115
Transfer folders and attributes from the model dictionary to the target domain resource dictionary.
118116
:param model_dict: the source model dictionary
119117
:param schema_folder: the schema for this folder
120118
:param target_dict: the target dictionary for the domain resource file.
121119
:param schema_path: the path of schema elements (no multi-element names), used for supported check
122-
:param model_path: the path of model elements (including multi-element names), used for logging
123120
"""
124121
folder_properties = schema_folder["properties"]
125122

@@ -129,21 +126,18 @@ def _process_folder(self, model_dict, schema_folder, target_dict, schema_path, m
129126
if wko_schema_helper.is_single_folder(properties):
130127
# single object instance
131128
next_schema_path = wko_schema_helper.append_path(schema_path, key)
132-
next_model_path = model_path + "/" + key
133129
if not wko_schema_helper.is_unsupported_folder(next_schema_path):
134130
next_target_dict = PyOrderedDict()
135131
target_dict[key] = next_target_dict
136-
self._process_folder(model_value, properties, next_target_dict, next_schema_path,
137-
next_model_path)
132+
self._process_folder(model_value, properties, next_target_dict, next_schema_path)
138133

139134
elif wko_schema_helper.is_multiple_folder(properties):
140135
# multiple object instances
141136
next_schema_path = wko_schema_helper.append_path(schema_path, key)
142-
next_model_path = model_path + "/" + key
143137
if not wko_schema_helper.is_unsupported_folder(next_schema_path):
144138
item_info = wko_schema_helper.get_array_item_info(properties)
145139
target_dict[key] = \
146-
self._process_multiple_folder(model_value, item_info, next_schema_path, next_model_path)
140+
self._process_multiple_folder(model_value, item_info, next_schema_path)
147141

148142
elif wko_schema_helper.is_simple_map(properties):
149143
# map of key / value pairs
@@ -154,30 +148,19 @@ def _process_folder(self, model_dict, schema_folder, target_dict, schema_path, m
154148
property_type = wko_schema_helper.get_type(properties)
155149
target_dict[key] = _get_target_value(model_value, property_type)
156150

157-
def _process_multiple_folder(self, model_value, item_info, schema_path, model_path):
151+
def _process_multiple_folder(self, model_value, item_info, schema_path):
158152
"""
159153
Process a multiple-element model section.
160-
There should be a dictionary of names, each containing a sub-folder.
154+
There should be a list of objects, each representing a sub-folder.
161155
:param model_value: the model contents for a folder
162156
:param item_info: describes the contents of the sub-folder for each element
163157
:param schema_path: the path of schema elements (no multi-element names), used for supported check
164-
:param model_path: the path of model elements (including multi-element names), used for logging
165158
"""
166159
child_list = list()
167-
for name in model_value:
168-
name_map = model_value[name]
160+
for name_map in model_value:
169161
next_target_dict = PyOrderedDict()
170-
next_model_path = model_path + "/" + name
171-
self._process_folder(name_map, item_info, next_target_dict, schema_path, next_model_path)
172-
173-
# see if the model name should become an attribute in the target dict
174-
mapped_name = get_mapped_key(schema_path)
175-
properties = wko_schema_helper.get_properties(item_info)
176-
if (mapped_name in properties.keys()) and (mapped_name not in next_target_dict.keys()):
177-
_add_to_top(next_target_dict, mapped_name, name)
178-
162+
self._process_folder(name_map, item_info, next_target_dict, schema_path)
179163
child_list.append(next_target_dict)
180-
181164
return child_list
182165

183166
def _update_resource_dictionary(self, resource_dict):
@@ -304,7 +287,7 @@ def _get_target_value(model_value, type_name):
304287
if type_name == 'boolean':
305288
# the model values can be true, false, 1, 0, etc.
306289
# target boolean values must be 'true' or 'false'
307-
return alias_utils.convert_to_type('boolean', model_value)
290+
return BooleanValue(model_value)
308291

309292
if type_name == 'array':
310293
# the model values can be 'abc,123'.
@@ -337,21 +320,6 @@ def _add_secrets(folder, secrets, domain_uid):
337320
secrets.append(secret_name)
338321

339322

340-
def get_mapped_key(schema_path):
341-
"""
342-
Because the WDT model does not support hyphenated lists, the name of each item in a
343-
multiple folder sometimes corresponds to one of its attributes, usually "name".
344-
If a different attribute name is used for the path, return that name.
345-
If the default 'name' is returned, caller should verify that it is an available attribute.
346-
:param schema_path: the slash-delimited path of the elements (no multi-element names)
347-
:return: the attribute key to be used
348-
"""
349-
mapped_key = dictionary_utils.get_element(MULTI_KEYS, schema_path)
350-
if mapped_key is not None:
351-
return mapped_key
352-
return 'name'
353-
354-
355323
def _add_to_top(dictionary, key, item):
356324
"""
357325
Add an item to the beginning of an ordered dictionary.

core/src/main/python/wlsdeploy/tool/validate/kubernetes_validator.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2020, Oracle Corporation and/or its affiliates.
2+
Copyright (c) 2020, 2021, 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
"""
55

@@ -111,14 +111,12 @@ def _validate_multiple_folder(self, model_value, property_map, schema_path, mode
111111
:param model_path: the path of model elements (including multi-element names), used for logging
112112
"""
113113
_method_name = '_validate_multiple_folder'
114-
if not isinstance(model_value, dict):
115-
self._logger.severe("WLSDPLY-05039", model_path, class_name=self._class_name, method_name=_method_name)
114+
if not isinstance(model_value, list):
115+
self._logger.severe("WLSDPLY-05040", model_path, class_name=self._class_name, method_name=_method_name)
116116
return
117117

118-
for name in model_value:
119-
name_map = model_value[name]
120-
next_model_path = model_path + "/" + name
121-
self.validate_folder(name_map, property_map, schema_path, next_model_path)
118+
for name_map in model_value:
119+
self.validate_folder(name_map, property_map, schema_path, model_path)
122120

123121
def _validate_simple_map(self, model_value, property_name, model_path):
124122
_method_name = '_validate_simple_map'
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
Copyright (c) 2021, Oracle and/or its affiliates.
3+
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
4+
5+
Contains a boolean value that can be recognized by the YAML and JSON writers.
6+
"""
7+
from wlsdeploy.aliases import alias_utils
8+
9+
10+
class BooleanValue(object):
11+
12+
def __init__(self, value):
13+
self.value = alias_utils.convert_boolean(value)
14+
15+
def get_value(self):
16+
return self.value
17+
18+
def get_string_value(self):
19+
if self.value:
20+
return 'true'
21+
else:
22+
return 'false'

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2020, Oracle Corporation and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2021, 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
"""
55
import java.io.File as JFile
@@ -93,7 +93,6 @@ class PythonToFile(object):
9393
def __init__(self, dictionary):
9494
self.dictionary = dictionary
9595
self.logger = platform_logger.PlatformLogger('wlsdeploy.translator')
96-
self._hyphenate_yaml_lists = False
9796

9897
def write_to_file(self, file_name):
9998
"""
@@ -114,9 +113,6 @@ def write_to_file(self, file_name):
114113
self.logger.exiting(class_name=self._class_name, method_name=_method_name)
115114
return return_file
116115

117-
def set_yaml_hyphenate_yaml_lists(self, hyphenate):
118-
self._hyphenate_yaml_lists = hyphenate
119-
120116
def _write_to_json_file(self, file_name):
121117
"""
122118
Convert the Python dictionary to JSON and write it to a file.
@@ -147,7 +143,6 @@ def _write_to_yaml_file(self, file_name):
147143
self.logger.finer('WLSDPLY-01712', 'YAML', file_name, class_name=self._class_name, method_name=_method_name)
148144
try:
149145
writer = JPythonToYaml(self.dictionary)
150-
writer.set_hyphenate_lists(self._hyphenate_yaml_lists)
151146
writer.write_to_yaml_file(file_name)
152147
except JYamlException, ye:
153148
translate_ex = exception_helper.create_translate_exception('WLSDPLY-01713', file_name,

core/src/main/python/wlsdeploy/yaml/yaml_translator.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
from wlsdeploy.exception import exception_helper
2424
from wlsdeploy.logging.platform_logger import PlatformLogger
25+
from wlsdeploy.util.boolean_value import BooleanValue
2526

2627

2728
class YamlToPython(object):
@@ -165,6 +166,8 @@ def convert_scalar_to_java_type(self, py_value):
165166
result = JLong(JString(str(py_value)))
166167
elif type(py_value) is float:
167168
result = JDouble(py_value)
169+
elif isinstance(py_value, BooleanValue):
170+
result = JBoolean(py_value.get_value())
168171
else:
169172
yaml_ex = exception_helper.create_yaml_exception('WLSDPLY-18201', type(py_value))
170173
self._logger.throwing(class_name=self._class_name, method_name=_method_name, error=yaml_ex)
@@ -182,8 +185,6 @@ def __init__(self, dictionary):
182185
# Fix error handling for None
183186
self._dictionary = dictionary
184187
self._logger = PlatformLogger('wlsdeploy.yaml')
185-
# No-op
186-
self._hyphenate_lists = False
187188
return
188189

189190
def write_to_yaml_file(self, file_name):
@@ -223,9 +224,6 @@ def write_to_yaml_file(self, file_name):
223224

224225
self._logger.exiting(class_name=self._class_name, method_name=_method_name)
225226

226-
def set_hyphenate_lists(self, hyphenate_lists):
227-
self._hyphenate_lists = hyphenate_lists
228-
229227
def _write_dictionary_to_yaml_file(self, dictionary, writer, file_name='<None>'):
230228
"""
231229
Do the actual heavy lifting of converting a dictionary and writing it to the file.

core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,7 @@ WLSDPLY-05036=Attribute {0} in model location {1}, uses the {2} macro expression
483483
WLSDPLY-05037=Custom folder {0} will not be validated
484484
WLSDPLY-05038=Expected a section with subfolders and attributes in model location {0}
485485
WLSDPLY-05039=Expected a section with named subfolders in model location {0}
486+
WLSDPLY-05040=Expected a list of objects in model location {0}
486487

487488
# wlsdeploy/tool/validate/kubernetes_validator.py
488489
WLSDPLY-05090=Model folder {0} is not supported, will be skipped

0 commit comments

Comments
 (0)