Skip to content

Commit 6d79613

Browse files
add variable value to injector
1 parent 6978b67 commit 6d79613

File tree

3 files changed

+89
-14
lines changed

3 files changed

+89
-14
lines changed

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

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
REGEXP_SUFFIX = 'suffix'
5353
REGEXP_PATTERN = 'pattern'
5454
FORCE = 'force'
55+
VARIABLE_VALUE = 'variable_value'
5556

5657
VARIABLE_SEP = '.'
5758
SUFFIX_SEP = '--'
@@ -280,11 +281,11 @@ def __format_variable_name_segment(self, location, attribute, suffix):
280281
def _variable_info(self, model, attribute, location, injector_values):
281282
# add code here to put in model if force in injector values
282283
if REGEXP in injector_values:
283-
return self._process_regexp(model, attribute, location, injector_values[REGEXP])
284+
return self._process_regexp(model, attribute, location, injector_values)
284285
else:
285-
return self._process_attribute(model, attribute, location)
286+
return self._process_attribute(model, attribute, location, injector_values)
286287

287-
def _process_attribute(self, model, attribute, location):
288+
def _process_attribute(self, model, attribute, location, injector_values):
288289
_method_name = '_process_attribute'
289290
_logger.entering(attribute, location.get_folder_path(), class_name=_class_name,
290291
method_name=_method_name)
@@ -302,20 +303,22 @@ def _process_attribute(self, model, attribute, location):
302303
_logger.finer('WLSDPLY-19526', attribute_value, attribute, str(location), class_name=_class_name,
303304
method_name=_method_name)
304305
if variable_value:
305-
variable_dict[variable_name] = variable_value
306+
variable_dict[variable_name] = self._check_replace_variable_value(location, attribute, variable_value,
307+
injector_values)
306308
_logger.exiting(class_name=_class_name, method_name=_method_name, result=variable_value)
307309
return variable_dict
308310

309-
def _process_regexp(self, model, attribute, location, regexp_list):
311+
def _process_regexp(self, model, attribute, location, injector_values):
310312
if isinstance(model[attribute], dict):
311-
return self._process_patterns_dictionary(attribute, model[attribute], location, regexp_list)
313+
return self._process_patterns_dictionary(attribute, model[attribute], location, injector_values)
312314
elif type(model[attribute]) == list:
313-
return self._process_patterns_list(attribute, model[attribute], location, regexp_list)
315+
return self._process_patterns_list(attribute, model[attribute], location, injector_values)
314316
else:
315-
return self._process_patterns_string(model, attribute, location, regexp_list)
317+
return self._process_patterns_string(model, attribute, location, injector_values)
316318

317-
def _process_patterns_string(self, model, attribute, location, regexp_list):
319+
def _process_patterns_string(self, model, attribute, location, injector_values):
318320
variable_dict = dict()
321+
regexp_list = injector_values[REGEXP]
319322
for dictionary in regexp_list:
320323
pattern = None
321324
suffix = None
@@ -325,7 +328,8 @@ def _process_patterns_string(self, model, attribute, location, regexp_list):
325328
suffix = dictionary[REGEXP_SUFFIX]
326329
variable_name, variable_value = self._process_pattern_string(model, attribute, location, pattern, suffix)
327330
if variable_value:
328-
variable_dict[variable_name] = variable_value
331+
variable_dict[variable_name] = self._check_replace_variable_value(location, attribute, variable_value,
332+
injector_values)
329333
return variable_dict
330334

331335
def _process_pattern_string(self, model, attribute, location, pattern, suffix):
@@ -350,6 +354,7 @@ def _process_pattern_string(self, model, attribute, location, pattern, suffix):
350354
_logger.finer('WLSDPLY-19524', pattern, attribute, model[attribute],
351355
location.get_folder_path, class_name=_class_name,
352356
method_name=_method_name)
357+
353358
_logger.exiting(class_name=_class_name, method_name=_method_name, result=variable_value)
354359
return variable_name, variable_value
355360

@@ -362,8 +367,9 @@ def _find_segment_in_string(self, attribute, attribute_value, location, pattern,
362367
_format_as_property(variable_name))
363368
return attribute_value, variable_name, variable_value
364369

365-
def _process_patterns_list(self, attribute, attribute_value, location, regexp_list):
370+
def _process_patterns_list(self, attribute, attribute_value, location, injector_values):
366371
variable_dict = dict()
372+
regexp_list = injector_values[REGEXP]
367373
for dictionary in regexp_list:
368374
pattern = None
369375
suffix = None
@@ -374,7 +380,8 @@ def _process_patterns_list(self, attribute, attribute_value, location, regexp_li
374380
variable_name, variable_value = self._process_pattern_list(attribute, attribute_value, location, pattern,
375381
suffix)
376382
if variable_value:
377-
variable_dict[variable_name] = variable_value
383+
variable_dict[variable_name] = self._check_replace_variable_value(location, attribute, variable_value,
384+
injector_values)
378385
return variable_dict
379386

380387
def _process_pattern_list(self, attribute_name, attribute_list, location, pattern, suffix):
@@ -399,8 +406,9 @@ def _process_pattern_list(self, attribute_name, attribute_list, location, patter
399406
_logger.exiting(class_name=_class_name, method_name=_method_name, result=variable_value)
400407
return variable_name, variable_value
401408

402-
def _process_patterns_dictionary(self, attribute, attribute_dict, location, regexp_list):
409+
def _process_patterns_dictionary(self, attribute, attribute_dict, location, injector_values):
403410
variable_dict = dict()
411+
regexp_list = injector_values[REGEXP]
404412
for dictionary in regexp_list:
405413
pattern = None
406414
suffix = None
@@ -411,7 +419,8 @@ def _process_patterns_dictionary(self, attribute, attribute_dict, location, rege
411419
variable_name, variable_value = self._process_pattern_dictionary(attribute, attribute_dict, location,
412420
pattern, suffix)
413421
if variable_value:
414-
variable_dict[variable_name] = variable_value
422+
variable_dict[variable_name] = self._check_replace_variable_value(location, attribute, variable_value,
423+
injector_values)
415424
return variable_dict
416425

417426
def _process_pattern_dictionary(self, attribute_name, attribute_dict, location, regexp, suffix):
@@ -497,9 +506,12 @@ def _find_special_name(self, mbean):
497506
mbean_name = mbean
498507
mbean_name_list = []
499508
name_list = _find_special_names_pattern.split(mbean)
509+
print 'mbean before split ', mbean
510+
print 'after pattern split ', name_list
500511
if name_list and len(name_list) > 1:
501512
mbean_name = name_list[0]
502513
mbean_name_list = name_list[1].split(',')
514+
print 'after second split ', mbean_name_list
503515
if mbean_name_list:
504516
new_list = []
505517
for entry in mbean_name_list:
@@ -516,6 +528,7 @@ def _find_special_name(self, mbean):
516528
else:
517529
new_list.append(entry)
518530
mbean_name_list = new_list
531+
print 'mbean ', mbean_name, ' mbean_name_list ', mbean_name_list
519532
return mbean_name, mbean_name_list
520533

521534
def _check_insert_attribute_model(self, location, model_section, attribute, injector_values):
@@ -528,6 +541,21 @@ def _check_insert_attribute_model(self, location, model_section, attribute, inje
528541
class_name=_class_name, method_name=_method_name)
529542
model_section[attribute] = wlst_value
530543

544+
def _check_replace_variable_value(self, location, attribute, variable_value, injector_values):
545+
_method_name = '_format_variable_value'
546+
if VARIABLE_VALUE in injector_values:
547+
value = injector_values[VARIABLE_VALUE]
548+
# might add code to call a method to populate the replacement value
549+
try:
550+
self.__aliases.get_wlst_attribute_name_and_value(location, attribute, value)
551+
variable_value = value
552+
_logger.fine('WLSDPLY-19542', value, variable_value, attribute, location.get_folder_path(),
553+
class_name=_class_name, method_name=_method_name)
554+
except AliasException, ae:
555+
_logger.warning('WLSDPLY-19541', value, attribute, location, ae.getLocalizedMessage(),
556+
class_name=_class_name, method_name=_method_name)
557+
return variable_value
558+
531559

532560
def _load_variable_file(variable_file_location, **kwargs):
533561
_method_name = '_load_variable_file'
@@ -705,6 +733,7 @@ def _format_as_property(prop_name):
705733
return '@@PROP:%s@@' % prop_name
706734

707735

736+
708737
def _split_injector(injector_path):
709738
"""
710739
Split the injector path into an mbean list and an attribute name from the injector path string

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,8 @@ WLSDPLY-19539=Unable to locate and call mbean name keyword {0} method {1} : {2}.
11721172
full mbean name list
11731173
WLSDPLY-19540=Attribute {0} not in the model at location {1} but the force attribute is present in the injector \
11741174
keyword so the attribute will be added to the model with the default value {2}
1175+
WLSDPLY-19541=Replacement variable value {0} cannot be formatted for the attribute {1} at location {2} : {3}
1176+
WLSDPLY-19542=Variable value has been set to {0} and replaces the model value {1} for attribute {2} at location {3}
11751177

11761178
# wlsdeploy/tool/variable_inject.py
11771179
WLSDPLY-19600=Use model variable injector file {0} from command line arguments

core/src/test/python/variable_injector_test.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,50 @@ def testForceAttribute(self):
260260
actual = self._helper.inject_variables(replacement_dict)
261261
self._compare_to_expected_dictionary(expected, actual)
262262

263+
def testReplaceVariableValueAttribute(self):
264+
expected = dict()
265+
expected[
266+
'JMSSystemResource.MyJmsModule.JmsResource.ForeignServer.MyForeignServer.JNDIProperty'
267+
'.java.naming.security.principal.Value'] = 'k8s'
268+
replacement_dict = dict()
269+
replacement_dict['JMSSystemResource.JmsResource.ForeignServer.'
270+
'JNDIProperty[java.naming.security.principal].Value'] = dict()
271+
replacement_dict['JMSSystemResource.JmsResource.ForeignServer.'
272+
'JNDIProperty[java.naming.security.principal].Value'][
273+
variable_injector.VARIABLE_VALUE] = 'k8s'
274+
actual = self._helper.inject_variables(replacement_dict)
275+
self._compare_to_expected_dictionary(expected, actual)
276+
277+
def testReplaceVariableValueSegmentInString(self):
278+
expected = dict()
279+
expected['JDBCSystemResource.Database2.JdbcResource.JDBCDriverParams.URL--Host'] = \
280+
'den00chv'
281+
replacement_dict = dict()
282+
replacement_dict['JDBCSystemResource[Database2].JdbcResource.JDBCDriverParams.URL'] = dict()
283+
list_entry = dict()
284+
list_entry[variable_injector.REGEXP_PATTERN] = '(?<=HOST=)[\w.-]+(?=\))'
285+
list_entry[variable_injector.REGEXP_SUFFIX] = 'Host'
286+
replacement_dict['JDBCSystemResource[Database2].JdbcResource.JDBCDriverParams.URL'][variable_injector.REGEXP] = [
287+
list_entry]
288+
replacement_dict['JDBCSystemResource[Database2].JdbcResource.JDBCDriverParams.URL'][
289+
variable_injector.VARIABLE_VALUE] = 'den00chv'
290+
actual = self._helper.inject_variables(replacement_dict)
291+
self._compare_to_expected_dictionary(expected, actual)
292+
293+
def testReplaceVariableValueSegmentInDictionary(self):
294+
expected = dict()
295+
expected['MailSession.MailSession-0.Properties--SmtpHost'] = 'localhost'
296+
expected['MailSession.MyMailSession.Properties--SmtpHost'] = 'localhost'
297+
replacement_dict = dict()
298+
replacement_dict['MailSession.Properties'] = dict()
299+
list_entry = dict()
300+
list_entry[variable_injector.REGEXP_PATTERN] = 'mail.smtp.host'
301+
list_entry[variable_injector.REGEXP_SUFFIX] = 'SmtpHost'
302+
replacement_dict['MailSession.Properties'][variable_injector.REGEXP] = [list_entry]
303+
replacement_dict['MailSession.Properties'][variable_injector.VARIABLE_VALUE] = 'localhost'
304+
actual = self._helper.inject_variables(replacement_dict)
305+
self._compare_to_expected_dictionary(expected, actual)
306+
263307
def _compare_to_expected_dictionary(self, expected, actual):
264308
self.assertEqual(len(expected), len(actual),
265309
'Not the same number of entries : expected=' + str(len(expected)) + ', actual=' + str(

0 commit comments

Comments
 (0)