From 4cfa2e2d98f6877d54da304ef17f096284430908 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Thu, 13 Sep 2018 15:25:32 +0100 Subject: Sonar/Checkstyle in service/plugins Sonar and Checkstyle changes in plugins and services, and knock on changes Issue-ID: POLICY-1034 Change-Id: Iff7df74e54fce2c661dcc2fae75ae93d4cacfe5b Signed-off-by: liamfallon --- .../carrier/restserver/ApexRestServerConsumer.java | 28 +++-- .../carrier/restserver/ApexRestServerProducer.java | 18 +-- .../RESTServerCarrierTechnologyParameters.java | 136 --------------------- .../RestServerCarrierTechnologyParameters.java | 136 +++++++++++++++++++++ .../carrier/restserver/RestServerEndpoint.java | 20 +-- 5 files changed, 172 insertions(+), 166 deletions(-) delete mode 100644 plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RESTServerCarrierTechnologyParameters.java create mode 100644 plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParameters.java (limited to 'plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver') diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumer.java index 8cf0c8f9c..94063af20 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumer.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumer.java @@ -56,9 +56,6 @@ public class ApexRestServerConsumer implements ApexEventConsumer, Runnable { // The amount of time to wait in milliseconds between checks that the consumer thread has stopped private static final long REST_SERVER_CONSUMER_WAIT_SLEEP_TIME = 50; - // The REST parameters read from the parameter service - private RESTServerCarrierTechnologyParameters restConsumerProperties; - // The event receiver that will receive events from this consumer private ApexEventReceiver eventReceiver; @@ -84,7 +81,7 @@ public class ApexRestServerConsumer implements ApexEventConsumer, Runnable { * * @return the next candidate value for a Execution ID */ - private static synchronized long getNextExecutionID() { + private static synchronized long getNextExecutionId() { return nextExecutionID.getAndIncrement(); } @@ -102,14 +99,16 @@ public class ApexRestServerConsumer implements ApexEventConsumer, Runnable { this.name = consumerName; // Check and get the REST Properties - if (!(consumerParameters.getCarrierTechnologyParameters() instanceof RESTServerCarrierTechnologyParameters)) { + if (!(consumerParameters.getCarrierTechnologyParameters() instanceof RestServerCarrierTechnologyParameters)) { final String errorMessage = "specified consumer properties are not applicable to REST Server consumer (" + this.name + ")"; LOGGER.warn(errorMessage); throw new ApexEventException(errorMessage); } - restConsumerProperties = - (RESTServerCarrierTechnologyParameters) consumerParameters.getCarrierTechnologyParameters(); + + // The REST parameters read from the parameter service + RestServerCarrierTechnologyParameters restConsumerProperties = + (RestServerCarrierTechnologyParameters) consumerParameters.getCarrierTechnologyParameters(); // Check if we are in synchronous mode if (!consumerParameters.isPeeredMode(EventHandlerPeeredMode.SYNCHRONOUS)) { @@ -131,12 +130,12 @@ public class ApexRestServerConsumer implements ApexEventConsumer, Runnable { } // Compose the URI for the standalone server - final String baseURI = String.format(BASE_URI_TEMPLATE, restConsumerProperties.getHost(), + final String baseUrl = String.format(BASE_URI_TEMPLATE, restConsumerProperties.getHost(), restConsumerProperties.getPort()); // Instantiate the standalone server final ResourceConfig rc = new ResourceConfig(RestServerEndpoint.class, AccessControlFilter.class); - server = GrizzlyHttpServerFactory.createHttpServer(URI.create(baseURI), rc); + server = GrizzlyHttpServerFactory.createHttpServer(URI.create(baseUrl), rc); while (!server.isStarted()) { ThreadUtilities.sleep(REST_SERVER_CONSUMER_WAIT_SLEEP_TIME); @@ -201,10 +200,11 @@ public class ApexRestServerConsumer implements ApexEventConsumer, Runnable { */ public Response receiveEvent(final String event) { // Get an execution ID for the event - final long executionId = getNextExecutionID(); + final long executionId = getNextExecutionId(); if (LOGGER.isDebugEnabled()) { - LOGGER.debug(name + ": sending event " + name + '_' + executionId + " to Apex, event=" + event); + String message = name + ": sending event " + name + '_' + executionId + " to Apex, event=" + event; + LOGGER.debug(message); } try { @@ -222,7 +222,8 @@ public class ApexRestServerConsumer implements ApexEventConsumer, Runnable { // Wait until the event is in the cache of events sent to apex do { ThreadUtilities.sleep(REST_SERVER_CONSUMER_WAIT_SLEEP_TIME); - } while (!synchronousEventCache.existsEventToApex(executionId)); + } + while (!synchronousEventCache.existsEventToApex(executionId)); // Now wait for the reply or for the event to time put do { @@ -238,7 +239,8 @@ public class ApexRestServerConsumer implements ApexEventConsumer, Runnable { // Return the event as a response to the call return Response.status(Response.Status.OK.getStatusCode()).entity(responseEvent.toString()).build(); } - } while (synchronousEventCache.existsEventToApex(executionId)); + } + while (synchronousEventCache.existsEventToApex(executionId)); // The event timed out final String errorMessage = "processing of event on event consumer " + name + " timed out, event=" + event; diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerProducer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerProducer.java index e51482ce4..cacdb3408 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerProducer.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerProducer.java @@ -41,9 +41,6 @@ import org.slf4j.LoggerFactory; public class ApexRestServerProducer implements ApexEventProducer { private static final Logger LOGGER = LoggerFactory.getLogger(ApexRestServerProducer.class); - // The REST carrier properties - private RESTServerCarrierTechnologyParameters restProducerProperties; - // The name for this producer private String name = null; @@ -62,14 +59,16 @@ public class ApexRestServerProducer implements ApexEventProducer { this.name = producerName; // Check and get the REST Properties - if (!(producerParameters.getCarrierTechnologyParameters() instanceof RESTServerCarrierTechnologyParameters)) { + if (!(producerParameters.getCarrierTechnologyParameters() instanceof RestServerCarrierTechnologyParameters)) { final String errorMessage = "specified producer properties are not applicable to REST Server producer (" + this.name + ")"; LOGGER.warn(errorMessage); throw new ApexEventException(errorMessage); } - restProducerProperties = - (RESTServerCarrierTechnologyParameters) producerParameters.getCarrierTechnologyParameters(); + + // The REST carrier properties + RestServerCarrierTechnologyParameters restProducerProperties = + (RestServerCarrierTechnologyParameters) producerParameters.getCarrierTechnologyParameters(); // Check if host and port are defined if (restProducerProperties.getHost() != null || restProducerProperties.getPort() != -1 @@ -131,7 +130,8 @@ public class ApexRestServerProducer implements ApexEventProducer { @Override public void sendEvent(final long executionId, final String eventName, final Object event) { if (LOGGER.isDebugEnabled()) { - LOGGER.debug(name + ": event " + executionId + ':' + eventName + " recevied from Apex, event=" + event); + String message = name + ": event " + executionId + ':' + eventName + " recevied from Apex, event=" + event; + LOGGER.debug(message); } // If we are not synchronized, then exit @@ -163,5 +163,7 @@ public class ApexRestServerProducer implements ApexEventProducer { * @see org.onap.policy.apex.service.engine.event.ApexEventProducer#stop() */ @Override - public void stop() {} + public void stop() { + // Implementation not required on this class + } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RESTServerCarrierTechnologyParameters.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RESTServerCarrierTechnologyParameters.java deleted file mode 100644 index cd7f388f2..000000000 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RESTServerCarrierTechnologyParameters.java +++ /dev/null @@ -1,136 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.plugins.event.carrier.restserver; - -import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters; -import org.onap.policy.common.parameters.GroupValidationResult; -import org.onap.policy.common.parameters.ValidationStatus; - -/** - * Apex parameters for REST as an event carrier technology with Apex as a REST client. - * - * The parameters for this plugin are: - *
    - *
  1. standalone: A flag indicating if APEX should start a standalone HTTP server to process REST requests (true) or - * whether it should use an underlying servlet infrastructure such as Apache Tomcat (False). This parameter is legal - * only on REST server event inputs. - *
  2. host: The host name to use when setting up a standalone HTTP server. This parameter is legal only on REST server - * event inputs in standalone mode. - *
  3. port: The port to use when setting up a standalone HTTP server. This parameter is legal only on REST server event - * inputs in standalone mode. - *
- * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class RESTServerCarrierTechnologyParameters extends CarrierTechnologyParameters { - // @formatter:off - private static final int MIN_USER_PORT = 1024; - private static final int MAX_USER_PORT = 65535; - - /** The label of this carrier technology. */ - public static final String RESTSERVER_CARRIER_TECHNOLOGY_LABEL = "RESTSERVER"; - - /** The producer plugin class for the REST carrier technology. */ - public static final String RESTSERVER_EVENT_PRODUCER_PLUGIN_CLASS = ApexRestServerProducer.class.getCanonicalName(); - - /** The consumer plugin class for the REST carrier technology. */ - public static final String RESTSERVER_EVENT_CONSUMER_PLUGIN_CLASS = ApexRestServerConsumer.class.getCanonicalName(); - - // REST server parameters - private boolean standalone = false; - private String host = null; - private int port = -1; - // @formatter:on - - /** - * Constructor to create a REST carrier technology parameters instance and register the instance with the parameter - * service. - */ - public RESTServerCarrierTechnologyParameters() { - super(); - - // Set the carrier technology properties for the web socket carrier technology - this.setLabel(RESTSERVER_CARRIER_TECHNOLOGY_LABEL); - this.setEventProducerPluginClass(RESTSERVER_EVENT_PRODUCER_PLUGIN_CLASS); - this.setEventConsumerPluginClass(RESTSERVER_EVENT_CONSUMER_PLUGIN_CLASS); - } - - /** - * Check if the REST server is running in standalone mode or is using an underlying servlet infrastructure to manage - * requests. - * - * @return true if in standalone mode - */ - public boolean isStandalone() { - return standalone; - } - - /** - * Gets the host. - * - * @return the host - */ - public String getHost() { - return host; - } - - /** - * Gets the port. - * - * @return the port - */ - public int getPort() { - return port; - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.apps.uservice.parameters.ApexParameterValidator#validate() - */ - @Override - public GroupValidationResult validate() { - final GroupValidationResult result = super.validate(); - - // Check if host is defined, it is only defined on REST server consumers - if (standalone) { - if (host != null && host.trim().length() == 0) { - result.setResult("host", ValidationStatus.INVALID, - "host not specified, host must be specified as a string"); - } - - // Check if port is defined, it is only defined on REST server consumers - if (port != -1 && port < MIN_USER_PORT || port > MAX_USER_PORT) { - result.setResult("port", ValidationStatus.INVALID, - "[" + port + "] invalid, must be specified as 1024 <= port <= 65535"); - } - } else { - if (host != null) { - result.setResult("host", ValidationStatus.INVALID, "host is specified only in standalone mode"); - } - if (port != -1) { - result.setResult("port", ValidationStatus.INVALID, "port is specified only in standalone mode"); - } - } - - return result; - } -} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParameters.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParameters.java new file mode 100644 index 000000000..76ec577b8 --- /dev/null +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParameters.java @@ -0,0 +1,136 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.event.carrier.restserver; + +import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters; +import org.onap.policy.common.parameters.GroupValidationResult; +import org.onap.policy.common.parameters.ValidationStatus; + +/** + * Apex parameters for REST as an event carrier technology with Apex as a REST client. + * + *

The parameters for this plugin are: + *

    + *
  1. standalone: A flag indicating if APEX should start a standalone HTTP server to process REST requests (true) or + * whether it should use an underlying servlet infrastructure such as Apache Tomcat (False). This parameter is legal + * only on REST server event inputs. + *
  2. host: The host name to use when setting up a standalone HTTP server. This parameter is legal only on REST server + * event inputs in standalone mode. + *
  3. port: The port to use when setting up a standalone HTTP server. This parameter is legal only on REST server event + * inputs in standalone mode. + *
+ * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class RestServerCarrierTechnologyParameters extends CarrierTechnologyParameters { + // @formatter:off + private static final int MIN_USER_PORT = 1024; + private static final int MAX_USER_PORT = 65535; + + /** The label of this carrier technology. */ + public static final String RESTSERVER_CARRIER_TECHNOLOGY_LABEL = "RESTSERVER"; + + /** The producer plugin class for the REST carrier technology. */ + public static final String RESTSERVER_EVENT_PRODUCER_PLUGIN_CLASS = ApexRestServerProducer.class.getCanonicalName(); + + /** The consumer plugin class for the REST carrier technology. */ + public static final String RESTSERVER_EVENT_CONSUMER_PLUGIN_CLASS = ApexRestServerConsumer.class.getCanonicalName(); + + // REST server parameters + private boolean standalone = false; + private String host = null; + private int port = -1; + // @formatter:on + + /** + * Constructor to create a REST carrier technology parameters instance and register the instance with the parameter + * service. + */ + public RestServerCarrierTechnologyParameters() { + super(); + + // Set the carrier technology properties for the web socket carrier technology + this.setLabel(RESTSERVER_CARRIER_TECHNOLOGY_LABEL); + this.setEventProducerPluginClass(RESTSERVER_EVENT_PRODUCER_PLUGIN_CLASS); + this.setEventConsumerPluginClass(RESTSERVER_EVENT_CONSUMER_PLUGIN_CLASS); + } + + /** + * Check if the REST server is running in standalone mode or is using an underlying servlet infrastructure to manage + * requests. + * + * @return true if in standalone mode + */ + public boolean isStandalone() { + return standalone; + } + + /** + * Gets the host. + * + * @return the host + */ + public String getHost() { + return host; + } + + /** + * Gets the port. + * + * @return the port + */ + public int getPort() { + return port; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.apps.uservice.parameters.ApexParameterValidator#validate() + */ + @Override + public GroupValidationResult validate() { + final GroupValidationResult result = super.validate(); + + // Check if host is defined, it is only defined on REST server consumers + if (standalone) { + if (host != null && host.trim().length() == 0) { + result.setResult("host", ValidationStatus.INVALID, + "host not specified, host must be specified as a string"); + } + + // Check if port is defined, it is only defined on REST server consumers + if (port != -1 && port < MIN_USER_PORT || port > MAX_USER_PORT) { + result.setResult("port", ValidationStatus.INVALID, + "[" + port + "] invalid, must be specified as 1024 <= port <= 65535"); + } + } else { + if (host != null) { + result.setResult("host", ValidationStatus.INVALID, "host is specified only in standalone mode"); + } + if (port != -1) { + result.setResult("port", ValidationStatus.INVALID, "port is specified only in standalone mode"); + } + } + + return result; + } +} diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerEndpoint.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerEndpoint.java index beee10fd0..f8524fcfd 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerEndpoint.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/main/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerEndpoint.java @@ -57,21 +57,21 @@ public class RestServerEndpoint { // This map is used to hold all the REST server event inputs. This is used to determine which consumer to send input // events to private static Map consumerMap = - new LinkedHashMap(); + new LinkedHashMap<>(); // The ID of this event input. This gets injected from the URL. @PathParam("eventInput") - private String eventInputID = null; + private String eventInputId = null; /** * Register an Apex consumer with the REST server end point. * - * @param consumerEventInputID The event input ID that indicates this consumer shoud be used + * @param consumerEventInputId The event input ID that indicates this consumer shoud be used * @param consumer The consumer to register */ - public static void registerApexRestServerConsumer(final String consumerEventInputID, + public static void registerApexRestServerConsumer(final String consumerEventInputId, final ApexRestServerConsumer consumer) { - consumerMap.put(consumerEventInputID, consumer); + consumerMap.put(consumerEventInputId, consumer); } /** @@ -102,7 +102,8 @@ public class RestServerEndpoint { postEventMessagesReceived++; if (LOGGER.isDebugEnabled()) { - LOGGER.debug("event input " + eventInputID + ", received POST of event \"" + jsonString + "\""); + String message = "event input " + eventInputId + ", received POST of event \"" + jsonString + "\""; + LOGGER.debug(message); } // Common handler method for POST and PUT requests @@ -121,7 +122,8 @@ public class RestServerEndpoint { putEventMessagesReceived++; if (LOGGER.isDebugEnabled()) { - LOGGER.debug("event input \"" + eventInputID + "\", received PUT of event \"" + jsonString + "\""); + String message = "event input \"" + eventInputId + "\", received PUT of event \"" + jsonString + "\""; + LOGGER.debug(message); } // Common handler method for POST and PUT requests @@ -136,10 +138,10 @@ public class RestServerEndpoint { */ private Response handleEvent(final String jsonString) { // Find the correct consumer for this REST message - final ApexRestServerConsumer eventConsumer = consumerMap.get(eventInputID); + final ApexRestServerConsumer eventConsumer = consumerMap.get(eventInputId); if (eventConsumer == null) { final String errorMessage = - "event input " + eventInputID + " is not defined in the Apex configuration file"; + "event input " + eventInputId + " is not defined in the Apex configuration file"; LOGGER.warn(errorMessage); return Response.status(Response.Status.BAD_REQUEST.getStatusCode()) .entity("{'errorMessage', '" + errorMessage + "'}").build(); -- cgit 1.2.3-korg