From a141c1b3d5323f0f7558aa7886de9915d9d43c36 Mon Sep 17 00:00:00 2001 From: Richard Killen Date: Mon, 23 Sep 2019 16:32:09 -0500 Subject: [PATCH 1/3] JIRA WDT-365 - Use the summary logger for validation tool --- .../deploy/logging/SummaryHandler.java | 42 ++ .../weblogic/deploy/util/WLSDeployExit.java | 16 + core/src/main/python/validate.py | 43 +- .../wlsdeploy/tool/create/wlsroles_helper.py | 24 +- .../tool/validate/validation_results.py | 391 ----------------- .../wlsdeploy/tool/validate/validator.py | 398 ++++++------------ .../main/python/wlsdeploy/util/variables.py | 34 +- .../deploy/messages/wlsdeploy_rb.properties | 11 - core/src/test/python/validation_test.py | 31 +- installer/src/main/bin/validateModel.cmd | 6 +- installer/src/main/bin/validateModel.sh | 7 +- 11 files changed, 261 insertions(+), 742 deletions(-) delete mode 100644 core/src/main/python/wlsdeploy/tool/validate/validation_results.py diff --git a/core/src/main/java/oracle/weblogic/deploy/logging/SummaryHandler.java b/core/src/main/java/oracle/weblogic/deploy/logging/SummaryHandler.java index 6e147f1e47..d25f4b0307 100644 --- a/core/src/main/java/oracle/weblogic/deploy/logging/SummaryHandler.java +++ b/core/src/main/java/oracle/weblogic/deploy/logging/SummaryHandler.java @@ -15,6 +15,7 @@ import java.util.logging.MemoryHandler; import oracle.weblogic.deploy.util.WLSDeployContext; +import oracle.weblogic.deploy.util.WLSDeployExit; import oracle.weblogic.deploy.util.WebLogicDeployToolingVersion; @@ -122,6 +123,47 @@ public static Properties getHandlerProperties() { return properties; } + /** + * Find the summary handler instance in the logging setup. + * If not found, return null. + * @return the summary handler instance, or null if not found. + */ + public static SummaryHandler findInstance() { + return (SummaryHandler) WLSDeployExit.findHandler(SummaryHandler.class); + } + + /** + * Returns the highest level of the messages in the summary. + * If no messages are found, the level INFO is returned. + * @return the maximum message level, or Level.INFO if none are found. + */ + public Level getMaximumMessageLevel() { + Level maxLevel = Level.INFO; + for(LevelHandler levelHandler : handlers) { + if(levelHandler.getTotalRecords() > 0) { + Level level = levelHandler.getLevel(); + if(level.intValue() > maxLevel.intValue()) { + maxLevel = level; + } + } + } + return maxLevel; + } + + /** + * Returns the message count in the summary for the specified level. + * @return the message count for the specified level. + */ + public int getMessageCount(Level level) { + for(LevelHandler levelHandler : handlers) { + Level handlerLevel = levelHandler.getLevel(); + if(handlerLevel.equals(level)) { + return levelHandler.getTotalRecords(); + } + } + return 0; + } + private void addLevelHandler(Level level) { LevelHandler handler; Handler levelTarget = getConsoleHandler(); diff --git a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployExit.java b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployExit.java index eb6ff3d057..69dd7ed403 100644 --- a/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployExit.java +++ b/core/src/main/java/oracle/weblogic/deploy/util/WLSDeployExit.java @@ -49,6 +49,22 @@ public static void exit(int error_code) { System.exit(error_code); } + /** + * Returns the first handler that is assignment-compatible with the specified class. + * @param handlerClass the class to check for compatibility + * @return the first matching handler, or null if none is found + */ + public static Handler findHandler(Class handlerClass) { + Stack handlers = reduceList(traverseHandlers(getTopLogList(), new LinkedList())); + while (handlers.size() > 0) { + Handler handler = handlers.pop(); + if(handlerClass.isInstance(handler)) { + return handler; + } + } + return null; + } + /** * Call any WLSDeployLogEnd Logger handlers so the handlers can perform end actions. * diff --git a/core/src/main/python/validate.py b/core/src/main/python/validate.py index 2146d620f7..50d15ed0a3 100644 --- a/core/src/main/python/validate.py +++ b/core/src/main/python/validate.py @@ -6,12 +6,15 @@ """ import javaos as os import sys +from java.util.logging import Level -from oracle.weblogic.deploy.util import CLAException +from oracle.weblogic.deploy.util import CLAException, WLSDeployExit from oracle.weblogic.deploy.util import TranslateException from oracle.weblogic.deploy.util import WebLogicDeployToolingVersion from oracle.weblogic.deploy.validate import ValidateException +from oracle.weblogic.deploy.logging import SummaryHandler + sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0]))) # imports from local packages start here @@ -20,6 +23,7 @@ from wlsdeploy.logging.platform_logger import PlatformLogger from wlsdeploy.tool.validate.validator import Validator from wlsdeploy.util import cla_helper +from wlsdeploy.util import tool_exit from wlsdeploy.util import wlst_helper from wlsdeploy.util.cla_utils import CommandLineArgUtil from wlsdeploy.util.model_context import ModelContext @@ -167,17 +171,14 @@ def __perform_model_file_validation(model_file_name, model_context): _method_name = '__perform_model_file_validation' - print_usage = model_context.get_print_usage() - __logger.entering(model_file_name, class_name=_class_name, method_name=_method_name) try: model_dictionary = cla_helper.merge_model_files(model_file_name) model_validator = Validator(model_context, logger=__logger) - validation_results = model_validator.validate_in_standalone_mode(model_dictionary, - model_context.get_variable_file(), - model_context.get_archive_file_name()) + model_validator.validate_in_standalone_mode(model_dictionary, model_context.get_variable_file(), + model_context.get_archive_file_name()) except TranslateException, te: __logger.severe('WLSDPLY-20009', _program_name, model_file_name, te.getLocalizedMessage(), error=te, class_name=_class_name, method_name=_method_name) @@ -185,18 +186,7 @@ def __perform_model_file_validation(model_file_name, model_context): __logger.throwing(ex, class_name=_class_name, method_name=_method_name) raise ex - if print_usage is None: - __logger.info('WLSDPLY-05403', - model_file_name, - validation_results.get_errors_count(), - validation_results.get_warnings_count(), - validation_results.get_infos_count(), - class_name=_class_name, method_name=_method_name) - - validation_results.print_details() - __logger.exiting(class_name=_class_name, method_name=_method_name) - return validation_results def main(args): @@ -214,6 +204,8 @@ def main(args): wlst_helper.silence() + exit_code = CommandLineArgUtil.PROG_OK_EXIT_CODE + try: model_context = __process_args(args) except CLAException, ex: @@ -239,15 +231,15 @@ def main(args): model_file_name = model_context.get_model_file() if model_file_name is not None: - validation_results = __perform_model_file_validation(model_file_name, model_context) - - if validation_results.get_errors_count() > 0: - cla_helper.clean_up_temp_files() - sys.exit(CommandLineArgUtil.PROG_ERROR_EXIT_CODE) - elif validation_results.get_warnings_count() > 0: - cla_helper.clean_up_temp_files() - sys.exit(CommandLineArgUtil.PROG_WARNING_EXIT_CODE) + __perform_model_file_validation(model_file_name, model_context) + summary_handler = SummaryHandler.findInstance() + if summary_handler is not None: + summary_level = summary_handler.getMaximumMessageLevel() + if summary_level == Level.SEVERE: + exit_code = CommandLineArgUtil.PROG_ERROR_EXIT_CODE + elif summary_level == Level.WARNING: + exit_code = CommandLineArgUtil.PROG_WARNING_EXIT_CODE except ValidateException, ve: __logger.severe('WLSDPLY-20000', _program_name, ve.getLocalizedMessage(), error=ve, @@ -257,6 +249,7 @@ def main(args): cla_helper.clean_up_temp_files() + tool_exit.end(model_context, exit_code) return diff --git a/core/src/main/python/wlsdeploy/tool/create/wlsroles_helper.py b/core/src/main/python/wlsdeploy/tool/create/wlsroles_helper.py index a27f53214a..37c277b421 100644 --- a/core/src/main/python/wlsdeploy/tool/create/wlsroles_helper.py +++ b/core/src/main/python/wlsdeploy/tool/create/wlsroles_helper.py @@ -25,6 +25,7 @@ } WLS_ROLE_UPDATE_OPERAND = '|' + class WLSRoles(object): """ Handle the WLSRoles section from the model domainInfo @@ -57,26 +58,25 @@ def process_roles(self): if self._wls_helper is not None and not self._wls_helper.is_weblogic_version_or_above('12.2.1'): self.logger.warning('WLSDPLY-12504', self._wls_helper.get_actual_weblogic_version(), class_name=self.__class_name, method_name=_method_name) else: - role_expressions = self._process_roles_map(self._wls_roles_map, None) + role_expressions = self._process_roles_map(self._wls_roles_map) if role_expressions is not None and len(role_expressions) > 0: self.logger.info('WLSDPLY-12500', role_expressions.keys(), class_name=self.__class_name, method_name=_method_name) self._update_xacml_role_mapper(role_expressions) self.logger.exiting(class_name=self.__class_name, method_name=_method_name) return - def validate_roles(self, validation_result): + def validate_roles(self): """ Validate WLSRoles section of the domainInfo independent of any domain home location """ _method_name = 'validate_roles' self.logger.entering(self._validation_roles_map, class_name=self.__class_name, method_name=_method_name) if self._validation_roles_map is not None and len(self._validation_roles_map) > 0: - self._validate_update_mode(self._validation_roles_map, validation_result) - self._process_roles_map(self._validation_roles_map, validation_result) + self._validate_update_mode(self._validation_roles_map) + self._process_roles_map(self._validation_roles_map) self.logger.exiting(class_name=self.__class_name, method_name=_method_name) - return validation_result - def _process_roles_map(self, roles_map, validation_result): + def _process_roles_map(self, roles_map): """ Loop through the WebLogic roles listed in the domainInfo and create a map of the role to the expression """ @@ -88,14 +88,12 @@ def _process_roles_map(self, roles_map, validation_result): expression = self._get_role_expression(role, roles_map) if string_utils.is_empty(expression): self.logger.finer('WLSDPLY-12501', role, class_name=self.__class_name, method_name=_method_name) - if validation_result is not None: - validation_result.add_warning('WLSDPLY-12501', role) + self.logger.warning('WLSDPLY-12501', role) continue update_role = self._is_role_update_mode(role, roles_map) if update_role and role not in WLS_GLOBAL_ROLES: self.logger.finer('WLSDPLY-12502', role, class_name=self.__class_name, method_name=_method_name) - if validation_result is not None: - validation_result.add_warning('WLSDPLY-12502', role) + self.logger.warning('WLSDPLY-12502', role) update_role = False # Add the role and expression to the map of roles to be processed if update_role: @@ -159,7 +157,7 @@ def _update_role_epression(self, role_name, expression_value, roles_map): result = expression_value + WLS_ROLE_UPDATE_OPERAND + WLS_GLOBAL_ROLES[role_name] return result - def _validate_update_mode(self, roles_map, validation_result): + def _validate_update_mode(self, roles_map): """ Check that the UpdateMode value of a role is one of append, prepend or replace Provide a warning for other values as these will be treated as the default of replace @@ -176,12 +174,12 @@ def _validate_update_mode(self, roles_map, validation_result): if APPEND == mode or PREPEND == mode or REPLACE == mode: continue self.logger.finer('WLSDPLY-12503', role_name, class_name=self.__class_name, method_name=_method_name) - if validation_result is not None: - validation_result.add_warning('WLSDPLY-12503', role_name) + self.logger.warning('WLSDPLY-12503', role_name) self.logger.exiting(class_name=self.__class_name, method_name=_method_name) return + def validator(roles_map, logger): """ Obtain a WLSRoles helper only for the validation of the WLSRoles section diff --git a/core/src/main/python/wlsdeploy/tool/validate/validation_results.py b/core/src/main/python/wlsdeploy/tool/validate/validation_results.py deleted file mode 100644 index cdd21f0615..0000000000 --- a/core/src/main/python/wlsdeploy/tool/validate/validation_results.py +++ /dev/null @@ -1,391 +0,0 @@ -""" -Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. -Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl. -""" - -import java.lang.System as JSystem -import java.lang.Thread as JThread -import java.util.logging.Level as JLevel -import java.util.logging.Logger as JLogger -import java.util.logging.LogRecord as JLogRecord - -from oracle.weblogic.deploy.exception import ExceptionHelper - -from wlsdeploy.util import model -from wlsdeploy.tool.validate import validation_utils -from wlsdeploy.aliases import model_constants - - -class ValidationResults(object): - """ - Class for logging and printing out validation results - - """ - _class_name = 'ValidationResults' - - def __init__(self): - self._validation_result_dict = { - '%s Section' % model.get_model_domain_info_key(): None, - '%s Section' % model.get_model_topology_key(): None, - '%s Section' % model.get_model_deployments_key(): None, - '%s Section' % model.get_model_resources_key(): None, - '%s Section' % model_constants.GLOBAL_VARIABLE_SUBSTITUTION: None - } - - def __str__(self): - return self.__to_string() - - def set_validation_result(self, validation_result): - self._validation_result_dict[validation_result.get_validation_area()] = validation_result - - def get_errors_count(self): - """ - - :return: - """ - results_summary = self.__get_summary() - return results_summary['errors_count'] - - def get_warnings_count(self): - """ - - :return: - """ - results_summary = self.__get_summary() - return results_summary['warnings_count'] - - def get_infos_count(self): - """ - - :return: - """ - results_summary = self.__get_summary() - return results_summary['infos_count'] - - def print_details(self): - """ - - :return: - """ - - results_summary = self.__get_summary() - - message_count = results_summary['infos_count'] - if message_count > 0: - indent_level = 0 - validation_utils.print_blank_lines() - validation_utils.print_indent('%s: %d' % (validation_utils.format_message('WLSDPLY-05201'), - message_count), indent_level + 1) - for validation_result in self._validation_result_dict.values(): - _print_results_category_details(validation_result.get_infos_messages(), indent_level) - - message_count = results_summary['warnings_count'] - if message_count > 0: - indent_level = 0 - validation_utils.print_blank_lines() - validation_utils.print_indent('%s: %d' % (validation_utils.format_message('WLSDPLY-05202'), - message_count), indent_level + 1) - for validation_result in self._validation_result_dict.values(): - _print_results_category_details(validation_result.get_warnings_messages(), indent_level) - - message_count = results_summary['errors_count'] - if message_count > 0: - indent_level = 0 - validation_utils.print_blank_lines() - validation_utils.print_indent('%s: %d' % (validation_utils.format_message('WLSDPLY-05203'), - message_count), indent_level + 1) - for validation_result in self._validation_result_dict.values(): - _print_results_category_details(validation_result.get_errors_messages(), indent_level) - - def log_results(self, logger): - """ - - :return: - """ - _method_name = 'log_results' - - if logger is not None: - # Get counts for all the ValidationResult objects - # in this ValidationResults object - results_summary = self.__get_summary() - - jlogger = JLogger.getLogger(logger.get_name(), logger.resource_bundle_name) - - jlogger.setLevel(JLevel.INFO) - - # Determine what the severity level is going to be for the - # summary log message. Needs to be set in accordance with - # what the severest validation message was. - if results_summary['infos_count'] > 0: - jlogger.setLevel(JLevel.INFO) - if results_summary['warnings_count'] > 0: - jlogger.setLevel(JLevel.WARNING) - if results_summary['errors_count'] > 0: - jlogger.setLevel(JLevel.SEVERE) - - total_messages_count = \ - int(results_summary['errors_count']) + int(results_summary['warnings_count']) + \ - int(results_summary['infos_count']) - - logger.log(jlogger.getLevel(), - 'WLSDPLY-05204', - results_summary['errors_count'], - results_summary['warnings_count'], - results_summary['infos_count'], - class_name=self._class_name, method_name=_method_name) - - if total_messages_count > 0: - logger.log(jlogger.getLevel(), 'WLSDPLY-05207', total_messages_count, - class_name=self._class_name, method_name=_method_name) - - for validation_result in self._validation_result_dict.values(): - if validation_result.get_infos_count() > 0: - jlogger.setLevel(JLevel.INFO) - self.__log_results_category_details(validation_result.get_infos_messages(), - _method_name, jlogger) - - for validation_result in self._validation_result_dict.values(): - if validation_result.get_warnings_count() > 0: - jlogger.setLevel(JLevel.WARNING) - self.__log_results_category_details(validation_result.get_warnings_messages(), - _method_name, jlogger) - - for validation_result in self._validation_result_dict.values(): - if validation_result.get_errors_count() > 0: - jlogger.setLevel(JLevel.SEVERE) - self.__log_results_category_details(validation_result.get_errors_messages(), - _method_name, jlogger) - - jlogger.setLevel(JLevel.INFO) - - return - - def __log_results_category_details(self, category_messages, method_name, jlogger): - """ - - :param category_messages: - :param method_name: - :param jlogger: - :return: - """ - - for i in range(len(category_messages)): - messages = category_messages[i] - _log_category_message(jlogger, messages['resource_id'], messages['args'], - class_name=self._class_name, method_name=method_name) - - def __get_summary(self): - """ - - :return: - """ - - results_summary = { - 'errors_count': 0, - 'warnings_count': 0, - 'infos_count': 0 - } - - for validation_result in self._validation_result_dict.values(): - if validation_result is not None: - results_summary['errors_count'] += validation_result.get_errors_count() - results_summary['warnings_count'] += validation_result.get_warnings_count() - results_summary['infos_count'] += validation_result.get_infos_count() - - return results_summary - - def __to_string(self): - """ - - :return: - """ - - tmp = '' - - for validation_result in self._validation_result_dict.values(): - if validation_result.get_errors_count() > 0 \ - or validation_result.get_warnings_count() > 0 \ - or validation_result.get_infos_count(): - tmp += str(validation_result) - tmp += ',' - - if tmp[-1:] == ',': - # Strip off trailing ',' - tmp = tmp[:-1] - - return '[%s]' % tmp - - -def _print_results_category_details(category_messages, indent_level): - """ - - :param category_messages: - :param indent_level: - :return: - """ - for i in range(len(category_messages)): - messages = category_messages[i] - validation_utils.print_indent( - ExceptionHelper.getMessage(messages['resource_id'], list(messages['args'])), indent_level + 2 - ) - - return - - -def _log_category_message(jlogger, message, *args, **kwargs): - method = kwargs.get('method_name', None) - clazz = kwargs.get('class_name', None) - record = JLogRecord(jlogger.getLevel(), message) - record.setLoggerName(jlogger.getName()) - record.setMillis(JSystem.currentTimeMillis()) - record.setParameters(list(*args)) - record.setResourceBundle(jlogger.getResourceBundle()) - if clazz is not None: - record.setSourceClassName(clazz) - if method is not None: - record.setSourceMethodName(method) - record.setThreadID(int(JThread.currentThread().getId())) - jlogger.log(record) - return - - -class ValidationResult(object): - """ - Class for capturing validation results - """ - def __init__(self, validation_area): - self._result = { - "validation_area": validation_area, - "errors": { - "count": 0, - "messages": [] - }, - "warnings": { - "count": 0, - "messages": [] - }, - "infos": { - "count": 0, - "messages": [] - } - } - - def __str__(self): - tmp = '"validation_area": "%s",' % self._result['validation_area'] - if self.get_errors_count() > 0: - tmp += self.__to_string('errors') - if self.get_warnings_count() > 0: - tmp += self.__to_string('warnings') - if self.get_infos_count() > 0: - tmp += self.__to_string('infos') - - if tmp[-1:] == ',': - # Strip off trailing ',' - tmp = tmp[:-1] - - return "{%s}" % tmp - - def add_error(self, resource_id, *args): - """ - - :param resource_id: - :param args: - :return: - """ - self._result['errors']['count'] += 1 - message = {'resource_id': resource_id, 'args': args} - self._result['errors']['messages'].append(message) - return - - def add_warning(self, resource_id, *args): - """ - - :param resource_id: - :param args: - :return: - """ - self._result['warnings']['count'] += 1 - message = {'resource_id': resource_id, 'args': args} - self._result['warnings']['messages'].append(message) - return - - def add_info(self, resource_id, *args): - """ - - :param resource_id: - :param args: - :return: - """ - self._result['infos']['count'] += 1 - message = {'resource_id': resource_id, 'args': args} - self._result['infos']['messages'].append(message) - return - - def get_validation_area(self): - """ - - :return: - """ - return self._result['validation_area'] - - def get_errors_count(self): - """ - - :return: - """ - return self._result['errors']['count'] - - def get_errors_messages(self): - """ - - :return: - """ - return self._result['errors']['messages'] - - def get_warnings_count(self): - """ - - :return: - """ - return self._result['warnings']['count'] - - def get_warnings_messages(self): - """ - - :return: - """ - return self._result['warnings']['messages'] - - def get_infos_count(self): - """ - - :return: - """ - return self._result['infos']['count'] - - def get_infos_messages(self): - """ - - :return: - """ - return self._result['infos']['messages'] - - def __to_string(self, category_name): - tmp = ' "%s": {' % category_name - tmp += '"count": %d, ' % self._result[category_name]['count'] - tmp += '"messages": [' - for message in self._result[category_name]['messages']: - tmp += "{" - tmp += '"%s": "%s",' % ('message', ExceptionHelper.getMessage(message['resource_id'], - list(message['args']))) - if tmp[-1:] == ',': - # Strip off trailing ',' - tmp = tmp[:-1] - tmp += "}," - if tmp[-1:] == ',': - # Strip off trailing ',' - tmp = tmp[:-1] - # Concatenate closing ']}' - tmp += "]}," - - return tmp diff --git a/core/src/main/python/wlsdeploy/tool/validate/validator.py b/core/src/main/python/wlsdeploy/tool/validate/validator.py index 434a1dd0d6..5c4792d55e 100644 --- a/core/src/main/python/wlsdeploy/tool/validate/validator.py +++ b/core/src/main/python/wlsdeploy/tool/validate/validator.py @@ -5,6 +5,9 @@ import os import copy +from java.util.logging import Level + +from oracle.weblogic.deploy.logging import SummaryHandler from oracle.weblogic.deploy.util import WLSDeployArchive from oracle.weblogic.deploy.util import VariableException @@ -20,7 +23,6 @@ from wlsdeploy.tool.util.alias_helper import AliasHelper from wlsdeploy.tool.util.archive_helper import ArchiveHelper from wlsdeploy.tool.validate import validation_utils -from wlsdeploy.tool.validate.validation_results import ValidationResults, ValidationResult from wlsdeploy.tool.validate.usage_printer import UsagePrinter from wlsdeploy.util import dictionary_utils from wlsdeploy.util import model @@ -65,7 +67,6 @@ def __init__(self, model_context, aliases=None, logger=None, wlst_mode=None, dom self._logger = logger self._validation_mode = None - self._validation_results = ValidationResults() self._variable_properties = {} self._wls_helper = WebLogicHelper(self._logger) @@ -108,7 +109,6 @@ def validate_in_standalone_mode(self, model_dict, variables_file_name=None, arch Defaults to None. :param archive_file_name: Path to file containing binaries associated with the model file. Defaults to None. - :return: A ValidationResults object :raises ValidationException: if an AliasException is raised during an invocation of an aliases API call. """ _method_name = 'validate_in_standalone_mode' @@ -124,7 +124,6 @@ def validate_in_standalone_mode(self, model_dict, variables_file_name=None, arch self.__validate_model_file(cloned_model_dict, variables_file_name, archive_file_name) self._logger.exiting(class_name=_class_name, method_name=_method_name) - return self._validation_results def validate_in_tool_mode(self, model_dict, variables_file_name=None, archive_file_name=None): """ @@ -161,14 +160,13 @@ def validate_in_tool_mode(self, model_dict, variables_file_name=None, archive_fi status = Validator.ValidationStatus.VALID - if self._validation_results.get_errors_count() > 0: - status = Validator.ValidationStatus.INVALID - elif self._validation_results.get_warnings_count() > 0: - status = Validator.ValidationStatus.WARNINGS_INVALID - elif self._validation_results.get_infos_count() > 0: - status = Validator.ValidationStatus.INFOS_VALID - - self._validation_results.log_results(self._logger) + summary_handler = SummaryHandler.findInstance() + if summary_handler is not None: + summary_level = summary_handler.getMaximumMessageLevel() + if summary_level == Level.SEVERE: + status = Validator.ValidationStatus.INVALID + elif summary_level == Level.WARNING: + status = Validator.ValidationStatus.WARNINGS_INVALID if status == Validator.ValidationStatus.VALID or status == Validator.ValidationStatus.INFOS_VALID \ or status == Validator.ValidationStatus.WARNINGS_INVALID: @@ -239,13 +237,10 @@ def __validate_model_file(self, model_dict, variables_file_name, archive_file_na try: if variables_file_name is not None: - self._logger.info('WLSDPLY-05004', variables_file_name, class_name=_class_name, method_name=_method_name) + self._logger.info('WLSDPLY-05004', variables_file_name, class_name=_class_name, + method_name=_method_name) self._variable_properties = variables.load_variables(variables_file_name) - validation_result = ValidationResult(_GLOBAL_LEVEL_VARAIBLE_SUBSTITUTE) - validation_result = variables.substitute(model_dict, self._variable_properties, self._model_context, - validation_result) - - self._validation_results.set_validation_result(validation_result) + variables.substitute(model_dict, self._variable_properties, self._model_context) except VariableException, ve: ex = exception_helper.create_validate_exception('WLSDPLY-20004', 'validateModel', ve.getLocalizedMessage(), error=ve) @@ -259,40 +254,18 @@ def __validate_model_file(self, model_dict, variables_file_name, archive_file_na # not going to validate the structure and only validate things referenced by the model, then no # need to load the archive_entries variable because it is not being used. - validation_result = ValidationResult(_ROOT_LEVEL_VALIDATION_AREA) - validation_result = self.__validate_root_level(model_dict, - model.get_model_top_level_keys(), - validation_result) - self._validation_results.set_validation_result(validation_result) - - validation_result = ValidationResult(_DOMAIN_INFO_VALIDATION_AREA) - validation_result = self.__validate_domain_info_section(model.get_model_domain_info_key(), - model_dict, - validation_result) - self._validation_results.set_validation_result(validation_result) - - validation_result = ValidationResult(_TOPOLOGY_VALIDATION_AREA) - validation_result = self.__validate_model_section(model.get_model_topology_key(), - model_dict, - self._aliases.get_model_topology_top_level_folder_names(), - validation_result) - self._validation_results.set_validation_result(validation_result) - - validation_result = ValidationResult(_RESOURCES_VALIDATION_AREA) - validation_result = \ - self.__validate_model_section(model.get_model_resources_key(), - model_dict, - self._aliases.get_model_resources_top_level_folder_names(), - validation_result) - self._validation_results.set_validation_result(validation_result) - - validation_result = ValidationResult(_APP_DEPLOYMENTS_VALIDATION_AREA) - validation_result = \ - self.__validate_model_section(model.get_model_deployments_key(), - model_dict, - self._aliases.get_model_app_deployments_top_level_folder_names(), - validation_result) - self._validation_results.set_validation_result(validation_result) + self.__validate_root_level(model_dict, model.get_model_top_level_keys()) + + self.__validate_domain_info_section(model.get_model_domain_info_key(), model_dict) + + self.__validate_model_section(model.get_model_topology_key(), model_dict, + self._aliases.get_model_topology_top_level_folder_names()) + + self.__validate_model_section(model.get_model_resources_key(), model_dict, + self._aliases.get_model_resources_top_level_folder_names()) + + self.__validate_model_section(model.get_model_deployments_key(), model_dict, + self._aliases.get_model_app_deployments_top_level_folder_names()) self._logger.exiting(class_name=_class_name, method_name=_method_name) return @@ -325,7 +298,7 @@ def __pre_validation_setup(self, model_dict, archive_file_name): self._logger, ExceptionType.VALIDATE) return - def __validate_root_level(self, model_dict, valid_root_level_keys, validation_result): + def __validate_root_level(self, model_dict, valid_root_level_keys): _method_name = '__validate_root_level' # Get list of root level keys from model_dict @@ -337,34 +310,29 @@ def __validate_root_level(self, model_dict, valid_root_level_keys, validation_re if self._validation_mode == _ValidationModes.STANDALONE: # The model_dict didn't have any top level keys, so record it # as a INFO message in the validate results and bail. - validation_result.add_info('WLSDPLY-05006', self._model_file_name) + self._logger.info('WLSDPLY-05006', self._model_file_name) else: # The model_dict didn't have any top level keys, so record it # as a ERROR message in the validate results and bail. - validation_result.add_error('WLSDPLY-05006', self._model_file_name) - - return validation_result + self._logger.severe('WLSDPLY-05006', self._model_file_name) + return # Loop through model_root_level_keys for key in model_root_level_keys: if key not in valid_root_level_keys: # Found a model_root_level_keys key that isn't in # valid_root_level_keys, so log it at the ERROR level - validation_result.add_error('WLSDPLY-05007', self._model_file_name, key, - '%s' % ', '.join(valid_root_level_keys)) + self._logger.severe('WLSDPLY-05007', self._model_file_name, key, + '%s' % ', '.join(valid_root_level_keys)) self._logger.exiting(class_name=_class_name, method_name=_method_name) - return validation_result - def __validate_domain_info_section(self, model_section_key, model_dict, validation_result): + def __validate_domain_info_section(self, model_section_key, model_dict): """ Performs validation on just the domainInfo section of the model. - :param model_section_key: Name of the model section, which is model_constants.DOMAIN_INFO :param model_dict: Python dictionary of the model file - :param validation_result: A validation result object used only for capturing validation messages, associated with the domainInfo model section - :return: """ _method_name = '__validate_domain_info_section' self._logger.info('WLSDPLY-05008', model_section_key, self._model_file_name, @@ -376,7 +344,7 @@ def __validate_domain_info_section(self, model_section_key, model_dict, validati # model_dict self._logger.info('WLSDPLY-05009', self._model_file_name, model_section_key, class_name=_class_name, method_name=_method_name) - return validation_result + return # Start with an empty location validation_location = LocationContext() @@ -402,7 +370,7 @@ def __validate_domain_info_section(self, model_section_key, model_dict, validati # section_dict_value is either the dict of a folder in the # section, or the value of an attribute in the section if '${' in section_dict_key: - validation_result.add_error('WLSDPLY-05035', model_folder_path, section_dict_key) + self._logger.severe('WLSDPLY-05035', model_folder_path, section_dict_key) log_value = self.__get_attribute_log_value(section_dict_key, section_dict_value, valid_attr_infos) self._logger.finer('WLSDPLY-05011', section_dict_key, log_value, @@ -412,43 +380,25 @@ def __validate_domain_info_section(self, model_section_key, model_dict, validati # section_dict_key is an attribute under the model section, and # also in valid_attr_infos. if section_dict_key == DOMAIN_LIBRARIES: - validation_result = self.__validate_path_tokens_attribute(section_dict_key, - section_dict_value, - model_folder_path, - validation_result) + self.__validate_path_tokens_attribute(section_dict_key, section_dict_value, model_folder_path) + elif section_dict_key == SERVER_GROUP_TARGETING_LIMITS: - validation_result = self.__validate_server_group_targeting_limits(section_dict_key, - section_dict_value, - valid_attr_infos, - model_folder_path, - validation_location, - validation_result) + self.__validate_server_group_targeting_limits(section_dict_key, section_dict_value, + valid_attr_infos, model_folder_path, + validation_location) elif section_dict_key == WLS_ROLES: - validation_result = self.__validate_wlsroles_section(section_dict_key, - section_dict_value, - valid_attr_infos, - path_tokens_attr_keys, - model_folder_path, - validation_location, - validation_result) + self.__validate_wlsroles_section(section_dict_key, section_dict_value, valid_attr_infos, + path_tokens_attr_keys, model_folder_path, validation_location) else: - validation_result = self.__validate_attribute(section_dict_key, - section_dict_value, - valid_attr_infos, - path_tokens_attr_keys, - model_folder_path, - validation_location, - validation_result) + self.__validate_attribute(section_dict_key, section_dict_value, valid_attr_infos, + path_tokens_attr_keys, model_folder_path, validation_location) else: # section_dict_key is not an attribute allowed under the model # section, so record this as a validate ERROR in the validate # results. - validation_result.add_error('WLSDPLY-05029', section_dict_key, model_folder_path, - valid_attr_infos.keys()) - - return validation_result + self._logger.severe('WLSDPLY-05029', section_dict_key, model_folder_path, valid_attr_infos.keys()) - def __validate_model_section(self, model_section_key, model_dict, valid_section_folders, validation_result): + def __validate_model_section(self, model_section_key, model_dict, valid_section_folders): _method_name = '__validate_model_section' self._logger.info('WLSDPLY-05008', model_section_key, self._model_file_name, @@ -460,7 +410,7 @@ def __validate_model_section(self, model_section_key, model_dict, valid_section_ # model_dict self._logger.info('WLSDPLY-05009', self._model_file_name, model_section_key, class_name=_class_name, method_name=_method_name) - return validation_result + return model_section_dict = model_dict[model_section_key] for section_dict_key, section_dict_value in model_section_dict.iteritems(): @@ -471,9 +421,7 @@ def __validate_model_section(self, model_section_key, model_dict, valid_section_ model_folder_path = self._alias_helper.get_model_folder_path(validation_location) if '${' in section_dict_key: - validation_result = _report_unsupported_variable_usage(section_dict_key, - model_folder_path, - validation_result) + self._report_unsupported_variable_usage(section_dict_key, model_folder_path) self._logger.finer('WLSDPLY-05011', section_dict_key, section_dict_value, class_name=_class_name, method_name=_method_name) @@ -488,13 +436,9 @@ def __validate_model_section(self, model_section_key, model_dict, valid_section_ if section_dict_key in valid_attr_infos: # section_dict_key is the name of an attribute in the section - validation_result = self.__validate_attribute(section_dict_key, - section_dict_value, - valid_attr_infos, - path_tokens_attr_keys, - model_folder_path, - validation_location, - validation_result) + self.__validate_attribute(section_dict_key, section_dict_value, valid_attr_infos, + path_tokens_attr_keys, model_folder_path, validation_location) + elif section_dict_key in valid_section_folders: # section_dict_key is a folder under the model section @@ -505,9 +449,7 @@ def __validate_model_section(self, model_section_key, model_dict, valid_section_ # Call self.__validate_section_folder() passing in section_dict_value # as the model_node to process - validation_result = self.__validate_section_folder(section_dict_value, - validation_location, - validation_result) + self.__validate_section_folder(section_dict_value, validation_location) else: # It's not one of the section's folders and it's not an attribute of a # the section. Record this as a validate ERROR in the validate @@ -517,31 +459,29 @@ def __validate_model_section(self, model_section_key, model_dict, valid_section_ section_dict_key) if result == ValidationCodes.VERSION_INVALID: # key is a VERSION_INVALID folder - validation_result.add_warning('WLSDPLY-05027', message) + self._logger.warning('WLSDPLY-05027', message, class_name=_class_name, method_name=_method_name) elif result == ValidationCodes.INVALID: - validation_result.add_error('WLSDPLY-05026', section_dict_key, 'folder', - model_folder_path, '%s' % ', '.join(valid_section_folders)) + self._logger.severe('WLSDPLY-05026', section_dict_key, 'folder', model_folder_path, + '%s' % ', '.join(valid_section_folders)) else: result, message = self._alias_helper.is_valid_model_attribute_name(validation_location, section_dict_key) if result == ValidationCodes.VERSION_INVALID: - validation_result.add_warning('WLSDPLY-05027', message) + self._logger.warning('WLSDPLY-05027', message, class_name=_class_name, method_name=_method_name) elif result == ValidationCodes.INVALID: - validation_result.add_error('WLSDPLY-05029', section_dict_key, - model_folder_path, '%s' % ', '.join(valid_attr_infos)) - - return validation_result + self._logger.severe('WLSDPLY-05029', section_dict_key, model_folder_path, + '%s' % ', '.join(valid_attr_infos)) - def __validate_section_folder(self, model_node, validation_location, validation_result): + def __validate_section_folder(self, model_node, validation_location): _method_name = '__validate_section_folder' result, message = self._alias_helper.is_version_valid_location(validation_location) if result == ValidationCodes.VERSION_INVALID: - validation_result.add_warning('WLSDPLY-05027', message) - return validation_result + self._logger.warning('WLSDPLY-05027', message, class_name=_class_name, method_name=_method_name) + return elif result == ValidationCodes.INVALID: - validation_result.add_error('WLSDPLY-05027', message) - return validation_result + self._logger.severe('WLSDPLY-05027', message) + return model_folder_path = self._alias_helper.get_model_folder_path(validation_location) self._logger.finest('1 model_folder_path={0}', model_folder_path, @@ -555,8 +495,7 @@ def __validate_section_folder(self, model_node, validation_location, validation_ for name in model_node: expanded_name = name if '${' in name: - expanded_name, validation_result = \ - self.__validate_variable_substitution(name, model_folder_path, validation_result) + expanded_name = self.__validate_variable_substitution(name, model_folder_path) self._logger.finest('2 expanded_name={0}', expanded_name, class_name=_class_name, method_name=_method_name) @@ -575,7 +514,7 @@ def __validate_section_folder(self, model_node, validation_location, validation_ value_dict = model_node[name] - self.__process_model_node(value_dict, new_location, validation_result) + self.__process_model_node(value_dict, new_location) elif self._alias_helper.requires_artificial_type_subfolder_handling(validation_location): self._logger.finer('3 model_node_type={0}', @@ -585,7 +524,7 @@ def __validate_section_folder(self, model_node, validation_location, validation_ for name in model_node: expanded_name = name if '${' in name: - _report_unsupported_variable_usage(name, model_folder_path, validation_result) + self._report_unsupported_variable_usage(name, model_folder_path) self._logger.finest('3 expanded_name={0}', expanded_name, class_name=_class_name, method_name=_method_name) @@ -604,7 +543,7 @@ def __validate_section_folder(self, model_node, validation_location, validation_ value_dict = model_node[name] - self.__process_model_node(value_dict, new_location, validation_result) + self.__process_model_node(value_dict, new_location) else: self._logger.finer('4 model_node_type={0}', @@ -627,12 +566,9 @@ def __validate_section_folder(self, model_node, validation_location, validation_ self._logger.finest('4 validation_location={0}', validation_location, class_name=_class_name, method_name=_method_name) - self.__process_model_node(model_node, validation_location, validation_result) - - return validation_result - - def __process_model_node(self, model_node, validation_location, validation_result): + self.__process_model_node(model_node, validation_location) + def __process_model_node(self, model_node, validation_location): _method_name = '__process_model_node' valid_folder_keys = self._alias_helper.get_model_subfolder_names(validation_location) @@ -651,7 +587,7 @@ def __process_model_node(self, model_node, validation_location, validation_resul for key, value in model_node.iteritems(): if '${' in key: - _report_unsupported_variable_usage(key, model_folder_path, validation_result) + self._report_unsupported_variable_usage(key, model_folder_path) self._logger.finer('5 key={0}', key, class_name=_class_name, method_name=_method_name) @@ -669,10 +605,9 @@ def __process_model_node(self, model_node, validation_location, validation_resul class_name=_class_name, method_name=_method_name) valid_attr_infos = self._alias_helper.get_model_attribute_names_and_types(new_location) - validation_result = self.__validate_attributes(value, valid_attr_infos, - new_location, validation_result) + self.__validate_attributes(value, valid_attr_infos, new_location) else: - self.__validate_section_folder(value, new_location, validation_result) + self.__validate_section_folder(value, new_location) elif key in valid_attr_infos: # aliases.get_model_attribute_names_and_types(location) filters out @@ -682,20 +617,15 @@ def __process_model_node(self, model_node, validation_location, validation_resul if valid_data_type in ['properties']: valid_prop_infos = {} properties = validation_utils.get_properties(value) - validation_result = self.__validate_properties(properties, valid_prop_infos, validation_location, - validation_result) + self.__validate_properties(properties, valid_prop_infos, validation_location) else: path_tokens_attr_keys = \ self._alias_helper.get_model_uses_path_tokens_attribute_names(validation_location) - validation_result = self.__validate_attribute(key, - value, - valid_attr_infos, - path_tokens_attr_keys, - model_folder_path, - validation_location, - validation_result) + self.__validate_attribute(key, value, valid_attr_infos, path_tokens_attr_keys, model_folder_path, + validation_location) + elif self._alias_helper.is_custom_folder_allowed(validation_location): # custom folders are not validated, just log this and continue self._logger.info('WLSDPLY-05037', model_folder_path, @@ -716,11 +646,11 @@ def __process_model_node(self, model_node, validation_location, validation_resul result, message = self._alias_helper.is_valid_model_folder_name(validation_location, key) if result == ValidationCodes.VERSION_INVALID: # key is a VERSION_INVALID folder - validation_result.add_warning('WLSDPLY-05027', message) + self._logger.warning('WLSDPLY-05027', message, class_name=_class_name, method_name=_method_name) elif result == ValidationCodes.INVALID: # key is an INVALID folder - validation_result.add_error('WLSDPLY-05026', key, 'folder', - model_folder_path, '%s' % ', '.join(valid_folder_keys)) + self._logger.severe('WLSDPLY-05026', key, 'folder', model_folder_path, + '%s' % ', '.join(valid_folder_keys)) else: # value is not a dict, so key must be the name of an attribute. key cannot be a # folder instance name, because the _alias_helper.supports_multiple_mbean_instances() @@ -730,16 +660,13 @@ def __process_model_node(self, model_node, validation_location, validation_resul result, message = self._alias_helper.is_valid_model_attribute_name(validation_location, key) if result == ValidationCodes.VERSION_INVALID: # key is a VERSION_INVALID attribute - validation_result.add_warning('WLSDPLY-05027', message) + self._logger.warning('WLSDPLY-05027', message, class_name=_class_name, method_name=_method_name) elif result == ValidationCodes.INVALID: # key is an INVALID attribute - validation_result.add_error('WLSDPLY-05029', key, - model_folder_path, '%s' % ', '.join(valid_attr_infos)) + self._logger.severe('WLSDPLY-05029', key, model_folder_path, + '%s' % ', '.join(valid_attr_infos)) - return validation_result - - def __validate_attributes(self, attributes_dict, valid_attr_infos, - validation_location, validation_result): + def __validate_attributes(self, attributes_dict, valid_attr_infos, validation_location): _method_name = '__validate_attributes' self._logger.finest('attributes_dict={0}', str(attributes_dict), @@ -752,18 +679,11 @@ def __validate_attributes(self, attributes_dict, valid_attr_infos, model_folder_path = self._alias_helper.get_model_folder_path(validation_location) for attribute_name, attribute_value in attributes_dict.iteritems(): - validation_result = self.__validate_attribute(attribute_name, - attribute_value, - valid_attr_infos, - path_tokens_attr_keys, - model_folder_path, - validation_location, - validation_result) - - return validation_result + self.__validate_attribute(attribute_name, attribute_value, valid_attr_infos, path_tokens_attr_keys, + model_folder_path, validation_location) def __validate_attribute(self, attribute_name, attribute_value, valid_attr_infos, path_tokens_attr_keys, - model_folder_path, validation_location, validation_result): + model_folder_path, validation_location): _method_name = '__validate_attribute' log_value = self.__get_attribute_log_value(attribute_name, attribute_value, valid_attr_infos) @@ -772,12 +692,10 @@ def __validate_attribute(self, attribute_name, attribute_value, valid_attr_infos class_name=_class_name, method_name=_method_name) if '${' in attribute_name: - validation_result = _report_unsupported_variable_usage(attribute_name, model_folder_path, validation_result) + self._report_unsupported_variable_usage(attribute_name, model_folder_path) if '${' in str(attribute_value): - attribute_value, validation_result = self.__validate_variable_substitution(attribute_value, - model_folder_path, - validation_result) + attribute_value = self.__validate_variable_substitution(attribute_value, model_folder_path) if attribute_name in valid_attr_infos: expected_data_type = valid_attr_infos[attribute_name] @@ -785,28 +703,22 @@ def __validate_attribute(self, attribute_name, attribute_value, valid_attr_infos self._logger.finer('WLSDPLY-05016', attribute_name, expected_data_type, actual_data_type, class_name=_class_name, method_name=_method_name) if validation_utils.is_compatible_data_type(expected_data_type, actual_data_type) is False: - validation_result.add_warning('WLSDPLY-05017', attribute_name, model_folder_path, - expected_data_type, actual_data_type) + self._logger.warning('WLSDPLY-05017', attribute_name, model_folder_path, expected_data_type, + actual_data_type, class_name=_class_name, method_name=_method_name) if attribute_name in path_tokens_attr_keys: - validation_result = self.__validate_path_tokens_attribute(attribute_name, - attribute_value, - model_folder_path, - validation_result) + self.__validate_path_tokens_attribute(attribute_name, attribute_value, model_folder_path) else: result, message = self._alias_helper.is_valid_model_attribute_name(validation_location, attribute_name) if result == ValidationCodes.VERSION_INVALID: - validation_result.add_warning('WLSDPLY-05027', message) + self._logger.warning('WLSDPLY-05027', message, class_name=_class_name, method_name=_method_name) elif result == ValidationCodes.INVALID: - validation_result.add_error('WLSDPLY-05029', attribute_name, - model_folder_path, '%s' % ', '.join(valid_attr_infos)) + self._logger.severe('WLSDPLY-05029', attribute_name, + model_folder_path, '%s' % ', '.join(valid_attr_infos)) self._logger.exiting(class_name=_class_name, method_name=_method_name) - return validation_result - - def __validate_properties(self, properties_dict, valid_prop_infos, - validation_location, validation_result): + def __validate_properties(self, properties_dict, valid_prop_infos, validation_location): _method_name = '__validate_properties' self._logger.entering(str(properties_dict), str(validation_location), @@ -814,18 +726,11 @@ def __validate_properties(self, properties_dict, valid_prop_infos, for property_name, property_value in properties_dict.iteritems(): valid_prop_infos[property_name] = validation_utils.get_python_data_type(property_value) - validation_result = self.__validate_property(property_name, - property_value, - valid_prop_infos, - validation_location, - validation_result) + self.__validate_property(property_name, property_value, valid_prop_infos, validation_location) self._logger.exiting(class_name=_class_name, method_name=_method_name) - return validation_result - - def __validate_property(self, property_name, property_value, valid_prop_infos, - model_folder_path, validation_result): + def __validate_property(self, property_name, property_value, valid_prop_infos, model_folder_path): _method_name = '__validate_property' @@ -833,13 +738,10 @@ def __validate_property(self, property_name, property_value, valid_prop_infos, class_name=_class_name, method_name=_method_name) if '${' in property_name: - property_name, validation_result = self.__validate_variable_substitution(property_name, - model_folder_path, - validation_result) + property_name = self.__validate_variable_substitution(property_name, model_folder_path) + if '${' in str(property_value): - property_value, validation_result = self.__validate_variable_substitution(property_value, - model_folder_path, - validation_result) + property_value = self.__validate_variable_substitution(property_value, model_folder_path) if property_name in valid_prop_infos: expected_data_type = valid_prop_infos[property_name] @@ -847,14 +749,12 @@ def __validate_property(self, property_name, property_value, valid_prop_infos, self._logger.finer('WLSDPLY-05018', property_name, expected_data_type, actual_data_type, class_name=_class_name, method_name=_method_name) if validation_utils.is_compatible_data_type(expected_data_type, actual_data_type) is False: - validation_result.add_warning('WLSDPLY-05019', property_name, model_folder_path, - expected_data_type, actual_data_type) + self._logger.warning('WLSDPLY-05019', property_name, model_folder_path, expected_data_type, + actual_data_type, class_name=_class_name, method_name=_method_name) else: - validation_result.add_error('WLSDPLY-05020', property_name, model_folder_path) - - return validation_result + self._logger.severe('WLSDPLY-05020', property_name, model_folder_path) - def __validate_variable_substitution(self, tokenized_value, model_folder_path, validation_result): + def __validate_variable_substitution(self, tokenized_value, model_folder_path): _method_name = '__validate_variable_substitution' self._logger.entering(tokenized_value, model_folder_path, class_name=_class_name, method_name=_method_name) @@ -875,7 +775,7 @@ def __validate_variable_substitution(self, tokenized_value, model_folder_path, v if property_value is not None: untokenized_value = untokenized_value.replace(token, property_value) else: - # FIXME(mwooten) - the cla_utils should be fixing all windows paths to use forward slashes already... + # FIXME(mwooten) - the cla_utils should be fixing all windows paths to use forward slashes already # assuming that the value is not None variables_file_name = self._model_context.get_variable_file() if variables_file_name is None: @@ -886,9 +786,9 @@ def __validate_variable_substitution(self, tokenized_value, model_folder_path, v class_name=_class_name, method_name=_method_name) self._logger.exiting(class_name=_class_name, method_name=_method_name, result=untokenized_value) - return untokenized_value, validation_result + return untokenized_value - def __validate_path_tokens_attribute(self, attribute_name, attribute_value, model_folder_path, validation_result): + def __validate_path_tokens_attribute(self, attribute_name, attribute_value, model_folder_path): _method_name = '__validate_path_tokens_attribute' self._logger.entering(attribute_name, attribute_value, model_folder_path, @@ -901,7 +801,7 @@ def __validate_path_tokens_attribute(self, attribute_name, attribute_value, mode valid_valus_data_types = ['list', 'string'] if value_data_type not in valid_valus_data_types: - validation_result.add_error('WLSDPLY-05023', attribute_name, model_folder_path, value_data_type) + self._logger.severe('WLSDPLY-05023', attribute_name, model_folder_path, value_data_type) else: attr_values = [] @@ -916,12 +816,9 @@ def __validate_path_tokens_attribute(self, attribute_name, attribute_value, mode attr_values.extend(attribute_value) for item_path in attr_values: - validation_result = self.__validate_single_path_in_archive(item_path.strip(), attribute_name, - model_folder_path, validation_result) + self.__validate_single_path_in_archive(item_path.strip(), attribute_name, model_folder_path) - return validation_result - - def __validate_single_path_in_archive(self, path, attribute_name, model_folder_path, validation_result): + def __validate_single_path_in_archive(self, path, attribute_name, model_folder_path): _method_name = '__validate_single_path_in_archive' # There are 3 possible conditions: @@ -938,16 +835,16 @@ def __validate_single_path_in_archive(self, path, attribute_name, model_folder_p if self._archive_helper is not None: archive_has_file = self._archive_helper.contains_file_or_path(path) if not archive_has_file: - validation_result.add_error('WLSDPLY-05024', attribute_name, model_folder_path, - path, self._archive_file_name) + self._logger.severe('WLSDPLY-05024', attribute_name, model_folder_path, path, + self._archive_file_name) else: # If running in standalone mode, and the archive was not supplied, simply # alert the user to the references but don;t fail validation because of # the dangling references. In TOOL mode, this is an error. if self._validation_mode == _ValidationModes.STANDALONE: - validation_result.add_info('WLSDPLY-05025', attribute_name, model_folder_path, path) + self._logger.info('WLSDPLY-05025', attribute_name, model_folder_path, path) elif self._validation_mode == _ValidationModes.TOOL: - validation_result.add_error('WLSDPLY-05025', attribute_name, model_folder_path, path) + self._logger.severe('WLSDPLY-05025', attribute_name, model_folder_path, path) else: tokens = validation_utils.extract_path_tokens(path) self._logger.finest('tokens={0}', str(tokens), class_name=_class_name, method_name=_method_name) @@ -955,12 +852,10 @@ def __validate_single_path_in_archive(self, path, attribute_name, model_folder_p if not self._model_context.has_token_prefix(path): if not os.path.isabs(path): - validation_result.add_info('WLSDPLY-05031', attribute_name, model_folder_path, path) - - return validation_result + self._logger.info('WLSDPLY-05031', attribute_name, model_folder_path, path) def __validate_server_group_targeting_limits(self, attribute_name, attribute_value, valid_attr_infos, - model_folder_path, validation_location, validation_result): + model_folder_path, validation_location): __method_name = '__validate_server_group_targeting_limits' self._logger.entering(attribute_name, attribute_value, valid_attr_infos, model_folder_path, @@ -968,76 +863,55 @@ def __validate_server_group_targeting_limits(self, attribute_name, attribute_val if attribute_value is not None: if not isinstance(attribute_value, dict): - validation_result.add_error('WLSDPLY-05032', - attribute_name, model_folder_path, - str(type(attribute_value))) + self._logger.severe('WLSDPLY-05032', attribute_name, model_folder_path, str(type(attribute_value))) else: model_folder_path += '/' + attribute_name for key, value in attribute_value.iteritems(): if type(key) is not str: # Force the key to a string for any value validation issues reported below key = str(key) - validation_result.add_error('WLSDPLY-05033', key, model_folder_path, str(type(key))) + self._logger.severe('WLSDPLY-05033', key, model_folder_path, str(type(key))) else: if '${' in key: - key, validation_result = \ - _report_unsupported_variable_usage(key, model_folder_path, validation_result) + self._report_unsupported_variable_usage(key, model_folder_path) if type(value) is str and MODEL_LIST_DELIMITER in value: value = value.split(MODEL_LIST_DELIMITER) if type(value) is list: for element in value: - validation_result = \ - _validate_single_server_group_target_limits_value(key, element.strip(), - model_folder_path, - validation_result) + self._validate_single_server_group_target_limits_value(key, element.strip(), + model_folder_path) elif type(value) is str: - validation_result = \ - _validate_single_server_group_target_limits_value(key, value, model_folder_path, - validation_result) + self._validate_single_server_group_target_limits_value(key, value, model_folder_path) else: - validation_result.add_error('WLSDPLY-05034', key, model_folder_path, str(type(value))) + self._logger.severe('WLSDPLY-05034', key, model_folder_path, str(type(value))) self._logger.exiting(class_name=_class_name, method_name=__method_name) - return validation_result def __validate_wlsroles_section(self, attribute_name, attribute_value, valid_attr_infos, path_tokens_attr_keys, - model_folder_path, validation_location, validation_result): + model_folder_path, validation_location): __method_name = '__validate_wlsroles_section' self._logger.entering(class_name=_class_name, method_name=__method_name) # Validate the basics of the WLSRoles section definition - validation_result = self.__validate_attribute(attribute_name, - attribute_value, - valid_attr_infos, - path_tokens_attr_keys, - model_folder_path, - validation_location, - validation_result) + self.__validate_attribute(attribute_name, attribute_value, valid_attr_infos, path_tokens_attr_keys, + model_folder_path, validation_location) # Validate WebLogic role content using WLSRoles helper wlsroles_validator = wlsroles_helper.validator(attribute_value, self._logger) - validation_result = wlsroles_validator.validate_roles(validation_result) + wlsroles_validator.validate_roles() self._logger.exiting(class_name=_class_name, method_name=__method_name) - return validation_result - - -def _validate_single_server_group_target_limits_value(key, value, model_folder_path, validation_result): - if type(value) is str: - if '${' in str(value): - value, validation_result = \ - _report_unsupported_variable_usage(str(value), model_folder_path, validation_result) - else: - validation_result.add_error('WLSDPLY-05035', key, str(value), model_folder_path, str(type(value))) - return validation_result - - -def _report_unsupported_variable_usage(tokenized_value, model_folder_path, validation_result): - tokens = validation_utils.extract_substitution_tokens(tokenized_value) - for token in tokens: - validation_result.add_error('WLSDPLY-05030', model_folder_path, token) + def _validate_single_server_group_target_limits_value(self, key, value, model_folder_path): + if type(value) is str: + if '${' in str(value): + self._report_unsupported_variable_usage(str(value), model_folder_path) + else: + self._logger.severe('WLSDPLY-05035', key, str(value), model_folder_path, str(type(value))) - return validation_result + def _report_unsupported_variable_usage(self, tokenized_value, model_folder_path): + tokens = validation_utils.extract_substitution_tokens(tokenized_value) + for token in tokens: + self._logger.severe('WLSDPLY-05030', model_folder_path, token) diff --git a/core/src/main/python/wlsdeploy/util/variables.py b/core/src/main/python/wlsdeploy/util/variables.py index 3128ca9493..9a99f6c45c 100644 --- a/core/src/main/python/wlsdeploy/util/variables.py +++ b/core/src/main/python/wlsdeploy/util/variables.py @@ -134,18 +134,17 @@ def get_variable_names(text): return names -def substitute(dictionary, variables, model_context, validation_result=None): +def substitute(dictionary, variables, model_context): """ Substitute fields in the specified dictionary with variable values. :param dictionary: the dictionary in which to substitute variables :param variables: a dictionary of variables for substitution :param model_context: used to resolve variables in file paths """ - _process_node(dictionary, variables, model_context, validation_result) - return validation_result + _process_node(dictionary, variables, model_context) -def _process_node(nodes, variables, model_context, validation_result): +def _process_node(nodes, variables, model_context): """ Process variables in the node. :param nodes: the dictionary to process @@ -161,18 +160,18 @@ def _process_node(nodes, variables, model_context, validation_result): value = nodes[key] # if the key changes with substitution, remove old key and map value to new key - new_key = _substitute(key, variables, model_context, validation_result) + new_key = _substitute(key, variables, model_context) if new_key is not key: nodes.pop(key) nodes[new_key] = value if isinstance(value, dict): - _process_node(value, variables, model_context, validation_result) + _process_node(value, variables, model_context) elif type(value) is str: - nodes[key] = _substitute(value, variables, model_context, validation_result) + nodes[key] = _substitute(value, variables, model_context) -def _substitute(text, variables, model_context, validation_result): +def _substitute(text, variables, model_context): """ Substitute the variable placeholders with the variable value. :param text: the text to process for variable placeholders @@ -206,15 +205,13 @@ def _substitute(text, variables, model_context, validation_result): # for @@PROP:key@@ variables, throw an exception if key is not found. if key not in variables: if model_context.get_validation_method() == 'strict': - if validation_result: - validation_result.add_error('WLSDPLY-01732', key) + _logger.severe('WLSDPLY-01732', key) ex = exception_helper.create_variable_exception('WLSDPLY-01732', key) _logger.throwing(ex, class_name=_class_name, method_name=method_name) raise ex else: - if validation_result: - validation_result.add_info('WLSDPLY-01732', key) - continue + _logger.info('WLSDPLY-01732', key) + continue value = variables[key] text = text.replace(token, value) @@ -223,7 +220,7 @@ def _substitute(text, variables, model_context, validation_result): if tokens: for token in tokens: path = token[7:-2] - value = _read_value_from_file(path, model_context, validation_result) + value = _read_value_from_file(path, model_context) text = text.replace(token, value) # special case for @@FILE:@@ORACLE_HOME@@/dir/name.txt@@ @@ -232,13 +229,13 @@ def _substitute(text, variables, model_context, validation_result): for token in tokens: path = token[7:-2] path = model_context.replace_token_string(path) - value = _read_value_from_file(path, model_context, validation_result) + value = _read_value_from_file(path, model_context) text = text.replace(token, value) return text -def _read_value_from_file(file_path, model_context, validation_result): +def _read_value_from_file(file_path, model_context): """ Read a single text value from the first line in the specified file. :param file_path: the file from which to read the value @@ -253,14 +250,11 @@ def _read_value_from_file(file_path, model_context, validation_result): file_reader.close() except IOException, e: if model_context.get_validation_method() == 'strict': - if validation_result: - validation_result.add_error('WLSDPLY-01733', file_path, e.getLocalizedMessage()) + _logger.severe('WLSDPLY-01733', file_path, e.getLocalizedMessage()) ex = exception_helper.create_variable_exception('WLSDPLY-01733', file_path, e.getLocalizedMessage(), error=e) _logger.throwing(ex, class_name=_class_name, method_name=method_name) raise ex else: - if validation_result: - validation_result.add_info('WLSDPLY-01733', file_path, e.getLocalizedMessage()) _logger.info('WLSDPLY-01733', file_path, e.getLocalizedMessage(), error=e, class_name=_class_name, method_name=method_name) line = '' diff --git a/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties b/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties index 2659731dd3..36331b30db 100644 --- a/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties +++ b/core/src/main/resources/oracle/weblogic/deploy/messages/wlsdeploy_rb.properties @@ -429,17 +429,6 @@ WLSDPLY-05108=Model location {0} has no folder path {1} beneath it. Valid folder one of the following: {2} WLSDPLY-05109=Valid Attributes are :- -# wlsdeploy/tools/validate/validation_results.py -WLSDPLY-05200=Validation Area: {0} -WLSDPLY-05201=Infos -WLSDPLY-05202=Warnings -WLSDPLY-05203=Errors -WLSDPLY-05204=Validation found {0} error, {1} warning, and {2} informational messages. -WLSDPLY-05205=Message: {0} -WLSDPLY-05206=Comment: {0} -WLSDPLY-05207=See the next {0} log messages for the details. - - # wlsdeploy/tools/validate/validation_utils.py WLSDPLY-05300={0} variable is referenced in the value of the {1} variable, but is not defined in {2} diff --git a/core/src/test/python/validation_test.py b/core/src/test/python/validation_test.py index 5e00252f83..a4064ce68b 100644 --- a/core/src/test/python/validation_test.py +++ b/core/src/test/python/validation_test.py @@ -4,13 +4,15 @@ """ import unittest import os +from java.util.logging import Level + +from oracle.weblogic.deploy.logging import SummaryHandler from wlsdeploy.logging.platform_logger import PlatformLogger from wlsdeploy.util.weblogic_helper import WebLogicHelper from wlsdeploy.util.model_translator import FileToPython from wlsdeploy.util.model_context import ModelContext -import validate from wlsdeploy.tool.validate.validator import Validator from wlsdeploy.tool.validate import validation_utils from wlsdeploy.aliases.wlst_modes import WlstModes @@ -20,7 +22,7 @@ from oracle.weblogic.deploy.validate import ValidateException from wlsdeploy.tool.create import wlsroles_helper -from wlsdeploy.tool.validate.validation_results import ValidationResult + class ValidationTestCase(unittest.TestCase): _program_name = 'validation_test' @@ -30,11 +32,12 @@ class ValidationTestCase(unittest.TestCase): # _model_file = _resources_dir + '/test_empty.json' # _variable_file = _resources_dir + "/test_invalid_variable_file.properties" # _archive_file = _resources_dir + "/test_jms_archive.zip" - _logger = PlatformLogger('wlsdeploy.validate') def setUp(self): self.name = 'ValidationTestCase' + self._logger = PlatformLogger('wlsdeploy.validate') self.wls_helper = WebLogicHelper(self._logger) + self._logger.logger.addHandler(SummaryHandler()) def testModelValidation(self): _method_name = 'testModelValidation' @@ -241,7 +244,6 @@ def testWLSRolesValidation(self): """ _method_name = 'testWLSRolesValidation' - validation_result = ValidationResult('Test WLSRoles Section') wlsroles_dict = {'Admin': {'UpdateMode': 'append', 'Expression': 'Grp(AppAdmin)'}, 'Deployer': {'UpdateMode': 'prepend', @@ -256,22 +258,15 @@ def testWLSRolesValidation(self): 'Expression': 'Grp(MyTester3)'}} wlsroles_validator = wlsroles_helper.validator(wlsroles_dict, self._logger) - validation_result = wlsroles_validator.validate_roles(validation_result) - self._logger.info('The WLSRoles validation result is: {0}', validation_result, - class_name=self._class_name, method_name=_method_name) + wlsroles_validator.validate_roles() + + handler = SummaryHandler.findInstance() + self.assertNotEqual(handler, None, "Summary handler is not present") # Verify only warnings resulted - self.assertEqual(validation_result.get_errors_count(), 0) - self.assertEqual(validation_result.get_warnings_count(), 3) - self.assertEqual(validation_result.get_infos_count(), 0) - - # Verify each warning message is a different message id - msgid_dict = {} - warn_msg_list = validation_result.get_warnings_messages() - for warn_msg in warn_msg_list: - id = warn_msg['resource_id'] - msgid_dict[id] = 'true' - self.assertEqual(len(msgid_dict), 3) + self.assertEqual(handler.getMessageCount(Level.SEVERE), 0) + self.assertEqual(handler.getMessageCount(Level.WARNING), 3) + if __name__ == '__main__': unittest.main() diff --git a/installer/src/main/bin/validateModel.cmd b/installer/src/main/bin/validateModel.cmd index dc08d5c7a6..a9fbddf463 100644 --- a/installer/src/main/bin/validateModel.cmd +++ b/installer/src/main/bin/validateModel.cmd @@ -272,7 +272,8 @@ IF NOT EXIST "%WLST%" ( ) :found_wlst -SET LOG_CONFIG_CLASS=oracle.weblogic.deploy.logging.WLSDeployLoggingConfig +SET LOG_CONFIG_CLASS=oracle.weblogic.deploy.logging.WLSDeployCustomizeLoggingConfig +SET WLSDEPLOY_LOG_HANDLER=oracle.weblogic.deploy.logging.SummaryHandler SET WLST_PROPERTIES=-Dcom.oracle.cie.script.throwException=true SET "WLST_PROPERTIES=-Djava.util.logging.config.class=%LOG_CONFIG_CLASS% %WLST_PROPERTIES%" SET "WLST_PROPERTIES=%WLST_PROPERTIES% %WLSDEPLOY_PROPERTIES%" @@ -283,6 +284,9 @@ IF NOT DEFINED WLSDEPLOY_LOG_PROPERTIES ( IF NOT DEFINED WLSDEPLOY_LOG_DIRECTORY ( SET WLSDEPLOY_LOG_DIRECTORY=%WLSDEPLOY_HOME%\logs ) +IF NOT DEFINED WLSDEPLOY_LOG_HANDLERS ( + SET WLSDEPLOY_LOG_HANDLERS=%WLSDEPLOY_LOG_HANDLER% +) ECHO JAVA_HOME = %JAVA_HOME% ECHO WLST_EXT_CLASSPATH = %WLST_EXT_CLASSPATH% diff --git a/installer/src/main/bin/validateModel.sh b/installer/src/main/bin/validateModel.sh index 68f3d29cf7..f227a06017 100644 --- a/installer/src/main/bin/validateModel.sh +++ b/installer/src/main/bin/validateModel.sh @@ -258,7 +258,8 @@ else fi fi -LOG_CONFIG_CLASS=oracle.weblogic.deploy.logging.WLSDeployLoggingConfig +LOG_CONFIG_CLASS=oracle.weblogic.deploy.logging.WLSDeployCustomizeLoggingConfig +WLSDEPLOY_LOG_HANDLER=oracle.weblogic.deploy.logging.SummaryHandler WLST_PROPERTIES=-Dcom.oracle.cie.script.throwException=true WLST_PROPERTIES="-Djava.util.logging.config.class=${LOG_CONFIG_CLASS} ${WLST_PROPERTIES} ${WLSDEPLOY_PROPERTIES}" export WLST_PROPERTIES @@ -271,6 +272,10 @@ if [ -z "${WLSDEPLOY_LOG_DIRECTORY}" ]; then WLSDEPLOY_LOG_DIRECTORY=${WLSDEPLOY_HOME}/logs; export WLSDEPLOY_LOG_DIRECTORY fi +if [ -z "${WLSDEPLOY_LOG_HANDLERS}" ]; then + WLSDEPLOY_LOG_HANDLERS=${WLSDEPLOY_LOG_HANDLER}; export WLSDEPLOY_LOG_HANDLERS +fi + echo "JAVA_HOME = ${JAVA_HOME}" echo "WLST_EXT_CLASSPATH = ${WLST_EXT_CLASSPATH}" echo "CLASSPATH = ${CLASSPATH}" From 7d77f340bff48a9a1173da86e3d8ed1b6c7eb26b Mon Sep 17 00:00:00 2001 From: Richard Killen Date: Tue, 24 Sep 2019 10:29:11 -0500 Subject: [PATCH 2/3] JIRA WDT-365 - Added class name, method name where needed --- .../wlsdeploy/tool/create/wlsroles_helper.py | 10 ++- .../wlsdeploy/tool/validate/validator.py | 70 ++++++++++++------- .../main/python/wlsdeploy/util/variables.py | 11 +-- 3 files changed, 56 insertions(+), 35 deletions(-) diff --git a/core/src/main/python/wlsdeploy/tool/create/wlsroles_helper.py b/core/src/main/python/wlsdeploy/tool/create/wlsroles_helper.py index 37c277b421..2d9b0d0670 100644 --- a/core/src/main/python/wlsdeploy/tool/create/wlsroles_helper.py +++ b/core/src/main/python/wlsdeploy/tool/create/wlsroles_helper.py @@ -87,13 +87,11 @@ def _process_roles_map(self, roles_map): # Get the role expression and if the role should be an update to the default set of roles expression = self._get_role_expression(role, roles_map) if string_utils.is_empty(expression): - self.logger.finer('WLSDPLY-12501', role, class_name=self.__class_name, method_name=_method_name) - self.logger.warning('WLSDPLY-12501', role) + self.logger.warning('WLSDPLY-12501', role, class_name=self.__class_name, method_name=_method_name) continue update_role = self._is_role_update_mode(role, roles_map) if update_role and role not in WLS_GLOBAL_ROLES: - self.logger.finer('WLSDPLY-12502', role, class_name=self.__class_name, method_name=_method_name) - self.logger.warning('WLSDPLY-12502', role) + self.logger.warning('WLSDPLY-12502', role, class_name=self.__class_name, method_name=_method_name) update_role = False # Add the role and expression to the map of roles to be processed if update_role: @@ -173,8 +171,8 @@ def _validate_update_mode(self, roles_map): mode = mode.lower() if APPEND == mode or PREPEND == mode or REPLACE == mode: continue - self.logger.finer('WLSDPLY-12503', role_name, class_name=self.__class_name, method_name=_method_name) - self.logger.warning('WLSDPLY-12503', role_name) + self.logger.warning('WLSDPLY-12503', role_name, class_name=self.__class_name, + method_name=_method_name) self.logger.exiting(class_name=self.__class_name, method_name=_method_name) return diff --git a/core/src/main/python/wlsdeploy/tool/validate/validator.py b/core/src/main/python/wlsdeploy/tool/validate/validator.py index 5c4792d55e..91fb1e2951 100644 --- a/core/src/main/python/wlsdeploy/tool/validate/validator.py +++ b/core/src/main/python/wlsdeploy/tool/validate/validator.py @@ -310,11 +310,13 @@ def __validate_root_level(self, model_dict, valid_root_level_keys): if self._validation_mode == _ValidationModes.STANDALONE: # The model_dict didn't have any top level keys, so record it # as a INFO message in the validate results and bail. - self._logger.info('WLSDPLY-05006', self._model_file_name) + self._logger.info('WLSDPLY-05006', self._model_file_name, class_name=_class_name, + method_name=_method_name) else: # The model_dict didn't have any top level keys, so record it # as a ERROR message in the validate results and bail. - self._logger.severe('WLSDPLY-05006', self._model_file_name) + self._logger.severe('WLSDPLY-05006', self._model_file_name, class_name=_class_name, + method_name=_method_name) return # Loop through model_root_level_keys @@ -323,7 +325,8 @@ def __validate_root_level(self, model_dict, valid_root_level_keys): # Found a model_root_level_keys key that isn't in # valid_root_level_keys, so log it at the ERROR level self._logger.severe('WLSDPLY-05007', self._model_file_name, key, - '%s' % ', '.join(valid_root_level_keys)) + '%s' % ', '.join(valid_root_level_keys), class_name=_class_name, + method_name=_method_name) self._logger.exiting(class_name=_class_name, method_name=_method_name) @@ -370,7 +373,8 @@ def __validate_domain_info_section(self, model_section_key, model_dict): # section_dict_value is either the dict of a folder in the # section, or the value of an attribute in the section if '${' in section_dict_key: - self._logger.severe('WLSDPLY-05035', model_folder_path, section_dict_key) + self._logger.severe('WLSDPLY-05035', model_folder_path, section_dict_key, class_name=_class_name, + method_name=_method_name) log_value = self.__get_attribute_log_value(section_dict_key, section_dict_value, valid_attr_infos) self._logger.finer('WLSDPLY-05011', section_dict_key, log_value, @@ -396,7 +400,8 @@ def __validate_domain_info_section(self, model_section_key, model_dict): # section_dict_key is not an attribute allowed under the model # section, so record this as a validate ERROR in the validate # results. - self._logger.severe('WLSDPLY-05029', section_dict_key, model_folder_path, valid_attr_infos.keys()) + self._logger.severe('WLSDPLY-05029', section_dict_key, model_folder_path, valid_attr_infos.keys(), + class_name=_class_name, method_name=_method_name) def __validate_model_section(self, model_section_key, model_dict, valid_section_folders): _method_name = '__validate_model_section' @@ -462,7 +467,8 @@ def __validate_model_section(self, model_section_key, model_dict, valid_section_ self._logger.warning('WLSDPLY-05027', message, class_name=_class_name, method_name=_method_name) elif result == ValidationCodes.INVALID: self._logger.severe('WLSDPLY-05026', section_dict_key, 'folder', model_folder_path, - '%s' % ', '.join(valid_section_folders)) + '%s' % ', '.join(valid_section_folders), class_name=_class_name, + method_name=_method_name) else: result, message = self._alias_helper.is_valid_model_attribute_name(validation_location, section_dict_key) @@ -470,7 +476,8 @@ def __validate_model_section(self, model_section_key, model_dict, valid_section_ self._logger.warning('WLSDPLY-05027', message, class_name=_class_name, method_name=_method_name) elif result == ValidationCodes.INVALID: self._logger.severe('WLSDPLY-05029', section_dict_key, model_folder_path, - '%s' % ', '.join(valid_attr_infos)) + '%s' % ', '.join(valid_attr_infos), class_name=_class_name, + method_name=_method_name) def __validate_section_folder(self, model_node, validation_location): _method_name = '__validate_section_folder' @@ -480,7 +487,7 @@ def __validate_section_folder(self, model_node, validation_location): self._logger.warning('WLSDPLY-05027', message, class_name=_class_name, method_name=_method_name) return elif result == ValidationCodes.INVALID: - self._logger.severe('WLSDPLY-05027', message) + self._logger.severe('WLSDPLY-05027', message, class_name=_class_name, method_name=_method_name) return model_folder_path = self._alias_helper.get_model_folder_path(validation_location) @@ -650,7 +657,8 @@ def __process_model_node(self, model_node, validation_location): elif result == ValidationCodes.INVALID: # key is an INVALID folder self._logger.severe('WLSDPLY-05026', key, 'folder', model_folder_path, - '%s' % ', '.join(valid_folder_keys)) + '%s' % ', '.join(valid_folder_keys), class_name=_class_name, + method_name=_method_name) else: # value is not a dict, so key must be the name of an attribute. key cannot be a # folder instance name, because the _alias_helper.supports_multiple_mbean_instances() @@ -664,7 +672,8 @@ def __process_model_node(self, model_node, validation_location): elif result == ValidationCodes.INVALID: # key is an INVALID attribute self._logger.severe('WLSDPLY-05029', key, model_folder_path, - '%s' % ', '.join(valid_attr_infos)) + '%s' % ', '.join(valid_attr_infos), class_name=_class_name, + method_name=_method_name) def __validate_attributes(self, attributes_dict, valid_attr_infos, validation_location): _method_name = '__validate_attributes' @@ -713,8 +722,9 @@ def __validate_attribute(self, attribute_name, attribute_value, valid_attr_infos if result == ValidationCodes.VERSION_INVALID: self._logger.warning('WLSDPLY-05027', message, class_name=_class_name, method_name=_method_name) elif result == ValidationCodes.INVALID: - self._logger.severe('WLSDPLY-05029', attribute_name, - model_folder_path, '%s' % ', '.join(valid_attr_infos)) + self._logger.severe('WLSDPLY-05029', attribute_name, model_folder_path, + '%s' % ', '.join(valid_attr_infos), class_name=_class_name, + method_name=_method_name) self._logger.exiting(class_name=_class_name, method_name=_method_name) @@ -752,7 +762,8 @@ def __validate_property(self, property_name, property_value, valid_prop_infos, m self._logger.warning('WLSDPLY-05019', property_name, model_folder_path, expected_data_type, actual_data_type, class_name=_class_name, method_name=_method_name) else: - self._logger.severe('WLSDPLY-05020', property_name, model_folder_path) + self._logger.severe('WLSDPLY-05020', property_name, model_folder_path, class_name=_class_name, + method_name=_method_name) def __validate_variable_substitution(self, tokenized_value, model_folder_path): _method_name = '__validate_variable_substitution' @@ -801,7 +812,8 @@ def __validate_path_tokens_attribute(self, attribute_name, attribute_value, mode valid_valus_data_types = ['list', 'string'] if value_data_type not in valid_valus_data_types: - self._logger.severe('WLSDPLY-05023', attribute_name, model_folder_path, value_data_type) + self._logger.severe('WLSDPLY-05023', attribute_name, model_folder_path, value_data_type, + class_name=_class_name, method_name=_method_name) else: attr_values = [] @@ -836,15 +848,17 @@ def __validate_single_path_in_archive(self, path, attribute_name, model_folder_p archive_has_file = self._archive_helper.contains_file_or_path(path) if not archive_has_file: self._logger.severe('WLSDPLY-05024', attribute_name, model_folder_path, path, - self._archive_file_name) + self._archive_file_name, class_name=_class_name, method_name=_method_name) else: # If running in standalone mode, and the archive was not supplied, simply - # alert the user to the references but don;t fail validation because of + # alert the user to the references but don't fail validation because of # the dangling references. In TOOL mode, this is an error. if self._validation_mode == _ValidationModes.STANDALONE: - self._logger.info('WLSDPLY-05025', attribute_name, model_folder_path, path) + self._logger.info('WLSDPLY-05025', attribute_name, model_folder_path, path, + class_name=_class_name, method_name=_method_name) elif self._validation_mode == _ValidationModes.TOOL: - self._logger.severe('WLSDPLY-05025', attribute_name, model_folder_path, path) + self._logger.severe('WLSDPLY-05025', attribute_name, model_folder_path, path, + class_name=_class_name, method_name=_method_name) else: tokens = validation_utils.extract_path_tokens(path) self._logger.finest('tokens={0}', str(tokens), class_name=_class_name, method_name=_method_name) @@ -852,7 +866,8 @@ def __validate_single_path_in_archive(self, path, attribute_name, model_folder_p if not self._model_context.has_token_prefix(path): if not os.path.isabs(path): - self._logger.info('WLSDPLY-05031', attribute_name, model_folder_path, path) + self._logger.info('WLSDPLY-05031', attribute_name, model_folder_path, path, + class_name=_class_name, method_name=_method_name) def __validate_server_group_targeting_limits(self, attribute_name, attribute_value, valid_attr_infos, model_folder_path, validation_location): @@ -863,14 +878,16 @@ def __validate_server_group_targeting_limits(self, attribute_name, attribute_val if attribute_value is not None: if not isinstance(attribute_value, dict): - self._logger.severe('WLSDPLY-05032', attribute_name, model_folder_path, str(type(attribute_value))) + self._logger.severe('WLSDPLY-05032', attribute_name, model_folder_path, str(type(attribute_value)), + class_name=_class_name, method_name=__method_name) else: model_folder_path += '/' + attribute_name for key, value in attribute_value.iteritems(): if type(key) is not str: # Force the key to a string for any value validation issues reported below key = str(key) - self._logger.severe('WLSDPLY-05033', key, model_folder_path, str(type(key))) + self._logger.severe('WLSDPLY-05033', key, model_folder_path, str(type(key)), + class_name=_class_name, method_name=__method_name) else: if '${' in key: self._report_unsupported_variable_usage(key, model_folder_path) @@ -885,7 +902,8 @@ def __validate_server_group_targeting_limits(self, attribute_name, attribute_val elif type(value) is str: self._validate_single_server_group_target_limits_value(key, value, model_folder_path) else: - self._logger.severe('WLSDPLY-05034', key, model_folder_path, str(type(value))) + self._logger.severe('WLSDPLY-05034', key, model_folder_path, str(type(value)), + class_name=_class_name, method_name=__method_name) self._logger.exiting(class_name=_class_name, method_name=__method_name) @@ -905,13 +923,17 @@ def __validate_wlsroles_section(self, attribute_name, attribute_value, valid_att self._logger.exiting(class_name=_class_name, method_name=__method_name) def _validate_single_server_group_target_limits_value(self, key, value, model_folder_path): + _method_name = '_validate_single_server_group_target_limits_value' if type(value) is str: if '${' in str(value): self._report_unsupported_variable_usage(str(value), model_folder_path) else: - self._logger.severe('WLSDPLY-05035', key, str(value), model_folder_path, str(type(value))) + self._logger.severe('WLSDPLY-05035', key, str(value), model_folder_path, str(type(value)), + class_name=_class_name, method_name=_method_name) def _report_unsupported_variable_usage(self, tokenized_value, model_folder_path): + _method_name = '_report_unsupported_variable_usage' tokens = validation_utils.extract_substitution_tokens(tokenized_value) for token in tokens: - self._logger.severe('WLSDPLY-05030', model_folder_path, token) + self._logger.severe('WLSDPLY-05030', model_folder_path, token, + class_name=_class_name, method_name=_method_name) diff --git a/core/src/main/python/wlsdeploy/util/variables.py b/core/src/main/python/wlsdeploy/util/variables.py index 9a99f6c45c..798f4c41f6 100644 --- a/core/src/main/python/wlsdeploy/util/variables.py +++ b/core/src/main/python/wlsdeploy/util/variables.py @@ -205,12 +205,12 @@ def _substitute(text, variables, model_context): # for @@PROP:key@@ variables, throw an exception if key is not found. if key not in variables: if model_context.get_validation_method() == 'strict': - _logger.severe('WLSDPLY-01732', key) + _logger.severe('WLSDPLY-01732', key, class_name=_class_name, method_name=method_name) ex = exception_helper.create_variable_exception('WLSDPLY-01732', key) _logger.throwing(ex, class_name=_class_name, method_name=method_name) raise ex else: - _logger.info('WLSDPLY-01732', key) + _logger.info('WLSDPLY-01732', key, class_name=_class_name, method_name=method_name) continue value = variables[key] @@ -250,13 +250,14 @@ def _read_value_from_file(file_path, model_context): file_reader.close() except IOException, e: if model_context.get_validation_method() == 'strict': - _logger.severe('WLSDPLY-01733', file_path, e.getLocalizedMessage()) + _logger.severe('WLSDPLY-01733', file_path, e.getLocalizedMessage(), class_name=_class_name, + method_name=method_name) ex = exception_helper.create_variable_exception('WLSDPLY-01733', file_path, e.getLocalizedMessage(), error=e) _logger.throwing(ex, class_name=_class_name, method_name=method_name) raise ex else: - _logger.info('WLSDPLY-01733', file_path, e.getLocalizedMessage(), error=e, - class_name=_class_name, method_name=method_name) + _logger.info('WLSDPLY-01733', file_path, e.getLocalizedMessage(), error=e, class_name=_class_name, + method_name=method_name) line = '' if line is None: From aec20a37d2f53b7d3b4613c462df82fbf3bd99e8 Mon Sep 17 00:00:00 2001 From: Richard Killen Date: Tue, 24 Sep 2019 10:57:04 -0500 Subject: [PATCH 3/3] JIRA WDT-365 - Skip summary log for print_usage --- core/src/main/python/validate.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/python/validate.py b/core/src/main/python/validate.py index 50d15ed0a3..54536c52f9 100644 --- a/core/src/main/python/validate.py +++ b/core/src/main/python/validate.py @@ -8,7 +8,7 @@ import sys from java.util.logging import Level -from oracle.weblogic.deploy.util import CLAException, WLSDeployExit +from oracle.weblogic.deploy.util import CLAException from oracle.weblogic.deploy.util import TranslateException from oracle.weblogic.deploy.util import WebLogicDeployToolingVersion from oracle.weblogic.deploy.validate import ValidateException @@ -247,9 +247,9 @@ def main(args): cla_helper.clean_up_temp_files() sys.exit(CommandLineArgUtil.PROG_ERROR_EXIT_CODE) - cla_helper.clean_up_temp_files() + cla_helper.clean_up_temp_files() - tool_exit.end(model_context, exit_code) + tool_exit.end(model_context, exit_code) return