summaryrefslogtreecommitdiffstats
path: root/examples/examples-onap-bbs/src
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-07-01 09:01:19 +0000
committerliamfallon <liam.fallon@est.tech>2019-07-01 09:01:19 +0000
commitf08984b16abf954b7b351f21a3822e21d9d4f7c2 (patch)
tree1dc21cf3240864f37efe304a75c8055d89f48662 /examples/examples-onap-bbs/src
parentc4baac8a79b0ca6340693ae47f9c424f3612e3bd (diff)
Fix issues from Checkstyle reviews
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>
Diffstat (limited to 'examples/examples-onap-bbs/src')
-rw-r--r--examples/examples-onap-bbs/src/main/java/org/onap/policy/apex/examples/bbs/WebClient.java12
-rw-r--r--examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js19
-rw-r--r--examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js4
-rw-r--r--examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js13
-rw-r--r--examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js42
-rw-r--r--examples/examples-onap-bbs/src/test/java/org/onap/policy/apex/examples/bbs/WebClientTest.java6
6 files changed, 37 insertions, 59 deletions
diff --git a/examples/examples-onap-bbs/src/main/java/org/onap/policy/apex/examples/bbs/WebClient.java b/examples/examples-onap-bbs/src/main/java/org/onap/policy/apex/examples/bbs/WebClient.java
index 939b104d1..e4186f131 100644
--- a/examples/examples-onap-bbs/src/main/java/org/onap/policy/apex/examples/bbs/WebClient.java
+++ b/examples/examples-onap-bbs/src/main/java/org/onap/policy/apex/examples/bbs/WebClient.java
@@ -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);
diff --git a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js
index 6e72e618c..a4be3707f 100644
--- a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js
+++ b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js
@@ -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);
}
}
diff --git a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js
index 7e116f0ea..a7809bf1b 100644
--- a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js
+++ b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js
@@ -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 != "") {
diff --git a/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js b/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js
index d588eaf48..02fc05839 100644
--- a/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js
+++ b/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js
@@ -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
diff --git a/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js b/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js
index 90b1b0075..871e146a7 100644
--- a/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js
+++ b/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js
@@ -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");
-
diff --git a/examples/examples-onap-bbs/src/test/java/org/onap/policy/apex/examples/bbs/WebClientTest.java b/examples/examples-onap-bbs/src/test/java/org/onap/policy/apex/examples/bbs/WebClientTest.java
index 2ff9435b2..e7bba5905 100644
--- a/examples/examples-onap-bbs/src/test/java/org/onap/policy/apex/examples/bbs/WebClientTest.java
+++ b/examples/examples-onap-bbs/src/test/java/org/onap/policy/apex/examples/bbs/WebClientTest.java
@@ -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);
}