diff options
Diffstat (limited to 'client')
10 files changed, 134 insertions, 104 deletions
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; } } |