Skip to content

Commit 30520ee

Browse files
Added ability to version folder level parameters in alias definitions
1 parent 9f46384 commit 30520ee

File tree

7 files changed

+179
-15
lines changed

7 files changed

+179
-15
lines changed

core/src/main/java/oracle/weblogic/deploy/util/FileUtils.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
33
* The Universal Permissive License (UPL), Version 1.0
44
*/
55
package oracle.weblogic.deploy.util;
@@ -52,6 +52,26 @@ public static InputStream getResourceAsStream(String fileName) {
5252
return FileUtils.class.getClassLoader().getResourceAsStream(fileName);
5353
}
5454

55+
/**
56+
* Get the specified file as an InputStream. This method will first
57+
* resolve the name to an absolute path and then get the InputStream
58+
*
59+
* @param fileName of the file to get
60+
* @return the InputStream, or null if it was not found.
61+
*
62+
* @param fileName
63+
* @return
64+
* @throws IOException
65+
*/
66+
public static InputStream getFileAsStream(String fileName) throws IOException {
67+
File file = validateExistingFile(fileName);
68+
InputStream inputStream = null;
69+
if (file != null) {
70+
inputStream = new FileInputStream(getCanonicalFile(file));
71+
}
72+
return inputStream;
73+
}
74+
5575
/**
5676
* Convert a file path into one that Jython will handle.
5777
*

core/src/main/python/wlsdeploy/aliases/alias_entries.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,9 +1254,11 @@ def __use_alias_dict(self, path_name, alias_dict, parent_dict):
12541254

12551255
def __resolve_folder_params(self, path_name, alias_dict):
12561256
"""
1257-
This is a folder that has different parameters based on version / offline.
1258-
Search through the folder params and find the correct set of parameters. Add
1259-
this set of parameters to the alias_dict directly and remove the folder_params array.
1257+
The folder params has a two-fold purpose. To identify valid version / wlst mode
1258+
combinations (all version / wlst mode combinations must be represented). And to
1259+
contain folder parameters that are different depending on the combination. Once
1260+
a folder parameter version has been selected, then all the folder parameters in the
1261+
valid entry are added to the alias_dict dictionary parameters.
12601262
:param alias_dict:
12611263
:return:
12621264
"""
@@ -1270,12 +1272,15 @@ def __resolve_folder_params(self, path_name, alias_dict):
12701272
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
12711273
raise ex
12721274

1273-
for folder_set in folder_params:
1274-
if self.__test_dictionary(path_name, folder_set):
1275-
_logger.finer('WLSDPLY-08135', path_name, class_name=_class_name, method_name=_method_name)
1276-
for key, value in folder_set.iteritems():
1277-
alias_dict[key] = value
1278-
break
1275+
if folder_params:
1276+
add_entry = folder_params[0]
1277+
for folder_set in folder_params:
1278+
if self.__test_dictionary(path_name, folder_set):
1279+
_logger.finer('WLSDPLY-08135', path_name, class_name=_class_name, method_name=_method_name)
1280+
add_entry = folder_set
1281+
break
1282+
for key, value in add_entry.iteritems():
1283+
alias_dict[key] = value
12791284

12801285
def __resolve_attribute_by_wlst_context(self, path_name, attr_name, attrs_dict):
12811286
"""

core/src/main/python/wlsdeploy/aliases/model_constants.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
33
The Universal Permissive License (UPL), Version 1.0
44
"""
55

@@ -190,6 +190,7 @@
190190
SAF_ERROR_HANDLING = 'SAFErrorHandling'
191191
SAF_IMPORTED_DESTINATION = 'SAFImportedDestinations'
192192
SAF_LOGIN_CONTEXT = 'SAFLoginContext'
193+
SAF_MESSAGE_LOG_FILE = 'JmssafMessageLogFile'
193194
SAF_QUEUE = 'SAFQueue'
194195
SAF_REMOTE_CONTEXT = 'SAFRemoteContext'
195196
SAF_TOPIC = 'SAFTopic'

core/src/main/resources/oracle/weblogic/deploy/aliases/category_modules/SAFAgent.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
{
2-
"copyright": "Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.",
2+
"copyright": "Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.",
33
"license": "The Universal Permissive License (UPL), Version 1.0",
44
"wlst_type": "SAFAgent${:s}",
55
"child_folders_type": "multiple",
66
"folders": {
77
"JmssafMessageLogFile": {
8+
"folder_params": [{
9+
"version": "[10,12.2.1)",
10+
"wlst_mode": "online"
11+
}, {
12+
"version": "[12.2.1,)"
13+
}],
814
"folders": {},
915
"attributes": {
1016
"BufferSizeKb": [ {"version": "[10,)", "wlst_mode": "both", "wlst_name": "BufferSize${Kb:KB}", "wlst_path": "WP001", "value": {"default": 8 }, "wlst_type": "integer" } ],

core/src/test/python/alias_json_file_test.py

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""
2-
Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
33
The Universal Permissive License (UPL), Version 1.0
44
"""
5+
import copy
6+
import os
57
import pprint
68
import unittest
79

@@ -20,6 +22,7 @@
2022
from wlsdeploy.aliases.alias_constants import DEFAULT
2123
from wlsdeploy.aliases.alias_constants import DEFAULT_NAME_VALUE
2224
from wlsdeploy.aliases.alias_constants import FLATTENED_FOLDER_DATA
25+
from wlsdeploy.aliases.alias_constants import FOLDER_PARAMS
2326
from wlsdeploy.aliases.alias_constants import FOLDERS
2427
from wlsdeploy.aliases.alias_constants import GET
2528
from wlsdeploy.aliases.alias_constants import GET_MBEAN_TYPE
@@ -48,6 +51,11 @@
4851

4952

5053
class ListTestCase(unittest.TestCase):
54+
_resources_dir = '../../test-classes/'
55+
_test_json_files = [
56+
'Test'
57+
]
58+
_test_category_file_map = dict()
5159

5260
_required_category_folder_keys = [
5361
'copyright',
@@ -67,6 +75,7 @@ class ListTestCase(unittest.TestCase):
6775
CONTAINS,
6876
DEFAULT_NAME_VALUE,
6977
FLATTENED_FOLDER_DATA,
78+
FOLDER_PARAMS,
7079
VERSION,
7180
WLST_CREATE_PATH,
7281
WLST_LIST_PATH,
@@ -121,6 +130,9 @@ def setUp(self):
121130
self.alias_entries = AliasEntries(wls_version='12.2.1.3')
122131
self.online_alias_entries = AliasEntries(wls_version='12.2.1.3', wlst_mode=WlstModes.ONLINE)
123132
self.category_file_map = self.alias_entries._unit_test_only_get_category_map_files()
133+
for testfile in self._test_json_files:
134+
category_file_path = os.path.join(self._resources_dir, '%s.json' % testfile)
135+
self._test_category_file_map[testfile] = category_file_path
124136

125137
def testForJsonFileTypos(self):
126138
category_results = dict()
@@ -132,10 +144,25 @@ def testForJsonFileTypos(self):
132144
message = pprint.pformat(category_results)
133145
self.assertEqual(len(category_results), 0, message)
134146

147+
def testTestFilesForJsonFileTypos(self):
148+
category_results = dict()
149+
for category_name, category_file_path in self._test_category_file_map.iteritems():
150+
category_dict = self._load_test_category_file(category_file_path)
151+
results = self._scan_category_dict_for_unknown_fields(category_name, category_dict)
152+
if len(results) > 0:
153+
category_results[category_name] = results
154+
message = pprint.pformat(category_results)
155+
self.assertEqual(len(category_results), 0, message)
156+
135157
def _load_category_file(self, category_file_path):
136158
category_input_stream = FileUtils.getResourceAsStream(category_file_path)
137159
self.assertNotEquals(category_input_stream, None)
160+
json_translator = JsonStreamTranslator(category_file_path, category_input_stream)
161+
return json_translator.parse()
138162

163+
def _load_test_category_file(self, category_file_path):
164+
category_input_stream = FileUtils.getFileAsStream(category_file_path)
165+
self.assertNotEquals(category_input_stream, None)
139166
json_translator = JsonStreamTranslator(category_file_path, category_input_stream)
140167
return json_translator.parse()
141168

@@ -277,7 +304,6 @@ def _verify_folder_wlst_paths_attribute_type(self, folder_name, attribute_value)
277304
result.append(self._get_invalid_dictionary_type_message(folder_name, WLST_PATHS, attribute_value))
278305
return result
279306

280-
281307
def _verify_folder_wlst_type_attribute_type(self, folder_name, attribute_value):
282308
result = []
283309
if type(attribute_value) is not str:
@@ -337,6 +363,31 @@ def _verify_folder_flattened_folder_data_attribute_value(self, folder_name, attr
337363
attribute_value[NAME_VALUE]))
338364
return result
339365

366+
def _verify_folder_folder_params_attribute_value(self, folder_name, attribute_value):
367+
result = []
368+
if type(attribute_value) is not list or (len(attribute_value) > 0 and
369+
type(attribute_value[0]) is not dict):
370+
result.append(self._get_invalid_list_of_dict_type_message(folder_name, FOLDER_PARAMS,
371+
attribute_value))
372+
else:
373+
folder_params = copy.deepcopy(attribute_value)
374+
for folder_param in folder_params:
375+
if VERSION not in folder_param:
376+
result.append(self._get_missing_required_attribute_key_message(folder_name,
377+
VERSION, FOLDER_PARAMS))
378+
for folder in folder_param:
379+
if folder in self._required_folder_keys:
380+
verify_function_name = '_verify_folder_%s_attribute_type' % folder
381+
verify_function = getattr(self, verify_function_name)
382+
result.extend(verify_function(folder_name, folder_param[folder]))
383+
elif folder in self._optional_folder_keys:
384+
verify_function_name = '_verify_folder_%s_attribute_value' % folder
385+
verify_function = getattr(self, verify_function_name)
386+
result.extend(verify_function(folder_name, folder_param[folder]))
387+
else:
388+
result.append(self._get_unknown_folder_key_message(folder_name, folder))
389+
return result
390+
340391
def _verify_folder_version_attribute_value(self, folder_name, attribute_value):
341392
result = []
342393
if type(attribute_value) is not str:
@@ -629,6 +680,10 @@ def _get_invalid_list_type_message(self, folder_name, attribute_name, attribute_
629680
return 'Folder at path %s has %s attribute that is expected to be a list but is a %s instead' % \
630681
(folder_name, attribute_name, str(type(attribute_value)))
631682

683+
def _get_invalid_list_of_dict_type_message(self, folder_name, attribute_name, attribute_value):
684+
return 'Folder at path %s has %s attribute that is expected to be a list of dict but is a %s instead' % \
685+
(folder_name, attribute_name, str(type(attribute_value)))
686+
632687
def _get_invalid_string_type_message(self, folder_name, attribute_name, attribute_value):
633688
return 'Folder at path %s has %s attribute that is expected to be a string but is a %s instead' % \
634689
(folder_name, attribute_name, str(type(attribute_value)))

core/src/test/python/aliases_test.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
33
The Universal Permissive License (UPL), Version 1.0
44
"""
55
from org.python.modules import jarray
@@ -599,6 +599,24 @@ def testVersionFilteredFolders(self):
599599
self.assertNotEqual(mbean_type, None, 'expected DynamicServers type not to be null')
600600
return
601601

602+
def testVersionFilteredFoldersWithFolderParams(self):
603+
old_wls_version = '10.3.6'
604+
new_wls_version = '12.2.1.3'
605+
606+
old_aliases = Aliases(self.model_context, WlstModes.OFFLINE, old_wls_version)
607+
new_aliases = Aliases(self.model_context, WlstModes.OFFLINE, new_wls_version)
608+
location = LocationContext()
609+
location.append_location(FOLDERS.SAF_AGENT)
610+
name_token = old_aliases.get_name_token(location)
611+
location.add_name_token(name_token, 'SafAgent')
612+
location.append_location(FOLDERS.SAF_MESSAGE_LOG_FILE)
613+
mbean_type = old_aliases.get_wlst_mbean_type(location)
614+
self.assertEqual(mbean_type, None, 'expected SAF Agent Message Log type to be null')
615+
mbean_type = new_aliases.get_wlst_mbean_type(location)
616+
self.assertNotEqual(mbean_type, None, 'expected SAF Agent Message Log not to be null')
617+
618+
return
619+
602620
def testDomainAttributeMethods(self):
603621
aliases = Aliases(self.model_context, WlstModes.OFFLINE)
604622
location = LocationContext()

core/src/test/resources/Test.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"copyright": "Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.",
3+
"license": "The Universal Permissive License (UPL), Version 1.0",
4+
"folder_params": [],
5+
"wlst_type": "Test",
6+
"child_folders_type": "multiple",
7+
"folders": {
8+
"ChildFolder-12213": {
9+
"folder_params": [ {
10+
"version": "[10.3.6,12.2.1.3)",
11+
"wlst_mode": "online",
12+
"wlst_type": "ChildFolder-1036",
13+
"wlst_paths": {"WP001": "/Test/%TEST%/child1036/%TEST%"}
14+
},{
15+
"version": "[12.2.1.3,)",
16+
"wlst_type": "ChildFolder-12213",
17+
"wlst_mode": "offline",
18+
"wlst_paths": {"WP001": "/Test/%TEST%/child12213/NO_NAME_0"}
19+
}],
20+
"wlst_type": "ChildFolder-1",
21+
"folders": {},
22+
"child_folders_type": "single",
23+
"attributes": {
24+
"Notes": [{"version": "[12.2.1.3,)", "wlst_mode": "both", "wlst_name": "Notes", "wlst_path": "WP001", "value": {"default": "None"}, "wlst_type": "string"}]
25+
},
26+
"wlst_attributes_path": "WP001",
27+
"wlst_paths": {
28+
"WP001": "/Test/%TEST%/ChildFolder-1/"
29+
}
30+
},
31+
"ChildFolder-2": {
32+
"folder_params": [{
33+
"version": "[10,12.2.1.3)",
34+
"wlst_mode": "offline"
35+
}, {
36+
"version": "[12.2.1.3,)"
37+
}],
38+
"wlst_type": "ChildFolder-2",
39+
"folders": {},
40+
"child_folders_type": "multiple",
41+
"attributes": {
42+
"Notes": [ {"version": "[12.2.1.3,)", "wlst_mode": "both", "wlst_name": "Notes", "wlst_path": "WP001", "value": {"default": "None" }, "wlst_type": "string" } ]
43+
},
44+
"wlst_attributes_path": "WP001",
45+
"wlst_paths": {
46+
"WP001": "/Test/%TEST%/ChildFolder-2/%CHILD2%"
47+
}
48+
}
49+
},
50+
"attributes": {
51+
"Attribute-1": [ {"version": "[10,12.1.1)", "wlst_mode": "offline", "wlst_name": "Attribute", "wlst_path": "WP001", "value": {"default": "None" }, "wlst_type": "string", "get_method": "${LSA:GET}" } ,
52+
{"version": "[12.1.1,)", "wlst_mode": "both", "wlst_name": "Attribute-1", "wlst_path": "WP001", "value": {"default": "None" }, "wlst_type": "string", "get_method": "${LSA:GET}" } ],
53+
"Attribute-2": [ {"version": "[12.1.1,)", "wlst_mode": "both", "wlst_name": "Attribute-2", "wlst_path": "WP001", "value": {"default": -1 }, "wlst_type": "integer" } ]
54+
},
55+
"wlst_attributes_path": "WP001",
56+
"wlst_paths": {
57+
"WP001": "/Test/%TEST%"
58+
}
59+
}

0 commit comments

Comments
 (0)