diff options
author | liamfallon <liam.fallon@ericsson.com> | 2018-09-13 23:48:50 +0100 |
---|---|---|
committer | liamfallon <liam.fallon@ericsson.com> | 2018-09-13 23:49:32 +0100 |
commit | cd68fc9bae7d6258f77ff59c1431e4f925f61a4c (patch) | |
tree | 53054a7c8e8738644785039c3a200c6b23d4b3ed /client/client-deployment/src/main/java/org | |
parent | 4cfa2e2d98f6877d54da304ef17f096284430908 (diff) |
Address sonar/Checkstyle Issues
Sweep through Apex codebase to fix most ceheckstyle and
straightforward sonar issues.
Issue-ID: POLICY-1034
Change-Id: I149d9a94ad893affc93573e8de5e3304b6bdde2d
Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Diffstat (limited to 'client/client-deployment/src/main/java/org')
5 files changed, 91 insertions, 24 deletions
diff --git a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRest.java b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRest.java index 1fb7a2259..0ebeec446 100644 --- a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRest.java +++ b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRest.java @@ -59,14 +59,14 @@ public class ApexDeploymentRest { // Create a resource configuration that scans for JAX-RS resources and providers // in org.onap.policy.apex.client.deployment.rest package - final ResourceConfig rc = new ResourceConfig().packages(parameters.getRESTPackages()); + final ResourceConfig rc = new ResourceConfig().packages(parameters.getRestPackages()); // Add MultiPartFeature class for jersey-media-multipart rc.register(MultiPartFeature.class); // create and start a new instance of grizzly http server // exposing the Jersey application at BASE_URI - server = GrizzlyHttpServerFactory.createHttpServer(parameters.getBaseURI(), rc); + server = GrizzlyHttpServerFactory.createHttpServer(parameters.getBaseUri(), rc); // Add static content server.getServerConfiguration().addHttpHandler(new org.glassfish.grizzly.http.server.CLStaticHttpHandler( 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 a0e6641db..73374053f 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 @@ -22,12 +22,21 @@ package org.onap.policy.apex.client.deployment.rest; import java.io.PrintStream; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + /** * The main class for ApexDeploymentRest. * * @author Michael Watkins (michael.watkins@ericsson.com) */ public class ApexDeploymentRestMain { + // Logger for this class + private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexDeploymentRestMain.class); + + // Recurring string constants + private static final String REST_ENDPOINT_PREFIX = "Apex Services REST endpoint ("; + // Services state public enum ServicesState { STOPPED, READY, INITIALIZING, RUNNING @@ -54,7 +63,7 @@ public class ApexDeploymentRestMain { final ApexDeploymentRestMain restMain = new ApexDeploymentRestMain(args, System.out); restMain.init(); } catch (final Exception e) { - System.err.println(e.getMessage()); + LOGGER.error("start failed", e); } } @@ -76,7 +85,7 @@ public class ApexDeploymentRestMain { parameters = parser.parse(args); } catch (final ApexDeploymentRestParameterException e) { throw new ApexDeploymentRestParameterException( - "Apex Services REST endpoint (" + this.toString() + ") parameter error, " + e.getMessage() + '\n' + REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, " + e.getMessage() + '\n' + parser.getHelp(ApexDeploymentRestMain.class.getCanonicalName())); } @@ -89,7 +98,7 @@ public class ApexDeploymentRestMain { final String validationMessage = parameters.validate(); if (validationMessage.length() > 0) { throw new ApexDeploymentRestParameterException( - "Apex Services REST endpoint (" + this.toString() + ") parameters invalid, " + validationMessage + REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, " + validationMessage + '\n' + parser.getHelp(ApexDeploymentRestMain.class.getCanonicalName())); } @@ -100,8 +109,8 @@ public class ApexDeploymentRestMain { * Initialize the rest service. */ public void init() { - outStream.println("Apex Services REST endpoint (" + this.toString() + ") starting at " - + parameters.getBaseURI().toString() + " . . ."); + outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at " + + parameters.getBaseUri().toString() + " . . ."); try { state = ServicesState.INITIALIZING; @@ -115,10 +124,10 @@ public class ApexDeploymentRestMain { state = ServicesState.RUNNING; if (parameters.getTimeToLive() == ApexDeploymentRestParameters.INFINITY_TIME_TO_LIVE) { - outStream.println("Apex Services REST endpoint (" + this.toString() + ") started at " - + parameters.getBaseURI().toString()); + outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started at " + + parameters.getBaseUri().toString()); } else { - outStream.println("Apex Services REST endpoint (" + this.toString() + ") started"); + outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started"); } // Find out how long is left to wait @@ -134,7 +143,7 @@ public class ApexDeploymentRestMain { } } catch (final Exception e) { outStream.println( - "Apex Services REST endpoint (" + this.toString() + ") failed at with error: " + e.getMessage()); + REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage()); } finally { if (apexDeploymentRest != null) { apexDeploymentRest.shutdown(); @@ -167,11 +176,11 @@ public class ApexDeploymentRestMain { */ public void shutdown() { if (apexDeploymentRest != null) { - outStream.println("Apex Services REST endpoint (" + this.toString() + ") shutting down"); + outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") shutting down"); apexDeploymentRest.shutdown(); } state = ServicesState.STOPPED; - outStream.println("Apex Services REST endpoint (" + this.toString() + ") shut down"); + outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") shut down"); } /** diff --git a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestParameterParser.java b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestParameterParser.java index 564be435c..7e305788f 100644 --- a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestParameterParser.java +++ b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestParameterParser.java @@ -81,7 +81,7 @@ public class ApexDeploymentRestParameterParser { } try { if (commandLine.hasOption('p')) { - parameters.setRESTPort(((Number) commandLine.getParsedOptionValue("port")).intValue()); + parameters.setRestPort(((Number) commandLine.getParsedOptionValue("port")).intValue()); } } catch (final ParseException e) { throw new ApexDeploymentRestParameterException("error parsing argument \"port\" :" + e.getMessage(), e); diff --git a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestParameters.java b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestParameters.java index af8cc5ab4..cadc3ef4e 100644 --- a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestParameters.java +++ b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestParameters.java @@ -44,6 +44,11 @@ public class ApexDeploymentRestParameters { private int restPort = DEFAULT_REST_PORT; private long timeToLive = INFINITY_TIME_TO_LIVE; + /** + * Validate the parameters. + * + * @return the result of the validation + */ public String validate() { String validationMessage = ""; validationMessage += validatePort(); @@ -52,18 +57,38 @@ public class ApexDeploymentRestParameters { return validationMessage; } - public URI getBaseURI() { + /** + * Gets the base uri. + * + * @return the base uri + */ + public URI getBaseUri() { return URI.create(DEFAULT_SERVER_URI_ROOT + restPort + DEFAULT_REST_PATH); } - public String[] getRESTPackages() { + /** + * Gets the rest packages. + * + * @return the rest packages + */ + public String[] getRestPackages() { return DEFAULT_PACKAGES; } + /** + * Gets the static path. + * + * @return the static path + */ public String getStaticPath() { return DEFAULT_STATIC_PATH; } + /** + * Validate port. + * + * @return the string + */ private String validatePort() { if (restPort < 1024 || restPort > 65535) { return "port must be greater than 1023 and less than 65536\n"; @@ -72,6 +97,11 @@ public class ApexDeploymentRestParameters { } } + /** + * Validate time to live. + * + * @return the string + */ private String validateTimeToLive() { if (timeToLive < -1) { return "time to live must be greater than -1 (set to -1 to wait forever)\n"; @@ -80,34 +110,67 @@ public class ApexDeploymentRestParameters { } } + /** + * Checks if is help set. + * + * @return true, if is help set + */ public boolean isHelpSet() { return helpSet; } + /** + * Sets the help. + * + * @param helpSet the new help + */ public void setHelp(final boolean helpSet) { this.helpSet = helpSet; } - public int getRESTPort() { + /** + * Gets the rest port. + * + * @return the rest port + */ + public int getRestPort() { return restPort; } - public void setRESTPort(final int restPort) { + /** + * Sets the rest port. + * + * @param restPort the new rest port + */ + public void setRestPort(final int restPort) { this.restPort = restPort; } + /** + * Gets the time to live. + * + * @return the time to live + */ public long getTimeToLive() { return timeToLive; } + /** + * Sets the time to live. + * + * @param timeToLive the new time to live + */ public void setTimeToLive(final long timeToLive) { this.timeToLive = timeToLive; } + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ @Override public String toString() { final StringBuilder ret = new StringBuilder(); - ret.append(this.getClass().getSimpleName()).append(": URI=").append(this.getBaseURI()).append(", TTL=") + ret.append(this.getClass().getSimpleName()).append(": URI=").append(this.getBaseUri()).append(", TTL=") .append(this.getTimeToLive()).append("sec"); return ret.toString(); } diff --git a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestResource.java b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestResource.java index 18aae5001..d3a7d654a 100644 --- a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestResource.java +++ b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestResource.java @@ -60,11 +60,6 @@ public class ApexDeploymentRestResource { private static final XLogger LOGGER = XLoggerFactory.getXLogger(ApexDeploymentRestResource.class); /** - * Constructor, a new resource director is created for each request. - */ - public ApexDeploymentRestResource() {} - - /** * Query the engine service for data. * * @param hostName the host name of the engine service to connect to. |