Fix remaining fixable Sonar issues on policy models 16/97116/1
authorliamfallon <liam.fallon@est.tech>
Tue, 15 Oct 2019 11:26:48 +0000 (12:26 +0100)
committerliamfallon <liam.fallon@est.tech>
Tue, 15 Oct 2019 11:26:52 +0000 (12:26 +0100)
This patch fixes the remaining  easy to fix Sonar issues on policy
models. The remaining issues are
- methods that do not follow Java naming conventions and fixing those
  will probably break policies that use those methods
- TODO statements to do with functionality we didn't get done in Dublin
  and will address in Frankfurt

Issue-ID: POLICY-2165
Change-Id: I7f604bc2335388bdc0dd9286ae17a5ab76517665
Signed-off-by: liamfallon <liam.fallon@est.tech>
models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/beans/CdsActionRequest.java
models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java
models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/Util.java

index 8aac67b..45fbbca 100644 (file)
@@ -19,6 +19,8 @@
 package org.onap.policy.controlloop.actor.cds.beans;
 
 import com.google.gson.annotations.SerializedName;
+
+import java.io.Serializable;
 import java.util.Map;
 import lombok.Getter;
 import lombok.Setter;
@@ -30,7 +32,8 @@ import org.slf4j.LoggerFactory;
 
 @Getter
 @Setter
-public class CdsActionRequest {
+public class CdsActionRequest implements Serializable {
+    private static final long serialVersionUID = -4172157702597791493L;
 
     private static final Logger LOGGER = LoggerFactory.getLogger(CdsActionRequest.class);
     private static final Coder CODER = new StandardCoder();
index 6e2494b..d8933c8 100644 (file)
@@ -142,7 +142,7 @@ public final class SoManager {
             final String vfModuleInstanceId,
             final SoRequest request) {
         return executors.submit(new AsyncSoRestCallThread(requestId, callback, serviceInstanceId, vnfInstanceId,
-                vfModuleInstanceId, request, this.url, this.user, this.password));
+                vfModuleInstanceId, request, this));
     }
 
     /**
@@ -173,18 +173,16 @@ public final class SoManager {
                 final SoCallback callback, final String serviceInstanceId,
                 final String vnfInstanceId, final String vfModuleInstanceId,
                 final SoRequest request,
-                final String url,
-                final String user,
-                final String password) {
+                final SoManager callingSoManager) {
             this.requestId = requestId;
             this.callback = callback;
             this.serviceInstanceId = serviceInstanceId;
             this.vnfInstanceId = vnfInstanceId;
             this.vfModuleInstanceId = vfModuleInstanceId;
             this.request = request;
-            this.baseUrl = url;
-            this.user = user;
-            this.password = password;
+            this.baseUrl = callingSoManager.url;
+            this.user = callingSoManager.user;
+            this.password = callingSoManager.password;
         }
 
         /**
index 11efd97..f21fb6f 100644 (file)
 
 package org.onap.policy.simulators;
 
-import java.io.IOException;
 import java.util.Properties;
 import org.onap.policy.common.endpoints.http.server.HttpServletServer;
 import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
 import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
 import org.onap.policy.common.gson.GsonMessageBodyHandler;
+import org.onap.policy.common.parameters.ParameterRuntimeException;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.network.NetworkUtil;
@@ -49,11 +49,12 @@ public class Util {
     public static final int SDNCSIM_SERVER_PORT = 6670;
     public static final int DMAAPSIM_SERVER_PORT = 3904;
 
+    private static final String CANNOT_PROCESS_PARAMETERS = "cannot parse parameters ";
     private static final String CANNOT_CONNECT = "cannot connect to port ";
     private static final String LOCALHOST = "localhost";
 
     private Util() {
-        // Prevent instantiation of thic class
+        // Prevent instantiation of this class
     }
 
     /**
@@ -61,11 +62,10 @@ public class Util {
      *
      * @return the simulator
      * @throws InterruptedException if a thread is interrupted
-     * @throws IOException if an IO errror occurs
      */
     public static HttpServletServer buildAaiSim() throws InterruptedException {
         final HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory()
-                        .build(AAISIM_SERVER_NAME, LOCALHOST, AAISIM_SERVER_PORT, "/", false, true);
+                .build(AAISIM_SERVER_NAME, LOCALHOST, AAISIM_SERVER_PORT, "/", false, true);
         testServer.addServletClass("/*", AaiSimulatorJaxRs.class.getName());
         testServer.waitedStart(5000);
         if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
@@ -79,11 +79,10 @@ public class Util {
      *
      * @return the simulator
      * @throws InterruptedException if a thread is interrupted
-     * @throws IOException if an IO errror occurs
      */
     public static HttpServletServer buildSdncSim() throws InterruptedException {
         final HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory()
-                        .build(SDNCSIM_SERVER_NAME, LOCALHOST, SDNCSIM_SERVER_PORT, "/", false, true);
+                .build(SDNCSIM_SERVER_NAME, LOCALHOST, SDNCSIM_SERVER_PORT, "/", false, true);
         testServer.addServletClass("/*", SdncSimulatorJaxRs.class.getName());
         testServer.waitedStart(5000);
         if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
@@ -98,11 +97,10 @@ public class Util {
      *
      * @return the simulator
      * @throws InterruptedException if a thread is interrupted
-     * @throws IOException if an IO errror occurs
      */
     public static HttpServletServer buildSoSim() throws InterruptedException {
         final HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory()
-                        .build(SOSIM_SERVER_NAME, LOCALHOST, SOSIM_SERVER_PORT, "/", false, true);
+                .build(SOSIM_SERVER_NAME, LOCALHOST, SOSIM_SERVER_PORT, "/", false, true);
         testServer.addServletClass("/*", SoSimulatorJaxRs.class.getName());
         testServer.waitedStart(5000);
         if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
@@ -116,11 +114,10 @@ public class Util {
      *
      * @return the simulator
      * @throws InterruptedException if a thread is interrupted
-     * @throws IOException if an IO errror occurs
      */
     public static HttpServletServer buildVfcSim() throws InterruptedException {
         final HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory()
-                        .build(VFCSIM_SERVER_NAME, LOCALHOST, VFCSIM_SERVER_PORT, "/", false, true);
+                .build(VFCSIM_SERVER_NAME, LOCALHOST, VFCSIM_SERVER_PORT, "/", false, true);
         testServer.addServletClass("/*", VfcSimulatorJaxRs.class.getName());
         testServer.waitedStart(5000);
         if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
@@ -134,11 +131,10 @@ public class Util {
      *
      * @return the simulator
      * @throws InterruptedException if a thread is interrupted
-     * @throws IOException if an IO errror occurs
      */
     public static HttpServletServer buildGuardSim() throws InterruptedException {
         HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory().build(GUARDSIM_SERVER_NAME,
-                        LOCALHOST, GUARDSIM_SERVER_PORT, "/", false, true);
+                LOCALHOST, GUARDSIM_SERVER_PORT, "/", false, true);
         testServer.setSerializationProvider(GsonMessageBodyHandler.class.getName());
         testServer.addServletClass("/*", GuardSimulatorJaxRs.class.getName());
         testServer.waitedStart(5000);
@@ -153,21 +149,25 @@ public class Util {
      *
      * @return the simulator
      * @throws InterruptedException if a thread is interrupted
-     * @throws IOException if an IO errror occurs
-     * @throws CoderException if the server parameters cannot be loaded
      */
-    public static HttpServletServer buildDmaapSim() throws InterruptedException, CoderException {
+    public static HttpServletServer buildDmaapSim() throws InterruptedException {
         String json = ResourceUtils.getResourceAsString("org/onap/policy/simulators/dmaap/DmaapParameters.json");
-        DmaapSimParameterGroup params = new StandardCoder().decode(json, DmaapSimParameterGroup.class);
+        DmaapSimParameterGroup params = null;
+        try {
+            params = new StandardCoder().decode(json, DmaapSimParameterGroup.class);
+        } catch (CoderException ce) {
+            throw new ParameterRuntimeException(
+                    CANNOT_PROCESS_PARAMETERS + "org/onap/policy/simulators/dmaap/DmaapParameters.json", ce);
+        }
 
         DmaapSimProvider.setInstance(new DmaapSimProvider(params));
 
         Properties props = DmaapSimRestServer.getServerProperties(params.getRestServerParameters());
 
         final String svcpfx = PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "."
-                        + params.getRestServerParameters().getName();
+                + params.getRestServerParameters().getName();
         props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX,
-                        Integer.toString(DMAAPSIM_SERVER_PORT));
+                Integer.toString(DMAAPSIM_SERVER_PORT));
         props.setProperty(svcpfx + PolicyEndPointProperties.PROPERTY_MANAGED_SUFFIX, "true");
 
         HttpServletServer testServer = HttpServletServerFactoryInstance.getServerFactory().build(props).get(0);