Fix issues from Checkstyle reviews 47/90647/3
authorliamfallon <liam.fallon@est.tech>
Mon, 1 Jul 2019 09:01:19 +0000 (09:01 +0000)
committerliamfallon <liam.fallon@est.tech>
Mon, 1 Jul 2019 09:01:19 +0000 (09:01 +0000)
Use lombok on fields in EnEvent.
Remove unnecessary code in BBS WebClient class
Address Sonar issue in Execurot class

Issue-ID: POLICY-1791
Change-Id: If07dc4529b121f8bfcd6ab1ae6c9def4774f9f4d
Signed-off-by: liamfallon <liam.fallon@est.tech>
core/core-engine/src/main/java/org/onap/policy/apex/core/engine/event/EnEvent.java
core/core-engine/src/main/java/org/onap/policy/apex/core/engine/executor/Executor.java
examples/examples-onap-bbs/src/main/java/org/onap/policy/apex/examples/bbs/WebClient.java
examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js
examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js
examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js
examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js
examples/examples-onap-bbs/src/test/java/org/onap/policy/apex/examples/bbs/WebClientTest.java

index d53fdf8..95ea6b5 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ *  Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -30,6 +31,9 @@ import java.util.Properties;
 import java.util.Random;
 import java.util.Set;
 
+import lombok.Getter;
+import lombok.Setter;
+
 import org.onap.policy.apex.core.engine.monitoring.EventMonitor;
 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
 import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
@@ -62,6 +66,8 @@ public class EnEvent extends HashMap<String, Object> {
     private final transient EventMonitor eventMonitor = new EventMonitor();
 
     // The stack of execution of this event, used for monitoring
+    @Getter
+    @Setter
     private AxConcept[] userArtifactStack;
 
     private static Random rand = new Random(System.nanoTime());
@@ -69,12 +75,18 @@ public class EnEvent extends HashMap<String, Object> {
     // An identifier for the current event execution. The default value here will always be a random
     // number, and should
     // be reset
+    @Getter
+    @Setter
     private long executionId = rand.nextLong();
 
     // Event related properties used during processing of this event
+    @Getter
+    @Setter
     private Properties executionProperties;
 
     // A string holding a message that indicates why processing of this event threw an exception
+    @Getter
+    @Setter
     private String exceptionMessage;
 
     /**
@@ -137,86 +149,6 @@ public class EnEvent extends HashMap<String, Object> {
         return axEvent.getKey().getId();
     }
 
-    /**
-     * Get the currently set value for the ExecutionID for this event. A ExecutionID in an EnEvent
-     * is used identify all EnEvents (input, internal and output events) used in a single Engine
-     * invocation. Therefore, a ExecutionID can be used to match which output event is the result of
-     * a particular input event. The default initialized value for the ExecutionID is always unique
-     * in a single JVM.
-     *
-     * @return the currently set value for the ExecutionID for this event.
-     */
-    public long getExecutionId() {
-        return executionId;
-    }
-
-    /**
-     * Set the value for the ExecutionID for this event. A ExecutionID in an EnEvent is used
-     * identify all EnEvents (input, internal and output events) used in a single Engine invocation.
-     * Therefore, a ExecutionID can be used to match which output event is the result of a
-     * particular input event. The default initialised value for the ExecutionID is always unique in
-     * a single JVM.
-     *
-     * @param executionId the new value for the ExecutionID for this event.
-     */
-    public void setExecutionId(final long executionId) {
-        this.executionId = executionId;
-    }
-
-    /**
-     * Get the event execution properties.
-     *
-     * @return the event execution properties
-     */
-    public Properties getExecutionProperties() {
-        return executionProperties;
-    }
-
-    /**
-     * Set the event execution properties.
-     *
-     * @param executionProperties the execution properties to set
-     */
-    public void setExecutionProperties(Properties executionProperties) {
-        this.executionProperties = executionProperties;
-    }
-
-    /**
-     * Gets the exception message explaining why processing of this event to fail.
-     *
-     * @return the exception message
-     */
-    public String getExceptionMessage() {
-        return exceptionMessage;
-    }
-
-    /**
-     * Sets the exception message explaining why processing of this event to fail.
-     *
-     * @param exceptionMessage the exception message
-     */
-    public void setExceptionMessage(final String exceptionMessage) {
-        this.exceptionMessage = exceptionMessage;
-    }
-
-    /**
-     * Get the user artifact stack of the event.
-     *
-     * @return the event user artifact stack
-     */
-    public AxConcept[] getUserArtifactStack() {
-        return userArtifactStack;
-    }
-
-    /**
-     * Store the user artifact stack of the event.
-     *
-     * @param usedArtifactStackArray the event user artifact stack
-     */
-    public void setUserArtifactStack(final AxConcept[] usedArtifactStackArray) {
-        userArtifactStack = usedArtifactStackArray;
-    }
-
     /**
      * {@inheritDoc}.
      */
index fa0b40e..cb0cfab 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ *  Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -113,7 +114,8 @@ public interface Executor<I, O, S, C> {
      *
      * @return The parent executor of this executor
      */
-    Executor<?, ?, ?, ?> getParent();
+    @SuppressWarnings("rawtypes")
+    Executor getParent();
 
     /**
      * Get the subject of the executor.
index 939b104..e4186f1 100644 (file)
@@ -70,11 +70,10 @@ public class WebClient {
      * @param username Simple Username
      * @param pass Simple password
      * @param contentType http content type
-     * @apram secureHttp flag indicating if HTTPS should be used
      * @return String response message
      */
     public String httpRequest(String requestUrl, String requestMethod, String outputStr, String username, String pass,
-            String contentType, boolean secureHttp) {
+            String contentType) {
         String result = "";
         StringBuilder builder = new StringBuilder();
         try {
@@ -82,13 +81,8 @@ public class WebClient {
             disableCertificateValidation();
 
             URL url = new URL(requestUrl);
-            HttpURLConnection httpUrlConn = null;
-            if (secureHttp) {
-                httpUrlConn = (HttpsURLConnection) url.openConnection();
-            }
-            else {
-                httpUrlConn = (HttpURLConnection) url.openConnection();
-            }
+            HttpURLConnection httpUrlConn = (HttpURLConnection) url.openConnection();
+
             httpUrlConn.setDoOutput(true);
             httpUrlConn.setDoInput(true);
             httpUrlConn.setUseCaches(false);
index 6e72e61..a4be370 100644 (file)
@@ -84,7 +84,7 @@ try {
 
     executor.logger.info("Query url" + urlGet);
 
-    result = client.httpRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json", true);
+    result = client.httpRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json");
     executor.logger.info("Data received From " + urlGet + " " + result);
     jsonObj = JSON.parse(result.toString());
 
@@ -116,7 +116,7 @@ try {
         executor.logger.info("ready to putAfter Parse " + JSON.stringify(putUpddateServInstance, null, 4));
         var urlPut = HTTP_PROTOCOL + AAI_URL + putUrl + "?resource_version=" + resource_version;
         result = client.httpRequest(urlPut, "PUT", JSON.stringify(putUpddateServInstance), AAI_USERNAME, AAI_PASSWORD,
-                "application/json", true);
+                "application/json");
         executor.logger.info("Data received From " + urlPut + " " + result);
         /* If failure to retrieve data proceed to Failure */
         if (result != "") {
@@ -157,7 +157,7 @@ try {
 
         /* 1. Get PNF */
         var urlGetPnf = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION + "/network/pnfs/pnf/" + pnfName;
-        pnfResponse = client.httpRequest(urlGetPnf, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json", true);
+        pnfResponse = client.httpRequest(urlGetPnf, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json");
         executor.logger.info("Data received From " + urlGetPnf + " " + pnfResponse);
         /* If failure to retrieve data proceed to Failure */
         if (result != "") {
@@ -166,7 +166,7 @@ try {
         pnfUpdate = JSON.parse(pnfResponse.toString());
         executor.logger.info(JSON.stringify(pnfUpdate, null, 4));
 
-        /*2. Create logical link */
+        /* 2. Create logical link */
         var link_name = attachmentPoint;
         var logicalLink = {
             "link-name" : link_name,
@@ -176,14 +176,14 @@ try {
         var urlNewLogicalLink = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION
                 + "/network/logical-links/logical-link/" + link_name;
         result = client.httpRequest(urlNewLogicalLink, "PUT", JSON.stringify(logicalLink), AAI_USERNAME, AAI_PASSWORD,
-                "application/json", true);
+                "application/json");
         executor.logger.info("Data received From " + urlNewLogicalLink + " " + result);
         /* If failure to retrieve data proceed to Failure */
         if (result != "") {
             aaiUpdateResult = false;
         }
 
-        /*3. Update pnf with new relation*/
+        /* 3. Update pnf with new relation */
         for (var i = 0; i < pnfUpdate["relationship-list"]["relationship"].length; i++) {
             if (pnfUpdate["relationship-list"]["relationship"][i]['related-to'] == 'logical-link') {
                 pnfUpdate["relationship-list"]["relationship"][i]['related-link'] = "/aai/" + AAI_VERSION
@@ -202,7 +202,7 @@ try {
         executor.logger.info("Put pnf to aai " + JSON.stringify(pnfUpdate, null, 4));
         var urlPutPnf = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION + "/network/pnfs/pnf/" + pnfName;
         result = client.httpRequest(urlPutPnf, "PUT", JSON.stringify(pnfUpdate), AAI_USERNAME, AAI_PASSWORD,
-                "application/json", true);
+                "application/json");
         executor.logger.info("Data received From " + urlPutPnf + " " + result);
 
         /* If failure to retrieve data proceed to Failure */
@@ -215,8 +215,7 @@ try {
         var linkResult;
         var urlOldLogicalLink = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION
                 + "/network/logical-links/logical-link/" + oldLinkName;
-        linkResult = client
-                .httpRequest(urlOldLogicalLink, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json", true);
+        linkResult = client.httpRequest(urlOldLogicalLink, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json");
         executor.logger.info("Data received From " + urlOldLogicalLink + " " + linkResult + " "
                 + linkResult.hasOwnProperty("link-name"));
         oldLinkResult = JSON.parse(linkResult.toString());
@@ -225,7 +224,7 @@ try {
             var urlDelOldLogicalLink = urlOldLogicalLink + "?resource-version=" + res_version;
             executor.logger.info("Delete called for " + urlDelOldLogicalLink);
             result = client.httpRequest(urlDelOldLogicalLink, "DELETE", null, AAI_USERNAME, AAI_PASSWORD,
-                    "application/json", true);
+                    "application/json");
             executor.logger.info("Delete called for " + urlDelOldLogicalLink + " result " + result);
         }
     }
index 7e116f0..a7809bf 100644 (file)
@@ -78,7 +78,7 @@ try {
 
     executor.logger.info("Query url" + urlGet);
 
-    result = client.httpRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json", true);
+    result = client.httpRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json");
     executor.logger.info("Data received From " + urlGet + " " + result);
     jsonObj = JSON.parse(result);
 
@@ -110,7 +110,7 @@ try {
         executor.logger.info("ready to putAfter Parse " + JSON.stringify(putUpddateServInstance, null, 4));
         var urlPut = HTTP_PROTOCOL + AAI_URL + putUrl + "?resource_version=" + resource_version;
         result = client.httpRequest(urlPut, "PUT", JSON.stringify(putUpddateServInstance), AAI_USERNAME, AAI_PASSWORD,
-                "application/json", true);
+                "application/json");
         executor.logger.info("Data received From " + urlPut + " " + result);
         /* If failure to retrieve data proceed to Failure */
         if (result != "") {
index d588eaf..02fc058 100644 (file)
@@ -1,7 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Huawei. All rights reserved.
- *  Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -124,8 +123,7 @@ executor.logger.info(client.toPrettyString(xmlDeleteAccess, 4));
 
 try {
     var urlPost1 = HTTP_PROTOCOL + SDNC_URL + "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation";
-    result = client.httpRequest(urlPost1, "POST", xmlDeleteAccess, SDNC_USERNAME, SDNC_PASSWORD, "application/xml",
-            false);
+    result = client.httpRequest(urlPost1, "POST", xmlDeleteAccess, SDNC_USERNAME, SDNC_PASSWORD, "application/xml");
     executor.logger.info("Data received From " + urlPost1 + " " + result);
     if (result == "") {
         sdncUpdateResult = false;
@@ -190,8 +188,7 @@ try {
     if (sdncUpdateResult == true) {
         var urlPost2 = HTTP_PROTOCOL + SDNC_URL
                 + "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation";
-        result = client.httpRequest(urlPost2, "POST", xmlCreateAccess, SDNC_USERNAME, SDNC_PASSWORD, "application/xml",
-                false);
+        result = client.httpRequest(urlPost2, "POST", xmlCreateAccess, SDNC_USERNAME, SDNC_PASSWORD, "application/xml");
         executor.logger.info("Data received From " + urlPost2 + " " + result);
         if (result == "") {
             sdncUpdateResult = false;
@@ -265,8 +262,8 @@ try {
     if (sdncUpdateResult == true) {
         var urlPost3 = HTTP_PROTOCOL + SDNC_URL
                 + "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation";
-        result = client.httpRequest(urlPost3, "POST", xmlChangeProfile, SDNC_USERNAME, SDNC_PASSWORD,
-                "application/xml", false);
+        result = client
+                .httpRequest(urlPost3, "POST", xmlChangeProfile, SDNC_USERNAME, SDNC_PASSWORD, "application/xml");
         executor.logger.info("Data received From " + urlPost3 + " " + result);
         if (result == "") {
             sdncUpdateResult = false;
@@ -344,4 +341,4 @@ function IsValidJSONString(str) {
     }
     return true;
 }
-/* Utility functions End */
+/* Utility functions End */
\ No newline at end of file
index 90b1b00..871e146 100644 (file)
@@ -28,12 +28,10 @@ executor.logger.info("Begin Execution ServiceUpdateStateCpeAuthTask.js");
 executor.logger.info(executor.subject.id);
 executor.logger.info(executor.inFields);
 
-var clEventType = Java.type(
-    "org.onap.policy.controlloop.VirtualControlLoopEvent");
+var clEventType = Java.type("org.onap.policy.controlloop.VirtualControlLoopEvent");
 var clEvent = executor.inFields.get("VirtualControlLoopEvent");
 
-var serviceInstanceId = clEvent.getAai().get(
-    "service-information.hsia-cfs-service-instance-id");
+var serviceInstanceId = clEvent.getAai().get("service-information.hsia-cfs-service-instance-id");
 var requestID = clEvent.getRequestId();
 
 var jsonObj;
@@ -53,8 +51,7 @@ var putUrl;
 var service_instance;
 var AAI_VERSION = "v14";
 try {
-    var br = Files.newBufferedReader(Paths.get(
-        "/home/apexuser/examples/config/ONAPBBS/config.txt"));
+    var br = Files.newBufferedReader(Paths.get("/home/apexuser/examples/config/ONAPBBS/config.txt"));
     var line;
     while ((line = br.readLine()) != null) {
         if (line.startsWith("AAI_URL")) {
@@ -66,11 +63,11 @@ try {
         } else if (line.startsWith("AAI_PASSWORD")) {
             var str = line.split("=");
             AAI_PASSWORD = str[str.length - 1];
-        }else if (line.startsWith("AAI_VERSION")) {
+        } else if (line.startsWith("AAI_VERSION")) {
             var str = line.split("=");
             AAI_VERSION = str[str.length - 1];
-         }
-     }
+        }
+    }
 } catch (err) {
     executor.logger.info("Failed to retrieve data " + err);
 }
@@ -79,25 +76,21 @@ executor.logger.info("AAI_URL=>" + AAI_URL);
 
 /* Get service instance Id from AAI */
 try {
-    var urlGet = HTTP_PROTOCOL + AAI_URL +
-        "/aai/" + AAI_VERSION + "/nodes/service-instances/service-instance/" +
-        SERVICE_INSTANCE_ID + "?format=resource_and_url"
+    var urlGet = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION + "/nodes/service-instances/service-instance/"
+            + SERVICE_INSTANCE_ID + "?format=resource_and_url"
     executor.logger.info("Query url" + urlGet);
 
-    result = client.httpRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD,
-            "application/json", true);
+    result = client.httpRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json");
     executor.logger.info("Data received From " + urlGet + " " + result);
     jsonObj = JSON.parse(result);
 
-
     /* Retrieve the service instance id */
     results = jsonObj['results'][0];
     putUrl = results["url"];
     service_instance = results['service-instance'];
     resource_version = service_instance['resource-version'];
-    executor.logger.info("After Parse service_instance " + JSON.stringify(
-            service_instance, null, 4) + "\n url " + putUrl +
-        "\n Service instace Id " + SERVICE_INSTANCE_ID);
+    executor.logger.info("After Parse service_instance " + JSON.stringify(service_instance, null, 4) + "\n url "
+            + putUrl + "\n Service instace Id " + SERVICE_INSTANCE_ID);
 
     if (result == "") {
         aaiUpdateResult = false;
@@ -112,19 +105,15 @@ var putUpddateServInstance;
 putUpddateServInstance = service_instance;
 if (newState == 'inService') {
     putUpddateServInstance['orchestration-status'] = "active";
-}
-else
-{
+} else {
     putUpddateServInstance['orchestration-status'] = "inActive";
 }
 try {
     if (aaiUpdateResult == true) {
-        executor.logger.info("ready to put After Parse " + JSON.stringify(
-            putUpddateServInstance, null, 4));
-        var urlPut = HTTP_PROTOCOL + AAI_URL +
-            putUrl + "?resource_version=" + resource_version;
+        executor.logger.info("ready to put After Parse " + JSON.stringify(putUpddateServInstance, null, 4));
+        var urlPut = HTTP_PROTOCOL + AAI_URL + putUrl + "?resource_version=" + resource_version;
         result = client.httpRequest(urlPut, "PUT", JSON.stringify(putUpddateServInstance), AAI_USERNAME, AAI_PASSWORD,
-                        "application/json", true);
+                "application/json");
         executor.logger.info("Data received From " + urlPut + " " + result);
         /* If failure to retrieve data proceed to Failure */
         if (result != "") {
@@ -145,4 +134,3 @@ if (aaiUpdateResult == true) {
 executor.logger.info(executor.outFields);
 var returnValue = executor.isTrue;
 executor.logger.info("End Execution ServiceUpdateStateCpeAuthTask.js");
-
index 2ff9435..e7bba59 100644 (file)
@@ -53,8 +53,8 @@ public class WebClientTest {
     @Test
     public void httpsRequest() {
         WebClient cl = new WebClient();
-        String result = cl.httpRequest("https://some.random.url/data", "POST", null, "admin", "admin",
-                "application/json", true);
+        String result =
+                cl.httpRequest("https://some.random.url/data", "POST", null, "admin", "admin", "application/json");
         assertNotNull(result);
     }
 
@@ -62,7 +62,7 @@ public class WebClientTest {
     public void httpRequest() {
         WebClient cl = new WebClient();
         String result =
-                cl.httpRequest("http://some.random.url/data", "GET", null, "admin", "admin", "application/json", false);
+                cl.httpRequest("http://some.random.url/data", "GET", null, "admin", "admin", "application/json");
         assertNotNull(result);
     }