Skip to content

Commit 454dff0

Browse files
rakillenddsharpe
authored andcommitted
Use summary logger for validation (#447)
* JIRA WDT-365 - Use the summary logger for validation tool * JIRA WDT-365 - Added class name, method name where needed * JIRA WDT-365 - Skip summary log for print_usage
1 parent 9f7f8a7 commit 454dff0

File tree

11 files changed

+288
-748
lines changed

11 files changed

+288
-748
lines changed

core/src/main/java/oracle/weblogic/deploy/logging/SummaryHandler.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.logging.MemoryHandler;
1616

1717
import oracle.weblogic.deploy.util.WLSDeployContext;
18+
import oracle.weblogic.deploy.util.WLSDeployExit;
1819
import oracle.weblogic.deploy.util.WebLogicDeployToolingVersion;
1920

2021

@@ -122,6 +123,47 @@ public static Properties getHandlerProperties() {
122123
return properties;
123124
}
124125

126+
/**
127+
* Find the summary handler instance in the logging setup.
128+
* If not found, return null.
129+
* @return the summary handler instance, or null if not found.
130+
*/
131+
public static SummaryHandler findInstance() {
132+
return (SummaryHandler) WLSDeployExit.findHandler(SummaryHandler.class);
133+
}
134+
135+
/**
136+
* Returns the highest level of the messages in the summary.
137+
* If no messages are found, the level INFO is returned.
138+
* @return the maximum message level, or Level.INFO if none are found.
139+
*/
140+
public Level getMaximumMessageLevel() {
141+
Level maxLevel = Level.INFO;
142+
for(LevelHandler levelHandler : handlers) {
143+
if(levelHandler.getTotalRecords() > 0) {
144+
Level level = levelHandler.getLevel();
145+
if(level.intValue() > maxLevel.intValue()) {
146+
maxLevel = level;
147+
}
148+
}
149+
}
150+
return maxLevel;
151+
}
152+
153+
/**
154+
* Returns the message count in the summary for the specified level.
155+
* @return the message count for the specified level.
156+
*/
157+
public int getMessageCount(Level level) {
158+
for(LevelHandler levelHandler : handlers) {
159+
Level handlerLevel = levelHandler.getLevel();
160+
if(handlerLevel.equals(level)) {
161+
return levelHandler.getTotalRecords();
162+
}
163+
}
164+
return 0;
165+
}
166+
125167
private void addLevelHandler(Level level) {
126168
LevelHandler handler;
127169
Handler levelTarget = getConsoleHandler();

core/src/main/java/oracle/weblogic/deploy/util/WLSDeployExit.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ public static void exit(int error_code) {
4949
System.exit(error_code);
5050
}
5151

52+
/**
53+
* Returns the first handler that is assignment-compatible with the specified class.
54+
* @param handlerClass the class to check for compatibility
55+
* @return the first matching handler, or null if none is found
56+
*/
57+
public static Handler findHandler(Class handlerClass) {
58+
Stack<Handler> handlers = reduceList(traverseHandlers(getTopLogList(), new LinkedList<Handler>()));
59+
while (handlers.size() > 0) {
60+
Handler handler = handlers.pop();
61+
if(handlerClass.isInstance(handler)) {
62+
return handler;
63+
}
64+
}
65+
return null;
66+
}
67+
5268
/**
5369
* Call any WLSDeployLogEnd Logger handlers so the handlers can perform end actions.
5470
*

core/src/main/python/validate.py

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
"""
77
import javaos as os
88
import sys
9+
from java.util.logging import Level
910

1011
from oracle.weblogic.deploy.util import CLAException
1112
from oracle.weblogic.deploy.util import TranslateException
1213
from oracle.weblogic.deploy.util import WebLogicDeployToolingVersion
1314
from oracle.weblogic.deploy.validate import ValidateException
1415

16+
from oracle.weblogic.deploy.logging import SummaryHandler
17+
1518
sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0])))
1619

1720
# imports from local packages start here
@@ -20,6 +23,7 @@
2023
from wlsdeploy.logging.platform_logger import PlatformLogger
2124
from wlsdeploy.tool.validate.validator import Validator
2225
from wlsdeploy.util import cla_helper
26+
from wlsdeploy.util import tool_exit
2327
from wlsdeploy.util import wlst_helper
2428
from wlsdeploy.util.cla_utils import CommandLineArgUtil
2529
from wlsdeploy.util.model_context import ModelContext
@@ -167,36 +171,22 @@ def __perform_model_file_validation(model_file_name, model_context):
167171

168172
_method_name = '__perform_model_file_validation'
169173

170-
print_usage = model_context.get_print_usage()
171-
172174
__logger.entering(model_file_name,
173175
class_name=_class_name, method_name=_method_name)
174176

175177
try:
176178
model_dictionary = cla_helper.merge_model_files(model_file_name)
177179
model_validator = Validator(model_context, logger=__logger)
178-
validation_results = model_validator.validate_in_standalone_mode(model_dictionary,
179-
model_context.get_variable_file(),
180-
model_context.get_archive_file_name())
180+
model_validator.validate_in_standalone_mode(model_dictionary, model_context.get_variable_file(),
181+
model_context.get_archive_file_name())
181182
except TranslateException, te:
182183
__logger.severe('WLSDPLY-20009', _program_name, model_file_name, te.getLocalizedMessage(),
183184
error=te, class_name=_class_name, method_name=_method_name)
184185
ex = exception_helper.create_validate_exception(te.getLocalizedMessage(), error=te)
185186
__logger.throwing(ex, class_name=_class_name, method_name=_method_name)
186187
raise ex
187188

188-
if print_usage is None:
189-
__logger.info('WLSDPLY-05403',
190-
model_file_name,
191-
validation_results.get_errors_count(),
192-
validation_results.get_warnings_count(),
193-
validation_results.get_infos_count(),
194-
class_name=_class_name, method_name=_method_name)
195-
196-
validation_results.print_details()
197-
198189
__logger.exiting(class_name=_class_name, method_name=_method_name)
199-
return validation_results
200190

201191

202192
def main(args):
@@ -214,6 +204,8 @@ def main(args):
214204

215205
wlst_helper.silence()
216206

207+
exit_code = CommandLineArgUtil.PROG_OK_EXIT_CODE
208+
217209
try:
218210
model_context = __process_args(args)
219211
except CLAException, ex:
@@ -239,24 +231,25 @@ def main(args):
239231
model_file_name = model_context.get_model_file()
240232

241233
if model_file_name is not None:
242-
validation_results = __perform_model_file_validation(model_file_name, model_context)
243-
244-
if validation_results.get_errors_count() > 0:
245-
cla_helper.clean_up_temp_files()
246-
sys.exit(CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
247-
elif validation_results.get_warnings_count() > 0:
248-
cla_helper.clean_up_temp_files()
249-
sys.exit(CommandLineArgUtil.PROG_WARNING_EXIT_CODE)
234+
__perform_model_file_validation(model_file_name, model_context)
250235

236+
summary_handler = SummaryHandler.findInstance()
237+
if summary_handler is not None:
238+
summary_level = summary_handler.getMaximumMessageLevel()
239+
if summary_level == Level.SEVERE:
240+
exit_code = CommandLineArgUtil.PROG_ERROR_EXIT_CODE
241+
elif summary_level == Level.WARNING:
242+
exit_code = CommandLineArgUtil.PROG_WARNING_EXIT_CODE
251243

252244
except ValidateException, ve:
253245
__logger.severe('WLSDPLY-20000', _program_name, ve.getLocalizedMessage(), error=ve,
254246
class_name=_class_name, method_name=_method_name)
255247
cla_helper.clean_up_temp_files()
256248
sys.exit(CommandLineArgUtil.PROG_ERROR_EXIT_CODE)
257249

258-
cla_helper.clean_up_temp_files()
250+
cla_helper.clean_up_temp_files()
259251

252+
tool_exit.end(model_context, exit_code)
260253
return
261254

262255

core/src/main/python/wlsdeploy/tool/create/wlsroles_helper.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
}
2626
WLS_ROLE_UPDATE_OPERAND = '|'
2727

28+
2829
class WLSRoles(object):
2930
"""
3031
Handle the WLSRoles section from the model domainInfo
@@ -57,26 +58,25 @@ def process_roles(self):
5758
if self._wls_helper is not None and not self._wls_helper.is_weblogic_version_or_above('12.2.1'):
5859
self.logger.warning('WLSDPLY-12504', self._wls_helper.get_actual_weblogic_version(), class_name=self.__class_name, method_name=_method_name)
5960
else:
60-
role_expressions = self._process_roles_map(self._wls_roles_map, None)
61+
role_expressions = self._process_roles_map(self._wls_roles_map)
6162
if role_expressions is not None and len(role_expressions) > 0:
6263
self.logger.info('WLSDPLY-12500', role_expressions.keys(), class_name=self.__class_name, method_name=_method_name)
6364
self._update_xacml_role_mapper(role_expressions)
6465
self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
6566
return
6667

67-
def validate_roles(self, validation_result):
68+
def validate_roles(self):
6869
"""
6970
Validate WLSRoles section of the domainInfo independent of any domain home location
7071
"""
7172
_method_name = 'validate_roles'
7273
self.logger.entering(self._validation_roles_map, class_name=self.__class_name, method_name=_method_name)
7374
if self._validation_roles_map is not None and len(self._validation_roles_map) > 0:
74-
self._validate_update_mode(self._validation_roles_map, validation_result)
75-
self._process_roles_map(self._validation_roles_map, validation_result)
75+
self._validate_update_mode(self._validation_roles_map)
76+
self._process_roles_map(self._validation_roles_map)
7677
self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
77-
return validation_result
7878

79-
def _process_roles_map(self, roles_map, validation_result):
79+
def _process_roles_map(self, roles_map):
8080
"""
8181
Loop through the WebLogic roles listed in the domainInfo and create a map of the role to the expression
8282
"""
@@ -87,15 +87,11 @@ def _process_roles_map(self, roles_map, validation_result):
8787
# Get the role expression and if the role should be an update to the default set of roles
8888
expression = self._get_role_expression(role, roles_map)
8989
if string_utils.is_empty(expression):
90-
self.logger.finer('WLSDPLY-12501', role, class_name=self.__class_name, method_name=_method_name)
91-
if validation_result is not None:
92-
validation_result.add_warning('WLSDPLY-12501', role)
90+
self.logger.warning('WLSDPLY-12501', role, class_name=self.__class_name, method_name=_method_name)
9391
continue
9492
update_role = self._is_role_update_mode(role, roles_map)
9593
if update_role and role not in WLS_GLOBAL_ROLES:
96-
self.logger.finer('WLSDPLY-12502', role, class_name=self.__class_name, method_name=_method_name)
97-
if validation_result is not None:
98-
validation_result.add_warning('WLSDPLY-12502', role)
94+
self.logger.warning('WLSDPLY-12502', role, class_name=self.__class_name, method_name=_method_name)
9995
update_role = False
10096
# Add the role and expression to the map of roles to be processed
10197
if update_role:
@@ -159,7 +155,7 @@ def _update_role_epression(self, role_name, expression_value, roles_map):
159155
result = expression_value + WLS_ROLE_UPDATE_OPERAND + WLS_GLOBAL_ROLES[role_name]
160156
return result
161157

162-
def _validate_update_mode(self, roles_map, validation_result):
158+
def _validate_update_mode(self, roles_map):
163159
"""
164160
Check that the UpdateMode value of a role is one of append, prepend or replace
165161
Provide a warning for other values as these will be treated as the default of replace
@@ -175,13 +171,13 @@ def _validate_update_mode(self, roles_map, validation_result):
175171
mode = mode.lower()
176172
if APPEND == mode or PREPEND == mode or REPLACE == mode:
177173
continue
178-
self.logger.finer('WLSDPLY-12503', role_name, class_name=self.__class_name, method_name=_method_name)
179-
if validation_result is not None:
180-
validation_result.add_warning('WLSDPLY-12503', role_name)
174+
self.logger.warning('WLSDPLY-12503', role_name, class_name=self.__class_name,
175+
method_name=_method_name)
181176

182177
self.logger.exiting(class_name=self.__class_name, method_name=_method_name)
183178
return
184179

180+
185181
def validator(roles_map, logger):
186182
"""
187183
Obtain a WLSRoles helper only for the validation of the WLSRoles section

0 commit comments

Comments
 (0)