Skip to content

Commit da5bf0a

Browse files
Run validator in standalone mode so archive is not required (#655)
* Run validator in standalone mode so archive is not required * Add comment to detail why using stand alone mode
1 parent 46b1edc commit da5bf0a

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

core/src/main/python/compare_model.py

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@
4545
from oracle.weblogic.deploy.validate import ValidateException
4646
from wlsdeploy.exception.expection_types import ExceptionType
4747

48-
VALIDATION_FAIL=2
49-
PATH_TOKEN='|'
50-
BLANK_LINE=""
48+
VALIDATION_FAIL = 2
49+
PATH_TOKEN = '|'
50+
BLANK_LINE = ""
5151

5252
_program_name = 'compareModel'
5353
_class_name = 'compare_model'
54-
__logger = PlatformLogger('wlsdeploy.compare_model')
54+
_logger = PlatformLogger('wlsdeploy.compare_model')
5555

5656
__required_arguments = [
5757
CommandLineArgUtil.ORACLE_HOME_SWITCH
@@ -81,6 +81,7 @@ def __process_args(args):
8181

8282
return ModelContext(_program_name, argument_map)
8383

84+
8485
class ModelDiffer:
8586

8687
def __init__(self, current_dict, past_dict):
@@ -229,18 +230,17 @@ def calculate_changed_model(self):
229230
self._add_results(all_removed, True)
230231

231232
except (KeyError, IndexError), ke:
232-
__logger.severe('WLSDPLY-05709', str(ke)),
233+
_logger.severe('WLSDPLY-05709', str(ke)),
233234
ex = exception_helper.create_pywlst_exception('WLSDPLY-05709', str(ke))
234-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
235+
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
235236
raise ex
236237
except AliasException, ae:
237-
__logger.severe('WLSDPLY-05709', ae.getLocalizedMessage(),
238+
_logger.severe('WLSDPLY-05709', ae.getLocalizedMessage(),
238239
error=ae, class_name=_class_name, method_name=_method_name)
239240
ex = exception_helper.create_compare_exception(ae.getLocalizedMessage(), error=ae)
240-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
241+
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
241242
raise ex
242243

243-
244244
def _is_alias_folder(self, path):
245245
"""
246246
Check if the delimited path is a folder or attribute
@@ -253,7 +253,7 @@ def _is_alias_folder(self, path):
253253
aliases = Aliases(model_context=model_context, wlst_mode=WlstModes.OFFLINE)
254254
location = LocationContext()
255255
last_token = path_tokens[-1]
256-
alias_helper = AliasHelper(aliases, __logger, ExceptionType.COMPARE)
256+
alias_helper = AliasHelper(aliases, _logger, ExceptionType.COMPARE)
257257

258258
found = True
259259
name_token_next = False
@@ -356,7 +356,6 @@ def _add_results(self, ar_changes, is_delete=False):
356356
else:
357357
pointer_dict[parent_key]['!' + app_key] = dict()
358358

359-
360359
def merge_dictionaries(self, dictionary, new_dictionary):
361360
"""
362361
Merge the values from the new dictionary to the existing one.
@@ -436,12 +435,18 @@ def compare(self):
436435

437436
variables.substitute(model_dictionary, variable_map, self.model_context)
438437

439-
return_code = validator.validate_in_tool_mode(model_dictionary,
440-
variables_file_name=None,
441-
archive_file_name=None)
438+
# Run this utility in stand-alone mode instead of tool mode,
439+
# which has stricter checks for the tools.
440+
# An archive is not used with the compare models and if the model
441+
# references a file in an archive, the compareModel will fail if
442+
# running in the stricter tool mode (even with lax).
443+
#
444+
return_code = validator.validate_in_standalone_mode(model_dictionary,
445+
None,
446+
archive_file_name=None)
442447

443448
if return_code == Validator.ReturnCode.STOP:
444-
__logger.severe('WLSDPLY-05705', model_file_name)
449+
_logger.severe('WLSDPLY-05705', model_file_name)
445450
return VALIDATION_FAIL
446451

447452
current_dict = model_dictionary
@@ -455,26 +460,26 @@ def compare(self):
455460
archive_file_name=None)
456461

457462
if return_code == Validator.ReturnCode.STOP:
458-
__logger.severe('WLSDPLY-05705', model_file_name)
463+
_logger.severe('WLSDPLY-05705', model_file_name)
459464
return VALIDATION_FAIL
460465
past_dict = model_dictionary
461466
except ValidateException, te:
462-
__logger.severe('WLSDPLY-20009', _program_name, model_file_name, te.getLocalizedMessage(),
467+
_logger.severe('WLSDPLY-20009', _program_name, model_file_name, te.getLocalizedMessage(),
463468
error=te, class_name=_class_name, method_name=_method_name)
464469
ex = exception_helper.create_compare_exception(te.getLocalizedMessage(), error=te)
465-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
470+
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
466471
return VALIDATION_FAIL
467472
except VariableException, ve:
468-
__logger.severe('WLSDPLY-20009', _program_name, model_file_name, ve.getLocalizedMessage(),
473+
_logger.severe('WLSDPLY-20009', _program_name, model_file_name, ve.getLocalizedMessage(),
469474
error=ve, class_name=_class_name, method_name=_method_name)
470475
ex = exception_helper.create_compare_exception(ve.getLocalizedMessage(), error=ve)
471-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
476+
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
472477
return VALIDATION_FAIL
473478
except TranslateException, pe:
474-
__logger.severe('WLSDPLY-20009', _program_name, model_file_name, pe.getLocalizedMessage(),
479+
_logger.severe('WLSDPLY-20009', _program_name, model_file_name, pe.getLocalizedMessage(),
475480
error=pe, class_name=_class_name, method_name=_method_name)
476481
ex = exception_helper.create_compare_exception(pe.getLocalizedMessage(), error=pe)
477-
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
482+
_logger.throwing(ex, class_name=_class_name, method_name=_method_name)
478483
return VALIDATION_FAIL
479484

480485
obj = ModelDiffer(current_dict, past_dict)
@@ -513,7 +518,7 @@ def compare(self):
513518
fos.close()
514519
if writer:
515520
writer.close()
516-
__logger.severe('WLSDPLY-05708', file_name, ioe.getLocalizedMessage(),
521+
_logger.severe('WLSDPLY-05708', file_name, ioe.getLocalizedMessage(),
517522
error=ioe, class_name=_class_name, method_name=_method_name)
518523
return 2
519524
else:
@@ -540,7 +545,7 @@ def debug(format_string, *arguments):
540545
if os.environ.has_key('DEBUG_COMPARE_MODEL_TOOL'):
541546
print format_string % (arguments)
542547
else:
543-
__logger.finest(format_string, arguments)
548+
_logger.finest(format_string, arguments)
544549

545550
def main():
546551
"""
@@ -549,9 +554,9 @@ def main():
549554
"""
550555
_method_name = 'main'
551556

552-
__logger.entering(class_name=_class_name, method_name=_method_name)
557+
_logger.entering(class_name=_class_name, method_name=_method_name)
553558
for index, arg in enumerate(sys.argv):
554-
__logger.finer('sys.argv[{0}] = {1}', str(index), str(arg), class_name=_class_name, method_name=_method_name)
559+
_logger.finer('sys.argv[{0}] = {1}', str(index), str(arg), class_name=_class_name, method_name=_method_name)
555560

556561
_outputdir = None
557562

@@ -612,7 +617,7 @@ def main():
612617
fos.close()
613618
if writer:
614619
writer.close()
615-
__logger.severe('WLSDPLY-05708', file_name, ioe.getLocalizedMessage(),
620+
_logger.severe('WLSDPLY-05708', file_name, ioe.getLocalizedMessage(),
616621
error=ioe, class_name=_class_name, method_name=_method_name)
617622
else:
618623
if len(compare_msgs) > 0:
@@ -631,23 +636,23 @@ def main():
631636
except CLAException, ex:
632637
exit_code = 2
633638
if exit_code != CommandLineArgUtil.HELP_EXIT_CODE:
634-
__logger.severe('WLSDPLY-20008', _program_name, ex.getLocalizedMessage(), error=ex,
639+
_logger.severe('WLSDPLY-20008', _program_name, ex.getLocalizedMessage(), error=ex,
635640
class_name=_class_name, method_name=_method_name)
636641
cla_helper.clean_up_temp_files()
637642
sys.exit(exit_code)
638643
except CompareException, ce:
639644
cla_helper.clean_up_temp_files()
640-
__logger.severe('WLSDPLY-05704', ce.getLocalizedMessage())
645+
_logger.severe('WLSDPLY-05704', ce.getLocalizedMessage())
641646
System.exit(2)
642647
except PyWLSTException, pe:
643648
cla_helper.clean_up_temp_files()
644-
__logger.severe('WLSDPLY-05704', pe.getLocalizedMessage())
649+
_logger.severe('WLSDPLY-05704', pe.getLocalizedMessage())
645650
System.exit(2)
646651
except:
647652
exc_type, exc_obj, exc_tb = sys.exc_info()
648653
eeString = traceback.format_exception(exc_type, exc_obj, exc_tb)
649654
cla_helper.clean_up_temp_files()
650-
__logger.severe('WLSDPLY-05704', eeString)
655+
_logger.severe('WLSDPLY-05704', eeString)
651656
System.exit(2)
652657

653658
def format_message(key, *args):

0 commit comments

Comments
 (0)