/*
* ============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 =
"\n" +
"\n" +
"svc_request_id_value\n" +
"delete\n" +
"svc_notification_url_value\n" +
"\n" +
"\n" +
"request_id_value\n" +
"DeleteAccessConnectivityInstance\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"service_id_value\n" +
"service_instance_id_value\n" +
"service_type_value\n" +
"customer_id_value\n" +
"customer_name_value\n" +
"\n" +
"srv_info_model_inv_uuid_value\n" +
"srv_info_model_custom_uuid_value\n" +
"srv_info_model_uuid_value\n" +
"srv_info_model_name_value\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"network_info_model_inv_uuid_value\n" +
"network_info_model_custom_uuid_value\n" +
"network_info_model_uuid_value\n" +
"network_info_model_name_value\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"manufacturer\n" +
"vendor_value\n" +
"\n" +
"\n" +
"serviceID\n" +
"service_id_value\n" +
"\n" +
"\n" +
"\n" +
"\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 =
"\n" +
"\n" +
"svc_request_id_value\n" +
"create\n" +
"svc_notification_url_value\n" +
"\n" +
"\n" +
"request_id_value\n" +
"CreateAccessConnectivityInstance\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"service_id_value\n" +
"service_instance_id_value\n" +
"service_type_value\n" +
"customer_id_value\n" +
"customer_name_value\n" +
"\n" +
"srv_info_model_inv_uuid_value\n" +
"srv_info_model_custom_uuid_value\n" +
"srv_info_model_uuid_value\n" +
"srv_info_model_name_value\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"network_info_model_inv_uuid_value\n" +
"network_info_model_custom_uuid_value\n" +
"network_info_model_uuid_value\n" +
"network_info_model_name_value\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"manufacturer\n" +
"vendor_value\n" +
"\n" +
"\n" +
"ONTSN\n" +
"ont_sn_value\n" +
"\n" +
"\n" +
"CVLAN\n" +
"c_vlan_value\n" +
"\n" +
"\n" +
"SVLAN\n" +
"s_vlan_value\n" +
"\n" +
"\n" +
"remote_id\n" +
"remote_id_value\n" +
"" +
"\n" +
"\n" +
"\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 =
"\n" +
"\n" +
"svc_request_id_value\n" +
"update\n" +
"svc_notification_url_value\n" +
"\n" +
"\n" +
"request_id_value\n" +
"ChangeInternetProfileInstance\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"service_id_value\n" +
"service_instance_id_value\n" +
"service_type_value\n" +
"customer_id_value\n" +
"customer_name_value\n" +
"\n" +
"srv_info_model_inv_uuid_value\n" +
"srv_info_model_custom_uuid_value\n" +
"srv_info_model_uuid_value\n" +
"srv_info_model_name_value\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"network_info_model_inv_uuid_value\n" +
"network_info_model_custom_uuid_value\n" +
"network_info_model_uuid_value\n" +
"network_info_model_name_value\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"\n" +
"manufacturer\n" +
"vendor_value\n" +
"\n" +
"\n" +
"service_id\n" +
"service_id_value\n" +
"\n" +
"\n" +
"ip_remote_id\n" +
"remote_id_value\n" +
"\n" +
"\n" +
"ont_sn\n" +
"ont_sn_value\n" +
"\n" +
"\n" +
"ip_service_type\n" +
"service_type_value\n" +
"\n" +
"\n" +
"ip_rg_mac_addr\n" +
"mac_value\n" +
"\n" +
"\n" +
"ip_upstream_speed\n" +
"up_speed_value\n" +
"\n" +
"\n" +
"ip_downstream_speed\n" +
"down_speed_value\n" +
"\n" +
"\n" +
"s_vlan\n" +
"s_vlan_value\n" +
"\n" +
"\n" +
"c_vlan\n" +
"c_vlan_value\n" +
"\n" +
"\n" +
"\n" +
"\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 */