Skip to content

Commit 6fd3159

Browse files
authored
Merge pull request #307 from oracle/issue-300-server-start-value-args
Issue #300 - Parse server start value args correctly; fixed server te…
2 parents ce3ea2c + a19f67a commit 6fd3159

File tree

9 files changed

+98
-98
lines changed

9 files changed

+98
-98
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,18 @@ class JVMArguments(object):
1818

1919
_class_name = 'JVMArguments'
2020
__client_server_regex = re.compile('-client|-server')
21+
22+
# examples: -Xmx200m -Xms100K
2123
__x_args_size_regex = re.compile('(-X(ms|mx|ss|mn) ?)([0-9]+[kmgKMG]? ?)')
24+
25+
# example: -Xrunjdwp:transport=dt_socket,address=8888,server=y,suspend=y
2226
__x_args_value_regex = re.compile('(-X[a-zS]+(/[ap])? ?):([\S]+ ?)')
27+
2328
__x_args_other_regex = re.compile('(-X[a-z]+ ?)(=([0-9]+[kmgKMG]? ?))?')
2429
__xx_args_switch_regex = re.compile('-XX:([+-] ?)([a-zA-Z0-9]+ ?)')
2530
__xx_args_value_regex = re.compile('-XX:([a-zA-Z0-9]+ ?)=([\S]+ ?)')
31+
32+
# examples: -Dabc -Dxyz=jkl,fdr,jdk -Drak=xyz
2633
__sys_props_regex = re.compile('-D([a-zA-Z0-9-_.]+ ?)(=([\S]+ ?))?')
2734

2835
__size_regex = re.compile('([0-9]+ ?)([kmgKMG]? ?)')
@@ -256,6 +263,8 @@ def __parse_args(self):
256263
self.__client_server_args.append(argument)
257264
elif self.__x_args_size_regex.match(argument):
258265
self.__process_x_size_arg(argument)
266+
elif self.__x_args_value_regex.match(argument):
267+
self.__process_x_value_arg(argument)
259268
elif self.__x_args_other_regex.match(argument):
260269
self.__process_x_other_arg(argument)
261270
elif self.__xx_args_switch_regex.match(argument):
@@ -310,7 +319,7 @@ def __process_x_other_arg(self, argument):
310319
add it to the internal map.
311320
:param argument: the argument string
312321
"""
313-
_method_name = '__process_x_value_arg'
322+
_method_name = '__process_x_other_arg'
314323

315324
match = self.__x_args_other_regex.match(argument)
316325
xarg = match.group(1)

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

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
from oracle.weblogic.deploy.aliases import VersionUtils
2525

2626
from wlsdeploy.aliases.alias_constants import ChildFoldersTypes
27-
from wlsdeploy.aliases.alias_jvmargs import JVMArguments
2827
from wlsdeploy.exception import exception_helper
2928
from wlsdeploy.logging.platform_logger import PlatformLogger
3029

@@ -52,14 +51,9 @@
5251
from wlsdeploy.aliases.alias_constants import WLST_READ_TYPE
5352
from wlsdeploy.aliases.alias_constants import WLST_TYPE
5453
from wlsdeploy.aliases.alias_constants import WLST_SUBFOLDERS_PATH
55-
from wlsdeploy.aliases.model_constants import ARGUMENTS
56-
from wlsdeploy.aliases.model_constants import SERVER
57-
from wlsdeploy.aliases.model_constants import SERVER_START
5854

5955
_class_name = 'alias_utils'
6056
_logger = PlatformLogger('wlsdeploy.aliases')
61-
_server_start_location_folder_path = '/' + SERVER + '/' + SERVER_START
62-
_server_start_argument_attribute_name = ARGUMENTS
6357
_windows_path_regex = re.compile(r'^[a-zA-Z]:[\\/].*')
6458

6559

@@ -149,30 +143,6 @@ def merge_model_and_existing_properties(model_props, existing_props, string_prop
149143
return result
150144

151145

152-
def merge_server_start_argument_values(model_args, existing_args):
153-
"""
154-
Merge the two arguments strings.
155-
:param model_args: the new string or list from the model
156-
:param existing_args: the old string (e.g., from WLST)
157-
:return: the resulting merged string
158-
"""
159-
_method_name = 'merge_server_start_argument_values'
160-
161-
_logger.entering(model_args, existing_args, class_name=_class_name, method_name=_method_name)
162-
if model_args is None or len(model_args) == 0:
163-
result = existing_args
164-
elif existing_args is None or len(existing_args) == 0:
165-
new_args = JVMArguments(_logger, model_args)
166-
result = new_args.get_arguments_string()
167-
else:
168-
new_args = JVMArguments(_logger, model_args)
169-
merged_args = JVMArguments(_logger, existing_args)
170-
merged_args.merge_jvm_arguments(new_args)
171-
result = merged_args.get_arguments_string()
172-
_logger.exiting(class_name=_class_name, method_name=_method_name, result=result)
173-
return result
174-
175-
176146
def count_substring_occurrences(substring, string):
177147
"""
178148
Count the number of occurrences of a substring in a string
@@ -555,17 +525,6 @@ def convert_boolean(value):
555525
return result
556526

557527

558-
def is_attribute_server_start_arguments(location, model_attribute_name):
559-
"""
560-
Is the location and attribute the Server/ServerStart folder's Argument attribute
561-
:param location: location
562-
:param model_attribute_name: attribute name
563-
:return: True if so, False otherwise
564-
"""
565-
return location.get_folder_path() == _server_start_location_folder_path and \
566-
model_attribute_name == _server_start_argument_attribute_name
567-
568-
569528
def compute_delimiter_from_data_type(data_type, value):
570529
"""
571530
Compute the delimiter from the data type

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
from wlsdeploy.aliases.alias_constants import RESTART_REQUIRED
4444
from wlsdeploy.aliases.alias_constants import SET_MBEAN_TYPE
4545
from wlsdeploy.aliases.alias_constants import SET_METHOD
46-
from wlsdeploy.aliases.alias_constants import STRING
4746
from wlsdeploy.aliases.alias_constants import USES_PATH_TOKENS
4847
from wlsdeploy.aliases.alias_constants import VALUE
4948
from wlsdeploy.aliases.alias_constants import WLST_NAME
@@ -411,18 +410,11 @@ def get_wlst_attribute_name_and_value(self, location, model_attribute_name, mode
411410
raise ex
412411
else:
413412
if data_type in ALIAS_LIST_TYPES or data_type in ALIAS_MAP_TYPES:
414-
to_type = data_type
415-
416413
merge = True
417414
if MERGE in attribute_info:
418415
merge = alias_utils.convert_boolean(attribute_info[MERGE])
419416

420-
if alias_utils.is_attribute_server_start_arguments(location, model_attribute_name):
421-
# convert to string, even if no existing value to merge
422-
merged_value = \
423-
alias_utils.merge_server_start_argument_values(model_attribute_value, existing_wlst_value)
424-
to_type = STRING
425-
elif merge and data_type in ALIAS_MAP_TYPES:
417+
if merge and data_type in ALIAS_MAP_TYPES:
426418
model_val = TypeUtils.convertToType(PROPERTIES, model_attribute_value)
427419
existing_val = TypeUtils.convertToType(PROPERTIES, existing_wlst_value)
428420
merged_value = alias_utils.merge_model_and_existing_properties(model_val, existing_val)
@@ -442,10 +434,10 @@ def get_wlst_attribute_name_and_value(self, location, model_attribute_name, mode
442434
subtype = 'java.lang.String'
443435
if SET_MBEAN_TYPE in attribute_info:
444436
subtype = attribute_info[SET_MBEAN_TYPE]
445-
wlst_attribute_value = alias_utils.convert_to_type(to_type, merged_value, subtype=subtype,
437+
wlst_attribute_value = alias_utils.convert_to_type(data_type, merged_value, subtype=subtype,
446438
delimiter=MODEL_LIST_DELIMITER)
447439
else:
448-
wlst_attribute_value = alias_utils.convert_to_type(to_type, merged_value,
440+
wlst_attribute_value = alias_utils.convert_to_type(data_type, merged_value,
449441
delimiter=MODEL_LIST_DELIMITER)
450442
else:
451443
wlst_attribute_value = alias_utils.convert_to_type(data_type, model_attribute_value,

core/src/main/python/wlsdeploy/tool/deploy/deployer_utils.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from oracle.weblogic.deploy.util import PyWLSTException
1212
from oracle.weblogic.deploy.util import WLSDeployArchive
1313

14-
from wlsdeploy.aliases.location_context import LocationContext
1514
from wlsdeploy.aliases.wlst_modes import WlstModes
1615
from wlsdeploy.exception import exception_helper
1716
from wlsdeploy.exception.expection_types import ExceptionType
@@ -26,34 +25,6 @@
2625
_wlst_helper = WlstHelper(_logger, ExceptionType.DEPLOY)
2726

2827

29-
def set_attribute(location, model_key, model_value, alias_helper, use_raw_value=False):
30-
"""
31-
Set a single attribute to the specified value.
32-
:param location: the location of the attribute to be set
33-
:param model_key: the key of the attribute to be set
34-
:param model_value: the value of the attribute to be set
35-
:param alias_helper: the alias helper to use for name resolution
36-
:param use_raw_value: apply passed value directly if true (example: mbean)
37-
"""
38-
method_name = 'set_attribute'
39-
40-
if use_raw_value:
41-
wlst_param = alias_helper.get_wlst_attribute_name(location, model_key)
42-
wlst_value = model_value
43-
else:
44-
wlst_param, wlst_value = alias_helper.get_wlst_attribute_name_and_value(location, model_key, model_value)
45-
46-
if wlst_param is None:
47-
_logger.info('WLSDPLY-20011', model_key, class_name=_class_name, method_name=method_name)
48-
return
49-
50-
if wlst_value is None:
51-
_logger.info('WLSDPLY-20012', model_key, str(model_value), class_name=_class_name, method_name=method_name)
52-
return
53-
54-
_wlst_helper.set(wlst_param, wlst_value)
55-
56-
5728
def get_existing_object_list(location, alias_helper):
5829
"""
5930
Get a list of the existing names at the specified location.

core/src/main/python/wlsdeploy/tool/util/attribute_setter.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from oracle.weblogic.deploy.aliases import TypeUtils
1414

15+
from wlsdeploy.aliases.alias_jvmargs import JVMArguments
1516
from wlsdeploy.aliases.location_context import LocationContext
1617
from wlsdeploy.aliases.wlst_modes import WlstModes
1718
from wlsdeploy.exception import exception_helper
@@ -590,6 +591,29 @@ def set_resource_manager_mbean(self, location, key, value, wlst_value):
590591
self.set_attribute(location, key, mbean, wlst_merge_value=wlst_value, use_raw_value=True)
591592
return
592593

594+
def set_jvm_args(self, location, key, value, wlst_value):
595+
"""
596+
Set the server start args string. The new arguments are merged and re-sorted with existing arguments.
597+
:param location: the location
598+
:param key: the attribute name
599+
:param value: the string value
600+
:param wlst_value: the existing value of the attribute from WLST
601+
:raises BundleAwareException of the specified type: if target is not found
602+
"""
603+
if value is None or len(value) == 0:
604+
result = value
605+
elif wlst_value is None or len(wlst_value) == 0:
606+
new_args = JVMArguments(self.__logger, value)
607+
result = new_args.get_arguments_string()
608+
else:
609+
new_args = JVMArguments(self.__logger, value)
610+
merged_args = JVMArguments(self.__logger, wlst_value)
611+
merged_args.merge_jvm_arguments(new_args)
612+
result = merged_args.get_arguments_string()
613+
614+
self.set_attribute(location, key, result, wlst_merge_value=wlst_value, use_raw_value=True)
615+
return
616+
593617
#
594618
# public set_attribute convenience methods
595619
#

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@
938938
"default_name_value": "${NO_NAME_0:%SERVER%}",
939939
"folders": {},
940940
"attributes": {
941-
"Arguments": [ {"version": "[10,)", "wlst_mode": "both", "wlst_name": "Arguments", "wlst_path": "WP001", "value": {"default": "None" }, "wlst_type": "delimited_string[space]" } ],
941+
"Arguments": [ {"version": "[10,)", "wlst_mode": "both", "wlst_name": "Arguments", "wlst_path": "WP001", "value": {"default": "None" }, "wlst_type": "delimited_string[space]", "set_method": "MBEAN.set_jvm_args" } ],
942942
"BeaHome": [ {"version": "[10,)", "wlst_mode": "both", "wlst_name": "BeaHome", "wlst_path": "WP001", "value": {"default": "None" }, "wlst_type": "string", "uses_path_tokens": "true"} ],
943943
"BootProperties": [ {"version": "[10,)", "wlst_mode": "online", "wlst_name": "BootProperties", "wlst_path": "WP001", "value": {"default": "None" }, "wlst_type": "properties", "get_method": "GET", "preferred_model_type": "list", "access": "RO"} ],
944944
"ClassPath": [ {"version": "[10,)", "wlst_mode": "both", "wlst_name": "ClassPath", "wlst_path": "WP001", "value": {"default": "None" }, "wlst_type": "delimited_string[path_separator]", "preferred_model_type": "delimited_string", "uses_path_tokens": "true"} ],

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@
948948
"attributes": {
949949
"BeaHome": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "BeaHome", "wlst_path": "WP001", "value": {"default": "None" }, "wlst_type": "string", "uses_path_tokens": "true"} ],
950950
"BootProperties": [ {"version": "[12.1.2,)", "wlst_mode": "online", "wlst_name": "BootProperties", "wlst_path": "WP001", "value": {"default": "None" }, "wlst_type": "properties", "get_method": "GET", "access": "RO", "restart_required": "true" } ],
951-
"ClassPath": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "ClassPath", "wlst_path": "WP001", "value": {"default": "None" }, "wlst_type": "delimited_string[path_separator]", "uses_path_tokens": "true"} ],
951+
"ClassPath": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "ClassPath", "wlst_path": "WP001", "value": {"default": "None" }, "wlst_type": "delimited_string[path_separator]", "preferred_model_type": "delimited_string", "uses_path_tokens": "true"} ],
952952
"JavaHome": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "JavaHome", "wlst_path": "WP001", "value": {"default": "None" }, "wlst_type": "string", "uses_path_tokens": "true"} ],
953953
"JavaVendor": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "JavaVendor", "wlst_path": "WP001", "value": {"default": "None" }, "wlst_type": "string" } ],
954954
"Arguments": [ {"version": "[12.1.2,)", "wlst_mode": "both", "wlst_name": "Arguments", "wlst_path": "WP001", "value": {"default": "None" }, "wlst_type": "delimited_string[space]" } ],

core/src/test/python/aliases_test.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,20 +1321,6 @@ def testListGetToList(self):
13211321
actual_attr, actual_value = self.aliases.get_wlst_attribute_name_and_value(location, actual_attr, actual_value)
13221322
self.assertEqual(wlst_list, actual_value)
13231323

1324-
# server start args can be a list in the model, merge values and become a string for WLST
1325-
def testServerStartArgs(self):
1326-
location = LocationContext().append_location(FOLDERS.SERVER)
1327-
location.add_name_token(self.aliases.get_name_token(location), 'AdminServer')
1328-
location = location.append_location(FOLDERS.SERVER_START)
1329-
location.add_name_token(self.aliases.get_name_token(location), 'AdminServer')
1330-
attribute = FOLDERS.ARGUMENTS
1331-
value = ['-Dxyz=123,456,789']
1332-
existing_value = '-Dxyz=123,555,789'
1333-
1334-
dummy_attr, wlst_value = self.aliases.get_wlst_attribute_name_and_value(location, attribute, value,
1335-
existing_value)
1336-
self.assertEqual('-Dxyz=123,456,789', wlst_value)
1337-
13381324
def testGetJTA(self):
13391325
location = LocationContext()
13401326
location.append_location(FOLDERS.JTA)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""
2+
Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3+
The Universal Permissive License (UPL), Version 1.0
4+
"""
5+
import unittest
6+
7+
from wlsdeploy.aliases.aliases import Aliases
8+
from wlsdeploy.aliases.wlst_modes import WlstModes
9+
from wlsdeploy.aliases.location_context import LocationContext
10+
from wlsdeploy.util.model_context import ModelContext
11+
12+
13+
class AttributesTypeTestCase(unittest.TestCase):
14+
"""
15+
1) Unit tests must be a class that extends unittest.TestCase
16+
2) Class methods with names starting with 'test' will be executed by the framework (all others skipped)
17+
"""
18+
wls_version = '12.2.1.3'
19+
20+
def testDelimitedAttributes(self):
21+
# This test ensures that delimited attributes are always comma-delimited for the model.
22+
# Space-delimited attributes are allowed to bypass this rule.
23+
24+
model_context = ModelContext("test", {})
25+
aliases = Aliases(model_context=model_context, wlst_mode=WlstModes.OFFLINE, wls_version=self.wls_version)
26+
27+
location = LocationContext()
28+
self._check_folder(location, aliases)
29+
30+
for folder_name in aliases.get_model_top_level_folder_names():
31+
location = LocationContext()
32+
location.append_location(folder_name)
33+
self._check_folder(location, aliases)
34+
35+
def _check_folder(self, location, aliases):
36+
test_value = ['one', 'two']
37+
expected_value = ','.join(test_value)
38+
39+
attr_infos = aliases.get_model_attribute_names_and_types(location)
40+
for key in attr_infos.keys():
41+
model_type = attr_infos[key]
42+
if model_type.startswith("delimited_string") and not model_type.endswith("[space]"):
43+
44+
wlst_name = aliases.get_wlst_attribute_name(location, key)
45+
if wlst_name is not None:
46+
model_name, value = aliases.get_model_attribute_name_and_value(location, wlst_name, test_value)
47+
message = "Value for attribute " + key + " in location " + str(location.get_folder_path()) + \
48+
" should be comma-delimited"
49+
self.assertEqual(expected_value, value, message)
50+
51+
folder_names = aliases.get_model_subfolder_names(location)
52+
for folder_name in folder_names:
53+
new_location = LocationContext(location).append_location(folder_name)
54+
self._check_folder(new_location, aliases)
55+
return
56+
57+
58+
if __name__ == '__main__':
59+
unittest.main()

0 commit comments

Comments
 (0)