summaryrefslogtreecommitdiffstats
path: root/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2019-04-29 11:43:01 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-29 11:43:01 +0000
commitb267849e414baddb1c14a4be29fc06d9703ed944 (patch)
tree1a06182611f78fcc53e9d09fe9b106c045feb234 /examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js
parentf6da9a3bafb6f4c30e7bb3accd4e17fdaaf5ce92 (diff)
parentad178d97b872542a57356dd0b24493d3fd4d925f (diff)
Merge "ONAP BBS: Apex Nomadic ONT bug fixes"
Diffstat (limited to 'examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js')
-rw-r--r--examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js141
1 files changed, 57 insertions, 84 deletions
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 9ddc91e8c..ac409ed2d 100644
--- a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js
+++ b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js
@@ -32,13 +32,20 @@ var attachmentPoint = executor.inFields.get("attachmentPoint");
var requestID = executor.inFields.get("requestID");
var serviceInstanceId = executor.inFields.get("serviceInstanceId");
+var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get(
+ attachmentPoint);
+executor.logger.info(NomadicONTContext);
+
//Get the AAI URL from configuraiotn file
var AAI_URL = "localhost:8080";
var CUSTOMER_ID = requestID;
var BBS_CFS_SERVICE_TYPE = "BBS-CFS-Access_Test";
-var SERVICE_INSTANCE_UUID = serviceInstanceId;
+var SERVICE_INSTANCE_ID = serviceInstanceId;
var HTTP_PROTOCOL = "https://";
-
+var wbClient = Java.type("org.onap.policy.apex.examples.bbs.WebClient");
+var client = new wbClient();
+var AAI_USERNAME = null;
+var AAI_PASSWORD = null;
try {
var br = Files.newBufferedReader(Paths.get(
"/home/apexuser/examples/config/ONAPBBS/config.txt"));
@@ -48,32 +55,57 @@ try {
if (line.startsWith("AAI_URL")) {
var str = line.split("=");
AAI_URL = str[str.length - 1];
- break;
+ } else if (line.startsWith("AAI_USERNAME")) {
+ var str = line.split("=");
+ AAI_USERNAME = str[str.length - 1];
+ } else if (line.startsWith("AAI_PASSWORD")) {
+ var str = line.split("=");
+ AAI_PASSWORD = str[str.length - 1];
}
-
}
} catch (err) {
executor.logger.info("Failed to retrieve data " + err);
}
executor.logger.info("AAI_URL " + AAI_URL);
+var aaiUpdateResult = true;
+/* 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 = client.httpsRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD,
+ "application/json", true, true);
+ executor.logger.info("Data received From " + urlGet + " " + result);
+ jsonObj = JSON.parse(result);
+
+ executor.logger.info(JSON.stringify(jsonObj, null, 4));
+ /* Retrieve the service instance id */
+ results = jsonObj['results'][0];
+ putUrl = results['url'];
+ service_instance = results['service-instance'];
+ 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;
+ }
+} catch (err) {
+ executor.logger.info("Failed to retrieve data " + err);
+ aaiUpdateResult = false;
+}
-
-var attachmentPoint = executor.inFields.get("attachmentPoint");
-var requestID = executor.inFields.get("requestID");
-var serviceInstanceId = executor.inFields.get("serviceInstanceId");
-
-var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get(
- attachmentPoint);
-executor.logger.info(NomadicONTContext);
-
-var putUpddateServInstance = JSON.parse(NomadicONTContext.get("aai_message"));
-
+var putUpddateServInstance = service_instance;
putUpddateServInstance['orchestration-status'] = "created";
-executor.logger.info(" string" + JSON.stringify(putUpddateServInstance, null, 4));
+if (putUpddateServInstance.hasOwnProperty('input-parameters'))
+ delete putUpddateServInstance['input-parameters'];
+executor.logger.info(" string" + JSON.stringify(putUpddateServInstance, null,
+ 4));
var resource_version = putUpddateServInstance['resource-version'];
var putUrl = NomadicONTContext.get("url");
-var aaiUpdateResult = true;
-
/*BBS Policy updates {{bbs-cfs-service-instance-UUID}} orchestration-status [ assigned --> created ]*/
try {
@@ -82,13 +114,12 @@ try {
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));
-
+ result = client.httpsRequest(urlPut, "PUT", JSON.stringify(
+ putUpddateServInstance), AAI_USERNAME, AAI_PASSWORD,
+ "application/json", true, true);
+ executor.logger.info("Data received From " + urlPut + " " + result);
/* If failure to retrieve data proceed to Failure */
- if (result == "") {
+ if (result != "") {
aaiUpdateResult = false;
}
}
@@ -101,8 +132,8 @@ if (aaiUpdateResult === true) {
NomadicONTContext.put("result", "SUCCESS");
} else {
NomadicONTContext.put("result", "FAILURE");
-}
+}
executor.outFields.put("requestID", requestID);
executor.outFields.put("attachmentPoint", attachmentPoint);
@@ -111,62 +142,4 @@ executor.outFields.put("serviceInstanceId", executor.inFields.get(
var returnValue = executor.isTrue;
executor.logger.info(executor.outFields);
-executor.logger.info("End Execution AAIServiceCreateTask.js");
-
-/* Utility functions Begin */
-
-function httpGet(theUrl) {
- var con = new java.net.URL(theUrl).openConnection();
- con.requestMethod = "GET";
- return asResponse(con);
-}
-
-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;
- write(con.outputStream, data);
- return asResponse(con);
-}
-
-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;
- write(con.outputStream, data);
- return asResponse(con);
-}
-
-function asResponse(con) {
- var d = read(con.inputStream);
- return {
- data: d,
- statusCode: con.resultCode
- };
-}
-
-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));
- var inputLine;
- var result = new java.lang.StringBuffer();
-
- while ((inputLine = inReader.readLine()) != null) {
- result.append(inputLine);
- }
- inReader.close();
- return result.toString();
-}
-
-/* Utility functions End */ \ No newline at end of file
+executor.logger.info("End Execution AAIServiceCreateTask.js"); \ No newline at end of file