diff options
Diffstat (limited to 'policy/apex/logic/SdncResourceUpdateTask.js')
-rw-r--r-- | policy/apex/logic/SdncResourceUpdateTask.js | 470 |
1 files changed, 470 insertions, 0 deletions
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 |