Fix more sonar issues 77/69377/3
authorPamela Dragosh <pdragosh@research.att.com>
Thu, 27 Sep 2018 16:28:19 +0000 (12:28 -0400)
committerPamela Dragosh <pdragosh@research.att.com>
Thu, 27 Sep 2018 20:59:41 +0000 (16:59 -0400)
Most of these are minor issues along with a few others.
They have been bugging me so I thought I would get them
done. Some also do not show up on sonarlint.

Issue-ID: POLICY-1129
Change-Id: I31f2765f6babdfa80b23f0589daacc98da8d2002
Signed-off-by: Pamela Dragosh <pdragosh@research.att.com>
26 files changed:
controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
controlloop/common/feature-controlloop-trans/src/main/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetrics.java
controlloop/common/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java
controlloop/common/guard/src/main/java/org/onap/policy/guard/PipEngineGetHistory.java
controlloop/common/guard/src/main/java/org/onap/policy/guard/Util.java
controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/AaiNqResponseWrapper.java
controlloop/common/model-impl/aai/src/main/java/org/onap/policy/aai/util/Serialization.java
controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/util/Serialization.java
controlloop/common/model-impl/appclcm/src/main/java/org/onap/policy/appclcm/util/Serialization.java
controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopEvent.java
controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/PhysicalControlLoopNotification.java
controlloop/common/model-impl/events/src/main/java/org/onap/policy/controlloop/util/Serialization.java
controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/HttpDeleteWithBody.java
controlloop/common/model-impl/sdnr/src/main/java/org/onap/policy/sdnr/util/Serialization.java
controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/util/Serialization.java
controlloop/common/policy-yaml/checkstyle-suppressions.xml
controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/compiler/ControlLoopCompiler.java
controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Policy.java
controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/Target.java
controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/builder/BuilderException.java
controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/Constraint.java
controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/GuardPolicy.java
controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/MatchParameters.java
controlloop/common/policy-yaml/src/main/java/org/onap/policy/controlloop/policy/guard/builder/impl/ControlLoopGuardBuilderImpl.java
controlloop/common/simulators/src/main/java/org/onap/policy/simulators/AaiSimulatorJaxRs.java
controlloop/common/simulators/src/main/java/org/onap/policy/simulators/Util.java

index c5344e3..0b2c14e 100644 (file)
@@ -64,14 +64,6 @@ public class ControlLoopOperationManager implements Serializable {
     private static final String GENERIC_VNF_VNF_NAME = "generic-vnf.vnf-name";
     private static final String GENERIC_VNF_VNF_ID = "generic-vnf.vnf-id";
 
-    @Override
-    public String toString() {
-        return "ControlLoopOperationManager [onset=" + (onset != null ? onset.getRequestId() : "null") + ", policy="
-                + (policy != null ? policy.getId() : "null") + ", attempts=" + attempts + ", policyResult="
-                + policyResult + ", currentOperation=" + currentOperation + ", operationHistory=" + operationHistory
-                + "]";
-    }
-
     //
     // These properties are not changeable, but accessible
     // for Drools Rule statements.
@@ -88,6 +80,51 @@ public class ControlLoopOperationManager implements Serializable {
     private PolicyResult policyResult = null;
     private ControlLoopEventManager eventManager = null;
     private String targetEntity;
+    private String guardApprovalStatus = "NONE";// "NONE", "PERMIT", "DENY"
+    private transient Object operationRequest;
+
+    /**
+     * Construct an instance.
+     * 
+     * @param onset the onset event
+     * @param policy the policy
+     * @param em the event manager
+     * @throws ControlLoopException if an error occurs
+     * @throws AaiException if an error occurs retrieving information from A&AI
+     */
+    public ControlLoopOperationManager(ControlLoopEvent onset, Policy policy, ControlLoopEventManager em)
+            throws ControlLoopException, AaiException {
+        this.onset = onset;
+        this.policy = policy;
+        this.guardApprovalStatus = "NONE";
+        this.eventManager = em;
+        this.targetEntity = getTarget(policy);
+
+        //
+        // Let's make a sanity check
+        //
+        switch (policy.getActor()) {
+            case "APPC":
+                if ("ModifyConfig".equalsIgnoreCase(policy.getRecipe())) {
+                    /*
+                     * The target vnf-id may not be the same as the source vnf-id specified in the
+                     * yaml, the target vnf-id is retrieved by a named query to A&AI.
+                     */
+                    String targetVnf = AppcLcmActorServiceProvider.vnfNamedQuery(policy.getTarget().getResourceID(),
+                            this.targetEntity);
+                    this.targetEntity = targetVnf;
+                }
+                break;
+            case "SO":
+                break;
+            case "SDNR":
+                break;
+            case "VFC":
+                break;
+            default:
+                throw new ControlLoopException("ControlLoopEventManager: policy has an unknown actor.");
+        }
+    }
 
     public ControlLoopEventManager getEventManager() {
         return eventManager;
@@ -101,6 +138,14 @@ public class ControlLoopOperationManager implements Serializable {
         return this.targetEntity;
     }
 
+    @Override
+    public String toString() {
+        return "ControlLoopOperationManager [onset=" + (onset != null ? onset.getRequestId() : "null") + ", policy="
+                + (policy != null ? policy.getId() : "null") + ", attempts=" + attempts + ", policyResult="
+                + policyResult + ", currentOperation=" + currentOperation + ", operationHistory=" + operationHistory
+                + "]";
+    }
+
     //
     // Internal class used for tracking
     //
@@ -118,9 +163,6 @@ public class ControlLoopOperationManager implements Serializable {
         }
     }
 
-    private String guardApprovalStatus = "NONE";// "NONE", "PERMIT", "DENY"
-    private transient Object operationRequest;
-
     public Object getOperationRequest() {
         return operationRequest;
     }
@@ -184,49 +226,6 @@ public class ControlLoopOperationManager implements Serializable {
         }
     }
 
-    /**
-     * Construct an instance.
-     * 
-     * @param onset the onset event
-     * @param policy the policy
-     * @param em the event manager
-     * @throws ControlLoopException if an error occurs
-     * @throws AaiException if an error occurs retrieving information from A&AI
-     */
-    public ControlLoopOperationManager(ControlLoopEvent onset, Policy policy, ControlLoopEventManager em)
-            throws ControlLoopException, AaiException {
-        this.onset = onset;
-        this.policy = policy;
-        this.guardApprovalStatus = "NONE";
-        this.eventManager = em;
-        this.targetEntity = getTarget(policy);
-
-        //
-        // Let's make a sanity check
-        //
-        switch (policy.getActor()) {
-            case "APPC":
-                if ("ModifyConfig".equalsIgnoreCase(policy.getRecipe())) {
-                    /*
-                     * The target vnf-id may not be the same as the source vnf-id specified in the
-                     * yaml, the target vnf-id is retrieved by a named query to A&AI.
-                     */
-                    String targetVnf = AppcLcmActorServiceProvider.vnfNamedQuery(policy.getTarget().getResourceID(),
-                            this.targetEntity);
-                    this.targetEntity = targetVnf;
-                }
-                break;
-            case "SO":
-                break;
-            case "SDNR":
-                break;
-            case "VFC":
-                break;
-            default:
-                throw new ControlLoopException("ControlLoopEventManager: policy has an unknown actor.");
-        }
-    }
-
     /**
      * Start an operation.
      * 
@@ -548,7 +547,7 @@ public class ControlLoopOperationManager implements Serializable {
      * @return The result of the response handling
      */
     private PolicyResult onResponse(VFCResponse vfcResponse) {
-        if (vfcResponse.getResponseDescriptor().getStatus().equalsIgnoreCase("finished")) {
+        if ("finished".equalsIgnoreCase(vfcResponse.getResponseDescriptor().getStatus())) {
             //
             // Consider it as success
             //
@@ -797,8 +796,6 @@ public class ControlLoopOperationManager implements Serializable {
                 throw new ControlLoopException("current oepration has failed after " + this.attempts + " retries");
             }
         }
-
-        return;
     }
 
     private boolean isRetriesMaxedOut() {
@@ -833,7 +830,7 @@ public class ControlLoopOperationManager implements Serializable {
 
 
         String opsHistPu = System.getProperty("OperationsHistoryPU");
-        if (opsHistPu == null || !opsHistPu.equals("TestOperationsHistoryPU")) {
+        if (!"TestOperationsHistoryPU".equals(opsHistPu)) {
             opsHistPu = "OperationsHistoryPU";
         } else {
             props.clear();
@@ -914,7 +911,7 @@ public class ControlLoopOperationManager implements Serializable {
      * @param outcome the abatement outcome
      */
     public void commitAbatement(String message, String outcome) {
-        logger.info("commitAbatement: " + message + ", " + outcome);
+        logger.info("commitAbatement: {}. {}", message, outcome);
         
         if (this.currentOperation == null) {
             try {
index 790d434..a1c587b 100644 (file)
@@ -313,8 +313,7 @@ class CacheBasedControlLoopMetricsManager implements ControlLoopMetrics {
     }
 
     protected void evicted(VirtualControlLoopNotification notification) {
-        // transaction(notification, ZonedDateTime.now());
-        MDCTransaction trans = MDCTransaction
+        MDCTransaction
                 .newTransaction(notification.getRequestId().toString(), notification.getFrom())
                 .setServiceName(notification.getClosedLoopControlName()).setTargetEntity(notification.getTarget())
                 .setStartTime(notification.getNotificationTime().toInstant()).setEndTime(Instant.now())
@@ -439,7 +438,7 @@ class CacheBasedControlLoopMetricsManager implements ControlLoopMetrics {
             default:
                 /* unexpected */
                 logger.warn("unexpected notification type {} in notification {}",
-                        notification.getNotification().toString(), notification);
+                        notification.getNotification(), notification);
                 break;
         }
 
@@ -448,7 +447,8 @@ class CacheBasedControlLoopMetricsManager implements ControlLoopMetrics {
 
     @Override
     public String toString() {
-        final StringBuffer sb = new StringBuffer("CacheBasedControlLoopMetricsManager{");
+        final StringBuilder sb = new StringBuilder();
+        sb.append("CacheBasedControlLoopMetricsManager{");
         sb.append("cacheSize=").append(cacheSize);
         sb.append(", transactionTimeout=").append(transactionTimeout);
         sb.append('}');
index 59a1816..fefea39 100644 (file)
@@ -151,7 +151,7 @@ public class CallGuardTask implements Runnable {
         //
         // Create an artificial Guard response in case we didn't get a clear Permit or Deny
         //
-        if (guardResponse.getResult().equals("Indeterminate")) {
+        if ("Indeterminate".equals(guardResponse.getResult())) {
             guardResponse.setOperation(recipe);
             guardResponse.setRequestID(UUID.fromString(requestId));
         }
index 2a1ef2f..37c4e4c 100644 (file)
@@ -122,7 +122,7 @@ public class PipEngineGetHistory extends StdConfigurableEngine {
             // Notice, we are checking here for the base issuer prefix.
             if (!string.contains(this.getIssuer())) {
                 logger.debug("Requested issuer '{}' does not match {}", string, getIssuer());
-                logger.debug("FeqLimiter PIP - Issuer {}  does not match with: ", string, this.getIssuer());
+                logger.debug("FeqLimiter PIP - Issuer {}  does not match with: {}", string, this.getIssuer());
                 return StdPIPResponse.PIP_RESPONSE_EMPTY;
             }
         }
@@ -184,14 +184,14 @@ public class PipEngineGetHistory extends StdConfigurableEngine {
         if (pipResponse.getStatus() != null && !pipResponse.getStatus().isOk()) {
             if (logger.isWarnEnabled()) {
                 logger.warn("PIP response error {}: {}", pipRequest.getAttributeId().stringValue(),
-                        pipResponse.getStatus().toString());
+                        pipResponse.getStatus());
             }
             return null;
         }
         if (pipResponse.getAttributes() != null && pipResponse.getAttributes().isEmpty()) {
             if (logger.isWarnEnabled()) {
                 logger.warn("No attributes in POP response {}: {}", pipRequest.getAttributeId().stringValue(),
-                        pipResponse.getStatus().toString());
+                        pipResponse.getStatus());
             }
             return null;
         }
@@ -309,7 +309,7 @@ public class PipEngineGetHistory extends StdConfigurableEngine {
 
         EntityManager em = null;
         String opsHistPu = System.getProperty("OperationsHistoryPU");
-        if (opsHistPu == null || !opsHistPu.equals("TestOperationsHistoryPU")) {
+        if (!"TestOperationsHistoryPU".equals(opsHistPu)) {
             opsHistPu = "OperationsHistoryPU";
         } else {
             props.clear();
@@ -328,7 +328,7 @@ public class PipEngineGetHistory extends StdConfigurableEngine {
         try {
             diff = now - getMsFromTimeWindow(timeWindow);
         } catch (Exception ex) {
-            logger.error("PIP thread got Exception " + ex);
+            logger.error("PIP thread got Exception ", ex);
             return -1;
         }
 
index 46a815c..d159bd4 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * guard
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. 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.
@@ -36,10 +36,6 @@ import org.yaml.snakeyaml.Yaml;
 import org.yaml.snakeyaml.constructor.Constructor;
 
 public final class Util {
-    private Util() {
-        // This static class cannot be instantiated
-    }
-
     /*
      * Keys for guard properties
      */
@@ -87,6 +83,10 @@ public final class Util {
         }
     }
 
+    private Util() {
+        // This static class cannot be instantiated
+    }
+
     /**
      * Load a Yaml file.
      * 
index eb4271b..038e3f8 100644 (file)
@@ -133,7 +133,7 @@ public class AaiNqResponseWrapper implements Serializable {
          * Walk the items looking for VF modules, allocating the list only when an item is
          * found.
          */
-        List<AaiNqInventoryResponseItem> vfModuleItems = new ArrayList<>(itemList.size());;
+        List<AaiNqInventoryResponseItem> vfModuleItems = new ArrayList<>(itemList.size());
 
         for (AaiNqInventoryResponseItem inventoryResponseItem : itemList) {
             AaiNqVfModule vfmod = inventoryResponseItem.getVfModule();
index 2c82634..5b504c0 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * aai
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. 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.
@@ -25,9 +25,9 @@ import com.google.gson.GsonBuilder;
 
 public final class Serialization {
 
-    private Serialization() {}
-
     public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
-            // .registerTypeAdapter(AAIQueryParameters.class, new notificationTypeAdapter())
             .create();
+
+    private Serialization() {}
+
 }
index 3e16f29..d8a397d 100644 (file)
@@ -40,6 +40,13 @@ import org.slf4j.LoggerFactory;
 public final class Serialization {
     public static final DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx");
 
+    public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
+            .registerTypeAdapter(ZonedDateTime.class, new GsonUtcAdapter())
+            .registerTypeAdapter(Instant.class, new GsonInstantAdapter())
+            // .registerTypeAdapter(CommonHeader1607.class, new gsonCommonHeaderInstance())
+            // .registerTypeAdapter(ResponseStatus1607.class, new gsonResponseStatus())
+            .create();
+
     private Serialization() {}
 
     public static class GsonUtcAdapter implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime> {
@@ -75,11 +82,4 @@ public final class Serialization {
 
     }
 
-    public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
-            .registerTypeAdapter(ZonedDateTime.class, new GsonUtcAdapter())
-            .registerTypeAdapter(Instant.class, new GsonInstantAdapter())
-            // .registerTypeAdapter(CommonHeader1607.class, new gsonCommonHeaderInstance())
-            // .registerTypeAdapter(ResponseStatus1607.class, new gsonResponseStatus())
-            .create();
-
 }
index 944d568..ee2d280 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * appc
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. 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.
@@ -37,6 +37,16 @@ import org.onap.policy.appclcm.LcmRequest;
 import org.onap.policy.appclcm.LcmResponse;
 
 public final class Serialization {
+    public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
+            .registerTypeAdapter(Instant.class, new InstantAdapter()).create();
+
+    public static final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
+            .registerTypeAdapter(LcmRequest.class, new RequestAdapter())
+            .registerTypeAdapter(LcmResponse.class, new ResponseAdapter()).create();
+
+    public static final Gson gsonJunit = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
+            .registerTypeAdapter(Instant.class, new InstantJunitAdapter()).create();
+
     private Serialization() {}
 
     public static class RequestAdapter implements JsonSerializer<LcmRequest>, JsonDeserializer<LcmRequest> {
@@ -100,14 +110,4 @@ public final class Serialization {
 
     }
 
-    public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
-            .registerTypeAdapter(Instant.class, new InstantAdapter()).create();
-
-    public static final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
-            .registerTypeAdapter(LcmRequest.class, new RequestAdapter())
-            .registerTypeAdapter(LcmResponse.class, new ResponseAdapter()).create();
-
-    public static final Gson gsonJunit = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
-            .registerTypeAdapter(Instant.class, new InstantJunitAdapter()).create();
-
 }
index 4cae5ca..9cb85ae 100644 (file)
@@ -32,8 +32,5 @@ public class PhysicalControlLoopEvent extends ControlLoopEvent {
      */
     public PhysicalControlLoopEvent(PhysicalControlLoopEvent event) {
         super(event);
-        if (event == null) {
-            return;
-        }
     }
 }
index 5dbc7f4..0b5db3a 100644 (file)
@@ -32,9 +32,6 @@ public class PhysicalControlLoopNotification extends ControlLoopNotification {
      */
     public PhysicalControlLoopNotification(PhysicalControlLoopEvent event) {
         super(event);
-        if (event == null) {
-            return;
-        }
     }
 
 }
index 864b317..4bbab7a 100644 (file)
@@ -40,6 +40,24 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public final class Serialization {
+    public static final Gson gson =
+            new GsonBuilder().disableHtmlEscaping().registerTypeAdapter(ZonedDateTime.class, new GsonUtcAdapter())
+                    .registerTypeAdapter(Instant.class, new GsonInstantAdapter())
+                    .registerTypeAdapter(ControlLoopNotificationType.class, new NotificationTypeAdapter())
+                    .registerTypeAdapter(ControlLoopTargetType.class, new TargetTypeAdapter()).create();
+
+
+    public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
+            .registerTypeAdapter(ZonedDateTime.class, new GsonUtcAdapter())
+            .registerTypeAdapter(Instant.class, new GsonInstantAdapter())
+            .registerTypeAdapter(ControlLoopNotificationType.class, new NotificationTypeAdapter())
+            .registerTypeAdapter(ControlLoopTargetType.class, new TargetTypeAdapter()).create();
+
+    public static final Gson gsonJunit = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
+            .registerTypeAdapter(ZonedDateTime.class, new GsonUtcAdapter())
+            .registerTypeAdapter(Instant.class, new GsonInstantAdapter())
+            .registerTypeAdapter(ControlLoopTargetType.class, new TargetTypeAdapter()).create();
+
     private Serialization() {}
 
     public static class NotificationTypeAdapter
@@ -104,22 +122,4 @@ public final class Serialization {
 
     }
 
-    public static final Gson gson =
-            new GsonBuilder().disableHtmlEscaping().registerTypeAdapter(ZonedDateTime.class, new GsonUtcAdapter())
-                    .registerTypeAdapter(Instant.class, new GsonInstantAdapter())
-                    .registerTypeAdapter(ControlLoopNotificationType.class, new NotificationTypeAdapter())
-                    .registerTypeAdapter(ControlLoopTargetType.class, new TargetTypeAdapter()).create();
-
-
-    public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
-            .registerTypeAdapter(ZonedDateTime.class, new GsonUtcAdapter())
-            .registerTypeAdapter(Instant.class, new GsonInstantAdapter())
-            .registerTypeAdapter(ControlLoopNotificationType.class, new NotificationTypeAdapter())
-            .registerTypeAdapter(ControlLoopTargetType.class, new TargetTypeAdapter()).create();
-
-    public static final Gson gsonJunit = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
-            .registerTypeAdapter(ZonedDateTime.class, new GsonUtcAdapter())
-            .registerTypeAdapter(Instant.class, new GsonInstantAdapter())
-            .registerTypeAdapter(ControlLoopTargetType.class, new TargetTypeAdapter()).create();
-
 }
index dc75334..3e52d4f 100644 (file)
@@ -31,10 +31,6 @@ import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
 public class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase {
     public static final String METHOD_NAME = "DELETE";
 
-    public String getMethod() {
-        return METHOD_NAME;
-    }
-
     public HttpDeleteWithBody(final String uri) {
         super();
         setURI(URI.create(uri));
@@ -48,4 +44,9 @@ public class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase {
     public HttpDeleteWithBody() {
         super();
     }
+
+    public String getMethod() {
+        return METHOD_NAME;
+    }
+
 }
index 0208884..3a116d7 100644 (file)
@@ -3,6 +3,7 @@
  * sdnr
  * ================================================================================
  * Copyright (C) 2018 Wipro Limited Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 AT&T Intellectual Property. 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.
@@ -38,6 +39,16 @@ import org.onap.policy.sdnr.PciResponse;
 
 
 public final class Serialization {
+    public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
+            .registerTypeAdapter(Instant.class, new InstantAdapter()).create();
+
+    public static final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
+            .registerTypeAdapter(PciRequest.class, new RequestAdapter())
+            .registerTypeAdapter(PciResponse.class, new ResponseAdapter()).create();
+
+    public static final Gson gsonJunit = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
+            .registerTypeAdapter(Instant.class, new InstantJunitAdapter()).create();
+
     private Serialization() {}
 
     public static class RequestAdapter implements JsonSerializer<PciRequest>, JsonDeserializer<PciRequest> {
@@ -101,14 +112,4 @@ public final class Serialization {
 
     }
 
-    public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
-            .registerTypeAdapter(Instant.class, new InstantAdapter()).create();
-
-    public static final Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
-            .registerTypeAdapter(PciRequest.class, new RequestAdapter())
-            .registerTypeAdapter(PciResponse.class, new ResponseAdapter()).create();
-
-    public static final Gson gsonJunit = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting()
-            .registerTypeAdapter(Instant.class, new InstantJunitAdapter()).create();
-
 }
index 2259296..19aca3a 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2017 Intel Corp. All rights reserved.
+ * Copyright (C) 2017-2018 Intel Corp. All rights reserved.
+ * Modifications Copyright (C) 2018 AT&T Intellectual Property. 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.
@@ -22,11 +23,11 @@ import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 
 public final class Serialization {
-    private Serialization() {
-    }
-
     public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping()
             .setPrettyPrinting()
             .create();
 
+    private Serialization() {
+    }
+
 }
index a23b257..01e6644 100644 (file)
@@ -25,6 +25,6 @@
  
 <suppressions>
   <suppress checks="AbbreviationAsWordInName"
-    files="ControlLoopCompiler.java|Target.java|ControlLoopPolicyBuilder.java"
+    files="Target.java|ControlLoopPolicyBuilder.java"
     lines="1-9999"/>
 </suppressions>
index 76c6f8f..f18752a 100644 (file)
@@ -268,7 +268,7 @@ public class ControlLoopCompiler implements Serializable {
                     String policyId, String connectedPolicy, 
                     FinalResultNodeWrapper finalResultNodeWrapper, 
                     PolicyResult policyResult, NodeWrapper node) throws CompilerException {
-        FinalResult finalResult = FinalResult.toResult(finalResultNodeWrapper.getID());
+        FinalResult finalResult = FinalResult.toResult(finalResultNodeWrapper.getId());
         if (FinalResult.isResult(connectedPolicy, finalResult)) {
             graph.addEdge(node, finalResultNodeWrapper, new LabeledEdge(node, finalResultNodeWrapper, 
                             new FinalResultEdgeWrapper(finalResult)));
@@ -294,7 +294,7 @@ public class ControlLoopCompiler implements Serializable {
                 validatePolicyNodeWrapper(graph, node, callback);
             }
             for (LabeledEdge edge : graph.outgoingEdgesOf(node)) {
-                LOGGER.info(edge.from.getID() + " invokes " + edge.to.getID() + " upon " + edge.edge.getID());
+                LOGGER.info("{} invokes {} upon {}", edge.from.getId(), edge.to.getId(), edge.edge.getId());
             }
         }
     }
@@ -302,7 +302,7 @@ public class ControlLoopCompiler implements Serializable {
     private static void validateTriggerNodeWrapper(DirectedGraph<NodeWrapper, LabeledEdge> graph, 
                     NodeWrapper node) throws CompilerException {
         if (LOGGER.isDebugEnabled()) {
-            LOGGER.info("Trigger Node {}", node.toString());
+            LOGGER.info("Trigger Node {}", node);
         }
         if (graph.inDegreeOf(node) > 0 ) {
             //
@@ -321,7 +321,7 @@ public class ControlLoopCompiler implements Serializable {
     private static void validateFinalResultNodeWrapper(DirectedGraph<NodeWrapper, LabeledEdge> graph, 
                     NodeWrapper node) throws CompilerException {
         if (LOGGER.isDebugEnabled()) {
-            LOGGER.info("FinalResult Node {}", node.toString());
+            LOGGER.info("FinalResult Node {}", node);
         }
         //
         // FinalResult nodes should NEVER have an out edge
@@ -334,7 +334,7 @@ public class ControlLoopCompiler implements Serializable {
     private static void validatePolicyNodeWrapper(DirectedGraph<NodeWrapper, LabeledEdge> graph, 
                     NodeWrapper node, ControlLoopCompilerCallback callback) throws CompilerException {
         if (LOGGER.isDebugEnabled()) {
-            LOGGER.info("Policy Node {}", node.toString());
+            LOGGER.info("Policy Node {}", node);
         }
         //
         // All Policy Nodes should have the 5 out degrees defined.
@@ -346,16 +346,24 @@ public class ControlLoopCompiler implements Serializable {
         // All Policy Nodes should have at least 1 in degrees 
         // 
         if (graph.inDegreeOf(node) == 0 && callback != null) {
-            callback.onWarning("Policy " + node.getID() + " is not reachable.");
+            callback.onWarning("Policy " + node.getId() + " is not reachable.");
         }
     }
     
     private static boolean okToAdd(Policy operPolicy, ControlLoopCompilerCallback callback) {
         boolean isOk = isPolicyIdOk(operPolicy, callback);
-        isOk = isActorOk(operPolicy, callback) ? isOk : false;
-        isOk = isRecipeOk(operPolicy, callback) ? isOk : false;
-        isOk = isTargetOk(operPolicy, callback) ? isOk : false;
-        isOk = arePolicyResultsOk(operPolicy, callback) ? isOk : false;
+        if (! isActorOk(operPolicy, callback)) {
+            isOk = false;
+        }
+        if (! isRecipeOk(operPolicy, callback)) {
+            isOk = false;
+        }
+        if (! isTargetOk(operPolicy, callback) ) {
+            isOk = false;
+        }
+        if (! arePolicyResultsOk(operPolicy, callback) ) {
+            isOk = false;
+        }
         return isOk;
     }
     
@@ -471,11 +479,21 @@ public class ControlLoopCompiler implements Serializable {
         // Check that policy results are connected to either default final * or another policy
         //
         boolean isOk = isSuccessPolicyResultOk(operPolicy, callback);
-        isOk = isFailurePolicyResultOk(operPolicy, callback) ? isOk : false;
-        isOk = isFailureRetriesPolicyResultOk(operPolicy, callback) ? isOk : false;
-        isOk = isFailureTimeoutPolicyResultOk(operPolicy, callback) ? isOk : false;
-        isOk = isFailureExceptionPolicyResultOk(operPolicy, callback) ? isOk : false;
-        isOk = isFailureGuardPolicyResultOk(operPolicy, callback) ? isOk : false;
+        if (! isFailurePolicyResultOk(operPolicy, callback) ) {
+            isOk = false;
+        }
+        if (! isFailureRetriesPolicyResultOk(operPolicy, callback) ) {
+            isOk = false;
+        }
+        if (! isFailureTimeoutPolicyResultOk(operPolicy, callback) ) {
+            isOk = false;
+        }
+        if (! isFailureExceptionPolicyResultOk(operPolicy, callback) ) {
+            isOk = false;
+        }
+        if (! isFailureGuardPolicyResultOk(operPolicy, callback) ) {
+            isOk = false;
+        }
         return isOk;
     }
     
@@ -562,7 +580,7 @@ public class ControlLoopCompiler implements Serializable {
     
     @FunctionalInterface
     private interface NodeWrapper extends Serializable {
-        public String   getID();
+        public String   getId();
     }
     
     private static class TriggerNodeWrapper implements NodeWrapper {
@@ -579,7 +597,7 @@ public class ControlLoopCompiler implements Serializable {
         }
 
         @Override
-        public String getID() {
+        public String getId() {
             return closedLoopControlName;
         }
         
@@ -599,7 +617,7 @@ public class ControlLoopCompiler implements Serializable {
         }
 
         @Override
-        public String getID() {
+        public String getId() {
             return result.toString();
         }
     }
@@ -618,14 +636,14 @@ public class ControlLoopCompiler implements Serializable {
         }
 
         @Override
-        public String getID() {
+        public String getId() {
             return policy.getId();
         }
     }
     
     @FunctionalInterface
     private interface EdgeWrapper extends Serializable {
-        public String getID();
+        public String getId();
         
     }
     
@@ -638,7 +656,7 @@ public class ControlLoopCompiler implements Serializable {
         }
 
         @Override
-        public String getID() {
+        public String getId() {
             return trigger;
         }
 
@@ -664,7 +682,7 @@ public class ControlLoopCompiler implements Serializable {
         }
 
         @Override
-        public String getID() {
+        public String getId() {
             return policyResult.toString();
         }
         
@@ -685,7 +703,7 @@ public class ControlLoopCompiler implements Serializable {
         }
         
         @Override
-        public String getID() {
+        public String getId() {
             return finalResult.toString();
         }
     }
index 22c58c8..06dc36e 100644 (file)
@@ -50,6 +50,93 @@ public class Policy implements Serializable {
         //Does Nothing Empty Constructor
     }
     
+    public Policy(String id) {
+        this.id = id;
+    }
+    
+    /**
+     * Constructor.
+     * 
+     * @param name name
+     * @param actor actor
+     * @param recipe recipe
+     * @param payload payload
+     * @param target target
+     */
+    public Policy(String name, String actor, String recipe, Map<String, String> payload, Target target) {
+        this.name = name;
+        this.actor = actor;
+        this.recipe = recipe;
+        this.target = target;
+        if (payload != null) {
+            this.payload = Collections.unmodifiableMap(payload);
+        }
+    }
+    
+    /**
+     * Constructor.
+     * 
+     * @param name name
+     * @param actor actor
+     * @param recipe recipe
+     * @param payload payload
+     * @param target target
+     * @param retries retries
+     * @param timeout timeout
+     */
+    public Policy(String name, String actor, String recipe, Map<String, String> payload, Target target, 
+                    Integer retries, Integer timeout) {
+        this(name, actor, recipe, payload, target);
+        this.retry = retries;
+        this.timeout = timeout;
+    }
+    
+    /**
+     * Constructor.
+     * 
+     * @param id id
+     * @param name name
+     * @param description description
+     * @param actor actor
+     * @param payload payload
+     * @param target target
+     * @param recipe recipe
+     * @param retries retries
+     * @param timeout timeout
+     */
+    public Policy(String id, String name, String description, String actor, Map<String, String> payload, 
+                    Target target, String recipe, Integer retries, Integer timeout) {
+        this(name, actor, recipe, payload, target, retries, timeout);
+        this.id = id;
+        this.description = description;
+    }
+    
+    /**
+     * Constructor.
+     * 
+     * @param policy copy object
+     */
+    public Policy(Policy policy) {
+        this.id = policy.id;
+        this.name = policy.name;
+        this.description = policy.description;
+        this.actor = policy.actor;
+        this.recipe = policy.recipe;
+        if (policy.payload != null) {
+            this.payload = Collections.unmodifiableMap(policy.payload);
+        }
+        this.target = policy.target;
+        this.operationsAccumulateParams = policy.operationsAccumulateParams;
+        this.retry = policy.retry;
+        this.timeout = policy.timeout;
+        this.success = policy.success;
+        this.failure = policy.failure;
+        this.failureException = policy.failureException;
+        this.failureGuard = policy.failureGuard;
+        this.failureRetries = policy.failureRetries;
+        this.failureTimeout = policy.failureTimeout;
+    }
+
     public String getId() {
         return id;
     }
@@ -178,93 +265,6 @@ public class Policy implements Serializable {
         this.failureGuard = failureGuard;
     }
 
-    public Policy(String id) {
-        this.id = id;
-    }
-    
-    /**
-     * Constructor.
-     * 
-     * @param name name
-     * @param actor actor
-     * @param recipe recipe
-     * @param payload payload
-     * @param target target
-     */
-    public Policy(String name, String actor, String recipe, Map<String, String> payload, Target target) {
-        this.name = name;
-        this.actor = actor;
-        this.recipe = recipe;
-        this.target = target;
-        if (payload != null) {
-            this.payload = Collections.unmodifiableMap(payload);
-        }
-    }
-    
-    /**
-     * Constructor.
-     * 
-     * @param name name
-     * @param actor actor
-     * @param recipe recipe
-     * @param payload payload
-     * @param target target
-     * @param retries retries
-     * @param timeout timeout
-     */
-    public Policy(String name, String actor, String recipe, Map<String, String> payload, Target target, 
-                    Integer retries, Integer timeout) {
-        this(name, actor, recipe, payload, target);
-        this.retry = retries;
-        this.timeout = timeout;
-    }
-    
-    /**
-     * Constructor.
-     * 
-     * @param id id
-     * @param name name
-     * @param description description
-     * @param actor actor
-     * @param payload payload
-     * @param target target
-     * @param recipe recipe
-     * @param retries retries
-     * @param timeout timeout
-     */
-    public Policy(String id, String name, String description, String actor, Map<String, String> payload, 
-                    Target target, String recipe, Integer retries, Integer timeout) {
-        this(name, actor, recipe, payload, target, retries, timeout);
-        this.id = id;
-        this.description = description;
-    }
-    
-    /**
-     * Constructor.
-     * 
-     * @param policy copy object
-     */
-    public Policy(Policy policy) {
-        this.id = policy.id;
-        this.name = policy.name;
-        this.description = policy.description;
-        this.actor = policy.actor;
-        this.recipe = policy.recipe;
-        if (policy.payload != null) {
-            this.payload = Collections.unmodifiableMap(policy.payload);
-        }
-        this.target = policy.target;
-        this.operationsAccumulateParams = policy.operationsAccumulateParams;
-        this.retry = policy.retry;
-        this.timeout = policy.timeout;
-        this.success = policy.success;
-        this.failure = policy.failure;
-        this.failureException = policy.failureException;
-        this.failureGuard = policy.failureGuard;
-        this.failureRetries = policy.failureRetries;
-        this.failureTimeout = policy.failureTimeout;
-    }
-
     public boolean isValid() {
         return id != null && name != null && actor != null && recipe != null && target != null;
     }
index 61d1ae2..eab6967 100644 (file)
@@ -33,22 +33,6 @@ public class Target implements Serializable {
         //Does Nothing Empty Constructor
     }
     
-    public String getResourceID() {
-        return resourceId;
-    }
-
-    public void setResourceID(String resourceId) {
-        this.resourceId = resourceId;
-    }
-
-    public TargetType getType() {
-        return type;
-    }
-
-    public void setType(TargetType type) {
-        this.type = type;
-    }
-
     public Target(TargetType type) {
         this.type = type;
     }
@@ -67,6 +51,22 @@ public class Target implements Serializable {
         this.resourceId = target.resourceId;
     }
     
+    public String getResourceID() {
+        return resourceId;
+    }
+
+    public void setResourceID(String resourceId) {
+        this.resourceId = resourceId;
+    }
+
+    public TargetType getType() {
+        return type;
+    }
+
+    public void setType(TargetType type) {
+        this.type = type;
+    }
+
     @Override
     public String toString() {
         return "Target [type=" + type + ", resourceId=" + resourceId + "]";
index 618678e..4038f3b 100644 (file)
@@ -22,10 +22,10 @@ package org.onap.policy.controlloop.policy.builder;
 
 public class BuilderException extends Exception {
 
+    private static final long serialVersionUID = 610064813684337895L;
+
     public BuilderException(String string) {
         super(string);
     }
 
-    private static final long serialVersionUID = 610064813684337895L;
-
 }
index 5ac1fdc..9332bfb 100644 (file)
@@ -191,10 +191,24 @@ public class Constraint {
         this.maxVnfCount = maxVnfCount;
     }
 
-    
+    /**
+     * Check if these constraint values are valid.
+     * 
+     * @return true if valid
+     */
     public boolean isValid() {
-        return ((freqLimitPerTarget == null && timeWindow != null)
-                        || (timeWindow == null && freqLimitPerTarget != null)) ? false : true;
+        //
+        // Sonar likes these statements combined as well as not use
+        // boolean literals.
+        //
+        // If the freqLimitPerTarget is null AND the timeWindow is NOT null
+        // OR
+        // timeWindow is null AND the freqLimitPerTarget is NOT null
+        //
+        // then we want to return false (hence the preceding !)
+        //
+        return ! ((freqLimitPerTarget == null && timeWindow != null)
+                        || (timeWindow == null && freqLimitPerTarget != null));
     }
     
     @Override
index 799c5fc..b76c457 100644 (file)
@@ -36,46 +36,6 @@ public class GuardPolicy {
         //Do Nothing Empty Constructor. 
     }
     
-    public String getId() {
-        return id;
-    }
-
-    public void setId(String id) {
-        this.id = id;
-    }
-
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    public String getDescription() {
-        return description;
-    }
-
-    public void setDescription(String description) {
-        this.description = description;
-    }
-
-    public MatchParameters getMatch_parameters() {
-        return matchParameters;
-    }
-
-    public void setMatch_parameters(MatchParameters matchParameters) {
-        this.matchParameters = matchParameters;
-    }
-
-    public LinkedList<Constraint> getLimit_constraints() {
-        return  limitConstraints;
-    }
-
-    public void setLimit_constraints(LinkedList<Constraint> limitConstraints) {
-        this.limitConstraints = limitConstraints;
-    }
-
     public GuardPolicy(String id) {
         this.id = id;
     }
@@ -140,6 +100,46 @@ public class GuardPolicy {
         }
     }
     
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public MatchParameters getMatch_parameters() {
+        return matchParameters;
+    }
+
+    public void setMatch_parameters(MatchParameters matchParameters) {
+        this.matchParameters = matchParameters;
+    }
+
+    public LinkedList<Constraint> getLimit_constraints() {
+        return  limitConstraints;
+    }
+
+    public void setLimit_constraints(LinkedList<Constraint> limitConstraints) {
+        this.limitConstraints = limitConstraints;
+    }
+
     public boolean isValid() {
         return (id == null || name == null) ? false : true;
     }
index 1bf1073..0b13809 100644 (file)
@@ -34,38 +34,6 @@ public class MatchParameters {
         // Do Nothing Empty Constructor.
     }   
     
-    public String getControlLoopName() {
-        return controlLoopName;
-    }
-
-    public void setControlLoopName(String controlLoopName) {
-        this.controlLoopName = controlLoopName;
-    }
-
-    public String getActor() {
-        return actor;
-    }
-
-    public void setActor(String actor) {
-        this.actor = actor;
-    }
-
-    public String getRecipe() {
-        return recipe;
-    }
-
-    public void setRecipe(String recipe) {
-        this.recipe = recipe;
-    }
-
-    public List<String> getTargets() {
-        return targets;
-    }
-
-    public void setTargets(List<String> targets) {
-        this.targets = targets;
-    }
-
     public MatchParameters(String actor, String recipe) {
         this.actor = actor;
         this.recipe = recipe;
@@ -105,6 +73,38 @@ public class MatchParameters {
         }
     }
 
+    public String getControlLoopName() {
+        return controlLoopName;
+    }
+
+    public void setControlLoopName(String controlLoopName) {
+        this.controlLoopName = controlLoopName;
+    }
+
+    public String getActor() {
+        return actor;
+    }
+
+    public void setActor(String actor) {
+        this.actor = actor;
+    }
+
+    public String getRecipe() {
+        return recipe;
+    }
+
+    public void setRecipe(String recipe) {
+        this.recipe = recipe;
+    }
+
+    public List<String> getTargets() {
+        return targets;
+    }
+
+    public void setTargets(List<String> targets) {
+        this.targets = targets;
+    }
+
     @Override
     public String toString() {
         return "MatchParameters [controlLoopName=" + controlLoopName + ", actor=" + actor + ", recipe=" + recipe
index f995ba4..da2b9a1 100644 (file)
@@ -235,7 +235,7 @@ public class ControlLoopGuardBuilderImpl implements ControlLoopGuardBuilder {
         try {
             ControlLoopGuardCompiler.compile(clGuard, callback);
         } catch (CompilerException e) {
-            logger.error(e.getMessage() + e);
+            logger.error("Build specification threw ", e);
             callback.results.addMessage(new MessageImpl(e.getMessage(), MessageLevel.EXCEPTION));
         }
         //
index 3bacead..8fa4892 100644 (file)
@@ -43,6 +43,9 @@ import org.onap.policy.aai.util.Serialization;
 public class AaiSimulatorJaxRs {
 
     private static final String VSERVER = "vserver";
+    private static final String DISABLE_CLOSEDLOOP = "disableClosedLoop";
+    private static final String ERROR = "error";
+    private static final String GETFAIL = "getFail";
 
     /**
      * A&AI get query.
@@ -77,7 +80,7 @@ public class AaiSimulatorJaxRs {
         if (request.getInstanceFilters().getInstanceFilter().get(0).containsKey(VSERVER)) {
             final String vserverName =
                     request.getInstanceFilters().getInstanceFilter().get(0).get(VSERVER).get("vserver-name");
-            if ("error".equals(vserverName)) {
+            if (ERROR.equals(vserverName)) {
                 Map<String,String> params = new TreeMap<>();
                 params.put("type", VSERVER);
                 return load("aai/AaiNqResponse-Error.json", params);
@@ -89,7 +92,7 @@ public class AaiSimulatorJaxRs {
         } else {
             final String vnfId =
                     request.getInstanceFilters().getInstanceFilter().get(0).get("generic-vnf").get("vnf-id");
-            if ("error".equals(vnfId)) {
+            if (ERROR.equals(vnfId)) {
                 Map<String,String> params = new TreeMap<>();
                 params.put("type", "generic-vnf");
                 return load("aai/AaiNqResponse-Error.json", params);
@@ -120,14 +123,14 @@ public class AaiSimulatorJaxRs {
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces("application/json")
     public String getByVnfName(@QueryParam("vnf-name") final String vnfName) {
-        if ("getFail".equals(vnfName)) {
+        if (GETFAIL.equals(vnfName)) {
             return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found"
                     + " for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"network/generic-vnfs/"
                     + "generic-vnf\",\"Node Not Found:No Node of type generic-vnf found at network/generic-vnfs"
                     + "/generic-vnf\",\"ERR.5.4.6114\"]}}}";
         }
-        final boolean isDisabled = "disableClosedLoop".equals(vnfName);
-        if ("error".equals(vnfName)) {
+        final boolean isDisabled = DISABLE_CLOSEDLOOP.equals(vnfName);
+        if (ERROR.equals(vnfName)) {
             return "{ \"vnf-id\": \"error\", \"vnf-name\": \"" + vnfName
                     + "\", \"vnf-type\": \"RT\", \"service-id\": \"d7bb0a21-66f2-4e6d-87d9-9ef3ced63ae4\", \""
                     + "equipment-role\": \"UCPE\", \"orchestration-status\": \"created\", \"management-option\": \""
@@ -195,13 +198,13 @@ public class AaiSimulatorJaxRs {
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces("application/json")
     public String getByVnfId(@PathParam("vnfId") final String vnfId) {
-        if ("getFail".equals(vnfId)) {
+        if (GETFAIL.equals(vnfId)) {
             return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found"
                     + " for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"network/generic-vnfs/"
                     + "generic-vnf/getFail\",\"Node Not Found:No Node of type generic-vnf found at network/"
                     + "generic-vnfs/generic-vnf/getFail\",\"ERR.5.4.6114\"]}}}";
         }
-        final boolean isDisabled = "disableClosedLoop".equals(vnfId);
+        final boolean isDisabled = DISABLE_CLOSEDLOOP.equals(vnfId);
         final String vnfName = getUuidValue(vnfId, "USUCP0PCOIL0110UJRT01");
         return "{ \"vnf-id\": \"" + vnfId + "\", \"vnf-name\": \"" + vnfName
                 + "\", \"vnf-type\": \"RT\", \"service-id\": \""
@@ -241,12 +244,12 @@ public class AaiSimulatorJaxRs {
     @Consumes(MediaType.APPLICATION_JSON)
     @Produces("application/json")
     public String getByVserverName(@QueryParam("vserver-name") final String vserverName) {
-        if ("getFail".equals(vserverName)) {
+        if (GETFAIL.equals(vserverName)) {
             return "{\"requestError\":{\"serviceException\":{\"messageId\":\"SVC3001\",\"text\":\"Resource not found"
                     + " for %1 using id %2 (msg=%3) (ec=%4)\",\"variables\":[\"GET\",\"nodes/vservers\",\"Node Not"
                     + " Found:No Node of type generic-vnf found at nodes/vservers\",\"ERR.5.4.6114\"]}}}";
         }
-        final boolean isDisabled = "disableClosedLoop".equals(vserverName);
+        final boolean isDisabled = DISABLE_CLOSEDLOOP.equals(vserverName);
         final String vserverId = getUuidValue(vserverName, "d0668d4f-c25e-4a1b-87c4-83845c01efd8");
         return "{\"vserver\": [{ \"vserver-id\": \"" + vserverId + "\", \"vserver-name\": \"" + vserverName
                 + "\", \"vserver-name2\": \"vjunos0\", \"vserver-selflink\": \"https://aai-ext1.test.att.com:8443/aai/v7/cloud-infrastructure/cloud-regions/cloud-region/att-aic/AAIAIC25/tenants/tenant/USMSO1SX7NJ0103UJZZ01%3A%3AuCPE-VMS/vservers/vserver/d0668d4f-c25e-4a1b-87c4-83845c01efd8\", \"in-maint\": false, \"is-closed-loop-disabled\": "
index 58aae62..16ae615 100644 (file)
@@ -26,10 +26,6 @@ import org.onap.policy.common.endpoints.http.server.HttpServletServer;
 import org.onap.policy.common.utils.network.NetworkUtil;
 
 public class Util {
-    private Util() {
-        // Prevent instantiation of thic class
-    }
-
     public static final String AAISIM_SERVER_NAME = "aaiSim";
     public static final String SOSIM_SERVER_NAME = "soSim";
     public static final String VFCSIM_SERVER_NAME = "vfcSim";
@@ -39,6 +35,13 @@ public class Util {
     public static final int SOSIM_SERVER_PORT = 6667;
     public static final int VFCSIM_SERVER_PORT = 6668;
     public static final int GUARDSIM_SERVER_PORT = 6669;
+    
+    private static final String CANNOT_CONNECT = "cannot connect to port ";
+    private static final String LOCALHOST = "localhost";
+
+    private Util() {
+        // Prevent instantiation of thic class
+    }
 
     /**
      * Build an A&AI simulator.
@@ -49,11 +52,11 @@ public class Util {
      */
     public static HttpServletServer buildAaiSim() throws InterruptedException, IOException {
         final HttpServletServer testServer =
-                HttpServletServer.factory.build(AAISIM_SERVER_NAME, "localhost", AAISIM_SERVER_PORT, "/", false, true);
+                HttpServletServer.factory.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)) {
-            throw new IllegalStateException("cannot connect to port " + testServer.getPort());
+        if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
+            throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort());
         }
         return testServer;
     }
@@ -67,11 +70,11 @@ public class Util {
      */
     public static HttpServletServer buildSoSim() throws InterruptedException, IOException {
         final HttpServletServer testServer =
-                HttpServletServer.factory.build(SOSIM_SERVER_NAME, "localhost", SOSIM_SERVER_PORT, "/", false, true);
+                HttpServletServer.factory.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)) {
-            throw new IllegalStateException("cannot connect to port " + testServer.getPort());
+        if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
+            throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort());
         }
         return testServer;
     }
@@ -85,11 +88,11 @@ public class Util {
      */
     public static HttpServletServer buildVfcSim() throws InterruptedException, IOException {
         final HttpServletServer testServer =
-                HttpServletServer.factory.build(VFCSIM_SERVER_NAME, "localhost", VFCSIM_SERVER_PORT, "/", false, true);
+                HttpServletServer.factory.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)) {
-            throw new IllegalStateException("cannot connect to port " + testServer.getPort());
+        if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
+            throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort());
         }
         return testServer;
     }
@@ -102,12 +105,12 @@ public class Util {
      * @throws IOException if an IO errror occurs
      */
     public static HttpServletServer buildGuardSim() throws InterruptedException, IOException {
-        HttpServletServer testServer = HttpServletServer.factory.build(GUARDSIM_SERVER_NAME, "localhost",
+        HttpServletServer testServer = HttpServletServer.factory.build(GUARDSIM_SERVER_NAME, LOCALHOST,
                 GUARDSIM_SERVER_PORT, "/", false, true);
         testServer.addServletClass("/*", GuardSimulatorJaxRs.class.getName());
         testServer.waitedStart(5000);
-        if (!NetworkUtil.isTcpPortOpen("localhost", testServer.getPort(), 5, 10000L)) {
-            throw new IllegalStateException("cannot connect to port " + testServer.getPort());
+        if (!NetworkUtil.isTcpPortOpen(LOCALHOST, testServer.getPort(), 5, 10000L)) {
+            throw new IllegalStateException(CANNOT_CONNECT + testServer.getPort());
         }
         return testServer;
     }