aboutsummaryrefslogtreecommitdiffstats
path: root/policy/apex/logic
diff options
context:
space:
mode:
Diffstat (limited to 'policy/apex/logic')
-rw-r--r--policy/apex/logic/AAIServiceAssignedTask.js260
-rw-r--r--policy/apex/logic/AAIServiceCreateTask.js116
-rw-r--r--policy/apex/logic/ErrorAAIServiceAssignedLogTask.js29
-rw-r--r--policy/apex/logic/ErrorSdncResourceUpdateTaskLogTask.js27
-rw-r--r--policy/apex/logic/GetBBSCloseLoopEventTask.js113
-rw-r--r--policy/apex/logic/NomadicEventSuccessTask.js47
-rw-r--r--policy/apex/logic/RUorInitStateSelect.js44
-rw-r--r--policy/apex/logic/SU2orInitStateSelect.js46
-rw-r--r--policy/apex/logic/SdncResourceUpdateTask.js470
-rw-r--r--policy/apex/logic/ServiceUpdateStateCpeAuthTask.js118
10 files changed, 1270 insertions, 0 deletions
diff --git a/policy/apex/logic/AAIServiceAssignedTask.js b/policy/apex/logic/AAIServiceAssignedTask.js
new file mode 100644
index 0000000..0cb4967
--- /dev/null
+++ b/policy/apex/logic/AAIServiceAssignedTask.js
@@ -0,0 +1,260 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Huawei. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+executor.logger.info("Begin Execution AAIServiceAssignedTask.js");
+executor.logger.info(executor.subject.id);
+executor.logger.info(executor.inFields);
+
+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 jsonObj;
+var aaiUpdateResult = true;
+
+var wbClient = org.onap.policy.apex.examples.bbs.WebClient;
+var client = new wbClient();
+
+/* Get AAI URL from Configuration file. */
+var AAI_URL = "localhost:8080";
+var CUSTOMER_ID = requestID;
+var SERVICE_INSTANCE_ID = serviceInstanceId;
+var AAI_VERSION = "v14";
+var resource_version;
+var relationship_list;
+var HTTP_PROTOCOL = "https://";
+var results;
+var putUrl;
+var service_instance;
+
+AAI_URL = executor.parameters.get("AAI_URL");
+AAI_USERNAME = executor.parameters.get("AAI_USERNAME");
+AAI_PASSWORD = executor.parameters.get("AAI_PASSWORD");
+AAI_VERSION = executor.parameters.get("AAI_VERSION");
+
+executor.logger.info("AAI_URL " + AAI_URL);
+
+/* Get service instance Id from AAI */
+try {
+ var urlGet = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION + "/nodes/service-instances/service-instance/"
+ + SERVICE_INSTANCE_ID + "?format=resource_and_url";
+
+ executor.logger.info("Query url" + urlGet);
+
+ result = client.httpRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json");
+ executor.logger.info("Data received From " + urlGet + " " + result);
+ jsonObj = JSON.parse(result.toString());
+
+ 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'];
+ 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 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;
+}
+
+/* BBS Policy updates orchestration status of {{bbs-cfs-service-instance-UUID}} [ active --> assigned ] */
+var putUpddateServInstance;
+putUpddateServInstance = service_instance;
+try {
+ if (aaiUpdateResult == true) {
+ 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 = client.httpRequest(urlPut, "PUT", JSON.stringify(putUpddateServInstance), AAI_USERNAME, AAI_PASSWORD,
+ "application/json");
+ executor.logger.info("Data received From " + urlPut + " " + result);
+ /* 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 (!service_instance.hasOwnProperty('input-parameters') || !service_instance.hasOwnProperty('metadata')) {
+ aaiUpdateResult = false;
+ executor.logger.info("Validate data failed. input-parameters or metadata is missing");
+}
+
+/* update logical link in pnf */
+var oldLinkName = "";
+try {
+ if (aaiUpdateResult == true) {
+ var pnfName = "";
+ var pnfResponse;
+ var pnfUpdate;
+ var relationShips = relationship_list["relationship"];
+
+ for (var i = 0; i < relationShips.length; i++) {
+ if (relationShips[i]["related-to"] == "pnf") {
+ var relationship_data = relationShips[i]["relationship-data"];
+ for (var j = 0; j < relationship_data.length; j++) {
+ if (relationship_data[j]["relationship-key"] == "pnf.pnf-name") {
+ pnfName = relationship_data[j]['relationship-value'];
+ break;
+ }
+ }
+ }
+ }
+ executor.logger.info("pnf-name found " + pnfName);
+ /* 1. Get PNF */
+ var urlGetPnf = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION + "/network/pnfs/pnf/" + pnfName;
+ executor.logger.info("*********************** Executing call to fetch PNF");
+ pnfResponse = client.httpRequest(urlGetPnf, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json");
+ executor.logger.info("Data received From " + urlGetPnf + " >" + pnfResponse + "<");
+ /* If failure to retrieve data proceed to Failure */
+ if (!pnfResponse) {
+ executor.logger.info("*********************** Fetch PNF with relation marked it ERROR");
+ aaiUpdateResult = false;
+ }
+ pnfUpdate = JSON.parse(pnfResponse.toString());
+ executor.logger.info(JSON.stringify(pnfUpdate, null, 4));
+
+ /* 2. Create logical link */
+ var link_name = attachmentPoint;
+ var logicalLink = {};
+ logicalLink["link-name"] = String(link_name);
+ logicalLink["in-maint"] = String(false);
+ logicalLink["link-type"] = "attachment-point";
+ // var logicalLink = "{\"link-name\":\"" + link_name + "\",\"in-maint\":false, \"link-type\":\"attachment-point\"}";
+ // var logicalLink = {
+ // "link-name" : link_name,
+ // "in-maint" : false,
+ // "link-type" : "attachment-point"
+ // };
+ var urlNewLogicalLink = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION
+ + "/network/logical-links/logical-link/" + link_name;
+ executor.logger.info("URL to be used >>" + urlNewLogicalLink + "<<");
+ var logicalLinkStr = JSON.stringify(logicalLink);
+ executor.logger.info("Body to be used >>" + logicalLinkStr + "<<");
+ executor.logger.info("*********************** Executing call to create new Logical Link");
+ result = client.httpRequest(urlNewLogicalLink, "PUT", logicalLinkStr, AAI_USERNAME, AAI_PASSWORD,
+ "application/json");
+ executor.logger.info("Data received From " + urlNewLogicalLink + " >" + result + "<");
+ /* If failure to retrieve data proceed to Failure */
+ if (result != "") {
+ executor.logger.info("*********************** CREATE NEW LOGICAL LINK marked it ERROR");
+ aaiUpdateResult = false;
+ }
+
+ /* 3. Update pnf with new relation */
+ for (var i = 0; i < pnfUpdate["relationship-list"]["relationship"].length; i++) {
+ if (pnfUpdate["relationship-list"]["relationship"][i]['related-to'] == 'logical-link') {
+ pnfUpdate["relationship-list"]["relationship"][i]['related-link'] = String("/aai/" + AAI_VERSION
+ + "/network/logical-links/logical-link/" + link_name);
+ for (var j = 0; j < pnfUpdate["relationship-list"]["relationship"][i]['relationship-data'].length; j++) {
+ if (pnfUpdate["relationship-list"]["relationship"][i]['relationship-data'][j]['relationship-key'] == "logical-link.link-name") {
+ oldLinkName = pnfUpdate["relationship-list"]["relationship"][i]['relationship-data'][j]['relationship-value'];
+ pnfUpdate["relationship-list"]["relationship"][i]['relationship-data'][j]['relationship-value'] = String(link_name);
+ break;
+ }
+ }
+ break;
+ }
+ }
+ executor.logger.info("*********************** Just before calling stringify");
+ var pnfUpdateStr = JSON.stringify(pnfUpdate);
+ executor.logger.info("Put pnf to aai " + pnfUpdateStr);
+ var urlPutPnf = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION + "/network/pnfs/pnf/" + pnfName;
+ executor.logger.info("*********************** Executing call to update PNF with new relation");
+ result = client.httpRequest(urlPutPnf, "PUT", pnfUpdateStr, AAI_USERNAME, AAI_PASSWORD,
+ "application/json");
+ executor.logger.info("Data received From " + urlPutPnf + " >" + result + "<");
+
+ /* If failure to retrieve data proceed to Failure */
+ if (result != "") {
+ executor.logger.info("*********************** UPDATE PNF with relation marked it ERROR");
+ aaiUpdateResult = false;
+ }
+ /* Get and Delete the Stale logical link */
+ var oldLinkResult;
+ var linkResult;
+ var urlOldLogicalLink = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION
+ + "/network/logical-links/logical-link/" + oldLinkName;
+ executor.logger.info("*********************** Executing call to fetch old logical link");
+ linkResult = client.httpRequest(urlOldLogicalLink, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json");
+ executor.logger.info("Data received From " + urlOldLogicalLink + " " + linkResult + " "
+ + linkResult.hasOwnProperty("link-name"));
+ oldLinkResult = JSON.parse(linkResult.toString());
+ if (oldLinkResult.hasOwnProperty("link-name") == true) {
+ var res_version = oldLinkResult["resource-version"];
+ var urlDelOldLogicalLink = urlOldLogicalLink + "?resource-version=" + res_version;
+ executor.logger.info("Delete called for " + urlDelOldLogicalLink);
+ executor.logger.info("*********************** Executing call to delete old logical link");
+ result = client.httpRequest(urlDelOldLogicalLink, "DELETE", null, AAI_USERNAME, AAI_PASSWORD,
+ "application/json");
+ executor.logger.info("Delete called for " + urlDelOldLogicalLink + " result " + result);
+ }
+ }
+} catch (err) {
+ executor.logger.info("Failed to retrieve data " + err);
+ aaiUpdateResult = false;
+}
+
+/* If Success then Fill output schema */
+if (aaiUpdateResult == true) {
+ executor.outFields.put("result", "SUCCESS");
+ NomadicONTContext.put("result", "SUCCESS");
+ executor.logger.info("*********************** Just before calling stringify when output to context (service-instance)");
+ NomadicONTContext.put("aai_message", JSON.stringify(service_instance));
+ executor.logger.info("*********************** Just after calling stringify when output to context (service-instance)");
+ NomadicONTContext.put("url", putUrl);
+} else {
+ executor.outFields.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.logger.info(executor.outFields);
+executor.logger.info("End Execution AAIServiceAssignedTask.js");
+
+true;
+
+/* Utility functions Begin */
+function IsValidJSONString(str) {
+ try {
+ JSON.parse(str);
+ } catch (e) {
+ return false;
+ }
+ return true;
+}
+/* Utility functions End */
diff --git a/policy/apex/logic/AAIServiceCreateTask.js b/policy/apex/logic/AAIServiceCreateTask.js
new file mode 100644
index 0000000..d6c86c2
--- /dev/null
+++ b/policy/apex/logic/AAIServiceCreateTask.js
@@ -0,0 +1,116 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Huawei. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+executor.logger.info("Begin Execution AAIServiceCreateTask.js");
+executor.logger.info(executor.subject.id);
+executor.logger.info(executor.inFields);
+
+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_ID = serviceInstanceId;
+var AAI_VERSION = "v14";
+var HTTP_PROTOCOL = "https://";
+var wbClient = org.onap.policy.apex.examples.bbs.WebClient;
+var client = new wbClient();
+var AAI_USERNAME = null;
+var AAI_PASSWORD = null;
+AAI_URL = executor.parameters.get("AAI_URL");
+AAI_USERNAME = executor.parameters.get("AAI_USERNAME");
+AAI_PASSWORD = executor.parameters.get("AAI_PASSWORD");
+AAI_VERSION = executor.parameters.get("AAI_VERSION");
+executor.logger.info("AAI_URL " + AAI_URL);
+var aaiUpdateResult = true;
+/* Get service instance Id from AAI */
+try {
+ var urlGet = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION + "/nodes/service-instances/service-instance/"
+ + SERVICE_INSTANCE_ID + "?format=resource_and_url";
+
+ executor.logger.info("Query url" + urlGet);
+
+ result = client.httpRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json");
+ 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 putUpddateServInstance = service_instance;
+putUpddateServInstance['orchestration-status'] = "created";
+executor.logger.info(" string" + JSON.stringify(putUpddateServInstance, null, 4));
+var resource_version = putUpddateServInstance['resource-version'];
+var putUrl = NomadicONTContext.get("url");
+
+/* BBS Policy updates {{bbs-cfs-service-instance-UUID}} orchestration-status [ assigned --> created ] */
+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 = client.httpRequest(urlPut, "PUT", JSON.stringify(putUpddateServInstance), AAI_USERNAME, AAI_PASSWORD,
+ "application/json");
+ executor.logger.info("Data received From " + urlPut + " " + result);
+ /* 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 Success then Fill output schema */
+if (aaiUpdateResult == true) {
+ NomadicONTContext.put("result", "SUCCESS");
+} else {
+ NomadicONTContext.put("result", "FAILURE");
+
+}
+
+executor.outFields.put("requestID", requestID);
+executor.outFields.put("attachmentPoint", attachmentPoint);
+executor.outFields.put("serviceInstanceId", executor.inFields.get("serviceInstanceId"));
+
+executor.logger.info(executor.outFields);
+executor.logger.info("End Execution AAIServiceCreateTask.js");
+
+true;
+
diff --git a/policy/apex/logic/ErrorAAIServiceAssignedLogTask.js b/policy/apex/logic/ErrorAAIServiceAssignedLogTask.js
new file mode 100644
index 0000000..a9d7f31
--- /dev/null
+++ b/policy/apex/logic/ErrorAAIServiceAssignedLogTask.js
@@ -0,0 +1,29 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Huawei. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * 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);
+
+executor.logger.info(executor.outFields);
+
+executor.logger.info("Begin Execution ErrorServiceUpdateOneLogTask.js");
+
+true;
diff --git a/policy/apex/logic/ErrorSdncResourceUpdateTaskLogTask.js b/policy/apex/logic/ErrorSdncResourceUpdateTaskLogTask.js
new file mode 100644
index 0000000..3fbb0df
--- /dev/null
+++ b/policy/apex/logic/ErrorSdncResourceUpdateTaskLogTask.js
@@ -0,0 +1,27 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Huawei. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * 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);
+
+executor.logger.info("End Execution ErrorResourceUpdateLogTask.js");
+
+true;
diff --git a/policy/apex/logic/GetBBSCloseLoopEventTask.js b/policy/apex/logic/GetBBSCloseLoopEventTask.js
new file mode 100644
index 0000000..3de6340
--- /dev/null
+++ b/policy/apex/logic/GetBBSCloseLoopEventTask.js
@@ -0,0 +1,113 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Huawei. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+executor.logger.info("Begin Execution GetBBSCloseLoopEventTask.js");
+executor.logger.info(executor.subject.id);
+executor.logger.info(executor.inFields);
+var returnValue = true;
+
+var clEventType = org.onap.policy.controlloop.VirtualControlLoopEvent;
+var clEvent = executor.inFields.get("VirtualControlLoopEvent");
+executor.logger.info(clEvent.toString());
+executor.logger.info(clEvent.getClosedLoopControlName());
+
+var requestID = clEvent.getRequestId();
+executor.logger.info("requestID = " + requestID);
+var attachmentPoint = null;
+var NomadicONTContext = null;
+var serviceInstanceId = null;
+
+if (clEvent.getAai().get("attachmentPoint") != null) {
+ 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.2");
+ 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 = false;
+}
+
+returnValue;
+
diff --git a/policy/apex/logic/NomadicEventSuccessTask.js b/policy/apex/logic/NomadicEventSuccessTask.js
new file mode 100644
index 0000000..1723410
--- /dev/null
+++ b/policy/apex/logic/NomadicEventSuccessTask.js
@@ -0,0 +1,47 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Huawei. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+executor.logger.info("Begin Execution NomadicEventSuccess.js");
+executor.logger.info(executor.subject.id);
+executor.logger.info(executor.inFields);
+
+var attachmentPoint = executor.inFields.get("attachmentPoint");
+var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get(
+ attachmentPoint);
+
+executor.logger.info(executor.outFields);
+executor.logger.info(executor.inFields);
+
+result = NomadicONTContext.get("result");
+var returnValue = true;
+
+if (result == "SUCCESS") {
+ executor.outFields.put("result", "SUCCCESS");
+ executor.logger.info("BBS policy Execution Done");
+} else {
+ executor.logger.info("BBS policy Execution Failed");
+ executor.outFields.put("result", "FAILURE");
+ returnValue = false;
+}
+
+executor.logger.info("End Execution NomadicEventSuccess.js");
+
+returnValue;
diff --git a/policy/apex/logic/RUorInitStateSelect.js b/policy/apex/logic/RUorInitStateSelect.js
new file mode 100644
index 0000000..04a36cd
--- /dev/null
+++ b/policy/apex/logic/RUorInitStateSelect.js
@@ -0,0 +1,44 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Huawei. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+executor.logger.info("Begin Execution RUorInitStateSelect.js");
+executor.logger.info(executor.subject.id);
+executor.logger.info(executor.inFields);
+
+var result = null;
+
+var attachmentPoint = executor.inFields.get("attachmentPoint");
+var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get(
+ attachmentPoint);
+
+result = NomadicONTContext.get("result");
+
+if (result == "SUCCESS") {
+ executor.subject.getTaskKey("SdncResourceUpdateTask").copyTo(executor.selectedTask);
+} else {
+ 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");
+
+true;
diff --git a/policy/apex/logic/SU2orInitStateSelect.js b/policy/apex/logic/SU2orInitStateSelect.js
new file mode 100644
index 0000000..eafbe92
--- /dev/null
+++ b/policy/apex/logic/SU2orInitStateSelect.js
@@ -0,0 +1,46 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Huawei. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * 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);
+
+var result = null;
+
+var attachmentPoint = executor.inFields.get("attachmentPoint");
+var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get(
+ attachmentPoint);
+
+executor.logger.info(executor.inFields);
+
+result = NomadicONTContext.get("result");
+
+if (result == "SUCCESS") {
+ executor.subject.getTaskKey("AAIServiceCreateTask").copyTo(executor.selectedTask);
+} else {
+ executor.subject.getTaskKey("SdncResourceUpdateErrorLogOutput").copyTo(
+ executor.selectedTask);
+ onsetFlag = executor.isFalse;
+}
+
+executor.logger.info("State Selected Task:" + executor.selectedTask);
+executor.logger.info("End Execution SU2orInitStateSelect.js");
+
+true;
diff --git a/policy/apex/logic/SdncResourceUpdateTask.js b/policy/apex/logic/SdncResourceUpdateTask.js
new file mode 100644
index 0000000..0d1bcd2
--- /dev/null
+++ b/policy/apex/logic/SdncResourceUpdateTask.js
@@ -0,0 +1,470 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Huawei. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+executor.logger.info("Begin Execution SdncResourceUpdateTask.js");
+executor.logger.info(executor.subject.id);
+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.util.UUID;
+
+var wbClient = org.onap.policy.apex.examples.bbs.WebClient;
+var client = new wbClient();
+
+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 aaiData = JSON.parse(NomadicONTContext.get("AAI"));
+var input_param = JSON.parse(putUpddateServInstance['input-parameters']);
+SDNC_URL = executor.parameters.get("SDNC_URL");
+SVC_NOTIFICATION_URL = executor.parameters.get("SVC_NOTIFICATION_URL");
+SDNC_USERNAME = executor.parameters.get("SDNC_USERNAME");
+SDNC_PASSWORD = executor.parameters.get("SDNC_PASSWORD");
+executor.logger.info("SDNC_URL " + SDNC_URL);
+
+var result;
+var jsonObj;
+var sdncUpdateResult = true;
+
+/* BBS Policy calls SDN-C GR-API to delete AccessConnectivity VF ID */
+/* Prepare Data */
+var xmlDeleteAccess =
+ "<input xmlns=\"org:onap:sdnc:northbound:generic-resource\">\n" +
+ "<sdnc-request-header>\n" +
+ "<svc-request-id>svc_request_id_value</svc-request-id>\n" +
+ "<svc-action>delete</svc-action>\n" +
+ "<svc-notification-url>svc_notification_url_value</svc-notification-url>\n" +
+ "</sdnc-request-header>\n" +
+ "<request-information>\n" +
+ "<request-id>request_id_value</request-id>\n" +
+ "<request-action>DeleteAccessConnectivityInstance</request-action>\n" +
+ "<source>null</source>\n" +
+ "<notification-url></notification-url>\n" +
+ "<order-number></order-number>\n" +
+ "<order-version></order-version>\n" +
+ "</request-information>\n" +
+ "<service-information>\n" +
+ "<service-id>service_id_value</service-id>\n" +
+ "<service-instance-id>service_instance_id_value</service-instance-id>\n" +
+ "<subscription-service-type>service_type_value</subscription-service-type>\n" +
+ "<global-customer-id>customer_id_value</global-customer-id>\n" +
+ "<subscriber-name>customer_name_value</subscriber-name>\n" +
+ "<onap-model-information>\n" +
+ "<model-invariant-uuid>srv_info_model_inv_uuid_value</model-invariant-uuid>\n" +
+ "<model-customization-uuid>srv_info_model_custom_uuid_value</model-customization-uuid>\n" +
+ "<model-uuid>srv_info_model_uuid_value</model-uuid>\n" +
+ "<model-name>srv_info_model_name_value</model-name>\n" +
+ "</onap-model-information>\n" +
+ "</service-information>\n" +
+ "<vnf-information>\n" +
+ "<onap-model-information>\n" +
+ "<model-invariant-uuid>network_info_model_inv_uuid_value</model-invariant-uuid>\n" +
+ "<model-customization-uuid>network_info_model_custom_uuid_value</model-customization-uuid>\n" +
+ "<model-uuid>network_info_model_uuid_value</model-uuid>\n" +
+ "<model-name>network_info_model_name_value</model-name>\n" +
+ "</onap-model-information>\n" +
+ "</vnf-information>\n" +
+ "<vnf-request-input>\n" +
+ "<vnf-input-parameters>\n" +
+ "<param>\n" +
+ "<name>manufacturer</name>\n" +
+ "<value>vendor_value</value>\n" +
+ "</param>\n" +
+ "<param>\n" +
+ "<name>serviceID</name>\n" +
+ "<value>service_id_value</value>\n" +
+ "</param>\n" +
+ "</vnf-input-parameters>\n" +
+ "</vnf-request-input>\n" +
+ "</input>\n";
+
+/* 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'], 'AccessConnectivity'));
+xmlDeleteAccess = xmlDeleteAccess.replace("srv_info_model_custom_uuid_value", getResourceCustomizationUuid(
+ input_param['service']['parameters']['resources'], 'AccessConnectivity'));
+xmlDeleteAccess = xmlDeleteAccess.replace("srv_info_model_uuid_value", getResourceUuid(
+ input_param['service']['parameters']['resources'], 'AccessConnectivity'));
+xmlDeleteAccess = xmlDeleteAccess.replace("srv_info_model_name_value", "AccessConnectivity");
+xmlDeleteAccess = xmlDeleteAccess.replace("network_info_model_inv_uuid_value", getResourceInvariantUuid(
+ input_param['service']['parameters']['resources'], 'AccessConnectivity'));
+xmlDeleteAccess = xmlDeleteAccess.replace("network_info_model_custom_uuid_value", getResourceCustomizationUuid(
+ input_param['service']['parameters']['resources'], 'AccessConnectivity'));
+xmlDeleteAccess = xmlDeleteAccess.replace("network_info_model_uuid_value", getResourceUuid(
+ input_param['service']['parameters']['resources'], 'AccessConnectivity'));
+xmlDeleteAccess = xmlDeleteAccess.replace("network_info_model_name_value", "AccessConnectivity");
+
+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(client.toPrettyString(xmlDeleteAccess, 4));
+
+try {
+ var urlPost1 = HTTP_PROTOCOL + SDNC_URL + "/restconf/operations/GENERIC-RESOURCE-API:vnf-topology-operation";
+ result = client.httpRequest(urlPost1, "POST", xmlDeleteAccess, SDNC_USERNAME, SDNC_PASSWORD, "application/xml");
+ executor.logger.info("Data received From " + urlPost1 + " " + result);
+ if (result == "") {
+ sdncUpdateResult = false;
+ }
+} catch (err) {
+ executor.logger.info("Failed to retrieve data " + err);
+ sdncUpdateResult = false;
+}
+
+/* BBS Policy calls SDN-C GR-API to create new AccessConnectivity VF */
+
+/* Prepare Data */
+var xmlCreateAccess =
+ "<input xmlns=\"org:onap:sdnc:northbound:generic-resource\">\n" +
+ "<sdnc-request-header>\n" +
+ "<svc-request-id>svc_request_id_value</svc-request-id>\n" +
+ "<svc-action>create</svc-action>\n" +
+ "<svc-notification-url>svc_notification_url_value</svc-notification-url>\n" +
+ "</sdnc-request-header>\n" +
+ "<request-information>\n" +
+ "<request-id>request_id_value</request-id>\n" +
+ "<request-action>CreateAccessConnectivityInstance</request-action>\n" +
+ "<source>null</source>\n" +
+ "<notification-url></notification-url>\n" +
+ "<order-number></order-number>\n" +
+ "<order-version></order-version>\n" +
+ "</request-information>\n" +
+ "<service-information>\n" +
+ "<service-id>service_id_value</service-id>\n" +
+ "<service-instance-id>service_instance_id_value</service-instance-id>\n" +
+ "<subscription-service-type>service_type_value</subscription-service-type>\n" +
+ "<global-customer-id>customer_id_value</global-customer-id>\n" +
+ "<subscriber-name>customer_name_value</subscriber-name>\n" +
+ "<onap-model-information>\n" +
+ "<model-invariant-uuid>srv_info_model_inv_uuid_value</model-invariant-uuid>\n" +
+ "<model-customization-uuid>srv_info_model_custom_uuid_value</model-customization-uuid>\n" +
+ "<model-uuid>srv_info_model_uuid_value</model-uuid>\n" +
+ "<model-name>srv_info_model_name_value</model-name>\n" +
+ "</onap-model-information>\n" +
+ "</service-information>\n" +
+ "<vnf-information>\n" +
+ "<onap-model-information>\n" +
+ "<model-invariant-uuid>network_info_model_inv_uuid_value</model-invariant-uuid>\n" +
+ "<model-customization-uuid>network_info_model_custom_uuid_value</model-customization-uuid>\n" +
+ "<model-uuid>network_info_model_uuid_value</model-uuid>\n" +
+ "<model-name>network_info_model_name_value</model-name>\n" +
+ "</onap-model-information>\n" +
+ "</vnf-information>\n" +
+ "<vnf-request-input>\n" +
+ "<vnf-input-parameters>\n" +
+ "<param>\n" +
+ "<name>manufacturer</name>\n" +
+ "<value>vendor_value</value>\n" +
+ "</param>\n" +
+ "<param>\n" +
+ "<name>ONTSN</name>\n" +
+ "<value>ont_sn_value</value>\n" +
+ "</param>\n" +
+ "<param>\n" +
+ "<name>CVLAN</name>\n" +
+ "<value>c_vlan_value</value>\n" +
+ "</param>\n" +
+ "<param>\n" +
+ "<name>SVLAN</name>\n" +
+ "<value>s_vlan_value</value>\n" +
+ "</param>\n" +
+ "<param>\n" +
+ "<name>remote_id</name>\n" +
+ "<value>remote_id_value</value>\n" +
+ "</param>" +
+ "</vnf-input-parameters>\n" +
+ "</vnf-request-input>\n" +
+ "</input>\n";
+
+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'], 'AccessConnectivity'));
+xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_custom_uuid_value", getResourceCustomizationUuid(
+ input_param['service']['parameters']['resources'], 'AccessConnectivity'));
+xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_uuid_value", getResourceUuid(
+ input_param['service']['parameters']['resources'], 'AccessConnectivity'));
+xmlCreateAccess = xmlCreateAccess.replace("srv_info_model_name_value", "AccessConnectivity");
+xmlCreateAccess = xmlCreateAccess.replace("network_info_model_inv_uuid_value", getResourceInvariantUuid(
+ input_param['service']['parameters']['resources'], 'AccessConnectivity'));
+xmlCreateAccess = xmlCreateAccess.replace("network_info_model_custom_uuid_value", getResourceCustomizationUuid(
+ input_param['service']['parameters']['resources'], 'AccessConnectivity'));
+xmlCreateAccess = xmlCreateAccess.replace("network_info_model_uuid_value", getResourceUuid(
+ input_param['service']['parameters']['resources'], 'AccessConnectivity'));
+xmlCreateAccess = xmlCreateAccess.replace("network_info_model_name_value", "AccessConnectivity");
+
+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", aaiData["svlan"]);
+xmlCreateAccess = xmlCreateAccess.replace("c_vlan_value", aaiData["cvlan"]);
+xmlCreateAccess = xmlCreateAccess.replace("remote_id_value", aaiData["remoteId"]);
+
+
+executor.logger.info(client.toPrettyString(xmlCreateAccess, 4));
+
+try {
+ if (sdncUpdateResult == true) {
+ var urlPost2 = HTTP_PROTOCOL + SDNC_URL
+ + "/restconf/operations/GENERIC-RESOURCE-API:vnf-topology-operation";
+ result = client.httpRequest(urlPost2, "POST", xmlCreateAccess, SDNC_USERNAME, SDNC_PASSWORD, "application/xml");
+ executor.logger.info("Data received From " + urlPost2 + " " + result);
+ if (result == "") {
+ sdncUpdateResult = false;
+ }
+ }
+} catch (err) {
+ executor.logger.info("Failed to retrieve data " + err);
+ sdncUpdateResult = false;
+}
+
+/* BBS Policy calls SDN-C GR-API to create change Internet Profile */
+var xmlChangeProfile =
+ "<input xmlns=\"org:onap:sdnc:northbound:generic-resource\">\n" +
+ "<sdnc-request-header>\n" +
+ "<svc-request-id>svc_request_id_value</svc-request-id>\n" +
+ "<svc-action>update</svc-action>\n" +
+ "<svc-notification-url>svc_notification_url_value</svc-notification-url>\n" +
+ "</sdnc-request-header>\n" +
+ "<request-information>\n" +
+ "<request-id>request_id_value</request-id>\n" +
+ "<request-action>ChangeInternetProfileInstance</request-action>\n" +
+ "<source>null</source>\n" +
+ "<notification-url></notification-url>\n" +
+ "<order-number></order-number>\n" +
+ "<order-version></order-version>\n" +
+ "</request-information>\n" +
+ "<service-information>\n" +
+ "<service-id>service_id_value</service-id>\n" +
+ "<service-instance-id>service_instance_id_value</service-instance-id>\n" +
+ "<subscription-service-type>service_type_value</subscription-service-type>\n" +
+ "<global-customer-id>customer_id_value</global-customer-id>\n" +
+ "<subscriber-name>customer_name_value</subscriber-name>\n" +
+ "<onap-model-information>\n" +
+ "<model-invariant-uuid>srv_info_model_inv_uuid_value</model-invariant-uuid>\n" +
+ "<model-customization-uuid>srv_info_model_custom_uuid_value</model-customization-uuid>\n" +
+ "<model-uuid>srv_info_model_uuid_value</model-uuid>\n" +
+ "<model-name>srv_info_model_name_value</model-name>\n" +
+ "</onap-model-information>\n" +
+ "</service-information>\n" +
+ "<vnf-information>\n" +
+ "<onap-model-information>\n" +
+ "<model-invariant-uuid>network_info_model_inv_uuid_value</model-invariant-uuid>\n" +
+ "<model-customization-uuid>network_info_model_custom_uuid_value</model-customization-uuid>\n" +
+ "<model-uuid>network_info_model_uuid_value</model-uuid>\n" +
+ "<model-name>network_info_model_name_value</model-name>\n" +
+ "</onap-model-information>\n" +
+ "</vnf-information>\n" +
+ "<vnf-request-input>\n" +
+ "<vnf-input-parameters>\n" +
+ "<param>\n" +
+ "<name>manufacturer</name>\n" +
+ "<value>vendor_value</value>\n" +
+ "</param>\n" +
+ "<param>\n" +
+ "<name>service_id</name>\n" +
+ "<value>service_id_value</value>\n" +
+ "</param>\n" +
+ "<param>\n" +
+ "<name>ip_remote_id</name>\n" +
+ "<value>remote_id_value</value>\n" +
+ "</param>\n" +
+ "<param>\n" +
+ "<name>ont_sn</name>\n" +
+ "<value>ont_sn_value</value>\n" +
+ "</param>\n" +
+ "<param>\n" +
+ "<name>ip_service_type</name>\n" +
+ "<value>service_type_value</value>\n" +
+ "</param>\n" +
+ "<param>\n" +
+ "<name>ip_rg_mac_addr</name>\n" +
+ "<value>mac_value</value>\n" +
+ "</param>\n" +
+ "<param>\n" +
+ "<name>ip_upstream_speed</name>\n" +
+ "<value>up_speed_value</value>\n" +
+ "</param>\n" +
+ "<param>\n" +
+ "<name>ip_downstream_speed</name>\n" +
+ "<value>down_speed_value</value>\n" +
+ "</param>\n" +
+ "<param>\n" +
+ "<name>s_vlan</name>\n" +
+ "<value>s_vlan_value</value>\n" +
+ "</param>\n" +
+ "<param>\n" +
+ "<name>c_vlan</name>\n" +
+ "<value>c_vlan_value</value>\n" +
+ "</param>\n" +
+ "</vnf-input-parameters>\n" +
+ "</vnf-request-input>\n" +
+ "</input>\n";
+
+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']);
+
+xmlChangeProfile = xmlChangeProfile.replace("srv_info_model_inv_uuid_value", getResourceInvariantUuid(
+ input_param['service']['parameters']['resources'], 'InternetProfile'));
+xmlChangeProfile = xmlChangeProfile.replace("srv_info_model_custom_uuid_value", getResourceCustomizationUuid(
+ input_param['service']['parameters']['resources'], 'InternetProfile'));
+xmlChangeProfile = xmlChangeProfile.replace("srv_info_model_uuid_value", getResourceUuid(
+ input_param['service']['parameters']['resources'], 'InternetProfile'));
+xmlChangeProfile = xmlChangeProfile.replace("srv_info_model_name_value", "InternetProfile");
+xmlChangeProfile = xmlChangeProfile.replace("network_info_model_inv_uuid_value", getResourceInvariantUuid(
+ input_param['service']['parameters']['resources'], 'InternetProfile'));
+xmlChangeProfile = xmlChangeProfile.replace("network_info_model_custom_uuid_value", getResourceCustomizationUuid(
+ input_param['service']['parameters']['resources'], 'InternetProfile'));
+xmlChangeProfile = xmlChangeProfile.replace("network_info_model_uuid_value", getResourceUuid(
+ input_param['service']['parameters']['resources'], 'InternetProfile'));
+xmlChangeProfile = xmlChangeProfile.replace("network_info_model_name_value", "InternetProfile");
+
+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("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", aaiData["svlan"]);
+xmlChangeProfile = xmlChangeProfile.replace("c_vlan_value", aaiData["cvlan"]);
+xmlChangeProfile = xmlChangeProfile.replace("remote_id_value", aaiData["remoteId"]);
+
+executor.logger.info(client.toPrettyString(xmlChangeProfile, 4));
+try {
+ if (sdncUpdateResult == true) {
+ var urlPost3 = HTTP_PROTOCOL + SDNC_URL
+ + "/restconf/operations/GENERIC-RESOURCE-API:vnf-topology-operation";
+ result = client
+ .httpRequest(urlPost3, "POST", xmlChangeProfile, SDNC_USERNAME, SDNC_PASSWORD, "application/xml");
+ executor.logger.info("Data received From " + urlPost3 + " " + result);
+ if (result == "") {
+ sdncUpdateResult = false;
+ }
+ }
+} catch (err) {
+ executor.logger.info("Failed to retrieve data " + err);
+ 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("serviceInstanceId"));
+
+executor.logger.info(executor.outFields);
+executor.logger.info("End Execution SdncResourceUpdateTask.js");
+
+true;
+
+function getMetaValue(metaJson, metaname) {
+ for (var i = 0; i < metaJson.length; i++) {
+ if (metaJson[i]['metaname'] == metaname) {
+ return metaJson[i]['metaval'];
+ }
+ }
+
+}
+
+function getResourceInvariantUuid(resJson, resourceName) {
+ for (var i = 0; i < resJson.length; i++) {
+ if (resJson[i]['resourceName'] == resourceName) {
+ return resJson[i]['resourceInvariantUuid'];
+ }
+ }
+
+}
+
+function getResourceUuid(resJson, resourceName) {
+ for (var i = 0; i < resJson.length; i++) {
+ if (resJson[i]['resourceName'] == resourceName) {
+ return resJson[i]['resourceUuid'];
+ }
+ }
+
+}
+
+function getResourceCustomizationUuid(resJson, resourceName) {
+ for (var i = 0; i < resJson.length; i++) {
+ if (resJson[i]['resourceName'] == resourceName) {
+ return resJson[i]['resourceCustomizationUuid'];
+ }
+ }
+
+}
+
+/* Utility functions Begin */
+function IsValidJSONString(str) {
+ try {
+ JSON.parse(str);
+ } catch (e) {
+ return false;
+ }
+ return true;
+}
+/* Utility functions End */ \ No newline at end of file
diff --git a/policy/apex/logic/ServiceUpdateStateCpeAuthTask.js b/policy/apex/logic/ServiceUpdateStateCpeAuthTask.js
new file mode 100644
index 0000000..b6b2c91
--- /dev/null
+++ b/policy/apex/logic/ServiceUpdateStateCpeAuthTask.js
@@ -0,0 +1,118 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Huawei. All rights reserved.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+executor.logger.info("Begin Execution ServiceUpdateStateCpeAuthTask.js");
+executor.logger.info(executor.subject.id);
+executor.logger.info(executor.inFields);
+
+var clEventType = org.onap.policy.controlloop.VirtualControlLoopEvent;
+var clEvent = executor.inFields.get("VirtualControlLoopEvent");
+
+var serviceInstanceId = clEvent.getAai().get("service-information.hsia-cfs-service-instance-id");
+var requestID = clEvent.getRequestId();
+
+var jsonObj;
+var aaiUpdateResult = true;
+var wbClient = 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");
+executor.logger.info("New CPE Authentication State: " + newState);
+/* 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;
+var AAI_VERSION = "v14";
+
+AAI_URL = executor.parameters.get("AAI_URL");
+AAI_USERNAME = executor.parameters.get("AAI_USERNAME");
+AAI_PASSWORD = executor.parameters.get("AAI_PASSWORD");
+AAI_VERSION = executor.parameters.get("AAI_VERSION");
+
+executor.logger.info("AAI_URL=>" + AAI_URL);
+
+/* Get service instance Id from AAI */
+try {
+ var urlGet = HTTP_PROTOCOL + AAI_URL + "/aai/" + AAI_VERSION + "/nodes/service-instances/service-instance/"
+ + SERVICE_INSTANCE_ID + "?format=resource_and_url"
+ executor.logger.info("Query url: " + urlGet);
+
+ result = client.httpRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD, "application/json");
+ executor.logger.info("Data received From " + urlGet + " " + result);
+ jsonObj = JSON.parse(result);
+
+ /* Retrieve the service instance id */
+ results = jsonObj['results'][0];
+ putUrl = results["url"];
+ service_instance = results['service-instance'];
+ resource_version = service_instance['resource-version'];
+ 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;
+}
+
+/* BBS Policy updates orchestration status of {{bbs-cfs-service-instance-UUID}} [ active --> assigned ] */
+var putUpddateServInstance;
+putUpddateServInstance = service_instance;
+
+if (newState == 'inService') {
+ putUpddateServInstance['orchestration-status'] = "active";
+} else {
+ putUpddateServInstance['orchestration-status'] = "inActive";
+}
+try {
+ if (aaiUpdateResult == true) {
+ executor.logger.info("ready to put After Parse " + JSON.stringify(putUpddateServInstance, null, 4));
+ var urlPut = HTTP_PROTOCOL + AAI_URL + putUrl + "?resource_version=" + resource_version;
+ result = client.httpRequest(urlPut, "PUT", JSON.stringify(putUpddateServInstance), AAI_USERNAME, AAI_PASSWORD,
+ "application/json");
+ executor.logger.info("Data received From " + urlPut + " " + result);
+ /* 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);
+executor.logger.info("End Execution ServiceUpdateStateCpeAuthTask.js");
+
+true;