summaryrefslogtreecommitdiffstats
path: root/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js
diff options
context:
space:
mode:
authorJorge Hernandez <jorge.hernandez-herrero@att.com>2019-04-22 17:38:54 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-22 17:38:54 +0000
commitca558cfb1ea47de081527771af47abb37a8cd964 (patch)
tree8fb802d8f6b323ded0442bcfd954e0332be4b84f /examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js
parente3a4e81b5e0ad5fec4d215ab7ef1b4f310370984 (diff)
parent39f7edcc4a181394b8895aef8b4b43a8a19b045b (diff)
Merge "ONAP BBS: Apex Nomadic ONT bug fixes"
Diffstat (limited to 'examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js')
-rw-r--r--examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js154
1 files changed, 91 insertions, 63 deletions
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 9c48f0d52..62c280531 100644
--- a/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js
+++ b/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js
@@ -17,31 +17,39 @@
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
-
load("nashorn:mozilla_compat.js");
importClass(java.io.BufferedReader);
importClass(java.io.IOException);
importClass(java.nio.file.Files);
importClass(java.nio.file.Paths);
+
executor.logger.info("Begin Execution ServiceUpdateStateCpeAuthTask.js");
executor.logger.info(executor.subject.id);
executor.logger.info(executor.inFields);
-var returnValue = executor.isTrue;
-//**************************************************************************//
-
-var clEventType = Java.type("org.onap.policy.controlloop.VirtualControlLoopEvent");
+var clEventType = Java.type(
+ "org.onap.policy.controlloop.VirtualControlLoopEvent");
var clEvent = executor.inFields.get("VirtualControlLoopEvent");
-executor.logger.info(clEvent.toString());
-executor.logger.info(clEvent.getClosedLoopControlName());
+var serviceInstanceId = clEvent.getAai().get(
+ "service-information.hsia-cfs-service-instance-id");
var requestID = clEvent.getRequestId();
-executor.logger.info("requestID = " + requestID);
-var attachmentPoint = null;
-var serviceInstanceId = null;
+
+var jsonObj;
+var aaiUpdateResult = true;
+
+/* Get AAI URL from Configuration file. */
var AAI_URL = "localhost:8080";
+var CUSTOMER_ID = requestID;
+var SERVICE_INSTANCE_ID = serviceInstanceId;
+var resource_version;
+var HTTP_PROTOCOL = "https://";
+var results;
+var putUrl;
+var service_instance;
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"));
// read line by line
var line;
while ((line = br.readLine()) != null) {
@@ -50,106 +58,126 @@ try {
AAI_URL = str[str.length - 1];
break;
}
-
}
} catch (err) {
executor.logger.info("Failed to retrieve data " + err);
}
+
executor.logger.info("AAI_URL=>" + AAI_URL);
-if (clEvent.getAai().get("attachmentPoint") != null) {
- attachmentPoint = clEvent.getAai().get("attachmentPoint");
- executor.logger.info("attachmentPoint = " + attachmentPoint);
- serviceInstanceId = clEvent.getAai().get("service-information.hsia-cfs-service-instance-id");
- executor.logger.info("serviceInstanceId = " + serviceInstanceId);
-
- var result;
- var jsonObj;
- var prevResult = true;
-
-
- /*BBS Policy updates {{bbs-cfs-service-instance-UUID}} orchestration-status [ assigned --> created ]*/
- var json = {id: 1, someValue: "1234"};
- try {
- var urlPut = "http://" + AAI_URL + "/RestConfServer/rest/operations/policy/cpe/cpeAuthUpdate";
- result = httpPut(urlPut, JSON.stringify(json)).data;
- executor.logger.info("Data received From " + urlPut + " " +result.toString());
- repos = JSON.parse(result);
- executor.logger.info("After Parse " + result.toString());
-
- if (result == "") {
- prevResult = false;
- }
- }catch (err) {
- executor.logger.info("Failed to retrieve data " + err);
- prevResult = false;
- }
-
- /* If Success then Fill output schema */
- if (prevResult == true) {
- executor.outFields.put("result", "SUCCCESS");
- } else {
- executor.outFields.put("result", "FAILURE");
- }
-
- executor.outFields.put("requestID", requestID);
- executor.outFields.put("attachmentPoint", attachmentPoint);
- executor.outFields.put("serviceInstanceId", attachmentPoint);
- executor.logger.info(executor.outFields);
+/* Get service instance Id from AAI */
+try {
+ var urlGet = HTTP_PROTOCOL + AAI_URL +
+ "/aai/v14/nodes/service-instances/service-instance/" +
+ SERVICE_INSTANCE_ID + "?format=resource_and_url"
+ executor.logger.info("Query url" + urlGet);
+
+ result = httpGet(urlGet).data;
+ executor.logger.info("Data received From " + urlGet + " " + result.toString());
+ jsonObj = JSON.parse(result);
+
+
+ /* Retrieve the service instance id */
+ results = jsonObj['results'];
+ putUrl = results["url"];
+ service_instance = results["service-instance"];
+ resource_version = service_instance['resource-version'];
+ executor.logger.info("After Parse " + JSON.stringify(jsonObj, null, 4));
+
+ if (result == "") {
+ aaiUpdateResult = false;
+ }
+} catch (err) {
+ executor.logger.info("Failed to retrieve data " + err);
+ aaiUpdateResult = false;
}
+/* BBS Policy updates orchestration status of {{bbs-cfs-service-instance-UUID}} [ active --> assigned ] */
+var putUpddateServInstance;
+putUpddateServInstance = service_instance;
+putUpddateServInstance["orchestration-status"] = "active";
+try {
+ if (aaiUpdateResult == true) {
+ executor.logger.info("ready to putAfter Parse " + JSON.stringify(
+ putUpddateServInstance, null, 4));
+ var urlPut = HTTP_PROTOCOL + AAI_URL +
+ putUrl + "?resource_version=" + resource_version;
+ result = httpPut(urlPut, JSON.stringify(putUpddateServInstance)).data;
+ executor.logger.info("Data received From " + urlPut + " " + result.toString());
+ jsonObj = JSON.parse(result);
+ executor.logger.info("After Parse " + JSON.stringify(jsonObj, null, 4));
+
+ /* If failure to retrieve data proceed to Failure */
+ if (result == "") {
+ aaiUpdateResult = false;
+ }
+ }
+} catch (err) {
+ executor.logger.info("Failed to retrieve data " + err);
+ aaiUpdateResult = false;
+}
+if (aaiUpdateResult == true) {
+ executor.outFields.put("result", "SUCCCESS");
+} else {
+ executor.outFields.put("result", "FAILURE");
+}
+executor.logger.info(executor.outFields);
var returnValue = executor.isTrue;
executor.logger.info("End Execution ServiceUpdateStateCpeAuthTask.js");
-function httpGet(theUrl){
+function httpGet(theUrl) {
var con = new java.net.URL(theUrl).openConnection();
con.requestMethod = "GET";
return asResponse(con);
}
-function httpPost(theUrl, data, contentType){
+function httpPost(theUrl, data, contentType) {
contentType = contentType || "application/json";
var con = new java.net.URL(theUrl).openConnection();
con.requestMethod = "POST";
con.setRequestProperty("Content-Type", contentType);
- con.doOutput=true;
+ con.doOutput = true;
write(con.outputStream, data);
return asResponse(con);
}
-function httpPut(theUrl, data, contentType){
+function httpPut(theUrl, data, contentType) {
contentType = contentType || "application/json";
var con = new java.net.URL(theUrl).openConnection();
con.requestMethod = "PUT";
con.setRequestProperty("Content-Type", contentType);
- con.doOutput=true;
+ con.doOutput = true;
write(con.outputStream, data);
return asResponse(con);
}
-function asResponse(con){
+function asResponse(con) {
var d = read(con.inputStream);
- return {data : d, statusCode : con.resultCode};
+ return {
+ data: d,
+ statusCode: con.resultCode
+ };
}
-function write(outputStream, data){
+function write(outputStream, data) {
var wr = new java.io.DataOutputStream(outputStream);
wr.writeBytes(data);
wr.flush();
wr.close();
}
-function read(inputStream){
- var inReader = new java.io.BufferedReader(new java.io.InputStreamReader(inputStream));
+function read(inputStream) {
+ var inReader = new java.io.BufferedReader(new java.io.InputStreamReader(
+ inputStream));
var inputLine;
var result = new java.lang.StringBuffer();
while ((inputLine = inReader.readLine()) != null) {
- result.append(inputLine);
+ result.append(inputLine);
}
inReader.close();
return result.toString();
-}
+} \ No newline at end of file