aboutsummaryrefslogtreecommitdiffstats
path: root/client/client-monitoring
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@ericsson.com>2018-09-14 16:45:06 +0100
committerliamfallon <liam.fallon@ericsson.com>2018-09-14 16:45:17 +0100
commita65e4772f4557a109917532b2d9c49680ce3bb15 (patch)
tree1669786f0b3ce82e005debc53218825d537841c8 /client/client-monitoring
parent6d72a4a1e5d8678ecd8b093480ea9543089015b0 (diff)
Fix exception not logged or rethrown
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>
Diffstat (limited to 'client/client-monitoring')
-rw-r--r--client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ApexMonitoringRestMain.java23
-rw-r--r--client/client-monitoring/src/main/java/org/onap/policy/apex/client/monitoring/rest/ParameterCheck.java40
2 files changed, 34 insertions, 29 deletions
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;
}
}