diff options
author | s00370346 <swarup.nayak1@huawei.com> | 2019-04-17 23:32:08 +0530 |
---|---|---|
committer | s00370346 <swarup.nayak1@huawei.com> | 2019-04-22 10:20:54 +0530 |
commit | 39f7edcc4a181394b8895aef8b4b43a8a19b045b (patch) | |
tree | bb6445f96fcea9abf7391c45a29735b93bdc683c /examples/examples-onap-bbs/src/main/resources/logic | |
parent | e5f139e3c865eb429dc11a987ad7a01b759c6692 (diff) |
ONAP BBS: Apex Nomadic ONT bug fixes
Issue-ID: DCAEGEN2-1237
Change-Id: I739f8e55113793f5cd4d3b70e0a1296d775bb414
Signed-off-by: s00370346 <swarup.nayak1@huawei.com>
Diffstat (limited to 'examples/examples-onap-bbs/src/main/resources/logic')
10 files changed, 646 insertions, 292 deletions
diff --git a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js index f488c27bf..744b6d48b 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js @@ -17,7 +17,6 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - load("nashorn:mozilla_compat.js"); importClass(org.apache.avro.Schema); importClass(java.io.BufferedReader); @@ -33,8 +32,9 @@ var attachmentPoint = executor.inFields.get("attachmentPoint"); var requestID = executor.inFields.get("requestID"); var serviceInstanceId = executor.inFields.get("serviceInstanceId"); -var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get(attachmentPoint); -executor.logger.info(vcpeClosedLoopStatus); +var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get( + attachmentPoint); +executor.logger.info(NomadicONTContext); var jsonObj; var aaiUpdateResult = true; @@ -42,14 +42,16 @@ var aaiUpdateResult = true; /* Get AAI URL from Configuration 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; +var SERVICE_INSTANCE_ID = serviceInstanceId; var resource_version; var relationship_list; -var orchStatus; +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) { @@ -63,12 +65,13 @@ try { executor.logger.info("Failed to retrieve data " + err); } -executor.logger.info("AAI_URL=>" + AAI_URL); +executor.logger.info("AAI_URL " + AAI_URL); /* Get service instance Id from AAI */ try { - //var urlGet = "https://" + AAI_URL + "/aai/v14/business/customers/customer/" + CUSTOMER_ID + "/service-subscriptions/service-subscription/" + BBS_CFS_SERVICE_TYPE + "/service-instances/service-instance/" + SERVICE_INSTANCE_UUID - var urlGet = "http://" + AAI_URL + "/RestConfServer/rest/operations/policy/su1/getService"; + 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; @@ -77,34 +80,34 @@ try { /* Retrieve the service instance id */ - service_instance_id = jsonObj['service-instance-id']; - resource_version = jsonObj['resource-version']; - relationship_list = jsonObj['relationship-list']; + results = jsonObj['results']; + putUrl = results["url"]; + service_instance = results["service-instance"]; + service_instance_id = service_instance['service-instance-id']; + resource_version = service_instance['resource-version']; + relationship_list = service_instance['relationship-list']; executor.logger.info("After Parse " + JSON.stringify(jsonObj, null, 4)); if (result == "") { aaiUpdateResult = false; } -}catch (err) { +} 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 ] */ -orchStatus = { - "service-instance-id": service_instance_id, - "resource-version": resource_version, - "orchestration-status": "assigned", - "relationship-list": relationship_list - }; +var putUpddateServInstance; +putUpddateServInstance = service_instance; try { if (aaiUpdateResult == true) { - executor.logger.info("ready to putAfter Parse " + JSON.stringify(orchStatus, null, 4)); - - //var urlPut = "https://" + AAI_URL + "/aai/v14/business/customers/customer/" + CUSTOMER_ID + "/service-subscriptions/service-subscription/" + BBS_CFS_SERVICE_TYPE + "/service-instances/service-instance/" + SERVICE_INSTANCE_UUID; - var urlPut = "http://" + AAI_URL + "/RestConfServer/rest/operations/policy/su1/putOrchStatus"; - result = httpPut(urlPut, JSON.stringify(orchStatus)).data; - executor.logger.info("Data received From " + urlPut + " " +result.toString()); + putUpddateServInstance["orchestration-status"] = "active"; + 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)); @@ -113,98 +116,83 @@ try { aaiUpdateResult = false; } } -}catch (err) { +} catch (err) { executor.logger.info("Failed to retrieve data " + err); aaiUpdateResult = false; } -/* BBS Policy fetches from AAI {{bbs-cfs-service-instance-UUID}} relationship-list, including: CPE PNF ID, AccessConnectivity VF ID, InternetProfile VF ID */ -try { - if (aaiUpdateResult == true) { - var urlGet2 = "http://" + AAI_URL + "/RestConfServer/rest/operations/policy/su1/getHsia"; - //var urlGet2 = "https://"+ AAI_URL + "/aai/v11/business/customers/customer/" + CUSTOMER_ID + "/service-subscriptions/service-subscription/" + BBS_CFS_SERVICE_TYPE +"/service-instances/service-instance/"+ SERVICE_INSTANCE_UUID + "?depth=all" - result = httpGet(urlGet2).data; - executor.logger.info("Data received From " + urlGet2 + " " +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 == "") || (jsonObj['orchestration-status'] != 'assigned')) { - executor.logger.info("Failed to get assigned status "); - aaiUpdateResult = false; - } - } -}catch (err) { - executor.logger.info("Failed to retrieve data " + err); - aaiUpdateResult = false; -} /* If Success then Fill output schema */ if (aaiUpdateResult === true) { - vcpeClosedLoopStatus.put("result", "SUCCESS"); - vcpeClosedLoopStatus.put("aai_message", JSON.stringify(orchStatus)); + NomadicONTContext.put("result", "SUCCESS"); + NomadicONTContext.put("aai_message", JSON.stringify(service_instance)); + NomadicONTContext.put("url", putUrl); } else { - vcpeClosedLoopStatus.put("result", "FAILURE"); + NomadicONTContext.put("result", "FAILURE"); } executor.outFields.put("requestID", requestID); executor.outFields.put("attachmentPoint", attachmentPoint); -executor.outFields.put("serviceInstanceId", executor.inFields.get("serviceInstanceId")); +executor.outFields.put("serviceInstanceId", executor.inFields.get( + "serviceInstanceId")); var returnValue = executor.isTrue; -executor.logger.info("==========>" + executor.outFields); +executor.logger.info(executor.outFields); executor.logger.info("End Execution AAIServiceAssignedTask.js"); /* Utility functions Begin */ -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(); } -/* Utility functions End */ - +/* Utility functions End */
\ No newline at end of file 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 e4f22369c..9ddc91e8c 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js @@ -37,9 +37,11 @@ var AAI_URL = "localhost:8080"; var CUSTOMER_ID = requestID; var BBS_CFS_SERVICE_TYPE = "BBS-CFS-Access_Test"; var SERVICE_INSTANCE_UUID = serviceInstanceId; +var HTTP_PROTOCOL = "https://"; 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) { @@ -53,106 +55,118 @@ try { } catch (err) { executor.logger.info("Failed to retrieve data " + err); } -executor.logger.info("AAI_URL=>" + AAI_URL); +executor.logger.info("AAI_URL " + AAI_URL); var attachmentPoint = executor.inFields.get("attachmentPoint"); var requestID = executor.inFields.get("requestID"); var serviceInstanceId = executor.inFields.get("serviceInstanceId"); -var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get(attachmentPoint); -executor.logger.info(vcpeClosedLoopStatus); +var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get( + attachmentPoint); +executor.logger.info(NomadicONTContext); -var jsonObj = JSON.parse(vcpeClosedLoopStatus.get("aai_message")); - -jsonObj['orchestration-status'] = "created"; -executor.logger.info(" string" + JSON.stringify(jsonObj, null, 4)); +var putUpddateServInstance = JSON.parse(NomadicONTContext.get("aai_message")); +putUpddateServInstance['orchestration-status'] = "created"; +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 { - //var urlPut = "https://" + AAI_URL + "/aai/v14/business/customers/customer/" + CUSTOMER_ID + "/service-subscriptions/service-subscription/" + BBS_CFS_SERVICE_TYPE + "/service-instances/service-instance/" + SERVICE_INSTANCE_UUID; - var urlPut = "http://" + AAI_URL + "/RestConfServer/rest/operations/policy/su2/aaiUpdate"; - result = httpPut(urlPut, JSON.stringify(jsonObj)).data; - executor.logger.info("Data received From " + urlPut + " " +result.toString()); - repos = JSON.parse(result); - executor.logger.info("After Parse " + result.toString()); - - if (result == "") { - aaiUpdateResult = false; + 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) { +} catch (err) { executor.logger.info("Failed to retrieve data " + err); aaiUpdateResult = false; } - /* If Success then Fill output schema */ if (aaiUpdateResult === true) { - vcpeClosedLoopStatus.put("result", "SUCCESS"); + NomadicONTContext.put("result", "SUCCESS"); } else { - vcpeClosedLoopStatus.put("result", "FAILURE"); + NomadicONTContext.put("result", "FAILURE"); } executor.outFields.put("requestID", requestID); executor.outFields.put("attachmentPoint", attachmentPoint); -executor.outFields.put("serviceInstanceId", executor.inFields.get("serviceInstanceId")); +executor.outFields.put("serviceInstanceId", executor.inFields.get( + "serviceInstanceId")); var returnValue = executor.isTrue; -executor.logger.info("==========>" + executor.outFields); +executor.logger.info(executor.outFields); executor.logger.info("End Execution AAIServiceCreateTask.js"); +/* Utility functions Begin */ -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(); } - +/* Utility functions End */
\ No newline at end of file diff --git a/examples/examples-onap-bbs/src/main/resources/logic/ErrorAAIServiceAssignedLogTask.js b/examples/examples-onap-bbs/src/main/resources/logic/ErrorAAIServiceAssignedLogTask.js index ee646fa36..91316bc40 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/ErrorAAIServiceAssignedLogTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/ErrorAAIServiceAssignedLogTask.js @@ -17,7 +17,6 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - executor.logger.info("Begin Execution ErrorServiceUpdateOneLogTask.js"); executor.logger.info(executor.subject.id); executor.logger.info(executor.inFields); diff --git a/examples/examples-onap-bbs/src/main/resources/logic/ErrorSdncResourceUpdateTaskLogTask.js b/examples/examples-onap-bbs/src/main/resources/logic/ErrorSdncResourceUpdateTaskLogTask.js index 19a61cabd..7ba674553 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/ErrorSdncResourceUpdateTaskLogTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/ErrorSdncResourceUpdateTaskLogTask.js @@ -17,7 +17,6 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - executor.logger.info("Begin Execution ErrorResourceUpdateLogTask.js"); executor.logger.info(executor.subject.id); executor.logger.info(executor.inFields); diff --git a/examples/examples-onap-bbs/src/main/resources/logic/GetBBSCloseLoopEventTask.js b/examples/examples-onap-bbs/src/main/resources/logic/GetBBSCloseLoopEventTask.js index 06b11acd5..57fe182e1 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/GetBBSCloseLoopEventTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/GetBBSCloseLoopEventTask.js @@ -17,7 +17,6 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - load("nashorn:mozilla_compat.js"); executor.logger.info("Begin Execution GetBBSCloseLoopEventTask.js"); @@ -25,9 +24,8 @@ 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()); @@ -35,65 +33,80 @@ executor.logger.info(clEvent.getClosedLoopControlName()); var requestID = clEvent.getRequestId(); executor.logger.info("requestID = " + requestID); var attachmentPoint = null; -var vcpeClosedLoopStatus = null; +var NomadicONTContext = null; var serviceInstanceId = null; if (clEvent.getAai().get("attachmentPoint") != null) { - attachmentPoint = clEvent.getAai().get("attachmentPoint"); - executor.logger.info("attachmentPoint = " + attachmentPoint); - vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get(attachmentPoint); - serviceInstanceId = clEvent.getAai().get("service-information.hsia-cfs-service-instance-id"); - executor.logger.info("serviceInstanceId = " + serviceInstanceId); - - if (vcpeClosedLoopStatus == null) { - executor.logger.info("Creating context information for new ONT Device \"" + attachmentPoint.toString() + "\""); - - vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").getSchemaHelper().createNewInstance(); - - vcpeClosedLoopStatus.put("closedLoopControlName", clEvent.getClosedLoopControlName()); - vcpeClosedLoopStatus.put("closedLoopAlarmStart", clEvent.getClosedLoopAlarmStart().toEpochMilli()); - vcpeClosedLoopStatus.put("closedLoopEventClient", clEvent.getClosedLoopEventClient()); - vcpeClosedLoopStatus.put("closedLoopEventStatus", clEvent.getClosedLoopEventStatus().toString()); - vcpeClosedLoopStatus.put("version", clEvent.getVersion()); - vcpeClosedLoopStatus.put("requestID", clEvent.getRequestId().toString()); - vcpeClosedLoopStatus.put("target_type", clEvent.getTargetType().toString()); - vcpeClosedLoopStatus.put("target", clEvent.getTarget()); - vcpeClosedLoopStatus.put("from", clEvent.getFrom()); - vcpeClosedLoopStatus.put("policyScope", "Nomadic ONT"); - vcpeClosedLoopStatus.put("policyName", clEvent.getPolicyName()); - vcpeClosedLoopStatus.put("policyVersion", "1.0.0"); - vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); - vcpeClosedLoopStatus.put("message", ""); - vcpeClosedLoopStatus.put("result", "SUCCESS"); - var aaiInfo = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").getSchemaHelper().createNewSubInstance("VCPE_AAI_Type"); - - aaiInfo.put("attachmentPoint", clEvent.getAai().get("attachmentPoint")); - aaiInfo.put("cvlan", clEvent.getAai().get("cvlan")); - aaiInfo.put("service_information_hsia_cfs_service_instance_id", clEvent.getAai().get("service-information.hsia-cfs-service-instance-id")); - aaiInfo.put("svlan", clEvent.getAai().get("svlan")); - aaiInfo.put("remoteId", clEvent.getAai().get("remoteId")); - - - vcpeClosedLoopStatus.put("AAI", aaiInfo); - - if (clEvent.getClosedLoopAlarmEnd() != null) { - vcpeClosedLoopStatus.put("closedLoopAlarmEnd", clEvent.getClosedLoopAlarmEnd().toEpochMilli()); - } else { - vcpeClosedLoopStatus.put("closedLoopAlarmEnd", java.lang.Long.valueOf(0)); - } - - executor.getContextAlbum("VCPEClosedLoopStatusAlbum").put(attachmentPoint.toString(), vcpeClosedLoopStatus); - executor.logger.info("Created context information for new vCPE VNF \"" + attachmentPoint.toString() + "\""); - } - - executor.outFields.put("requestID", requestID); - executor.outFields.put("attachmentPoint", attachmentPoint); - executor.outFields.put("serviceInstanceId", attachmentPoint); - executor.logger.info(executor.outFields); + attachmentPoint = clEvent.getAai().get("attachmentPoint"); + executor.logger.info("attachmentPoint = " + attachmentPoint); + NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get( + attachmentPoint); + serviceInstanceId = clEvent.getAai().get( + "service-information.hsia-cfs-service-instance-id"); + executor.logger.info("serviceInstanceId = " + serviceInstanceId); + + if (NomadicONTContext == null) { + executor.logger.info( + "Creating context information for new ONT Device \"" + + attachmentPoint.toString() + "\""); + + NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").getSchemaHelper() + .createNewInstance(); + + NomadicONTContext.put("closedLoopControlName", clEvent.getClosedLoopControlName()); + NomadicONTContext.put("closedLoopAlarmStart", clEvent.getClosedLoopAlarmStart() + .toEpochMilli()); + NomadicONTContext.put("closedLoopEventClient", clEvent.getClosedLoopEventClient()); + NomadicONTContext.put("closedLoopEventStatus", clEvent.getClosedLoopEventStatus() + .toString()); + NomadicONTContext.put("version", clEvent.getVersion()); + NomadicONTContext.put("requestID", clEvent.getRequestId().toString()); + NomadicONTContext.put("target_type", clEvent.getTargetType().toString()); + NomadicONTContext.put("target", clEvent.getTarget()); + NomadicONTContext.put("from", clEvent.getFrom()); + NomadicONTContext.put("policyScope", "Nomadic ONT"); + NomadicONTContext.put("policyName", clEvent.getPolicyName()); + NomadicONTContext.put("policyVersion", "1.0.0"); + NomadicONTContext.put("notificationTime", java.lang.System.currentTimeMillis()); + NomadicONTContext.put("message", ""); + NomadicONTContext.put("result", "SUCCESS"); + var aaiInfo = executor.getContextAlbum("NomadicONTContextAlbum").getSchemaHelper() + .createNewSubInstance("VCPE_AAI_Type"); + + aaiInfo.put("attachmentPoint", clEvent.getAai().get("attachmentPoint")); + aaiInfo.put("cvlan", clEvent.getAai().get("cvlan")); + aaiInfo.put("service_information_hsia_cfs_service_instance_id", clEvent + .getAai().get( + "service-information.hsia-cfs-service-instance-id")); + aaiInfo.put("svlan", clEvent.getAai().get("svlan")); + aaiInfo.put("remoteId", clEvent.getAai().get("remoteId")); + + + NomadicONTContext.put("AAI", aaiInfo); + + if (clEvent.getClosedLoopAlarmEnd() != null) { + NomadicONTContext.put("closedLoopAlarmEnd", clEvent.getClosedLoopAlarmEnd() + .toEpochMilli()); + } else { + NomadicONTContext.put("closedLoopAlarmEnd", java.lang.Long.valueOf( + 0)); + } + + executor.getContextAlbum("NomadicONTContextAlbum").put(attachmentPoint.toString(), + NomadicONTContext); + executor.logger.info("Created context information for new vCPE VNF \"" + + attachmentPoint.toString() + "\""); + } + + executor.outFields.put("requestID", requestID); + executor.outFields.put("attachmentPoint", attachmentPoint); + executor.outFields.put("serviceInstanceId", serviceInstanceId); + executor.logger.info(executor.outFields); + executor.logger.info("Event Successfully Received and stored in album"); +} +else +{ + executor.message = "Received NULL attachment-point"; + returnValue = executor.isFalse; } - -executor.logger.info("********************* Event Successfully Received and stored in album *********************"); - -//**************************************************************************// - diff --git a/examples/examples-onap-bbs/src/main/resources/logic/NomadicEventSuccessTask.js b/examples/examples-onap-bbs/src/main/resources/logic/NomadicEventSuccessTask.js index f6a7c4ce7..36b21b8f4 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/NomadicEventSuccessTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/NomadicEventSuccessTask.js @@ -25,22 +25,23 @@ executor.logger.info(executor.subject.id); executor.logger.info(executor.inFields); var attachmentPoint = executor.inFields.get("attachmentPoint"); -var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get(attachmentPoint); +var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get( + attachmentPoint); -executor.logger.info("==========>" + executor.outFields); -executor.logger.info("==========>" + executor.inFields); +executor.logger.info(executor.outFields); +executor.logger.info(executor.inFields); -result = vcpeClosedLoopStatus.get("result"); +result = NomadicONTContext.get("result"); if (result === "SUCCESS") { returnValue = executor.isTrue; executor.outFields.put("result", "SUCCCESS"); - executor.logger.info("BBS policy Execution Done$$$$$$$$$$$"); + executor.logger.info("BBS policy Execution Done"); } else { - executor.logger.info("BBS policy Execution Failed$$$$$$$$$$$"); + executor.logger.info("BBS policy Execution Failed"); executor.outFields.put("result", "FAILURE"); returnValue = executor.isFalse; } var returnValue = executor.isTrue; -executor.logger.info("End Execution NomadicEventSuccess.js"); +executor.logger.info("End Execution NomadicEventSuccess.js");
\ No newline at end of file diff --git a/examples/examples-onap-bbs/src/main/resources/logic/RUorInitStateSelect.js b/examples/examples-onap-bbs/src/main/resources/logic/RUorInitStateSelect.js index 959eab772..6e609b1cc 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/RUorInitStateSelect.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/RUorInitStateSelect.js @@ -25,19 +25,21 @@ var returnValue = executor.isTrue; var result = null; var attachmentPoint = executor.inFields.get("attachmentPoint"); -var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get(attachmentPoint); +var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get( + attachmentPoint); -executor.logger.info("==========>" + executor.outFields); -executor.logger.info("==========>" + executor.inFields); +executor.logger.info(executor.outFields); +executor.logger.info(executor.inFields); -result = vcpeClosedLoopStatus.get("result"); +result = NomadicONTContext.get("result"); if (result === "SUCCESS") { executor.subject.getTaskKey("SdncResourceUpdateTask").copyTo(executor.selectedTask); } else { - executor.subject.getTaskKey("ErrorAAIServiceAssignedLogTask").copyTo(executor.selectedTask); + executor.subject.getTaskKey("ErrorAAIServiceAssignedLogTask").copyTo( + executor.selectedTask); onsetFlag = executor.isFalse; -} +} executor.logger.info("State Selected Task:" + executor.selectedTask); -executor.logger.info("End Execution RUorInitStateSelect.js"); +executor.logger.info("End Execution RUorInitStateSelect.js");
\ No newline at end of file diff --git a/examples/examples-onap-bbs/src/main/resources/logic/SU2orInitStateSelect.js b/examples/examples-onap-bbs/src/main/resources/logic/SU2orInitStateSelect.js index 6b4c4ff34..214a76fe8 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/SU2orInitStateSelect.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/SU2orInitStateSelect.js @@ -17,7 +17,6 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - executor.logger.info("Begin Execution SU2orInitStateSelect.js"); executor.logger.info(executor.subject.id); executor.logger.info(executor.inFields); @@ -26,19 +25,21 @@ var returnValue = executor.isTrue; var result = null; var attachmentPoint = executor.inFields.get("attachmentPoint"); -var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get(attachmentPoint); +var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get( + attachmentPoint); -executor.logger.info("==========>" + executor.outFields); -executor.logger.info("==========>" + executor.inFields); +executor.logger.info(executor.outFields); +executor.logger.info(executor.inFields); -result = vcpeClosedLoopStatus.get("result"); +result = NomadicONTContext.get("result"); if (result === "SUCCESS") { executor.subject.getTaskKey("AAIServiceCreateTask").copyTo(executor.selectedTask); } else { - executor.subject.getTaskKey("SdncResourceUpdateErrorLogOutput").copyTo(executor.selectedTask); + executor.subject.getTaskKey("SdncResourceUpdateErrorLogOutput").copyTo( + executor.selectedTask); onsetFlag = executor.isFalse; } executor.logger.info("State Selected Task:" + executor.selectedTask); -executor.logger.info("End Execution RUorInitStateSelect.js");
\ No newline at end of file +executor.logger.info("End Execution SU2orInitStateSelect.js");
\ No newline at end of file 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 6a302ea6a..033d778be 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js @@ -17,13 +17,16 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ - load("nashorn:mozilla_compat.js"); importClass(org.apache.avro.Schema); importClass(java.io.BufferedReader); importClass(java.io.IOException); importClass(java.nio.file.Files); 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); @@ -31,14 +34,24 @@ executor.logger.info(executor.inFields); var attachmentPoint = executor.inFields.get("attachmentPoint"); var requestID = executor.inFields.get("requestID"); var serviceInstanceId = executor.inFields.get("serviceInstanceId"); +var uuidType = Java.type("java.util.UUID"); -var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get(attachmentPoint); -executor.logger.info(vcpeClosedLoopStatus); + + +var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get( + attachmentPoint); +var sdncUUID = uuidType.randomUUID(); +executor.logger.info(NomadicONTContext); var jsonObj; var aaiUpdateResult = true; var SDNC_URL = "localhost:8080"; +var HTTP_PROTOCOL ="https://" +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")); + var br = Files.newBufferedReader(Paths.get( + "/home/apexuser/examples/config/ONAPBBS/config.txt")); // read line by line var line; while ((line = br.readLine()) != null) { @@ -46,118 +59,414 @@ try { 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; } } } catch (err) { executor.logger.info("Failed to retrieve data " + err); } -executor.logger.info("SDNC_URL=>" + SDNC_URL); - +executor.logger.info("SDNC_URL " + SDNC_URL); +executor.logger.info("input param " + JSON.stringify(input_param, + null, 4)); var result; var jsonObj; -var aaiUpdateResult = true; +var sdncUpdateResult = true; + + /* BBS Policy calls SDN-C GR-API to delete AccessConnectivity VF ID */ -var json = {id: 1, someValue: "1234"}; +/* Prepare Data*/ +var xmlDeleteAccess = ""; +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; + } + +} catch (err) { + executor.logger.info("Failed to retrieve data " + err); +} + +/* BBS Policy calls SDN-C GR-API to delete AccessConnectivity */ +xmlDeleteAccess = xmlDeleteAccess.replace("svc_request_id_value", sdncUUID); +xmlDeleteAccess = xmlDeleteAccess.replace("svc_notification_url_value", + SVC_NOTIFICATION_URL); +xmlDeleteAccess = xmlDeleteAccess.replace("request_id_value", sdncUUID); +xmlDeleteAccess = xmlDeleteAccess.replace("service_id_value", sdncUUID); +xmlDeleteAccess = xmlDeleteAccess.replace("service_instance_id_value", + putUpddateServInstance['service-instance-id']); +xmlDeleteAccess = xmlDeleteAccess.replace("service_type_value", input_param[ + 'service']['serviceType']); +xmlDeleteAccess = xmlDeleteAccess.replace("customer_id_value", input_param[ + 'service']['globalSubscriberId']); +xmlDeleteAccess = xmlDeleteAccess.replace("customer_name_value", input_param[ + 'service']['globalSubscriberId']); + +xmlDeleteAccess = xmlDeleteAccess.replace("srv_info_model_inv_uuid_value", + getResourceInvariantUuid(input_param['service']['parameters'][ + 'resources' + ], 'OLT')); +xmlDeleteAccess = xmlDeleteAccess.replace("srv_info_model_custom_uuid_value", + getResourceCustomizationUuid(input_param['service']['parameters'][ + 'resources' + ], 'OLT')); +xmlDeleteAccess = xmlDeleteAccess.replace("srv_info_model_uuid_value", + getResourceUuid(input_param['service']['parameters']['resources'], + 'OLT')); +xmlDeleteAccess = xmlDeleteAccess.replace("srv_info_model_name_value", "OLT"); +xmlDeleteAccess = xmlDeleteAccess.replace("network_info_model_inv_uuid_value", + getResourceInvariantUuid(input_param['service']['parameters'][ + 'resources' + ], 'OLT')); +xmlDeleteAccess = xmlDeleteAccess.replace( + "network_info_model_custom_uuid_value", getResourceCustomizationUuid( + input_param['service']['parameters']['resources'], 'OLT')); +xmlDeleteAccess = xmlDeleteAccess.replace("network_info_model_uuid_value", + getResourceUuid(input_param['service']['parameters']['resources'], + 'OLT')); +xmlDeleteAccess = xmlDeleteAccess.replace("network_info_model_name_value", + "OLT"); + +xmlDeleteAccess = xmlDeleteAccess.replace("vendor_value", input_param['service'] + ['parameters']['requestInputs']['ont_ont_manufacturer']); +xmlDeleteAccess = xmlDeleteAccess.replace("service_id_value", getMetaValue( + putUpddateServInstance['metadata']['metadatum'], + 'controller-service-id')); +executor.logger.info("Delete Access Prfile " + xmlDeleteAccess); + try { - var urlPost1 = "http://" + SDNC_URL + "/RestConfServer/rest/operations/policy/ru/createInstance"; - result = httpPost(urlPost1, JSON.stringify(json) ,"application/json").data; - executor.logger.info("Data received From " + urlPost1 + " " +result.toString()); + 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()); if (result == "") { - aaiUpdateResult = false; + sdncUpdateResult = false; } -}catch (err) { +} catch (err) { executor.logger.info("Failed to retrieve data " + err); - aaiUpdateResult = false; + sdncUpdateResult = false; } + + /* BBS Policy calls SDN-C GR-API to create new AccessConnectivity VF */ + +/* Prepare Data*/ +var xmlCreateAccess = ""; try { - if (aaiUpdateResult == true) { - var json = {id: 2, someValue: "1234"}; - var urlPost2 = "http://" + SDNC_URL + "/RestConfServer/rest/operations/policy/ru/createInstance"; - result = httpPost(urlPost2, JSON.stringify(json), "application/json").data; - executor.logger.info("Data received From " + urlPost2 + " " +result.toString()); + 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; + } + +} catch (err) { + executor.logger.info("Failed to retrieve data " + err); +} +xmlCreateAccess = xmlCreateAccess.replace("svc_request_id_value", sdncUUID); +xmlCreateAccess = xmlCreateAccess.replace("svc_notification_url_value", + SVC_NOTIFICATION_URL); +xmlCreateAccess = xmlCreateAccess.replace("request_id_value", requestID); +xmlCreateAccess = xmlCreateAccess.replace("service_id_value", sdncUUID); +xmlCreateAccess = xmlCreateAccess.replace("service_instance_id_value", + putUpddateServInstance['service-instance-id']); +xmlCreateAccess = xmlCreateAccess.replace("service_type_value", input_param[ + 'service']['serviceType']); +xmlCreateAccess = xmlCreateAccess.replace("customer_id_value", input_param[ + 'service']['globalSubscriberId']); +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' + ], 'OLT')); +xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_custom_uuid_value", + getResourceCustomizationUuid(input_param['service']['parameters'][ + 'resources' + ], 'OLT')); +xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_uuid_value", + getResourceUuid(input_param['service']['parameters']['resources'], + 'OLT')); +xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_name_value", "OLT"); +xmlCreateAccess = xmlCreateAccess.replace("network_info_model_inv_uuid_value", + getResourceInvariantUuid(input_param['service']['parameters'][ + 'resources' + ], 'OLT')); +xmlCreateAccess = xmlCreateAccess.replace( + "network_info_model_custom_uuid_value", getResourceCustomizationUuid( + input_param['service']['parameters']['resources'], 'OLT')); +xmlCreateAccess = xmlCreateAccess.replace("network_info_model_uuid_value", + getResourceUuid(input_param['service']['parameters']['resources'], + 'OLT')); +xmlCreateAccess = xmlCreateAccess.replace("network_info_model_name_value", + "OLT"); + +xmlCreateAccess = xmlCreateAccess.replace("vendor_value", input_param['service'] + ['parameters']['requestInputs']['ont_ont_manufacturer']); +xmlCreateAccess = xmlCreateAccess.replace("ont_sn_value", input_param['service'] + ['parameters']['requestInputs']['ont_ont_serial_num']); +xmlCreateAccess = xmlCreateAccess.replace("s_vlan_value", getMetaValue( + putUpddateServInstance['metadata']['metadatum'], 'svlan')); +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); +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()); if (result == "") { + sdncUpdateResult = false; } } -}catch (err) { +} catch (err) { executor.logger.info("Failed to retrieve data " + err); - aaiUpdateResult = false; + 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; + } + +} catch (err) { + executor.logger.info("Failed to retrieve data " + err); +} + +xmlChangeProfile = xmlChangeProfile.replace("svc_request_id_value", sdncUUID); +xmlChangeProfile = xmlChangeProfile.replace("svc_notification_url_value", + SVC_NOTIFICATION_URL); +xmlChangeProfile = xmlChangeProfile.replace("request_id_value", requestID); +xmlChangeProfile = xmlChangeProfile.replace("service_id_value", sdncUUID); +xmlChangeProfile = xmlChangeProfile.replace("service_instance_id_value", + putUpddateServInstance['service-instance-id']); +xmlChangeProfile = xmlChangeProfile.replace("service_type_value", input_param[ + 'service']['serviceType']); +xmlChangeProfile = xmlChangeProfile.replace("customer_id_value", input_param[ + 'service']['globalSubscriberId']); +xmlChangeProfile = xmlChangeProfile.replace("customer_name_value", input_param[ + 'service']['globalSubscriberId']); + +xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_inv_uuid_value", + getResourceInvariantUuid(input_param['service']['parameters'][ + 'resources' + ], 'EdgeInternetProfile')); +xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_custom_uuid_value", + getResourceCustomizationUuid(input_param['service']['parameters'][ + 'resources' + ], 'EdgeInternetProfile')); +xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_uuid_value", + getResourceUuid(input_param['service']['parameters']['resources'], + 'EdgeInternetProfile')); +xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_name_value", + "EdgeInternetProfile"); +xmlCreateAccess = xmlCreateAccess.replace("network_info_model_inv_uuid_value", + getResourceInvariantUuid(input_param['service']['parameters'][ + 'resources' + ], 'EdgeInternetProfile')); +xmlCreateAccess = xmlCreateAccess.replace( + "network_info_model_custom_uuid_value", getResourceCustomizationUuid( + input_param['service']['parameters']['resources'], + 'EdgeInternetProfile')); +xmlCreateAccess = xmlCreateAccess.replace("network_info_model_uuid_value", + getResourceUuid(input_param['service']['parameters']['resources'], + 'EdgeInternetProfile')); +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( + putUpddateServInstance['metadata']['metadatum'], + 'controller-service-id')); +xmlChangeProfile = xmlChangeProfile.replace("access_id_value", getMetaValue( + putUpddateServInstance['metadata']['metadatum'], 'remote-id')); +xmlChangeProfile = xmlChangeProfile.replace("ont_sn_value", input_param[ + 'service']['parameters']['requestInputs']['ont_ont_serial_num']); +xmlChangeProfile = xmlChangeProfile.replace("service_type_value", input_param[ + 'service']['serviceType']); +xmlChangeProfile = xmlChangeProfile.replace("mac_value", getMetaValue( + putUpddateServInstance['metadata']['metadatum'], 'rgw-mac-address')); +xmlChangeProfile = xmlChangeProfile.replace("up_speed_value", getMetaValue( + putUpddateServInstance['metadata']['metadatum'], 'up-speed')); +xmlChangeProfile = xmlChangeProfile.replace("down_speed_value", getMetaValue( + putUpddateServInstance['metadata']['metadatum'], 'down-speed')); +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); + +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()); + + if (result == "") { + sdncUpdateResult = false; + } + } +} catch (err) { + executor.logger.info("Failed to retrieve data " + err); + sdncUpdateResult = false; } /* If Success then Fill output schema */ -if (aaiUpdateResult === true) { - vcpeClosedLoopStatus.put("result", "SUCCESS"); + +if (sdncUpdateResult === true) { + NomadicONTContext.put("result", "SUCCESS"); } else { - vcpeClosedLoopStatus.put("result", "FAILURE"); + NomadicONTContext.put("result", "FAILURE"); } executor.outFields.put("requestID", requestID); executor.outFields.put("attachmentPoint", attachmentPoint); -executor.outFields.put("serviceInstanceId", executor.inFields.get("serviceInstanceId")); +executor.outFields.put("serviceInstanceId", executor.inFields.get( + "serviceInstanceId")); var returnValue = executor.isTrue; -executor.logger.info("==========>" + executor.outFields); +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) { + var metaValue = metaJson[i]['metaval']; + return metaValue; + } + } + +} + +function getResourceInvariantUuid(resJson, resourceName) { + for (var i = 0; i < resJson.length; i++) { + if (resJson[i]['resourceName'] == resourceName) { + var resValue = resJson[i]['resourceInvariantUuid']; + return resValue; + } + } + +} + +function getResourceUuid(resJson, resourceName) { + for (var i = 0; i < resJson.length; i++) { + if (resJson[i]['resourceName'] == resourceName) { + var resValue = resJson[i]['resourceUuid']; + return resValue; + } + } + +} + +function getResourceCustomizationUuid(resJson, resourceName) { + for (var i = 0; i < resJson.length; i++) { + if (resJson[i]['resourceName'] == resourceName) { + var resValue = resJson[i]['resourceCustomizationUuid']; + return resValue; + } + } + +} + /* Utility functions Begin */ -function httpGet(theUrl){ +function httpGet(theUrl) { var con = new java.net.URL(theUrl).openConnection(); con.requestMethod = "GET"; return asresult(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 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){ +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 asresult(con); } -function asresult(con){ +function asresult(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)); - var inputLine; - var result = new java.lang.StringBuffer(); +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); + while ((inputLine = inReader.readLine()) != null) { + result.append(inputLine); + } + inReader.close(); + return result.toString(); } - inReader.close(); - return result.toString(); -} -/* Utility functions End */ + /* Utility functions End */
\ No newline at end of file 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 |