diff options
50 files changed, 318 insertions, 202 deletions
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCommandLineEditorMain.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCommandLineEditorMain.java index 0df8ac629..b632514a5 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCommandLineEditorMain.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCommandLineEditorMain.java @@ -104,8 +104,7 @@ public class ApexCommandLineEditorMain { parameters.getApexPropertiesStream()); } catch (final Exception e) { LOGGER.error("start of Apex command line editor failed, error reading Apex model properties from " - + parameters.getApexPropertiesLocation()); - LOGGER.error(e.getMessage()); + + parameters.getApexPropertiesLocation(), e); errorCount++; return; } @@ -160,7 +159,7 @@ public class ApexCommandLineEditorMain { errorCount); } } catch (final IOException e) { - LOGGER.error("execution of Apex command line editor failed: " + e.getMessage()); + LOGGER.error("execution of Apex command line editor failed: " + e.getMessage(), e); } } diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelHandler.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelHandler.java index 2e1a4732b..3d14a83f4 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelHandler.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelHandler.java @@ -132,7 +132,7 @@ public class ApexModelHandler { + "\" not found for command \"" + command.getName() + "\""); } catch (final ClassNotFoundException e) { throw new CommandLineException("specified class \"" + command.getApiMethod() + "\" not found for command \"" - + command.getName() + "\""); + + command.getName() + "\"", e); } } @@ -163,7 +163,7 @@ public class ApexModelHandler { } } catch (final Exception e) { throw new CommandLineException("number of argument mismatch on method \"" + command.getApiMethod() - + "\" for command \"" + command.getName() + "\""); + + "\" for command \"" + command.getName() + "\"", e); } return parameterArray; diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java index 513f31e67..4f0aeb58b 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java @@ -43,6 +43,8 @@ import org.onap.policy.apex.model.modelapi.ApexApiResult; import org.onap.policy.apex.model.modelapi.ApexApiResult.Result; import org.onap.policy.apex.model.utilities.TextFileUtils; import org.onap.policy.apex.model.utilities.TreeMapUtils; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; /** * This class implements the editor loop, the loop of execution that continuously executes commands until the quit @@ -51,6 +53,9 @@ import org.onap.policy.apex.model.utilities.TreeMapUtils; * @author Liam Fallon (liam.fallon@ericsson.com) */ public class CommandLineEditorLoop { + // Get a reference to the logger + private static final XLogger LOGGER = XLoggerFactory.getXLogger(CommandLineEditorLoop.class); + // Recurring string constants private static final String COMMAND = "command "; @@ -129,6 +134,7 @@ public class CommandLineEditorLoop { catch (final CommandLineException e) { writer.println(e.getMessage()); errorCount++; + LOGGER.debug("command line error", e); continue; } @@ -157,6 +163,7 @@ public class CommandLineEditorLoop { catch (final CommandLineException e) { writer.println(e.getMessage()); errorCount++; + LOGGER.debug("command line error", e); continue; } @@ -197,8 +204,10 @@ public class CommandLineEditorLoop { catch (final CommandLineException e) { writer.println(e.getMessage()); errorCount++; + LOGGER.debug("command line error", e); } catch (final Exception e) { e.printStackTrace(writer); + LOGGER.error("command line error", e); } } @@ -255,7 +264,7 @@ public class CommandLineEditorLoop { final KeywordNode searchKeywordNode = keywordNodeDeque.peek(); // We have got to the arguments, time to stop looking - if (commandWords.get(i).indexOf('=') > 0) { + if (commandWords.get(i).indexOf('=') >= 0) { unwindStack(startKeywordNode); throw new CommandLineException("command not found: " + stringAL2String(commandWords)); } diff --git a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestMain.java b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestMain.java index 73374053f..134914f11 100644 --- a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestMain.java +++ b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestMain.java @@ -85,21 +85,21 @@ public class ApexDeploymentRestMain { parameters = parser.parse(args); } catch (final ApexDeploymentRestParameterException e) { throw new ApexDeploymentRestParameterException( - REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + e.getMessage() + '\n' - + parser.getHelp(ApexDeploymentRestMain.class.getCanonicalName())); + REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + e.getMessage() + '\n' + + parser.getHelp(ApexDeploymentRestMain.class.getCanonicalName()), e); } if (parameters.isHelpSet()) { throw new ApexDeploymentRestParameterException( - parser.getHelp(ApexDeploymentRestMain.class.getCanonicalName())); + parser.getHelp(ApexDeploymentRestMain.class.getCanonicalName())); } // Validate the parameters final String validationMessage = parameters.validate(); if (validationMessage.length() > 0) { throw new ApexDeploymentRestParameterException( - REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage - + '\n' + parser.getHelp(ApexDeploymentRestMain.class.getCanonicalName())); + REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage + '\n' + + parser.getHelp(ApexDeploymentRestMain.class.getCanonicalName())); } state = ServicesState.READY; @@ -109,8 +109,8 @@ public class ApexDeploymentRestMain { * Initialize the rest service. */ public void init() { - outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at " - + parameters.getBaseUri().toString() + " . . ."); + outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at " + parameters.getBaseUri().toString() + + " . . ."); try { state = ServicesState.INITIALIZING; @@ -125,7 +125,7 @@ public class ApexDeploymentRestMain { if (parameters.getTimeToLive() == ApexDeploymentRestParameters.INFINITY_TIME_TO_LIVE) { outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started at " - + parameters.getBaseUri().toString()); + + parameters.getBaseUri().toString()); } else { outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started"); } @@ -142,8 +142,9 @@ public class ApexDeploymentRestMain { Thread.sleep(1000); } } catch (final Exception e) { - outStream.println( - REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage()); + String message = REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage(); + outStream.println(message); + LOGGER.warn(message, e); } finally { if (apexDeploymentRest != null) { apexDeploymentRest.shutdown(); @@ -167,7 +168,7 @@ public class ApexDeploymentRestMain { public String toString() { final StringBuilder ret = new StringBuilder(); ret.append(this.getClass().getSimpleName()).append(": Config=[").append(this.parameters).append("], State=") - .append(this.getState()); + .append(this.getState()); return ret.toString(); } diff --git a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ParameterCheck.java b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ParameterCheck.java index b68ffebcf..fb18a002f 100644 --- a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ParameterCheck.java +++ b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ParameterCheck.java @@ -32,12 +32,19 @@ import org.slf4j.ext.XLoggerFactory; * @author Liam Fallon (liam.fallon@ericsson.com) */ public final class ParameterCheck { + // Recurring string constants + private static final String OF_PARAMETER = "\"of parameter \""; + private static final String VALUE = "value \""; + private static final String PARAMETER = "parameter \""; + private static final String NOT_FOUND = "\" not found"; + private static final int MAX_PORT = 65535; /** * private constructor to prevent subclassing of this utility class. */ - private ParameterCheck() {} + private ParameterCheck() { + } /** * The Enum StartStop is used to hold. @@ -65,14 +72,14 @@ public final class ParameterCheck { */ public static String getHostName(final Map<String, String[]> parameterMap) { if (!parameterMap.containsKey(HOSTNAME_PAR)) { - LOGGER.warn("parameter \"" + HOSTNAME_PAR + "\" not found"); + LOGGER.warn(PARAMETER + HOSTNAME_PAR + NOT_FOUND); return null; } final String[] hostNameValue = parameterMap.get(HOSTNAME_PAR); if (hostNameValue.length == 0 || hostNameValue[0].trim().length() == 0) { - LOGGER.warn("value of parameter \"" + HOSTNAME_PAR + "\" not found"); + LOGGER.warn("value of parameter \"" + HOSTNAME_PAR + NOT_FOUND); return null; } @@ -87,14 +94,14 @@ public final class ParameterCheck { */ public static int getPort(final Map<String, String[]> parameterMap) { if (!parameterMap.containsKey(PORT_PAR)) { - LOGGER.warn("parameter \"" + PORT_PAR + "\" not found"); + LOGGER.warn(PARAMETER + PORT_PAR + NOT_FOUND); return -1; } final String[] portValue = parameterMap.get(PORT_PAR); if (portValue.length == 0 || portValue[0].trim().length() == 0) { - LOGGER.warn("value of parameter \"" + PORT_PAR + "\" not found"); + LOGGER.warn("value of parameter \"" + PORT_PAR + NOT_FOUND); return -1; } @@ -102,13 +109,14 @@ public final class ParameterCheck { try { port = Integer.parseInt(portValue[0]); } catch (final Exception e) { - LOGGER.warn("value \"" + portValue[0] + "\"of parameter \"" + PORT_PAR + "\" not a valid integer", e); + LOGGER.warn(VALUE + portValue[0] + OF_PARAMETER + PORT_PAR + "\" not a valid integer", e); return -1; } if (port <= 0 || port > MAX_PORT) { - LOGGER.warn("value \"" + portValue[0] + "\"of parameter \"" + PORT_PAR - + "\" not a valid port between 0 and 65535"); + String message = VALUE + portValue[0] + OF_PARAMETER + PORT_PAR + + "\" not a valid port between 0 and 65535"; + LOGGER.warn(message); return -1; } @@ -131,14 +139,16 @@ public final class ParameterCheck { } } if (artifactKeyParameter == null) { - LOGGER.warn("parameter \"" + AXARTIFACTKEY_PAR + "\" not found"); + LOGGER.warn(PARAMETER + AXARTIFACTKEY_PAR + NOT_FOUND); return null; } final String[] axArtifactKeyArray = artifactKeyParameter.split("#"); if (axArtifactKeyArray.length != 2) { - LOGGER.warn("value \"" + artifactKeyParameter + "\" of parameter \"" + AXARTIFACTKEY_PAR + "\" not valid"); + String message = VALUE + artifactKeyParameter + "\" of parameter \"" + AXARTIFACTKEY_PAR + + "\" not valid"; + LOGGER.warn(message); return null; } @@ -153,17 +163,17 @@ public final class ParameterCheck { * @return the start stop */ public static ParameterCheck.StartStop getStartStop(final Map<String, String[]> parameterMap, - final AxArtifactKey engineKey) { + final AxArtifactKey engineKey) { final String startStopPar = AXARTIFACTKEY_PAR + '#' + engineKey.getId(); if (!parameterMap.containsKey(startStopPar)) { - LOGGER.warn("parameter \"" + startStopPar + "\" not found"); + LOGGER.warn("parameter \"{}\" not found", startStopPar); return null; } final String[] startStopValue = parameterMap.get(startStopPar); if (startStopValue.length == 0 || startStopValue[0].trim().length() == 0) { - LOGGER.warn("value of parameter \"" + startStopPar + "\" not found"); + LOGGER.warn("value of parameter \"{}\" not found", startStopPar); return null; } @@ -173,8 +183,7 @@ public final class ParameterCheck { } else if (startStopValue[0].equalsIgnoreCase("stop")) { startStop = ParameterCheck.StartStop.STOP; } else { - LOGGER.warn("value \"" + startStopValue[0] + "\"of parameter \"" + startStopPar - + "\" not \"start\" or \"stop\""); + LOGGER.warn("value \"{}\"of parameter \"{}\" not \"start\" or \"stop\"", startStopValue[0], startStopPar); return null; } @@ -190,21 +199,21 @@ public final class ParameterCheck { */ public static long getLong(final Map<String, String[]> parameterMap, final String longName) { if (!parameterMap.containsKey(longName)) { - LOGGER.warn("parameter \"" + longName + "\" not found"); + LOGGER.warn("parameter \"{}\" not found", longName); return -1; } final String[] longValue = parameterMap.get(longName); if (longValue.length == 0 || longValue[0].trim().length() == 0) { - LOGGER.warn("value of parameter \"" + longName + "\" not found"); + LOGGER.warn("value of parameter \"{}\" not found", longName); return -1; } try { return Long.parseLong(longValue[0]); } catch (final Exception e) { - LOGGER.warn("value \"" + longValue[0] + "\"of parameter \"" + longName + "\" not a valid long", e); + LOGGER.warn(VALUE + longValue[0] + OF_PARAMETER + longName + "\" not a valid long", e); return -1; } } diff --git a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorMain.java b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorMain.java index 3f54467cd..ea4f206ce 100644 --- a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorMain.java +++ b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorMain.java @@ -95,9 +95,8 @@ public class ApexEditorMain { // Get and check the parameters parameters = parser.parse(args); } catch (final ApexEditorParameterException e) { - throw new ApexEditorParameterException( - REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + e.getMessage() + '\n' - + parser.getHelp(ApexEditorMain.class.getCanonicalName())); + throw new ApexEditorParameterException(REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + + e.getMessage() + '\n' + parser.getHelp(ApexEditorMain.class.getCanonicalName()), e); } if (parameters.isHelpSet()) { @@ -107,9 +106,8 @@ public class ApexEditorMain { // Validate the parameters final String validationMessage = parameters.validate(); if (validationMessage.length() > 0) { - throw new ApexEditorParameterException( - REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage - + '\n' + parser.getHelp(ApexEditorMain.class.getCanonicalName())); + throw new ApexEditorParameterException(REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + + validationMessage + '\n' + parser.getHelp(ApexEditorMain.class.getCanonicalName())); } state = EditorState.READY; @@ -119,8 +117,8 @@ public class ApexEditorMain { * Initialize the Apex editor. */ public void init() { - outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at " - + parameters.getBaseUri().toString() + " . . ."); + outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at " + parameters.getBaseUri().toString() + + " . . ."); try { state = EditorState.INITIALIZING; @@ -135,7 +133,7 @@ public class ApexEditorMain { if (parameters.getTimeToLive() == ApexEditorParameters.INFINITY_TIME_TO_LIVE) { outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started at " - + parameters.getBaseUri().toString()); + + parameters.getBaseUri().toString()); } else { outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started"); } @@ -152,8 +150,9 @@ public class ApexEditorMain { Thread.sleep(EDITOR_RNNING_CHECK_TIMEOUT); } } catch (final Exception e) { - outStream.println( - REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage()); + String message = REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage(); + outStream.println(message); + LOGGER.warn(message, e); } finally { if (apexEditor != null) { apexEditor.shutdown(); @@ -181,7 +180,7 @@ public class ApexEditorMain { public String toString() { final StringBuilder ret = new StringBuilder(); ret.append(this.getClass().getSimpleName()).append(": Config=[").append(parameters).append("], State=") - .append(this.getState()); + .append(this.getState()); return ret.toString(); } diff --git a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorParameters.java b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorParameters.java index 55d10c1a1..5c0c5eb7c 100644 --- a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorParameters.java +++ b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorParameters.java @@ -23,12 +23,18 @@ package org.onap.policy.apex.client.editor.rest; import java.net.URI; import java.net.URISyntaxException; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + /** * This class reads and handles command line parameters to the Apex CLI editor. * * @author Liam Fallon (liam.fallon@ericsson.com) */ public class ApexEditorParameters { + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEditorParameters.class); + /** The default port for connecting to the Web editor on. */ public static final int DEFAULT_REST_PORT = 18989; @@ -120,7 +126,9 @@ public class ApexEditorParameters { new URI(getBaseUri().toString()).parseServerAuthority(); return ""; } catch (final URISyntaxException e) { - return "listen address is not valid. " + e.getMessage() + "\n"; + String message = "listen address is not valid. " + e.getMessage() + "\n"; + LOGGER.warn(message, e); + return message; } } diff --git a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorRestResource.java b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorRestResource.java index 8bed63d28..72c294169 100644 --- a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorRestResource.java +++ b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorRestResource.java @@ -2000,6 +2000,7 @@ public class ApexEditorRestResource { objecttochange.addProperty(DESCRIPTION, desc); augmessages.add(gson.toJson(jsonObject)); } catch (final Exception e) { + LOGGER.debug("error adding key information", e); augmessages.add(message); } } diff --git a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/bean/BeanBase.java b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/bean/BeanBase.java index b2222f827..c3f249fb4 100644 --- a/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/bean/BeanBase.java +++ b/client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/bean/BeanBase.java @@ -27,6 +27,9 @@ import java.lang.reflect.Method; * The base class for Beans. */ public abstract class BeanBase { + // Recurring string constants + private static final String PROBLEM_RETRIEVING_FIELD_PREFIX = "Problem retrieving field called ('"; + private static final String JSON_BEAN_SUFFIX = "') from JSON bean "; /** * Gets a named field from the bean. @@ -44,7 +47,7 @@ public abstract class BeanBase { return (String) method.invoke(this); } catch (final Exception e) { throw new IllegalArgumentException( - "Problem retrieving field called ('" + field + "') from JSON bean " + this, e); + PROBLEM_RETRIEVING_FIELD_PREFIX + field + JSON_BEAN_SUFFIX + this, e); } } } @@ -59,9 +62,9 @@ public abstract class BeanBase { } } catch (final Exception e) { throw new IllegalArgumentException( - "Problem retrieving field called ('" + field + "') from JSON bean " + this, e); + PROBLEM_RETRIEVING_FIELD_PREFIX + field + JSON_BEAN_SUFFIX + this, e); } } - throw new IllegalArgumentException("Problem retrieving field called ('" + field + "') from JSON bean " + this); + throw new IllegalArgumentException(PROBLEM_RETRIEVING_FIELD_PREFIX + field + JSON_BEAN_SUFFIX + this); } } diff --git a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestMain.java b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestMain.java index c89fcf473..b11cd7ff3 100644 --- a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestMain.java +++ b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestMain.java @@ -74,7 +74,7 @@ public class ApexServicesRestMain { final ApexServicesRestMain editorMain = new ApexServicesRestMain(args, System.out); editorMain.init(); } catch (final Exception e) { - LOGGER.error(e.getMessage()); + LOGGER.error("error starting REST client", e); } } @@ -95,9 +95,8 @@ public class ApexServicesRestMain { // Get and check the parameters parameters = parser.parse(args); } catch (final ApexServicesRestParameterException e) { - throw new ApexServicesRestParameterException( - REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + e.getMessage() + '\n' - + parser.getHelp(ApexServicesRestMain.class.getCanonicalName())); + throw new ApexServicesRestParameterException(REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + + e.getMessage() + '\n' + parser.getHelp(ApexServicesRestMain.class.getCanonicalName()), e); } if (parameters.isHelpSet()) { @@ -108,8 +107,8 @@ public class ApexServicesRestMain { final String validationMessage = parameters.validate(); if (validationMessage.length() > 0) { throw new ApexServicesRestParameterException( - REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage - + '\n' + parser.getHelp(ApexServicesRestMain.class.getCanonicalName())); + REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage + '\n' + + parser.getHelp(ApexServicesRestMain.class.getCanonicalName())); } state = EditorState.READY; @@ -119,8 +118,8 @@ public class ApexServicesRestMain { * Initialize the Apex editor. */ public void init() { - outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at " - + parameters.getBaseUri().toString() + " . . ."); + outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at " + parameters.getBaseUri().toString() + + " . . ."); try { state = EditorState.INITIALIZING; @@ -135,7 +134,7 @@ public class ApexServicesRestMain { if (parameters.getTimeToLive() == ApexServicesRestParameters.INFINITY_TIME_TO_LIVE) { outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started at " - + parameters.getBaseUri().toString()); + + parameters.getBaseUri().toString()); } else { outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started"); } @@ -152,8 +151,9 @@ public class ApexServicesRestMain { Thread.sleep(EDITOR_RNNING_CHECK_TIMEOUT); } } catch (final Exception e) { - outStream.println( - REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage()); + String message = REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage(); + outStream.println(message); + LOGGER.warn(message, e); } finally { if (apexServices != null) { apexServices.shutdown(); @@ -181,7 +181,7 @@ public class ApexServicesRestMain { public String toString() { final StringBuilder ret = new StringBuilder(); ret.append(this.getClass().getSimpleName()).append(": Config=[").append(parameters).append("], State=") - .append(this.getState()); + .append(this.getState()); return ret.toString(); } diff --git a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ParameterCheck.java b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ParameterCheck.java index d7b7229c4..d0b374fd4 100644 --- a/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ParameterCheck.java +++ b/client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ParameterCheck.java @@ -32,12 +32,17 @@ import org.slf4j.ext.XLoggerFactory; * @author Liam Fallon (liam.fallon@ericsson.com) */ public final class ParameterCheck { + // Recurring string constants + private static final String PARAMETER = "parameter \""; + private static final String NOT_FOUND = "\" not found"; + private static final int MAX_PORT = 65535; /** * private constructor to prevent subclassing of this utility class. */ - private ParameterCheck() {} + private ParameterCheck() { + } /** * The Enum StartStop is used to hold. @@ -65,14 +70,14 @@ public final class ParameterCheck { */ public static String getHostName(final Map<String, String[]> parameterMap) { if (!parameterMap.containsKey(HOSTNAME_PAR)) { - LOGGER.warn("parameter \"" + HOSTNAME_PAR + "\" not found"); + LOGGER.warn(PARAMETER + HOSTNAME_PAR + NOT_FOUND); return null; } final String[] hostNameValue = parameterMap.get(HOSTNAME_PAR); if (hostNameValue.length == 0 || hostNameValue[0].trim().length() == 0) { - LOGGER.warn("value of parameter \"" + HOSTNAME_PAR + "\" not found"); + LOGGER.warn("value of parameter \"" + HOSTNAME_PAR + NOT_FOUND); return null; } @@ -87,14 +92,14 @@ public final class ParameterCheck { */ public static int getPort(final Map<String, String[]> parameterMap) { if (!parameterMap.containsKey(PORT_PAR)) { - LOGGER.warn("parameter \"" + PORT_PAR + "\" not found"); + LOGGER.warn(PARAMETER + PORT_PAR + NOT_FOUND); return -1; } final String[] portValue = parameterMap.get(PORT_PAR); if (portValue.length == 0 || portValue[0].trim().length() == 0) { - LOGGER.warn("value of parameter \"" + PORT_PAR + "\" not found"); + LOGGER.warn("value of parameter \"" + PORT_PAR + NOT_FOUND); return -1; } @@ -102,13 +107,13 @@ public final class ParameterCheck { try { port = Integer.parseInt(portValue[0]); } catch (final Exception e) { - LOGGER.warn("value \"" + portValue[0] + "\"of parameter \"" + PORT_PAR + "\" not a valid integer", e); + LOGGER.warn("value \"{}\"of parameter \"" + PORT_PAR + "\" not a valid integer", portValue[0], e); return -1; } if (port <= 0 || port > MAX_PORT) { - LOGGER.warn("value \"" + portValue[0] + "\"of parameter \"" + PORT_PAR - + "\" not a valid port between 0 and 65535"); + LOGGER.warn("value \"{}\"of parameter \"" + PORT_PAR + "\" not a valid port between 0 and 65535", + portValue[0]); return -1; } @@ -131,14 +136,14 @@ public final class ParameterCheck { } } if (artifactKeyParameter == null) { - LOGGER.warn("parameter \"" + AXARTIFACTKEY_PAR + "\" not found"); + LOGGER.warn(PARAMETER + AXARTIFACTKEY_PAR + NOT_FOUND); return null; } final String[] axArtifactKeyArray = artifactKeyParameter.split("#"); if (axArtifactKeyArray.length != 2) { - LOGGER.warn("value \"" + artifactKeyParameter + "\" of parameter \"" + AXARTIFACTKEY_PAR + "\" not valid"); + LOGGER.warn("value \"{}\" of parameter \"" + AXARTIFACTKEY_PAR + "\" not valid", artifactKeyParameter); return null; } @@ -153,17 +158,17 @@ public final class ParameterCheck { * @return the start stop */ public static ParameterCheck.StartStop getStartStop(final Map<String, String[]> parameterMap, - final AxArtifactKey engineKey) { + final AxArtifactKey engineKey) { final String startStopPar = AXARTIFACTKEY_PAR + '#' + engineKey.getId(); if (!parameterMap.containsKey(startStopPar)) { - LOGGER.warn("parameter \"" + startStopPar + "\" not found"); + LOGGER.warn("parameter \"{}\" not found", startStopPar); return null; } final String[] startStopValue = parameterMap.get(startStopPar); if (startStopValue.length == 0 || startStopValue[0].trim().length() == 0) { - LOGGER.warn("value of parameter \"" + startStopPar + "\" not found"); + LOGGER.warn("value of parameter \"{}\" not found", startStopPar); return null; } @@ -173,8 +178,7 @@ public final class ParameterCheck { } else if (startStopValue[0].equalsIgnoreCase("stop")) { startStop = ParameterCheck.StartStop.STOP; } else { - LOGGER.warn("value \"" + startStopValue[0] + "\"of parameter \"" + startStopPar - + "\" not \"start\" or \"stop\""); + LOGGER.warn("value \"{}\" of parameter \"{}\" not \"start\" or \"stop\"", startStopValue[0], startStopPar); return null; } @@ -190,21 +194,21 @@ public final class ParameterCheck { */ public static long getLong(final Map<String, String[]> parameterMap, final String longName) { if (!parameterMap.containsKey(longName)) { - LOGGER.warn("parameter \"" + longName + "\" not found"); + LOGGER.warn("parameter \"{}\" not found", longName); return -1; } final String[] longValue = parameterMap.get(longName); if (longValue.length == 0 || longValue[0].trim().length() == 0) { - LOGGER.warn("value of parameter \"" + longName + "\" not found"); + LOGGER.warn("value of parameter \"{}\" not found", longName); return -1; } try { return Long.parseLong(longValue[0]); } catch (final Exception e) { - LOGGER.warn("value \"" + longValue[0] + "\"of parameter \"" + longName + "\" not a valid long", e); + LOGGER.warn("value \"{}\"of parameter \"{}\" not a valid long", longValue[0], longName, e); return -1; } } diff --git a/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestMain.java b/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestMain.java index 297ee97e9..e1b5a9174 100644 --- a/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestMain.java +++ b/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestMain.java @@ -85,21 +85,21 @@ public class ApexMonitoringRestMain { parameters = parser.parse(args); } catch (final ApexMonitoringRestParameterException e) { throw new ApexMonitoringRestParameterException( - REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + e.getMessage() + '\n' - + parser.getHelp(ApexMonitoringRestMain.class.getCanonicalName())); + REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + e.getMessage() + '\n' + + parser.getHelp(ApexMonitoringRestMain.class.getCanonicalName()), e); } if (parameters.isHelpSet()) { throw new ApexMonitoringRestParameterException( - parser.getHelp(ApexMonitoringRestMain.class.getCanonicalName())); + parser.getHelp(ApexMonitoringRestMain.class.getCanonicalName())); } // Validate the parameters final String validationMessage = parameters.validate(); if (validationMessage.length() > 0) { throw new ApexMonitoringRestParameterException( - REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage - + '\n' + parser.getHelp(ApexMonitoringRestMain.class.getCanonicalName())); + REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage + '\n' + + parser.getHelp(ApexMonitoringRestMain.class.getCanonicalName())); } state = ServicesState.READY; @@ -109,8 +109,8 @@ public class ApexMonitoringRestMain { * Initialize the rest service. */ public void init() { - outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at " - + parameters.getBaseUri().toString() + " . . ."); + outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at " + parameters.getBaseUri().toString() + + " . . ."); try { state = ServicesState.INITIALIZING; @@ -125,7 +125,7 @@ public class ApexMonitoringRestMain { if (parameters.getTimeToLive() == ApexMonitoringRestParameters.INFINITY_TIME_TO_LIVE) { outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started at " - + parameters.getBaseUri().toString()); + + parameters.getBaseUri().toString()); } else { outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started"); } @@ -142,8 +142,9 @@ public class ApexMonitoringRestMain { Thread.sleep(1000); } } catch (final Exception e) { - outStream.println( - REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage()); + String message = REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage(); + outStream.println(message); + LOGGER.warn(message, e); } finally { if (apexMonitoringRest != null) { apexMonitoringRest.shutdown(); @@ -167,7 +168,7 @@ public class ApexMonitoringRestMain { public String toString() { final StringBuilder ret = new StringBuilder(); ret.append(this.getClass().getSimpleName()).append(": Config=[").append(this.parameters).append("], State=") - .append(this.getState()); + .append(this.getState()); return ret.toString(); } diff --git a/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ParameterCheck.java b/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ParameterCheck.java index c8eb5ad66..90527751e 100644 --- a/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ParameterCheck.java +++ b/client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ParameterCheck.java @@ -32,12 +32,17 @@ import org.slf4j.ext.XLoggerFactory; * @author Liam Fallon (liam.fallon@ericsson.com) */ public final class ParameterCheck { + // Recurring string constants + private static final String PARAMETER = "parameter \""; + private static final String NOT_FOUND = "\" not found"; + private static final int MAX_PORT = 65535; /** * private constructor to prevent subclassing of this utility class. */ - private ParameterCheck() {} + private ParameterCheck() { + } /** * The Enum StartStop is used to hold . @@ -65,14 +70,14 @@ public final class ParameterCheck { */ public static String getHostName(final Map<String, String[]> parameterMap) { if (!parameterMap.containsKey(HOSTNAME_PAR)) { - LOGGER.warn("parameter \"" + HOSTNAME_PAR + "\" not found"); + LOGGER.warn(PARAMETER + HOSTNAME_PAR + NOT_FOUND); return null; } final String[] hostNameValue = parameterMap.get(HOSTNAME_PAR); if (hostNameValue.length == 0 || hostNameValue[0].trim().length() == 0) { - LOGGER.warn("value of parameter \"" + HOSTNAME_PAR + "\" not found"); + LOGGER.warn("value of parameter \"" + HOSTNAME_PAR + NOT_FOUND); return null; } @@ -87,14 +92,14 @@ public final class ParameterCheck { */ public static int getPort(final Map<String, String[]> parameterMap) { if (!parameterMap.containsKey(PORT_PAR)) { - LOGGER.warn("parameter \"" + PORT_PAR + "\" not found"); + LOGGER.warn(PARAMETER + PORT_PAR + NOT_FOUND); return -1; } final String[] portValue = parameterMap.get(PORT_PAR); if (portValue.length == 0 || portValue[0].trim().length() == 0) { - LOGGER.warn("value of parameter \"" + PORT_PAR + "\" not found"); + LOGGER.warn("value of parameter \"" + PORT_PAR + NOT_FOUND); return -1; } @@ -102,13 +107,13 @@ public final class ParameterCheck { try { port = Integer.parseInt(portValue[0]); } catch (final Exception e) { - LOGGER.warn("value \"" + portValue[0] + "\"of parameter \"" + PORT_PAR + "\" not a valid integer", e); + LOGGER.warn("value \"{}\"of parameter \"" + PORT_PAR + "\" not a valid integer", portValue[0], e); return -1; } if (port <= 0 || port > MAX_PORT) { - LOGGER.warn("value \"" + portValue[0] + "\"of parameter \"" + PORT_PAR - + "\" not a valid port between 0 and 65535"); + LOGGER.warn("value \"{}\"of parameter \"" + PORT_PAR + "\" not a valid port between 0 and 65535", + portValue[0]); return -1; } @@ -131,14 +136,14 @@ public final class ParameterCheck { } } if (artifactKeyParameter == null) { - LOGGER.warn("parameter \"" + AXARTIFACTKEY_PAR + "\" not found"); + LOGGER.warn(PARAMETER + AXARTIFACTKEY_PAR + NOT_FOUND); return null; } final String[] axArtifactKeyArray = artifactKeyParameter.split("#"); if (axArtifactKeyArray.length != 2) { - LOGGER.warn("value \"" + artifactKeyParameter + "\" of parameter \"" + AXARTIFACTKEY_PAR + "\" not valid"); + LOGGER.warn("value \"{}\" of parameter \"" + AXARTIFACTKEY_PAR + "\" not valid", artifactKeyParameter); return null; } @@ -153,17 +158,17 @@ public final class ParameterCheck { * @return the start stop */ public static ParameterCheck.StartStop getStartStop(final Map<String, String[]> parameterMap, - final AxArtifactKey engineKey) { + final AxArtifactKey engineKey) { final String startStopPar = AXARTIFACTKEY_PAR + '#' + engineKey.getId(); if (!parameterMap.containsKey(startStopPar)) { - LOGGER.warn("parameter \"" + startStopPar + "\" not found"); + LOGGER.warn("parameter \"{}\" not found", startStopPar); return null; } final String[] startStopValue = parameterMap.get(startStopPar); if (startStopValue.length == 0 || startStopValue[0].trim().length() == 0) { - LOGGER.warn("value of parameter \"" + startStopPar + "\" not found"); + LOGGER.warn("value of parameter \"{}\" not found", startStopPar); return null; } @@ -173,8 +178,7 @@ public final class ParameterCheck { } else if (startStopValue[0].equalsIgnoreCase("stop")) { startStop = ParameterCheck.StartStop.STOP; } else { - LOGGER.warn("value \"" + startStopValue[0] + "\"of parameter \"" + startStopPar - + "\" not \"start\" or \"stop\""); + LOGGER.warn("value \"{}\"of parameter \"{}\" not \"start\" or \"stop\"", startStopValue[0], startStopPar); return null; } @@ -190,21 +194,21 @@ public final class ParameterCheck { */ public static long getLong(final Map<String, String[]> parameterMap, final String longName) { if (!parameterMap.containsKey(longName)) { - LOGGER.warn("parameter \"" + longName + "\" not found"); + LOGGER.warn("parameter \"{}\" not found", longName); return -1; } final String[] longValue = parameterMap.get(longName); if (longValue.length == 0 || longValue[0].trim().length() == 0) { - LOGGER.warn("value of parameter \"" + longName + "\" not found"); + LOGGER.warn("value of parameter \"{}\" not found", longName); return -1; } try { return Long.parseLong(longValue[0]); } catch (final Exception e) { - LOGGER.warn("value \"" + longValue[0] + "\"of parameter \"" + longName + "\" not a valid long", e); + LOGGER.warn("value \"{}\"of parameter \"{}\" not a valid long", longValue[0], longName, e); return -1; } } diff --git a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java index c6a34e364..7a903e9d1 100644 --- a/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java +++ b/context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java @@ -235,7 +235,7 @@ public class JavaSchemaHelper extends AbstractSchemaHelper { final String returnString = getUserKey().getId() + ": object \"" + object.toString() + "\" of class \"" + object.getClass().getCanonicalName() + "\" not compatible with class \"" + getSchemaClass().getCanonicalName() + "\""; - LOGGER.warn(returnString); + LOGGER.warn(returnString, e); throw new ContextRuntimeException(returnString); } } diff --git a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/event/EnField.java b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/event/EnField.java index a7ce251bd..15fbacf45 100644 --- a/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/event/EnField.java +++ b/core/core-engine/src/main/java/org/onap/policy/apex/core/engine/event/EnField.java @@ -147,6 +147,9 @@ public class EnField implements Serializable { schemaHelper.unmarshal(value); return true; } catch (final Exception e) { + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("value {} is not assignable to this field", value, e); + } return false; } } diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/xml/XPathReader.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/xml/XPathReader.java index bd2474339..08046c924 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/xml/XPathReader.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/xml/XPathReader.java @@ -92,7 +92,7 @@ public class XPathReader { xpath = XPathFactory.newInstance().newXPath(); LOGGER.info("Initialized XPath reader"); } catch (final Exception ex) { - LOGGER.error("Error parsing XML file/stream from XPath reading, reason :\n" + ex.getMessage()); + LOGGER.error("Error parsing XML file/stream from XPath reading, reason :\n" + ex.getMessage(), ex); } } @@ -108,7 +108,7 @@ public class XPathReader { final XPathExpression xPathExpression = xpath.compile(expression); return xPathExpression.evaluate(xmlDocument, returnType); } catch (final XPathExpressionException ex) { - LOGGER.error("Failed to read XML file for XPath processing, reason:\n" + ex.getMessage()); + LOGGER.error("Failed to read XML file for XPath processing, reason:\n" + ex.getMessage(), ex); return null; } } diff --git a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestApexActionListener.java b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestApexActionListener.java index ccf4539aa..60fa169dd 100644 --- a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestApexActionListener.java +++ b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestApexActionListener.java @@ -69,11 +69,8 @@ public class TestApexActionListener implements EnEventListener { */ @Override public void onEnEvent(final EnEvent actionEvent) { - try { - Thread.sleep(100); - } catch (final InterruptedException e) { - e.printStackTrace(); - } + ThreadUtilities.sleep(100); + if (actionEvent != null) { System.out.println("Action event from engine:" + actionEvent.getName()); resultEvents.add(actionEvent); diff --git a/examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/concepts/AutoLearn.java b/examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/concepts/AutoLearn.java index d935af5f0..968b20499 100644 --- a/examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/concepts/AutoLearn.java +++ b/examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/concepts/AutoLearn.java @@ -31,9 +31,9 @@ import java.util.List; public class AutoLearn implements Serializable { private static final long serialVersionUID = 3825970380434170754L; - private List<Double> avDiffs = null; + private transient List<Double> avDiffs = null; - private List<Long> counts = null; + private transient List<Long> counts = null; /** * Checks if the Autolearn instance is initialized. diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestAnomalyDetectionTslUseCase.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestAnomalyDetectionTslUseCase.java index cb7e3c824..c29a3cb6e 100644 --- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestAnomalyDetectionTslUseCase.java +++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestAnomalyDetectionTslUseCase.java @@ -38,6 +38,7 @@ import org.onap.policy.apex.core.engine.EngineParameters; import org.onap.policy.apex.core.engine.engine.ApexEngine; import org.onap.policy.apex.core.engine.engine.impl.ApexEngineFactory; import org.onap.policy.apex.core.engine.event.EnEvent; +import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.examples.adaptive.model.AdaptiveDomainModelFactory; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; @@ -148,7 +149,7 @@ public class TestAnomalyDetectionTslUseCase { assertEquals("ExecutionIDs are different", triggerEvent.getExecutionId(), result.getExecutionId()); triggerEvent.clear(); result.clear(); - Thread.sleep(1); + ThreadUtilities.sleep(1); apexEngine1.stop(); } @@ -215,7 +216,7 @@ public class TestAnomalyDetectionTslUseCase { result.clear(); } apexEngine1.stop(); - Thread.sleep(1000); + ThreadUtilities.sleep(1000); } /** diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestApexActionListener.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestApexActionListener.java index ec7c197b7..006d3de6f 100644 --- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestApexActionListener.java +++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestApexActionListener.java @@ -69,11 +69,8 @@ public class TestApexActionListener implements EnEventListener { */ @Override public void onEnEvent(final EnEvent actionEvent) { - try { - Thread.sleep(100); - } catch (final InterruptedException e) { - e.printStackTrace(); - } + ThreadUtilities.sleep(100); + if (actionEvent != null) { System.out.println("Action event from engine:" + actionEvent.getName()); resultEvents.add(actionEvent); diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestAutoLearnTslUseCase.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestAutoLearnTslUseCase.java index 3052c31a7..10d69a457 100644 --- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestAutoLearnTslUseCase.java +++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestAutoLearnTslUseCase.java @@ -38,6 +38,7 @@ import org.onap.policy.apex.core.engine.EngineParameters; import org.onap.policy.apex.core.engine.engine.ApexEngine; import org.onap.policy.apex.core.engine.engine.impl.ApexEngineFactory; import org.onap.policy.apex.core.engine.event.EnEvent; +import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.onap.policy.apex.examples.adaptive.model.AdaptiveDomainModelFactory; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; @@ -146,7 +147,7 @@ public class TestAutoLearnTslUseCase { assertEquals("ExecutionIDs are different", triggerEvent.getExecutionId(), result.getExecutionId()); triggerEvent.clear(); result.clear(); - Thread.sleep(1); + ThreadUtilities.sleep(10); apexEngine1.stop(); } @@ -234,12 +235,11 @@ public class TestAutoLearnTslUseCase { LOGGER.info("Iteration " + iteration + ": \tpreval\t" + prevval + "\tval\t" + val + "\tavval\t" + avval); result.clear(); - Thread.sleep(1); + ThreadUtilities.sleep(10); } apexEngine1.stop(); - Thread.sleep(1000); - + ThreadUtilities.sleep(1000); } /** diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java index 2dfd1af61..b2722fd78 100644 --- a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java +++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java @@ -71,11 +71,8 @@ public class TestSaleAuthListener implements EnEventListener { */ @Override public void onEnEvent(final EnEvent saleauthEvent) { - try { - Thread.sleep(100); - } catch (final InterruptedException e) { - e.printStackTrace(); - } + ThreadUtilities.sleep(100); + if (saleauthEvent != null) { System.out.println("SaleAuth event from engine:" + saleauthEvent.getName()); resultEvents.add(saleauthEvent); diff --git a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AaiAndGuardSim.java b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AaiAndGuardSim.java index 369e6172c..bb754d99f 100644 --- a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AaiAndGuardSim.java +++ b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AaiAndGuardSim.java @@ -32,6 +32,7 @@ import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; */ public class AaiAndGuardSim { private static final String BASE_URI = "http://localhost:54321/AAIAndGuardSim"; + private static final int MAX_LOOPS = 100000; private HttpServer server; /** @@ -64,13 +65,10 @@ public class AaiAndGuardSim { public static void main(final String[] args) throws Exception { final AaiAndGuardSim sim = new AaiAndGuardSim(); - while (true) { - try { - Thread.sleep(100); - } catch (final InterruptedException e) { - break; - } + for (int index = 0; index < MAX_LOOPS; index++) { + ThreadUtilities.sleep(100); } + sim.tearDown(); } } diff --git a/examples/examples-servlet/src/main/java/org/onap/policy/apex/examples/servlet/ApexServletListener.java b/examples/examples-servlet/src/main/java/org/onap/policy/apex/examples/servlet/ApexServletListener.java index f6de1285e..78871c385 100644 --- a/examples/examples-servlet/src/main/java/org/onap/policy/apex/examples/servlet/ApexServletListener.java +++ b/examples/examples-servlet/src/main/java/org/onap/policy/apex/examples/servlet/ApexServletListener.java @@ -57,7 +57,7 @@ public class ApexServletListener implements ServletContextListener { final String configFileName = servletContextEvent.getServletContext().getInitParameter("config-file"); final String modelFileName = servletContextEvent.getServletContext().getInitParameter("model-file"); - LOGGER.info("Apex Servliet has been started, config-file= " + configFileName + ", model-file=" + modelFileName); + LOGGER.info("Apex Servliet has been started, config-file={}, model-file={}", configFileName, modelFileName); // Check that a configuration file have been specified if (servletContextEvent.getServletContext().getInitParameter("config-file") == null) { @@ -68,7 +68,7 @@ public class ApexServletListener implements ServletContextListener { } // Construct the Apex command line arguments - final List<String> argsList = new ArrayList<String>(); + final List<String> argsList = new ArrayList<>(); argsList.add("-config-file"); argsList.add(configFileName); diff --git a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbum.java b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbum.java index 564e2d48c..3d008e992 100644 --- a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbum.java +++ b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbum.java @@ -274,11 +274,10 @@ public class AxContextAlbum extends AxConcept { "scope is not defined")); } - try { - Assertions.validateStringParameter(SCOPE_STRING, scope, SCOPE_REGEXP); - } catch (final IllegalArgumentException e) { + String stringCheckResult = Assertions.getStringParameterValidationMessage(SCOPE_STRING, scope, SCOPE_REGEXP); + if (stringCheckResult != null) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "scope invalid-" + e.getMessage())); + "scope invalid-" + stringCheckResult)); } if (itemSchema.equals(AxArtifactKey.getNullKey())) { diff --git a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchema.java b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchema.java index 5dad2e9e8..767b1d02e 100644 --- a/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchema.java +++ b/model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchema.java @@ -234,11 +234,11 @@ public class AxContextSchema extends AxConcept { "schema flavour is not defined")); } - try { - Assertions.validateStringParameter(SCHEMA_FLAVOUR, schemaFlavour, SCHEMA_FLAVOUR_REGEXP); - } catch (final IllegalArgumentException e) { + String flavourValidationResult = Assertions.getStringParameterValidationMessage(SCHEMA_FLAVOUR, schemaFlavour, + SCHEMA_FLAVOUR_REGEXP); + if (flavourValidationResult != null) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "schema flavour invalid-" + e.getMessage())); + "schema flavour invalid-" + flavourValidationResult)); } if (schemaDefinition.replaceAll(WHITESPACE_REGEXP, "").length() == 0) { diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineStats.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineStats.java index fb99e265b..8bd5756ab 100644 --- a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineStats.java +++ b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineStats.java @@ -38,6 +38,7 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.Validat * @author Liam Fallon (liam.fallon@ericsson.com) */ public class TestEngineStats { + private static final Object WAIT_LOCK = new Object(); @Test public void testEngineStats() { @@ -98,11 +99,15 @@ public class TestEngineStats { stats.engineStart(); stats.setEventCount(4); stats.executionEnter(new AxArtifactKey()); - try { - Thread.sleep(10); - } catch (final Exception e) { - fail("test should not throw an exeption"); + + synchronized (WAIT_LOCK) { + try { + WAIT_LOCK.wait(10); + } catch (InterruptedException e) { + fail("test should not throw an exception"); + } } + stats.executionExit(); final double avExecutionTime = stats.getAverageExecutionTime(); assertTrue(avExecutionTime >= 2.0 && avExecutionTime < 10.0); diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogic.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogic.java index 99642d1ae..ad86fb42c 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogic.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogic.java @@ -271,11 +271,11 @@ public class AxLogic extends AxConcept { "logic flavour is not defined")); } - try { - Assertions.validateStringParameter(LOGIC_FLAVOUR_TOKEN, logicFlavour, LOGIC_FLAVOUR_REGEXP); - } catch (final IllegalArgumentException e) { + String flavourValidationString = Assertions.getStringParameterValidationMessage(LOGIC_FLAVOUR_TOKEN, + logicFlavour, LOGIC_FLAVOUR_REGEXP); + if (flavourValidationString != null) { result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.INVALID, - "logic flavour invalid-" + e.getMessage())); + "logic flavour invalid-" + flavourValidationString)); } if (logic.replaceAll(WHITESPACE_REGEXP, "").length() == 0) { diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicy.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicy.java index a03b49f13..3c43c6edd 100644 --- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicy.java +++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicy.java @@ -49,6 +49,8 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxValidationMessage; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; import org.onap.policy.apex.model.utilities.Assertions; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; /** * This class holds the definition of an Apex policy. A policy is made up of a tree of states, each represented by an @@ -88,6 +90,9 @@ import org.onap.policy.apex.model.utilities.Assertions; public class AxPolicy extends AxConcept { private static final long serialVersionUID = -1775614096390365941L; + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(AxPolicy.class); + @EmbeddedId @XmlElement(name = "policyKey", required = true) private AxArtifactKey key; @@ -364,7 +369,7 @@ public class AxPolicy extends AxConcept { */ private AxValidationResult validateStateTree(AxValidationResult result) { try { - // Cpnstructor validates policy state tree + // Constructor validates policy state tree AxStateTree policyStateTree = getStateTree(); // Check for unused states @@ -378,8 +383,10 @@ public class AxPolicy extends AxConcept { + " is not referenced in the policy execution tree")); } } catch (PolicyRuntimeException pre) { - result.addValidationMessage(new AxValidationMessage(key, this.getClass(), ValidationResult.WARNING, - "state tree in policy is invalid")); + AxValidationMessage validationMessage = new AxValidationMessage(key, this.getClass(), + ValidationResult.WARNING, "state tree in policy is invalid"); + LOGGER.trace(validationMessage.getMessage(), pre); + result.addValidationMessage(validationMessage); } return result; diff --git a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/Assertions.java b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/Assertions.java index a3ecccebe..02a91a72c 100644 --- a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/Assertions.java +++ b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/Assertions.java @@ -20,6 +20,9 @@ package org.onap.policy.apex.model.utilities; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + /** * The Class Assertions is a template class that is used as a shorthand for assertions in the source code. * @@ -27,6 +30,9 @@ package org.onap.policy.apex.model.utilities; * @author Liam Fallon (liam.fallon@ericsson.com) */ public final class Assertions { + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(Assertions.class); + /** * Private constructor used to prevent sub class instantiation. */ @@ -46,8 +52,13 @@ public final class Assertions { try { validateStringParameter(parameterName, parameterValue, pattern); } catch (IllegalArgumentException e) { - // This will cause a SONAR error but eliminates all SONAR messages in callers - return e.getMessage(); + String message = "parameter " + parameterName + " with value " + parameterValue + + " does not match regular expression " + pattern; + if (LOGGER.isTraceEnabled()) { + LOGGER.trace(message, e); + } + + return message; } return null; diff --git a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/typeutils/ClassBuilder.java b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/typeutils/ClassBuilder.java index ffebc405f..2e6e96d0b 100644 --- a/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/typeutils/ClassBuilder.java +++ b/model/utilities/src/main/java/org/onap/policy/apex/model/utilities/typeutils/ClassBuilder.java @@ -24,6 +24,9 @@ import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + //CHECKSTYLE:OFF: checkstyle:IllegalImport import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; //CHECKSTYLE:ON: checkstyle:IllegalImport @@ -38,6 +41,9 @@ import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; */ @SuppressWarnings("restriction") public class ClassBuilder { + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(ClassBuilder.class); + private final Class<?> clazz; private final List<ClassBuilder> parameters = new ArrayList<>(); @@ -62,7 +68,8 @@ public class ClassBuilder { } catch (ClassNotFoundException e) { try { return new ClassBuilder(Class.forName("java.lang." + className)); - } catch (Exception ignore) { + } catch (Exception classFindException) { + LOGGER.warn("class nout found", classFindException); throw new IllegalArgumentException("Class '" + className + "' not found. Also looked for a class called 'java.lang." + className + "'", e); } diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java index 9cdb5845b..a9418d834 100644 --- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java +++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java @@ -70,7 +70,7 @@ public class AvroSchemaHelper extends AbstractSchemaHelper { } catch (final Exception e) { final String resultSting = userKey.getId() + ": avro context schema \"" + schema.getId() + "\" schema is invalid: " + e.getMessage() + ", schema: " + schema.getSchema(); - LOGGER.warn(resultSting); + LOGGER.warn(resultSting, e); throw new ContextRuntimeException(resultSting); } @@ -189,7 +189,7 @@ public class AvroSchemaHelper extends AbstractSchemaHelper { + (object != null ? object.getClass().getCanonicalName() : "null") + "\" must be assignable to \"" + getSchemaClass().getCanonicalName() + "\" or be a Json string representation of it for Avro unmarshalling"; - LOGGER.warn(returnString); + LOGGER.warn(returnString, e); throw new ContextRuntimeException(returnString); } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducer.java index 7277a7dc3..0580d7159 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducer.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducer.java @@ -233,7 +233,7 @@ public class ApexJmsProducer implements ApexEventProducer { } catch (final Exception e) { final String errorMessage = COULD_NOT_SEND_PREFIX + eventname + JMS_MESSAGE_PRODUCER_TAG + this.name + ", could not create JMS Object Message for object \"" + eventObject; - LOGGER.warn(errorMessage); + LOGGER.warn(errorMessage, e); throw new ApexEventRuntimeException(errorMessage); } } else { @@ -243,7 +243,7 @@ public class ApexJmsProducer implements ApexEventProducer { } catch (final Exception e) { final String errorMessage = COULD_NOT_SEND_PREFIX + eventname + JMS_MESSAGE_PRODUCER_TAG + this.name + ", could not create JMS Text Message for object \"" + eventObject; - LOGGER.warn(errorMessage); + LOGGER.warn(errorMessage, e); throw new ApexEventRuntimeException(errorMessage); } } @@ -253,7 +253,7 @@ public class ApexJmsProducer implements ApexEventProducer { } catch (final Exception e) { final String errorMessage = COULD_NOT_SEND_PREFIX + eventname + JMS_MESSAGE_PRODUCER_TAG + this.name + ", send failed for object \"" + eventObject; - LOGGER.warn(errorMessage); + LOGGER.warn(errorMessage, e); throw new ApexEventRuntimeException(errorMessage); } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumer.java index dea839ebb..7d6c60ca1 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumer.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumer.java @@ -166,7 +166,7 @@ public class ApexRestRequestorConsumer implements ApexEventConsumer, Runnable { } catch (final Exception e) { final String errorMessage = "could not queue request \"" + restRequest + "\" on REST Requestor consumer (" + this.name + ")"; - LOGGER.warn(errorMessage); + LOGGER.warn(errorMessage, e); throw new ApexEventRuntimeException(errorMessage); } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumer.java index 94063af20..35490926a 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumer.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumer.java @@ -212,7 +212,7 @@ public class ApexRestServerConsumer implements ApexEventConsumer, Runnable { eventReceiver.receiveEvent(executionId, event); } catch (final Exception e) { final String errorMessage = "error receiving events on event consumer " + name + ", " + e.getMessage(); - LOGGER.warn(errorMessage); + LOGGER.warn(errorMessage, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()) .entity("{'errorMessage', '" + errorMessage + "'}").build(); } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketConsumer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketConsumer.java index fe3e47b82..17955c3be 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketConsumer.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketConsumer.java @@ -98,7 +98,7 @@ public class ApexWebSocketConsumer implements ApexEventConsumer, WsStringMessage try { wsStringMessager.start(this); } catch (final MessagingException e) { - LOGGER.warn("could not start web socket consumer"); + LOGGER.warn("could not start web socket consumer", e); } } @@ -188,7 +188,7 @@ public class ApexWebSocketConsumer implements ApexEventConsumer, WsStringMessage } catch (final Exception e) { final String errorMessage = "Error sending event " + name + '_' + eventsRead + ", " + e.getMessage() + ", event:\n" + eventString; - LOGGER.warn(errorMessage); + LOGGER.warn(errorMessage, e); } } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketProducer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketProducer.java index 7dd1ab947..6f04024b4 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketProducer.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketProducer.java @@ -85,7 +85,7 @@ public class ApexWebSocketProducer implements ApexEventProducer, WsStringMessage wsStringMessager.start(this); } catch (final MessagingException e) { String message = "could not start web socket producer (" + this.name + ")"; - LOGGER.warn(message); + LOGGER.warn(message, e); } } diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsObjectEventConverter.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsObjectEventConverter.java index ca02709fe..25aa4f8ee 100644 --- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsObjectEventConverter.java +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsObjectEventConverter.java @@ -84,7 +84,7 @@ public final class Apex2JmsObjectEventConverter implements ApexEventProtocolConv } catch (Exception e) { final String errorMessage = "message \"" + eventObject + "\" received from JMS does not have a \"getObject()\" method"; - LOGGER.warn(errorMessage); + LOGGER.warn(errorMessage, e); throw new ApexEventRuntimeException(errorMessage); } diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsTextEventConverter.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsTextEventConverter.java index 1c44dd111..55548b9d7 100644 --- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsTextEventConverter.java +++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsTextEventConverter.java @@ -55,7 +55,7 @@ public final class Apex2JmsTextEventConverter extends Apex2JsonEventConverter { } catch (Exception e) { final String errorMessage = "message \"" + eventObject + "\" received from JMS does not have a \"getText()\" method"; - LOGGER.warn(errorMessage); + LOGGER.warn(errorMessage, e); throw new ApexEventRuntimeException(errorMessage); } diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java index 8c7911bce..5a0d11d4c 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java @@ -26,8 +26,8 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicLong; import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * The Class ApexEvent is an event class that external systems use to send events to and receive @@ -37,12 +37,13 @@ import org.slf4j.ext.XLoggerFactory; * @author Liam Fallon (liam.fallon@ericsson.com) */ public class ApexEvent extends HashMap<String, Object> implements Serializable { - // Recurring string constants - private static final String EVENT_PREAMBLE = "event \""; + private static final long serialVersionUID = -4451918242101961685L; - private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexEvent.class); + // Get a reference to the logger + private static final Logger LOGGER = LoggerFactory.getLogger(ApexEvent.class); - private static final long serialVersionUID = -4451918242101961685L; + // Recurring string constants + private static final String EVENT_PREAMBLE = "event \""; // Holds the next identifier for event execution. private static AtomicLong nextExecutionID = new AtomicLong(0L); @@ -286,6 +287,9 @@ public class ApexEvent extends HashMap<String, Object> implements Serializable { try { return super.put(validKey(key), value); } catch (final ApexEventException e) { + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("put failed", e); + } return null; } } @@ -303,6 +307,10 @@ public class ApexEvent extends HashMap<String, Object> implements Serializable { validKey(key); } } catch (final ApexEventException e) { + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("putAll failed", e); + } + // One of the keys is invalid return; } diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorConsumer.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorConsumer.java index 8c135f19a..f74751a63 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorConsumer.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorConsumer.java @@ -110,7 +110,7 @@ public class EventRequestorConsumer implements ApexEventConsumer, Runnable { } catch (final Exception e) { final String errorMessage = "could not queue request \"" + eventObject + "\" on event Requestor consumer (" + this.name + ")"; - LOGGER.warn(errorMessage); + LOGGER.warn(errorMessage, e); throw new ApexEventRuntimeException(errorMessage); } } diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JsonEventConverter.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JsonEventConverter.java index ce511be7f..343ef9ac0 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JsonEventConverter.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JsonEventConverter.java @@ -376,7 +376,7 @@ public class Apex2JsonEventConverter implements ApexEventProtocolConverter { } catch (final Exception e) { // The element is not a string so throw an error throw new ApexEventRuntimeException("field \"" + fieldName + "\" with type \"" - + jsonField.getClass().getCanonicalName() + "\" is not a string value"); + + jsonField.getClass().getCanonicalName() + "\" is not a string value", e); } // Is regular expression checking required diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArguments.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArguments.java index bdbd82dc2..ff0eef7f0 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArguments.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArguments.java @@ -101,7 +101,7 @@ public class ApexCommandLineArguments { try { parse(args); } catch (final ApexException e) { - throw new ApexRuntimeException("parse error on Apex parameters"); + throw new ApexRuntimeException("parse error on Apex parameters", e); } } diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventhandler/EventHandlerParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventhandler/EventHandlerParameters.java index afd877fd2..8505127e6 100644 --- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventhandler/EventHandlerParameters.java +++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventhandler/EventHandlerParameters.java @@ -29,6 +29,8 @@ import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParame import org.onap.policy.common.parameters.GroupValidationResult; import org.onap.policy.common.parameters.ParameterGroup; import org.onap.policy.common.parameters.ValidationStatus; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * The parameters for a single event producer, event consumer or synchronous event handler. @@ -51,6 +53,9 @@ import org.onap.policy.common.parameters.ValidationStatus; * @author Liam Fallon (liam.fallon@ericsson.com) */ public class EventHandlerParameters implements ParameterGroup { + // Get a reference to the logger + private static final Logger LOGGER = LoggerFactory.getLogger(EventHandlerParameters.class); + private String name = null; private CarrierTechnologyParameters carrierTechnologyParameters = null; private EventProtocolParameters eventProtocolParameters = null; @@ -325,8 +330,9 @@ public class EventHandlerParameters implements ParameterGroup { try { Pattern.compile(eventNameFilter); } catch (final PatternSyntaxException pse) { - result.setResult("eventNameFilter", ValidationStatus.INVALID, - "event handler eventNameFilter is not a valid regular expression: " + pse.getMessage()); + String message = "event handler eventNameFilter is not a valid regular expression: " + pse.getMessage(); + LOGGER.trace(message, pse); + result.setResult("eventNameFilter", ValidationStatus.INVALID, message); } } @@ -380,6 +386,7 @@ public class EventHandlerParameters implements ParameterGroup { /** * Get the requestor timeout. + * * @return the requestorTimeout. */ public long getRequestorTimeout() { diff --git a/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/model/EvalDomainModelFactory.java b/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/model/EvalDomainModelFactory.java index a36aa1030..883793290 100644 --- a/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/model/EvalDomainModelFactory.java +++ b/testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/model/EvalDomainModelFactory.java @@ -210,7 +210,7 @@ public class EvalDomainModelFactory { * @return the sample policy model */ public AxPolicyModel getOodaPolicyModel() { - final AxTasks tasks = new AxTasks(new AxArtifactKey("Tasks", "0.0.1")); + final AxTasks tasks = new AxTasks(new AxArtifactKey("Tasks", DEFAULT_VERSION)); final AxLogicReader logicReader = new PolicyLogicReader().setLogicPackage(PACKAGE) .setDefaultLogic("EvalTask_Logic"); diff --git a/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2cli/Application.java b/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2cli/Application.java index 236750310..b6c6b774c 100644 --- a/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2cli/Application.java +++ b/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2cli/Application.java @@ -26,6 +26,8 @@ import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.tools.common.CliOptions; import org.onap.policy.apex.tools.common.CliParser; import org.onap.policy.apex.tools.common.OutputFile; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Process an Apex Policy Model file to generate the CLI commands to generate an equivalent Apex Policy Model. @@ -33,6 +35,8 @@ import org.onap.policy.apex.tools.common.OutputFile; * @author Sven van der Meer <sven.van.der.meer@ericsson.com> */ public final class Application { + // Get a reference to the logger + private static final Logger LOGGER = LoggerFactory.getLogger(Application.class); /** The name of the application. */ public static final String APP_NAME = "gen-model2cli"; @@ -118,7 +122,9 @@ public final class Application { final Model2Cli app = new Model2Cli(modelFile, outfile, !cmd.hasOption("sv"), APP_NAME); app.runApp(); } catch (final ApexException aex) { - System.err.println(APP_NAME + ": caught APEX exception with message: " + aex.getMessage()); + String message = APP_NAME + ": caught APEX exception with message: " + aex.getMessage(); + System.err.println(message); + LOGGER.warn(message, aex); } } } diff --git a/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2event/Application.java b/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2event/Application.java index 2bc70f69e..9735293cf 100644 --- a/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2event/Application.java +++ b/tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2event/Application.java @@ -25,6 +25,8 @@ import org.apache.commons.cli.HelpFormatter; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.tools.common.CliOptions; import org.onap.policy.apex.tools.common.CliParser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Model 2 event generator with main method. @@ -32,6 +34,8 @@ import org.onap.policy.apex.tools.common.CliParser; * @author Sven van der Meer (sven.van.der.meer@ericsson.com) */ public final class Application { + // Get a reference to the logger + private static final Logger LOGGER = LoggerFactory.getLogger(Application.class); /** The name of the application. */ public static final String APP_NAME = "gen-model2event"; @@ -105,7 +109,9 @@ public final class Application { final Model2JsonEventSchema app = new Model2JsonEventSchema(modelFile, type, APP_NAME); app.runApp(); } catch (final ApexException aex) { - System.err.println(APP_NAME + ": caught APEX exception with message: " + aex.getMessage()); + String message = APP_NAME + ": caught APEX exception with message: " + aex.getMessage(); + System.err.println(message); + LOGGER.warn(message, aex); } } } diff --git a/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/Application.java b/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/Application.java index bfd6573bc..7c7d7e9c6 100644 --- a/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/Application.java +++ b/tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/Application.java @@ -29,6 +29,8 @@ import org.apache.commons.cli.HelpFormatter; import org.apache.commons.lang3.Validate; import org.onap.policy.apex.tools.common.CliOptions; import org.onap.policy.apex.tools.common.CliParser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Simple console application with main method. @@ -36,6 +38,8 @@ import org.onap.policy.apex.tools.common.CliParser; * @author Sven van der Meer (sven.van.der.meer@ericsson.com) */ public final class Application { + // Get a reference to the logger + private static final Logger LOGGER = LoggerFactory.getLogger(Application.class); /** * Private constructor prevents subclassing. @@ -133,11 +137,17 @@ public final class Application { final SimpleEcho simpleEcho = new SimpleEcho(server, port, appName); simpleEcho.connect(); } catch (final URISyntaxException uex) { - System.err.println(appName + ": URI exception, could not create URI from server and port settings"); + String message = appName + ": URI exception, could not create URI from server and port settings"; + System.err.println(message); + LOGGER.warn(message, uex); } catch (final NullPointerException nex) { - System.err.println(appName + ": null pointer, server or port were null"); + String message = appName + ": null pointer, server or port were null"; + System.err.println(message); + LOGGER.warn(message, nex); } catch (final IllegalArgumentException iex) { - System.err.println(appName + ": illegal argument, server or port were blank"); + String message = appName + ": illegal argument, server or port were blank"; + System.err.println(message); + LOGGER.warn(message, iex); } } @@ -167,15 +177,25 @@ public final class Application { final SimpleConsole simpleConsole = new SimpleConsole(server, port, appName); simpleConsole.runClient(); } catch (final URISyntaxException uex) { - System.err.println(appName + ": URI exception, could not create URI from server and port settings"); + String message = appName + ": URI exception, could not create URI from server and port settings"; + System.err.println(message); + LOGGER.warn(message, uex); } catch (final NullPointerException nex) { - System.err.println(appName + ": null pointer, server or port were null"); + String message = appName + ": null pointer, server or port were null"; + System.err.println(message); + LOGGER.warn(message, nex); } catch (final IllegalArgumentException iex) { - System.err.println(appName + ": illegal argument, server or port were blank"); + String message = appName + ": illegal argument, server or port were blank"; + System.err.println(message); + LOGGER.warn(message, iex); } catch (final NotYetConnectedException nex) { - System.err.println(appName + ": not yet connected, connection to server took too long"); + String message = appName + ": not yet connected, connection to server took too long"; + System.err.println(message); + LOGGER.warn(message, nex); } catch (final IOException ioe) { - System.err.println(appName + ": IO exception, something went wrong on the standard input"); + String message = appName + ": IO exception, something went wrong on the standard input"; + System.err.println(message); + LOGGER.warn(message, ioe); } } } diff --git a/tools/tools-common/src/main/java/org/onap/policy/apex/tools/common/Console.java b/tools/tools-common/src/main/java/org/onap/policy/apex/tools/common/Console.java index 28337fdeb..aacc22013 100644 --- a/tools/tools-common/src/main/java/org/onap/policy/apex/tools/common/Console.java +++ b/tools/tools-common/src/main/java/org/onap/policy/apex/tools/common/Console.java @@ -25,6 +25,8 @@ import java.util.List; import org.apache.commons.lang3.StringUtils; import org.apache.commons.text.StrBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.slf4j.ext.XLoggerFactory; import org.slf4j.helpers.MessageFormatter; @@ -36,7 +38,6 @@ import org.slf4j.helpers.MessageFormatter; * @author Sven van der Meer (sven.van.der.meer@ericsson.com) */ public final class Console { - /** The console as static object. */ public static final Console CONSOLE = new Console(); diff --git a/tools/tools-common/src/main/java/org/onap/policy/apex/tools/common/OutputFile.java b/tools/tools-common/src/main/java/org/onap/policy/apex/tools/common/OutputFile.java index b529a7e08..59d15d19d 100644 --- a/tools/tools-common/src/main/java/org/onap/policy/apex/tools/common/OutputFile.java +++ b/tools/tools-common/src/main/java/org/onap/policy/apex/tools/common/OutputFile.java @@ -32,6 +32,8 @@ import java.nio.file.Path; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Standard output file handling and tests. @@ -39,6 +41,8 @@ import org.apache.commons.lang3.Validate; * @author Sven van der Meer (sven.van.der.meer@ericsson.com) */ public class OutputFile { + // Get a reference to the logger + private static final Logger LOGGER = LoggerFactory.getLogger(OutputFile.class); /** The output file name. */ private final String fileName; @@ -86,6 +90,7 @@ public class OutputFile { try { return new BufferedWriter(new FileWriter(toFile())); } catch (final IOException e) { + LOGGER.warn("write error", e); return null; } } @@ -99,6 +104,7 @@ public class OutputFile { try { return new FileOutputStream(toFile()); } catch (final IOException e) { + LOGGER.warn("stream creation error", e); return null; } } @@ -123,7 +129,9 @@ public class OutputFile { try { file.createNewFile(); } catch (final IOException e) { - return "could not create output file: " + e.getMessage(); + String message = "could not create output file: " + e.getMessage(); + LOGGER.warn(message, e); + return message; } } |