diff options
author | s00370346 <swarup.nayak1@huawei.com> | 2019-05-03 11:40:28 +0530 |
---|---|---|
committer | s00370346 <swarup.nayak1@huawei.com> | 2019-05-03 19:08:01 +0530 |
commit | 27bace73bcc915aac85b48d7857cce2b26a44644 (patch) | |
tree | f510a00ecdd462dd86c6dbbaea292c6064181e17 /examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js | |
parent | 62bc4a162b169971349bce415f97ace15c15eeef (diff) |
ONAP BBS Policy: CPE-Authentication event throwing error
Issue-ID: POLICY-1734
Change-Id: I8d209afb67e9b46a7db516fce76977e679d7ab7b
Signed-off-by: s00370346 <swarup.nayak1@huawei.com>
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.js | 78 |
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 |