aboutsummaryrefslogtreecommitdiffstats
path: root/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.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/SdncResourceUpdateTask.js
parentf6da9a3bafb6f4c30e7bb3accd4e17fdaaf5ce92 (diff)
parentad178d97b872542a57356dd0b24493d3fd4d925f (diff)
Merge "ONAP BBS: Apex Nomadic ONT bug fixes"
Diffstat (limited to 'examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js')
-rw-r--r--examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js140
1 files changed, 36 insertions, 104 deletions
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 033d778be..60d4efed9 100644
--- a/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js
+++ b/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js
@@ -26,7 +26,6 @@ importClass(java.nio.file.Paths);
importPackage(org.json.XML);
-
executor.logger.info("Begin Execution SdncResourceUpdateTask.js");
executor.logger.info(executor.subject.id);
executor.logger.info(executor.inFields);
@@ -36,7 +35,8 @@ var requestID = executor.inFields.get("requestID");
var serviceInstanceId = executor.inFields.get("serviceInstanceId");
var uuidType = Java.type("java.util.UUID");
-
+var wbClient = Java.type("org.onap.policy.apex.examples.bbs.WebClient");
+var client = new wbClient();
var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get(
attachmentPoint);
@@ -45,39 +45,39 @@ executor.logger.info(NomadicONTContext);
var jsonObj;
var aaiUpdateResult = true;
var SDNC_URL = "localhost:8080";
-var HTTP_PROTOCOL ="https://"
+var HTTP_PROTOCOL = "http://"
var SVC_NOTIFICATION_URL;
var putUpddateServInstance = JSON.parse(NomadicONTContext.get("aai_message"));
var input_param = JSON.parse(putUpddateServInstance['input-parameters']);
try {
var br = Files.newBufferedReader(Paths.get(
"/home/apexuser/examples/config/ONAPBBS/config.txt"));
- // read line by line
var line;
while ((line = br.readLine()) != null) {
if (line.startsWith("SDNC_URL")) {
var str = line.split("=");
SDNC_URL = str[str.length - 1];
- break;
} else if (line.startsWith("SVC_NOTIFICATION_URL")) {
var str = line.split("=");
SVC_NOTIFICATION_URL = str[str.length - 1];
- break;
+ }
+ else if (line.startsWith("SDNC_USERNAME")) {
+ var str = line.split("=");
+ SDNC_USERNAME = str[str.length - 1];
+ } else if (line.startsWith("SDNC_PASSWORD")) {
+ var str = line.split("=");
+ SDNC_PASSWORD = str[str.length - 1];
}
}
} catch (err) {
executor.logger.info("Failed to retrieve data " + err);
}
executor.logger.info("SDNC_URL " + SDNC_URL);
-executor.logger.info("input param " + JSON.stringify(input_param,
- null, 4));
var result;
var jsonObj;
var sdncUpdateResult = true;
-
-
/* BBS Policy calls SDN-C GR-API to delete AccessConnectivity VF ID */
/* Prepare Data*/
var xmlDeleteAccess = "";
@@ -85,7 +85,6 @@ try {
var br = Files.newBufferedReader(Paths.get(
"/home/apexuser/examples/config/ONAPBBS/sdnc_DeleteAccessConnectivityInstance.txt"
));
- // read line by line
var line;
while ((line = br.readLine()) != null) {
xmlDeleteAccess += line;
@@ -140,16 +139,14 @@ xmlDeleteAccess = xmlDeleteAccess.replace("vendor_value", input_param['service']
xmlDeleteAccess = xmlDeleteAccess.replace("service_id_value", getMetaValue(
putUpddateServInstance['metadata']['metadatum'],
'controller-service-id'));
-executor.logger.info("Delete Access Prfile " + xmlDeleteAccess);
+executor.logger.info(client.toPrettyString(xmlDeleteAccess, 4));
try {
var urlPost1 = HTTP_PROTOCOL + SDNC_URL +
"/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation";
- result = httpDelete(urlPost1, xmlDeleteAccess, "application/xml").data;
- executor.logger.info("Data received From " + urlPost1 + " " + result.toString());
- jsonObj = JSON.parse(result);
- executor.logger.info("After Parse " + jsonObj.toString());
-
+ result = client.httpRequest(urlPost1, "POST", xmlDeleteAccess, SDNC_USERNAME, SDNC_PASSWORD,
+ "application/xml", true, true);
+ executor.logger.info("Data received From " + urlPost1 + " " + result);
if (result == "") {
sdncUpdateResult = false;
}
@@ -158,7 +155,6 @@ try {
sdncUpdateResult = false;
}
-
/* BBS Policy calls SDN-C GR-API to create new AccessConnectivity VF */
/* Prepare Data*/
@@ -167,7 +163,6 @@ try {
var br = Files.newBufferedReader(Paths.get(
"/home/apexuser/examples/config/ONAPBBS/sdnc_CreateAccessConnectivityInstance.txt"
));
- // read line by line
var line;
while ((line = br.readLine()) != null) {
xmlCreateAccess += line;
@@ -190,7 +185,6 @@ xmlCreateAccess = xmlCreateAccess.replace("customer_id_value", input_param[
xmlCreateAccess = xmlCreateAccess.replace("customer_name_value", input_param[
'service']['globalSubscriberId']);
-
xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_inv_uuid_value",
getResourceInvariantUuid(input_param['service']['parameters'][
'resources'
@@ -226,18 +220,17 @@ xmlCreateAccess = xmlCreateAccess.replace("c_vlan_value", getMetaValue(
putUpddateServInstance['metadata']['metadatum'], 'cvlan'));
xmlCreateAccess = xmlCreateAccess.replace("access_id_value", getMetaValue(
putUpddateServInstance['metadata']['metadatum'], 'remote-id'));
-executor.logger.info("Create Access Prfile " + xmlCreateAccess);
+executor.logger.info(client.toPrettyString(xmlCreateAccess, 4));
+
try {
if (sdncUpdateResult == true) {
var urlPost2 = HTTP_PROTOCOL + SDNC_URL +
"/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation";
- result = httpPost(urlPost2, xmlCreateAccess, "application/xml").data;
- executor.logger.info("Data received From " + urlPost2 + " " + result.toString());
- jsonObj = JSON.parse(result);
- executor.logger.info("After Parse " + jsonObj.toString());
-
+ result = client.httpRequest(urlPost2, "POST", xmlCreateAccess, SDNC_USERNAME, SDNC_PASSWORD,
+ "application/xml", true, true);
+ executor.logger.info("Data received From " + urlPost2 + " " + result);
if (result == "") {
- sdncUpdateResult = false;
+ sdncUpdateResult = false;
}
}
} catch (err) {
@@ -245,15 +238,12 @@ try {
sdncUpdateResult = false;
}
-
-
/* BBS Policy calls SDN-C GR-API to create change Internet Profile */
var xmlChangeProfile = "";
try {
var br = Files.newBufferedReader(Paths.get(
"/home/apexuser/examples/config/ONAPBBS/sdnc_ChangeInternetProfileInstance.txt"
));
- // read line by line
var line;
while ((line = br.readLine()) != null) {
xmlChangeProfile += line;
@@ -304,7 +294,6 @@ xmlCreateAccess = xmlCreateAccess.replace("network_info_model_uuid_value",
xmlCreateAccess = xmlCreateAccess.replace("network_info_model_name_value",
"EdgeInternetProfile");
-
xmlChangeProfile = xmlChangeProfile.replace("vendor_value", input_param[
'service']['parameters']['requestInputs']['ont_ont_manufacturer']);
xmlChangeProfile = xmlChangeProfile.replace("service_id_value", getMetaValue(
@@ -326,16 +315,15 @@ xmlChangeProfile = xmlChangeProfile.replace("s_vlan_value", getMetaValue(
putUpddateServInstance['metadata']['metadatum'], 'svlan'));
xmlChangeProfile = xmlChangeProfile.replace("c_vlan_value", getMetaValue(
putUpddateServInstance['metadata']['metadatum'], 'cvlan'));
-executor.logger.info("Change Internet Profile " + xmlChangeProfile);
+executor.logger.info(client.toPrettyString(xmlChangeProfile, 4));
try {
if (sdncUpdateResult == true) {
- var urlPost3 = HTTP_PROTOCOL + SDNC_URL + "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation";
- result = httpPost(urlPost3, xmlChangeProfile, "application/xml").data;
- executor.logger.info("Data received From " + urlPost3 + " " + result.toString());
- jsonObj = JSON.parse(result);
- executor.logger.info("After Parse " + jsonObj.toString());
-
+ 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", true, true);
+ executor.logger.info("Data received From " + urlPost3 + " " + result);
if (result == "") {
sdncUpdateResult = false;
}
@@ -345,16 +333,16 @@ try {
sdncUpdateResult = false;
}
-
/* If Success then Fill output schema */
if (sdncUpdateResult === true) {
NomadicONTContext.put("result", "SUCCESS");
+ executor.outFields.put("result", "SUCCESS");
} else {
NomadicONTContext.put("result", "FAILURE");
+ executor.outFields.put("result", "FAILURE");
}
-
executor.outFields.put("requestID", requestID);
executor.outFields.put("attachmentPoint", attachmentPoint);
executor.outFields.put("serviceInstanceId", executor.inFields.get(
@@ -364,7 +352,6 @@ var returnValue = executor.isTrue;
executor.logger.info(executor.outFields);
executor.logger.info("End Execution SdncResourceUpdateTask.js");
-
function getMetaValue(metaJson, metaname) {
for (var i = 0; i < metaJson.length; i++) {
if (metaJson[i]['metaname'] == metaname) {
@@ -406,67 +393,12 @@ function getResourceCustomizationUuid(resJson, resourceName) {
}
/* Utility functions Begin */
-function httpGet(theUrl) {
- var con = new java.net.URL(theUrl).openConnection();
- con.requestMethod = "GET";
- return asresult(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 asresult(con);
-}
-
-function httpDelete(theUrl, data, contentType) {
- contentType = contentType || "application/json";
- var con = new java.net.URL(theUrl).openConnection();
- con.requestMethod = "DELETE";
- con.setRequestProperty("Content-Type", contentType);
- con.doOutput = true;
- write(con.outputStream, data);
- return asresult(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 asresult(con);
-}
-
-function asresult(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();
+function IsValidJSONString(str) {
+ try {
+ JSON.parse(str);
+ } catch (e) {
+ return false;
}
- /* Utility functions End */ \ No newline at end of file
+ return true;
+}
+/* Utility functions End */ \ No newline at end of file