Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -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();
Expand Down
16 changes: 16 additions & 0 deletions core/src/main/java/oracle/weblogic/deploy/util/WLSDeployExit.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Handler> handlers = reduceList(traverseHandlers(getTopLogList(), new LinkedList<Handler>()));
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.
*
Expand Down
43 changes: 18 additions & 25 deletions core/src/main/python/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
Expand All @@ -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
Expand Down Expand Up @@ -167,36 +171,22 @@ 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)
ex = exception_helper.create_validate_exception(te.getLocalizedMessage(), error=te)
__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):
Expand All @@ -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:
Expand All @@ -239,24 +231,25 @@ 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,
class_name=_class_name, method_name=_method_name)
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)
return


Expand Down
28 changes: 12 additions & 16 deletions core/src/main/python/wlsdeploy/tool/create/wlsroles_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
}
WLS_ROLE_UPDATE_OPERAND = '|'


class WLSRoles(object):
"""
Handle the WLSRoles section from the model domainInfo
Expand Down Expand Up @@ -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
"""
Expand All @@ -87,15 +87,11 @@ def _process_roles_map(self, roles_map, validation_result):
# 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)
if validation_result is not None:
validation_result.add_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)
if validation_result is not None:
validation_result.add_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:
Expand Down Expand Up @@ -159,7 +155,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
Expand All @@ -175,13 +171,13 @@ def _validate_update_mode(self, roles_map, validation_result):
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)
if validation_result is not None:
validation_result.add_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


def validator(roles_map, logger):
"""
Obtain a WLSRoles helper only for the validation of the WLSRoles section
Expand Down
Loading