aboutsummaryrefslogtreecommitdiffstats
path: root/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2019-05-09 16:07:59 +0000
committerGerrit Code Review <gerrit@onap.org>2019-05-09 16:07:59 +0000
commite460bd5616557985f28da94e82eb0d2673069913 (patch)
tree0e7a5837ae82d9f49a3fcf25ea25ee36bfbbf92c /examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js
parent1f0eee7003f13f48c38145a34d3c8a78c5659912 (diff)
parent27bace73bcc915aac85b48d7857cce2b26a44644 (diff)
Merge "ONAP BBS Policy: CPE-Authentication event throwing error"
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.js78
1 files changed, 17 insertions, 61 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 86e4dfe1c..839956cc9 100644
--- a/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js
+++ b/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js
@@ -39,7 +39,8 @@ var jsonObj;
var aaiUpdateResult = true;
var wbClient = Java.type("org.onap.policy.apex.examples.bbs.WebClient");
var client = new wbClient();
-
+var oldState = clEvent.getAai().get("cpe.old-authentication-state");
+var newState = clEvent.getAai().get("cpe.new-authentication-state");
/* Get AAI URL from Configuration file. */
var AAI_URL = "localhost:8080";
var CUSTOMER_ID = requestID;
@@ -78,17 +79,20 @@ try {
SERVICE_INSTANCE_ID + "?format=resource_and_url"
executor.logger.info("Query url" + urlGet);
- result = httpGet(urlGet).data;
+ 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);
/* Retrieve the service instance id */
- results = jsonObj['results'];
+ results = jsonObj['results'][0];
putUrl = results["url"];
- service_instance = results["service-instance"];
+ service_instance = results['service-instance'];
resource_version = service_instance['resource-version'];
- executor.logger.info("After Parse " + JSON.stringify(jsonObj, null, 4));
+ 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;
@@ -101,10 +105,16 @@ try {
/* BBS Policy updates orchestration status of {{bbs-cfs-service-instance-UUID}} [ active --> assigned ] */
var putUpddateServInstance;
putUpddateServInstance = service_instance;
-putUpddateServInstance["orchestration-status"] = "active";
+if (newState == 'inService') {
+ putUpddateServInstance['orchestration-status'] = "active";
+}
+else
+{
+ putUpddateServInstance['orchestration-status'] = "inActive";
+}
try {
if (aaiUpdateResult == true) {
- executor.logger.info("ready to putAfter Parse " + JSON.stringify(
+ executor.logger.info("ready to put After Parse " + JSON.stringify(
putUpddateServInstance, null, 4));
var urlPut = HTTP_PROTOCOL + AAI_URL +
putUrl + "?resource_version=" + resource_version;
@@ -131,57 +141,3 @@ executor.logger.info(executor.outFields);
var returnValue = executor.isTrue;
executor.logger.info("End Execution ServiceUpdateStateCpeAuthTask.js");
-
-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();
-} \ No newline at end of file