Fix exception not logged or rethrown 99/66699/1
authorliamfallon <liam.fallon@ericsson.com>
Fri, 14 Sep 2018 15:45:06 +0000 (16:45 +0100)
committerliamfallon <liam.fallon@ericsson.com>
Fri, 14 Sep 2018 15:45:17 +0000 (16:45 +0100)
Eclipse sonarlint does not check for exception dropping by default,
it must be configured. This commit addresses exception dropping in
apex.

Change-Id: I406838990b3424c2912124b25d7326502cacc96c
Issue-ID: POLICY-1034
Signed-off-by: liamfallon <liam.fallon@ericsson.com>
50 files changed:
auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCommandLineEditorMain.java
auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelHandler.java
auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java
client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestMain.java
client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ParameterCheck.java
client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorMain.java
client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorParameters.java
client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/ApexEditorRestResource.java
client/client-editor/src/main/java/org/onap/policy/apex/client/editor/rest/bean/BeanBase.java
client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ApexServicesRestMain.java
client/client-full/src/main/java/org/onap/policy/apex/client/full/rest/ParameterCheck.java
client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestMain.java
client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ParameterCheck.java
context/context-management/src/main/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelper.java
core/core-engine/src/main/java/org/onap/policy/apex/core/engine/event/EnField.java
core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/xml/XPathReader.java
examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestApexActionListener.java
examples/examples-adaptive/src/main/java/org/onap/policy/apex/examples/adaptive/concepts/AutoLearn.java
examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestAnomalyDetectionTslUseCase.java
examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestApexActionListener.java
examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/TestAutoLearnTslUseCase.java
examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java
examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/AaiAndGuardSim.java
examples/examples-servlet/src/main/java/org/onap/policy/apex/examples/servlet/ApexServletListener.java
model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextAlbum.java
model/context-model/src/main/java/org/onap/policy/apex/model/contextmodel/concepts/AxContextSchema.java
model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineStats.java
model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxLogic.java
model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/concepts/AxPolicy.java
model/utilities/src/main/java/org/onap/policy/apex/model/utilities/Assertions.java
model/utilities/src/main/java/org/onap/policy/apex/model/utilities/typeutils/ClassBuilder.java
plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/main/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelper.java
plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducer.java
plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumer.java
plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumer.java
plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketConsumer.java
plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketProducer.java
plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsObjectEventConverter.java
plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsTextEventConverter.java
services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java
services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorConsumer.java
services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JsonEventConverter.java
services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArguments.java
services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventhandler/EventHandlerParameters.java
testsuites/integration/integration-common/src/main/java/org/onap/policy/apex/testsuites/integration/common/model/EvalDomainModelFactory.java
tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2cli/Application.java
tools/model-generator/src/main/java/org/onap/policy/apex/tools/model/generator/model2event/Application.java
tools/simple-wsclient/src/main/java/org/onap/policy/apex/tools/simple/wsclient/Application.java
tools/tools-common/src/main/java/org/onap/policy/apex/tools/common/Console.java
tools/tools-common/src/main/java/org/onap/policy/apex/tools/common/OutputFile.java

index 0df8ac6..b632514 100644 (file)
@@ -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);
         }
     }
 
index 2e1a473..3d14a83 100644 (file)
@@ -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;
index 513f31e..4f0aeb5 100644 (file)
@@ -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));
             }
index 7337405..134914f 100644 (file)
@@ -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();
     }
 
index b68ffeb..fb18a00 100644 (file)
@@ -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;
         }
     }
index 3f54467..ea4f206 100644 (file)
@@ -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();
     }
 
index 55d10c1..5c0c5eb 100644 (file)
@@ -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;
         }
     }
 
index 8bed63d..72c2941 100644 (file)
@@ -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);
             }
         }
index b2222f8..c3f249f 100644 (file)
@@ -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);
     }
 }
index c89fcf4..b11cd7f 100644 (file)
@@ -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();
     }
 
index d7b7229..d0b374f 100644 (file)
@@ -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;
         }
     }
index 297ee97..e1b5a91 100644 (file)
@@ -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();
     }
 
index c8eb5ad..9052775 100644 (file)
@@ -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;
         }
     }
index c6a34e3..7a903e9 100644 (file)
@@ -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);
         }
     }
index a7ce251..15fbacf 100644 (file)
@@ -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;
         }
     }
index bd24743..08046c9 100644 (file)
@@ -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;
         }
     }
index ccf4539..60fa169 100644 (file)
@@ -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);
index d935af5..968b204 100644 (file)
@@ -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.
index cb7e3c8..c29a3cb 100644 (file)
@@ -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);
     }
 
     /**
index ec7c197..006d3de 100644 (file)
@@ -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);
index 3052c31..10d69a4 100644 (file)
@@ -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);
     }
 
     /**
index 2dfd1af..b2722fd 100644 (file)
@@ -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);
index 369e617..bb754d9 100644 (file)
@@ -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();
     }
 }
index f6de128..78871c3 100644 (file)
@@ -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);
 
index 564e2d4..3d008e9 100644 (file)
@@ -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())) {
index 5dad2e9..767b1d0 100644 (file)
@@ -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) {
index fb99e26..8bd5756 100644 (file)
@@ -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);
index 99642d1..ad86fb4 100644 (file)
@@ -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) {
index a03b49f..3c43c6e 100644 (file)
@@ -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;
index a3eccce..02a91a7 100644 (file)
@@ -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;
index ffebc40..2e6e96d 100644 (file)
@@ -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);
             }
index 9cdb584..a9418d8 100644 (file)
@@ -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);
         }
     }
index 7277a7d..0580d71 100644 (file)
@@ -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);
         }
     }
index dea839e..7d6c60c 100644 (file)
@@ -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);
         }
     }
index 94063af..3549092 100644 (file)
@@ -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();
         }
index fe3e47b..17955c3 100644 (file)
@@ -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);
         }
     }
 }
index 7dd1ab9..6f04024 100644 (file)
@@ -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);
         }
     }
 
index ca02709..25aa4f8 100644 (file)
@@ -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);
         }
 
index 1c44dd1..55548b9 100644 (file)
@@ -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);
         }
 
index 8c7911b..5a0d11d 100644 (file)
@@ -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;
         }
index 8c135f1..f74751a 100644 (file)
@@ -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);
         }
     }
index ce511be..343ef9a 100644 (file)
@@ -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
index bdbd82d..ff0eef7 100644 (file)
@@ -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);
         }
     }
 
index afd877f..8505127 100644 (file)
@@ -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() {
index a36aa10..8837932 100644 (file)
@@ -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");
index 2367503..b6c6b77 100644 (file)
@@ -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 &lt;sven.van.der.meer@ericsson.com&gt;
  */
 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);
         }
     }
 }
index 2bc70f6..9735293 100644 (file)
@@ -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);
         }
     }
 }
index bfd6573..7c7d7e9 100644 (file)
@@ -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);
         }
     }
 }
index 28337fd..aacc220 100644 (file)
@@ -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();
 
index b529a7e..59d15d1 100644 (file)
@@ -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;
             }
         }