diff options
author | s00370346 <swarup.nayak1@huawei.com> | 2019-04-24 19:10:05 +0530 |
---|---|---|
committer | s00370346 <swarup.nayak1@huawei.com> | 2019-04-26 19:57:18 +0530 |
commit | ad178d97b872542a57356dd0b24493d3fd4d925f (patch) | |
tree | 1ea456a64321f391cb8d9509828cb329a5f5b866 /examples/examples-onap-bbs/src/main/resources | |
parent | ca558cfb1ea47de081527771af47abb37a8cd964 (diff) |
ONAP BBS: Apex Nomadic ONT bug fixes
Issue-ID: DCAEGEN2-1237
Change-Id: Ibc1b5a221af5eb28799764498b2751d99f5764f3
Signed-off-by: s00370346 <swarup.nayak1@huawei.com>
Diffstat (limited to 'examples/examples-onap-bbs/src/main/resources')
12 files changed, 318 insertions, 438 deletions
diff --git a/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/config.txt b/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/config.txt index 794398be4..d132aa2f3 100644 --- a/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/config.txt +++ b/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/config.txt @@ -1,3 +1,7 @@ AAI_URL=aai.api.simpledemo.openecomp.org:30233 -SDNC_URL=aai.api.simpledemo.openecomp.org:8443 +AAI_USERNAME=AAI +AAI_PASSWORD=AAI +SDNC_URL=sdnc.api.simpledemo.onap.org:30202 +SDNC_USERNAME=admin +SDNC_PASSWORD=Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U SVC_NOTIFICATION_URL=http://c1.vm1.mso.simpledemo.openecomp.org:8080
\ No newline at end of file diff --git a/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_ChangeInternetProfileInstance.txt b/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_ChangeInternetProfileInstance.txt index 2304e5739..193e3bb2d 100644 --- a/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_ChangeInternetProfileInstance.txt +++ b/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_ChangeInternetProfileInstance.txt @@ -1,81 +1,80 @@ -<input> - <sdnc-request-header> - <svc-request-id>svc_request_id_value</svc-request-id> - <svc-action>update</svc-action> - <svc-notification-url>svc_notification_url_value</svc-notification-url> - </sdnc-request-header> - <request-information> - <request-id>request_id_value</request-id> - <request-action>ChangeInternetProfileInstance</request-action> - <source>null</source> - <notification-url></notification-url> - <order-number></order-number> - <order-version></order-version> - </request-information> - <service-information> - <service-id>service_id_value</service-id> - <service-instance-id>service_instance_id_value</service-instance-id> - <subscription-service-type>service_type_value</subscription-service-type> - <global-customer-id>customer_id_value</global-customer-id> - <subscriber-name>customer_name_value</subscriber-name> - <onap-model-information> - <model-invariant-uuid>srv_info_model_inv_uuid_value</model-invariant-uuid> +<input xmlns="org:onap:sdnc:northbound:generic-resource"> + <sdnc-request-header> + <svc-request-id>svc_request_id_value</svc-request-id> + <svc-action>update</svc-action> + <svc-notification-url>svc_notification_url_value</svc-notification-url> + </sdnc-request-header> + <request-information> + <request-id>request_id_value</request-id> + <request-action>ChangeInternetProfileInstance</request-action> + <source>null</source> + <notification-url></notification-url> + <order-number></order-number> + <order-version></order-version> + </request-information> + <service-information> + <service-id>service_id_value</service-id> + <service-instance-id>service_instance_id_value</service-instance-id> + <subscription-service-type>service_type_value</subscription-service-type> + <global-customer-id>customer_id_value</global-customer-id> + <subscriber-name>customer_name_value</subscriber-name> + <onap-model-information> + <model-invariant-uuid>srv_info_model_inv_uuid_value</model-invariant-uuid> <model-customization-uuid>srv_info_model_custom_uuid_value</model-customization-uuid> <model-uuid>srv_info_model_uuid_value</model-uuid> <model-name>srv_info_model_name_value</model-name> - </onap-model-information> - </service-information> - <network-information> - <onap-model-information> - <model-invariant-uuid>network_info_model_inv_uuid_value</model-invariant-uuid> + </onap-model-information> + </service-information> + <network-information> + <onap-model-information> + <model-invariant-uuid>network_info_model_inv_uuid_value</model-invariant-uuid> <model-customization-uuid>network_info_model_custom_uuid_value</model-customization-uuid> <model-uuid>network_info_model_uuid_value</model-uuid> <model-name>network_info_model_name_value</model-name> - </onap-model-information> - </network-information> - <network-request-input> - <network-input-parameters> - <param> - <name>vendor</name> - <value>vendor_value</value> - </param> - <param> - <name>service_id</name> - <value>service_id_value</value> - </param> - <param> - <name>access_id</name> - <value>access_id_value</value> - </param> - <param> - <name>ont_sn</name> - <value>ont_sn_value</value> - </param> - <param> - <name>service_type</name> - <value>service_type_value</value> - </param> - <param> - <name>mac</name> - <value>mac_value</value> - </param> - <param> - <name>up_speed</name> - <value>up_speed_value</value> - </param> - <param> - <name>down_speed</name> - <value>down_speed_value</value> - </param> - <param> - <name>s_vlan</name> - <value>s_vlan_value</value> - </param> - <param> - <name>c_vlan</name> - <value>c_vlan_value</value> - </param> - </network-input-parameters> - </network-request-input> - <_xmlns>org:onap:sdnc:northbound:generic-resource</_xmlns> + </onap-model-information> + </network-information> + <network-request-input> + <network-input-parameters> + <param> + <name>vendor</name> + <value>vendor_value</value> + </param> + <param> + <name>service_id</name> + <value>service_id_value</value> + </param> + <param> + <name>access_id</name> + <value>access_id_value</value> + </param> + <param> + <name>ont_sn</name> + <value>ont_sn_value</value> + </param> + <param> + <name>service_type</name> + <value>service_type_value</value> + </param> + <param> + <name>mac</name> + <value>mac_value</value> + </param> + <param> + <name>up_speed</name> + <value>up_speed_value</value> + </param> + <param> + <name>down_speed</name> + <value>down_speed_value</value> + </param> + <param> + <name>s_vlan</name> + <value>s_vlan_value</value> + </param> + <param> + <name>c_vlan</name> + <value>c_vlan_value</value> + </param> + </network-input-parameters> + </network-request-input> </input> diff --git a/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_CreateAccessConnectivityInstance.txt b/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_CreateAccessConnectivityInstance.txt index 7410c0bc6..9168ff17d 100644 --- a/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_CreateAccessConnectivityInstance.txt +++ b/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_CreateAccessConnectivityInstance.txt @@ -1,61 +1,60 @@ -<input> - <sdnc-request-header> - <svc-request-id>svc_request_id_value</svc-request-id> - <svc-action>create</svc-action> - <svc-notification-url>svc_notification_url_value</svc-notification-url> - </sdnc-request-header> - <request-information> - <request-id>request_id_value</request-id> - <request-action>CreateAccessConnectivityInstance</request-action> - <source>null</source> - <notification-url></notification-url> - <order-number></order-number> - <order-version></order-version> - </request-information> - <service-information> - <service-id>service_id_value</service-id> +<input xmlns="org:onap:sdnc:northbound:generic-resource"> + <sdnc-request-header> + <svc-request-id>svc_request_id_value</svc-request-id> + <svc-action>create</svc-action> + <svc-notification-url>svc_notification_url_value</svc-notification-url> + </sdnc-request-header> + <request-information> + <request-id>request_id_value</request-id> + <request-action>CreateAccessConnectivityInstance</request-action> + <source>null</source> + <notification-url></notification-url> + <order-number></order-number> + <order-version></order-version> + </request-information> + <service-information> + <service-id>service_id_value</service-id> <service-instance-id>service_instance_id_value</service-instance-id> <subscription-service-type>service_type_value</subscription-service-type> <global-customer-id>customer_id_value</global-customer-id> <subscriber-name>customer_name_value</subscriber-name> - <onap-model-information> - <model-invariant-uuid>srv_info_model_inv_uuid_value</model-invariant-uuid> + <onap-model-information> + <model-invariant-uuid>srv_info_model_inv_uuid_value</model-invariant-uuid> <model-customization-uuid>srv_info_model_custom_uuid_value</model-customization-uuid> <model-uuid>srv_info_model_uuid_value</model-uuid> <model-name>srv_info_model_name_value</model-name> - </onap-model-information> - </service-information> - <network-information> - <onap-model-information> - <model-invariant-uuid>network_info_model_inv_uuid_value</model-invariant-uuid> + </onap-model-information> + </service-information> + <network-information> + <onap-model-information> + <model-invariant-uuid>network_info_model_inv_uuid_value</model-invariant-uuid> <model-customization-uuid>network_info_model_custom_uuid_value</model-customization-uuid> <model-uuid>network_info_model_uuid_value</model-uuid> <model-name>network_info_model_name_value</model-name> - </onap-model-information> - </network-information> - <network-request-input> - <network-input-parameters> - <param> - <name>vendor</name> - <value>vendor_value</value> - </param> - <param> - <name>ONTSN</name> - <value>ont_sn_value</value> - </param> - <param> - <name>CVLAN</name> - <value>c_vlan_value</value> - </param> - <param> - <name>SVLAN</name> - <value>s_vlan_value</value> - </param> - <param> - <name>accessID</name> - <value>access_id_value</value> - </param> - </network-input-parameters> - </network-request-input> - <_xmlns>org:onap:sdnc:northbound:generic-resource</_xmlns> + </onap-model-information> + </network-information> + <network-request-input> + <network-input-parameters> + <param> + <name>vendor</name> + <value>vendor_value</value> + </param> + <param> + <name>ONTSN</name> + <value>ont_sn_value</value> + </param> + <param> + <name>CVLAN</name> + <value>c_vlan_value</value> + </param> + <param> + <name>SVLAN</name> + <value>s_vlan_value</value> + </param> + <param> + <name>accessID</name> + <value>access_id_value</value> + </param> + </network-input-parameters> + </network-request-input> </input> diff --git a/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_DeleteAccessConnectivityInstance.txt b/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_DeleteAccessConnectivityInstance.txt index e464e2ee1..a3fe0bd4d 100644 --- a/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_DeleteAccessConnectivityInstance.txt +++ b/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/sdnc_DeleteAccessConnectivityInstance.txt @@ -1,49 +1,48 @@ -<input> - <sdnc-request-header> - <svc-request-id>svc_request_id_value</svc-request-id> - <svc-action>delete</svc-action> - <svc-notification-url>svc_notification_url_value</svc-notification-url> - </sdnc-request-header> - <request-information> - <request-id>request_id_value</request-id> - <request-action>DeleteAccessConnectivityInstance</request-action> - <source>null</source> - <notification-url></notification-url> - <order-number></order-number> - <order-version></order-version> - </request-information> - <service-information> - <service-id>service_id_value</service-id> +<input xmlns="org:onap:sdnc:northbound:generic-resource"> + <sdnc-request-header> + <svc-request-id>svc_request_id_value</svc-request-id> + <svc-action>delete</svc-action> + <svc-notification-url>svc_notification_url_value</svc-notification-url> + </sdnc-request-header> + <request-information> + <request-id>request_id_value</request-id> + <request-action>DeleteAccessConnectivityInstance</request-action> + <source>null</source> + <notification-url></notification-url> + <order-number></order-number> + <order-version></order-version> + </request-information> + <service-information> + <service-id>service_id_value</service-id> <service-instance-id>service_instance_id_value</service-instance-id> <subscription-service-type>service_type_value</subscription-service-type> <global-customer-id>customer_id_value</global-customer-id> <subscriber-name>customer_name_value</subscriber-name> - <onap-model-information> - <model-invariant-uuid>srv_info_model_inv_uuid_value</model-invariant-uuid> - <model-customization-uuid>srv_info_model_custom_uuid_value</model-customization-uuid> - <model-uuid>srv_info_model_uuid_value</model-uuid> - <model-name>srv_info_model_name_value</model-name> - </onap-model-information> - </service-information> - <network-information> - <onap-model-information> + <onap-model-information> + <model-invariant-uuid>srv_info_model_inv_uuid_value</model-invariant-uuid> + <model-customization-uuid>srv_info_model_custom_uuid_value</model-customization-uuid> + <model-uuid>srv_info_model_uuid_value</model-uuid> + <model-name>srv_info_model_name_value</model-name> + </onap-model-information> + </service-information> + <network-information> + <onap-model-information> <model-invariant-uuid>network_info_model_inv_uuid_value</model-invariant-uuid> <model-customization-uuid>network_info_model_custom_uuid_value</model-customization-uuid> <model-uuid>network_info_model_uuid_value</model-uuid> <model-name>network_info_model_name_value</model-name> - </onap-model-information> - </network-information> - <network-request-input> - <network-input-parameters> - <param> - <name>vendor</name> - <value>vendor_value</value> - </param> - <param> - <name>serviceID</name> - <value>serviceID_value</value> - </param> - </network-input-parameters> - </network-request-input> - <_xmlns>org:onap:sdnc:northbound:generic-resource</_xmlns> + </onap-model-information> + </network-information> + <network-request-input> + <network-input-parameters> + <param> + <name>vendor</name> + <value>vendor_value</value> + </param> + <param> + <name>serviceID</name> + <value>serviceID_value</value> + </param> + </network-input-parameters> + </network-request-input> </input> diff --git a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js index 744b6d48b..9d38db1b4 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js @@ -39,6 +39,10 @@ executor.logger.info(NomadicONTContext); var jsonObj; var aaiUpdateResult = true; +var wbClient = Java.type("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; @@ -52,13 +56,17 @@ var service_instance; try { var br = Files.newBufferedReader(Paths.get( "/home/apexuser/examples/config/ONAPBBS/config.txt")); - // read line by line var line; while ((line = br.readLine()) != null) { if (line.startsWith("AAI_URL")) { var str = line.split("="); AAI_URL = str[str.length - 1]; - break; + } else if (line.startsWith("AAI_USERNAME")) { + var str = line.split("="); + AAI_USERNAME = str[str.length - 1]; + } else if (line.startsWith("AAI_PASSWORD")) { + var str = line.split("="); + AAI_PASSWORD = str[str.length - 1]; } } } catch (err) { @@ -72,21 +80,25 @@ try { var urlGet = HTTP_PROTOCOL + AAI_URL + "/aai/v14/nodes/service-instances/service-instance/" + SERVICE_INSTANCE_ID + "?format=resource_and_url"; - executor.logger.info("Query url" + urlGet); - result = httpGet(urlGet).data; - executor.logger.info("Data received From " + urlGet + " " + result.toString()); - jsonObj = JSON.parse(result); + executor.logger.info("Query url" + urlGet); + result = client.httpsRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD, + "application/json", true, true); + executor.logger.info("Data received From " + urlGet + " " + result); + jsonObj = JSON.parse(result.toString()); + executor.logger.info(JSON.stringify(jsonObj, null, 4)); /* Retrieve the service instance id */ - results = jsonObj['results']; - putUrl = results["url"]; - service_instance = results["service-instance"]; + 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 " + JSON.stringify(jsonObj, null, 4)); + executor.logger.info("After Parse service_instance " + JSON.stringify( + service_instance, null, 4) + "\n url " + putUrl + + "\n Service instace Id " + service_instance_id); if (result == "") { aaiUpdateResult = false; @@ -106,13 +118,12 @@ try { putUpddateServInstance, null, 4)); var urlPut = HTTP_PROTOCOL + AAI_URL + putUrl + "?resource_version=" + resource_version; - result = httpPut(urlPut, JSON.stringify(putUpddateServInstance)).data; - executor.logger.info("Data received From " + urlPut + " " + result.toString()); - jsonObj = JSON.parse(result); - executor.logger.info("After Parse " + JSON.stringify(jsonObj, null, 4)); - + result = client.httpsRequest(urlPut, "PUT", JSON.stringify( + putUpddateServInstance), AAI_USERNAME, AAI_PASSWORD, + "application/json", true, true); + executor.logger.info("Data received From " + urlPut + " " + result); /* If failure to retrieve data proceed to Failure */ - if (result == "") { + if (result != "") { aaiUpdateResult = false; } } @@ -121,12 +132,20 @@ try { 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"); +} /* If Success then Fill output schema */ if (aaiUpdateResult === true) { + executor.outFields.put("result", "SUCCESS"); NomadicONTContext.put("result", "SUCCESS"); NomadicONTContext.put("aai_message", JSON.stringify(service_instance)); NomadicONTContext.put("url", putUrl); } else { + executor.outFields.put("result", "FAILURE"); NomadicONTContext.put("result", "FAILURE"); } @@ -139,60 +158,13 @@ var returnValue = executor.isTrue; executor.logger.info(executor.outFields); executor.logger.info("End Execution AAIServiceAssignedTask.js"); - /* Utility functions Begin */ -function httpGet(theUrl) { - var con = new java.net.URL(theUrl).openConnection(); - con.requestMethod = "GET"; - return asResponse(con); -} - -function httpPost(theUrl, data, contentType) { - contentType = contentType || "application/json"; - var con = new java.net.URL(theUrl).openConnection(); - con.requestMethod = "POST"; - con.setRequestProperty("Content-Type", contentType); - con.doOutput = true; - write(con.outputStream, data); - return asResponse(con); -} - -function httpPut(theUrl, data, contentType) { - contentType = contentType || "application/json"; - var con = new java.net.URL(theUrl).openConnection(); - con.requestMethod = "PUT"; - con.setRequestProperty("Content-Type", contentType); - con.doOutput = true; - write(con.outputStream, data); - return asResponse(con); -} - -function asResponse(con) { - var d = read(con.inputStream); - return { - data: d, - statusCode: con.resultCode - }; -} - -function write(outputStream, data) { - var wr = new java.io.DataOutputStream(outputStream); - wr.writeBytes(data); - wr.flush(); - wr.close(); -} - -function read(inputStream) { - var inReader = new java.io.BufferedReader(new java.io.InputStreamReader( - inputStream)); - var inputLine; - var result = new java.lang.StringBuffer(); - - while ((inputLine = inReader.readLine()) != null) { - result.append(inputLine); +function IsValidJSONString(str) { + try { + JSON.parse(str); + } catch (e) { + return false; } - inReader.close(); - return result.toString(); + return true; } - /* Utility functions End */
\ No newline at end of file diff --git a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js index 9ddc91e8c..ac409ed2d 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js @@ -32,13 +32,20 @@ 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_UUID = serviceInstanceId; +var SERVICE_INSTANCE_ID = serviceInstanceId; var HTTP_PROTOCOL = "https://"; - +var wbClient = Java.type("org.onap.policy.apex.examples.bbs.WebClient"); +var client = new wbClient(); +var AAI_USERNAME = null; +var AAI_PASSWORD = null; try { var br = Files.newBufferedReader(Paths.get( "/home/apexuser/examples/config/ONAPBBS/config.txt")); @@ -48,32 +55,57 @@ try { if (line.startsWith("AAI_URL")) { var str = line.split("="); AAI_URL = str[str.length - 1]; - break; + } else if (line.startsWith("AAI_USERNAME")) { + var str = line.split("="); + AAI_USERNAME = str[str.length - 1]; + } else if (line.startsWith("AAI_PASSWORD")) { + var str = line.split("="); + AAI_PASSWORD = str[str.length - 1]; } - } } catch (err) { executor.logger.info("Failed to retrieve data " + err); } executor.logger.info("AAI_URL " + AAI_URL); +var aaiUpdateResult = true; +/* Get service instance Id from AAI */ +try { + var urlGet = HTTP_PROTOCOL + AAI_URL + + "/aai/v14/nodes/service-instances/service-instance/" + + SERVICE_INSTANCE_ID + "?format=resource_and_url"; + + executor.logger.info("Query url" + urlGet); + + result = client.httpsRequest(urlGet, "GET", null, AAI_USERNAME, AAI_PASSWORD, + "application/json", true, true); + executor.logger.info("Data received From " + urlGet + " " + result); + jsonObj = JSON.parse(result); + + 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 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 putUpddateServInstance = JSON.parse(NomadicONTContext.get("aai_message")); - +var putUpddateServInstance = service_instance; putUpddateServInstance['orchestration-status'] = "created"; -executor.logger.info(" string" + JSON.stringify(putUpddateServInstance, null, 4)); +if (putUpddateServInstance.hasOwnProperty('input-parameters')) + delete putUpddateServInstance['input-parameters']; +executor.logger.info(" string" + JSON.stringify(putUpddateServInstance, null, + 4)); var resource_version = putUpddateServInstance['resource-version']; var putUrl = NomadicONTContext.get("url"); -var aaiUpdateResult = true; - /*BBS Policy updates {{bbs-cfs-service-instance-UUID}} orchestration-status [ assigned --> created ]*/ try { @@ -82,13 +114,12 @@ try { putUpddateServInstance, null, 4)); var urlPut = HTTP_PROTOCOL + AAI_URL + putUrl + "?resource_version=" + resource_version; - result = httpPut(urlPut, JSON.stringify(putUpddateServInstance)).data; - executor.logger.info("Data received From " + urlPut + " " + result.toString()); - jsonObj = JSON.parse(result); - executor.logger.info("After Parse " + JSON.stringify(jsonObj, null, 4)); - + result = client.httpsRequest(urlPut, "PUT", JSON.stringify( + putUpddateServInstance), AAI_USERNAME, AAI_PASSWORD, + "application/json", true, true); + executor.logger.info("Data received From " + urlPut + " " + result); /* If failure to retrieve data proceed to Failure */ - if (result == "") { + if (result != "") { aaiUpdateResult = false; } } @@ -101,8 +132,8 @@ if (aaiUpdateResult === true) { NomadicONTContext.put("result", "SUCCESS"); } else { NomadicONTContext.put("result", "FAILURE"); -} +} executor.outFields.put("requestID", requestID); executor.outFields.put("attachmentPoint", attachmentPoint); @@ -111,62 +142,4 @@ executor.outFields.put("serviceInstanceId", executor.inFields.get( var returnValue = executor.isTrue; executor.logger.info(executor.outFields); -executor.logger.info("End Execution AAIServiceCreateTask.js"); - -/* Utility functions Begin */ - -function httpGet(theUrl) { - var con = new java.net.URL(theUrl).openConnection(); - con.requestMethod = "GET"; - return asResponse(con); -} - -function httpPost(theUrl, data, contentType) { - contentType = contentType || "application/json"; - var con = new java.net.URL(theUrl).openConnection(); - con.requestMethod = "POST"; - con.setRequestProperty("Content-Type", contentType); - con.doOutput = true; - write(con.outputStream, data); - return asResponse(con); -} - -function httpPut(theUrl, data, contentType) { - contentType = contentType || "application/json"; - var con = new java.net.URL(theUrl).openConnection(); - con.requestMethod = "PUT"; - con.setRequestProperty("Content-Type", contentType); - con.doOutput = true; - write(con.outputStream, data); - return asResponse(con); -} - -function asResponse(con) { - var d = read(con.inputStream); - return { - data: d, - statusCode: con.resultCode - }; -} - -function write(outputStream, data) { - var wr = new java.io.DataOutputStream(outputStream); - wr.writeBytes(data); - wr.flush(); - wr.close(); -} - -function read(inputStream) { - var inReader = new java.io.BufferedReader(new java.io.InputStreamReader( - inputStream)); - var inputLine; - var result = new java.lang.StringBuffer(); - - while ((inputLine = inReader.readLine()) != null) { - result.append(inputLine); - } - inReader.close(); - return result.toString(); -} - -/* Utility functions End */
\ No newline at end of file +executor.logger.info("End Execution AAIServiceCreateTask.js");
\ No newline at end of file diff --git a/examples/examples-onap-bbs/src/main/resources/logic/ErrorSdncResourceUpdateTaskLogTask.js b/examples/examples-onap-bbs/src/main/resources/logic/ErrorSdncResourceUpdateTaskLogTask.js index 7ba674553..946d956b1 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/ErrorSdncResourceUpdateTaskLogTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/ErrorSdncResourceUpdateTaskLogTask.js @@ -21,7 +21,5 @@ executor.logger.info("Begin Execution ErrorResourceUpdateLogTask.js"); executor.logger.info(executor.subject.id); executor.logger.info(executor.inFields); -executor.logger.info(executor.outFields); - var returnValue = executor.isTrue; executor.logger.info("End Execution ErrorResourceUpdateLogTask.js"); diff --git a/examples/examples-onap-bbs/src/main/resources/logic/RUorInitStateSelect.js b/examples/examples-onap-bbs/src/main/resources/logic/RUorInitStateSelect.js index 6e609b1cc..810903a28 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/RUorInitStateSelect.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/RUorInitStateSelect.js @@ -28,9 +28,6 @@ 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"); if (result === "SUCCESS") { diff --git a/examples/examples-onap-bbs/src/main/resources/logic/SU2orInitStateSelect.js b/examples/examples-onap-bbs/src/main/resources/logic/SU2orInitStateSelect.js index 214a76fe8..3abd75071 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/SU2orInitStateSelect.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/SU2orInitStateSelect.js @@ -28,7 +28,6 @@ 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"); diff --git a/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js b/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js index 033d778be..60d4efed9 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js @@ -26,7 +26,6 @@ importClass(java.nio.file.Paths); importPackage(org.json.XML); - executor.logger.info("Begin Execution SdncResourceUpdateTask.js"); executor.logger.info(executor.subject.id); executor.logger.info(executor.inFields); @@ -36,7 +35,8 @@ var requestID = executor.inFields.get("requestID"); var serviceInstanceId = executor.inFields.get("serviceInstanceId"); var uuidType = Java.type("java.util.UUID"); - +var wbClient = Java.type("org.onap.policy.apex.examples.bbs.WebClient"); +var client = new wbClient(); var NomadicONTContext = executor.getContextAlbum("NomadicONTContextAlbum").get( attachmentPoint); @@ -45,39 +45,39 @@ executor.logger.info(NomadicONTContext); var jsonObj; var aaiUpdateResult = true; var SDNC_URL = "localhost:8080"; -var HTTP_PROTOCOL ="https://" +var HTTP_PROTOCOL = "http://" var SVC_NOTIFICATION_URL; var putUpddateServInstance = JSON.parse(NomadicONTContext.get("aai_message")); var input_param = JSON.parse(putUpddateServInstance['input-parameters']); try { var br = Files.newBufferedReader(Paths.get( "/home/apexuser/examples/config/ONAPBBS/config.txt")); - // read line by line var line; while ((line = br.readLine()) != null) { if (line.startsWith("SDNC_URL")) { var str = line.split("="); SDNC_URL = str[str.length - 1]; - break; } else if (line.startsWith("SVC_NOTIFICATION_URL")) { var str = line.split("="); SVC_NOTIFICATION_URL = str[str.length - 1]; - break; + } + else if (line.startsWith("SDNC_USERNAME")) { + var str = line.split("="); + SDNC_USERNAME = str[str.length - 1]; + } else if (line.startsWith("SDNC_PASSWORD")) { + var str = line.split("="); + SDNC_PASSWORD = str[str.length - 1]; } } } catch (err) { executor.logger.info("Failed to retrieve data " + err); } executor.logger.info("SDNC_URL " + SDNC_URL); -executor.logger.info("input param " + JSON.stringify(input_param, - null, 4)); var result; var jsonObj; var sdncUpdateResult = true; - - /* BBS Policy calls SDN-C GR-API to delete AccessConnectivity VF ID */ /* Prepare Data*/ var xmlDeleteAccess = ""; @@ -85,7 +85,6 @@ try { var br = Files.newBufferedReader(Paths.get( "/home/apexuser/examples/config/ONAPBBS/sdnc_DeleteAccessConnectivityInstance.txt" )); - // read line by line var line; while ((line = br.readLine()) != null) { xmlDeleteAccess += line; @@ -140,16 +139,14 @@ xmlDeleteAccess = xmlDeleteAccess.replace("vendor_value", input_param['service'] xmlDeleteAccess = xmlDeleteAccess.replace("service_id_value", getMetaValue( putUpddateServInstance['metadata']['metadatum'], 'controller-service-id')); -executor.logger.info("Delete Access Prfile " + xmlDeleteAccess); +executor.logger.info(client.toPrettyString(xmlDeleteAccess, 4)); try { var urlPost1 = HTTP_PROTOCOL + SDNC_URL + "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation"; - result = httpDelete(urlPost1, xmlDeleteAccess, "application/xml").data; - executor.logger.info("Data received From " + urlPost1 + " " + result.toString()); - jsonObj = JSON.parse(result); - executor.logger.info("After Parse " + jsonObj.toString()); - + result = client.httpRequest(urlPost1, "POST", xmlDeleteAccess, SDNC_USERNAME, SDNC_PASSWORD, + "application/xml", true, true); + executor.logger.info("Data received From " + urlPost1 + " " + result); if (result == "") { sdncUpdateResult = false; } @@ -158,7 +155,6 @@ try { sdncUpdateResult = false; } - /* BBS Policy calls SDN-C GR-API to create new AccessConnectivity VF */ /* Prepare Data*/ @@ -167,7 +163,6 @@ try { var br = Files.newBufferedReader(Paths.get( "/home/apexuser/examples/config/ONAPBBS/sdnc_CreateAccessConnectivityInstance.txt" )); - // read line by line var line; while ((line = br.readLine()) != null) { xmlCreateAccess += line; @@ -190,7 +185,6 @@ xmlCreateAccess = xmlCreateAccess.replace("customer_id_value", input_param[ 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' @@ -226,18 +220,17 @@ xmlCreateAccess = xmlCreateAccess.replace("c_vlan_value", getMetaValue( putUpddateServInstance['metadata']['metadatum'], 'cvlan')); xmlCreateAccess = xmlCreateAccess.replace("access_id_value", getMetaValue( putUpddateServInstance['metadata']['metadatum'], 'remote-id')); -executor.logger.info("Create Access Prfile " + xmlCreateAccess); +executor.logger.info(client.toPrettyString(xmlCreateAccess, 4)); + try { if (sdncUpdateResult == true) { var urlPost2 = HTTP_PROTOCOL + SDNC_URL + "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation"; - result = httpPost(urlPost2, xmlCreateAccess, "application/xml").data; - executor.logger.info("Data received From " + urlPost2 + " " + result.toString()); - jsonObj = JSON.parse(result); - executor.logger.info("After Parse " + jsonObj.toString()); - + result = client.httpRequest(urlPost2, "POST", xmlCreateAccess, SDNC_USERNAME, SDNC_PASSWORD, + "application/xml", true, true); + executor.logger.info("Data received From " + urlPost2 + " " + result); if (result == "") { - sdncUpdateResult = false; + sdncUpdateResult = false; } } } catch (err) { @@ -245,15 +238,12 @@ try { sdncUpdateResult = false; } - - /* BBS Policy calls SDN-C GR-API to create change Internet Profile */ var xmlChangeProfile = ""; try { var br = Files.newBufferedReader(Paths.get( "/home/apexuser/examples/config/ONAPBBS/sdnc_ChangeInternetProfileInstance.txt" )); - // read line by line var line; while ((line = br.readLine()) != null) { xmlChangeProfile += line; @@ -304,7 +294,6 @@ xmlCreateAccess = xmlCreateAccess.replace("network_info_model_uuid_value", xmlCreateAccess = xmlCreateAccess.replace("network_info_model_name_value", "EdgeInternetProfile"); - xmlChangeProfile = xmlChangeProfile.replace("vendor_value", input_param[ 'service']['parameters']['requestInputs']['ont_ont_manufacturer']); xmlChangeProfile = xmlChangeProfile.replace("service_id_value", getMetaValue( @@ -326,16 +315,15 @@ xmlChangeProfile = xmlChangeProfile.replace("s_vlan_value", getMetaValue( putUpddateServInstance['metadata']['metadatum'], 'svlan')); xmlChangeProfile = xmlChangeProfile.replace("c_vlan_value", getMetaValue( putUpddateServInstance['metadata']['metadatum'], 'cvlan')); -executor.logger.info("Change Internet Profile " + xmlChangeProfile); +executor.logger.info(client.toPrettyString(xmlChangeProfile, 4)); try { if (sdncUpdateResult == true) { - var urlPost3 = HTTP_PROTOCOL + SDNC_URL + "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation"; - result = httpPost(urlPost3, xmlChangeProfile, "application/xml").data; - executor.logger.info("Data received From " + urlPost3 + " " + result.toString()); - jsonObj = JSON.parse(result); - executor.logger.info("After Parse " + jsonObj.toString()); - + var urlPost3 = HTTP_PROTOCOL + SDNC_URL + + "/restconf/operations/GENERIC-RESOURCE-API:network-topology-operation"; + result = client.httpRequest(urlPost3, "POST", xmlChangeProfile, SDNC_USERNAME, SDNC_PASSWORD, + "application/xml", true, true); + executor.logger.info("Data received From " + urlPost3 + " " + result); if (result == "") { sdncUpdateResult = false; } @@ -345,16 +333,16 @@ try { 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( @@ -364,7 +352,6 @@ var returnValue = executor.isTrue; executor.logger.info(executor.outFields); executor.logger.info("End Execution SdncResourceUpdateTask.js"); - function getMetaValue(metaJson, metaname) { for (var i = 0; i < metaJson.length; i++) { if (metaJson[i]['metaname'] == metaname) { @@ -406,67 +393,12 @@ function getResourceCustomizationUuid(resJson, resourceName) { } /* Utility functions Begin */ -function httpGet(theUrl) { - var con = new java.net.URL(theUrl).openConnection(); - con.requestMethod = "GET"; - return asresult(con); -} - -function httpPost(theUrl, data, contentType) { - contentType = contentType || "application/json"; - var con = new java.net.URL(theUrl).openConnection(); - con.requestMethod = "POST"; - con.setRequestProperty("Content-Type", contentType); - con.doOutput = true; - write(con.outputStream, data); - return asresult(con); -} - -function httpDelete(theUrl, data, contentType) { - contentType = contentType || "application/json"; - var con = new java.net.URL(theUrl).openConnection(); - con.requestMethod = "DELETE"; - con.setRequestProperty("Content-Type", contentType); - con.doOutput = true; - write(con.outputStream, data); - return asresult(con); -} - -function httpPut(theUrl, data, contentType) { - contentType = contentType || "application/json"; - var con = new java.net.URL(theUrl).openConnection(); - con.requestMethod = "PUT"; - con.setRequestProperty("Content-Type", contentType); - con.doOutput = true; - write(con.outputStream, data); - return asresult(con); -} - -function asresult(con) { - var d = read(con.inputStream); - return { - data: d, - statusCode: con.resultCode - }; -} - -function write(outputStream, data) { - var wr = new java.io.DataOutputStream(outputStream); - wr.writeBytes(data); - wr.flush(); - wr.close(); -} - -function read(inputStream) { - var inReader = new java.io.BufferedReader(new java.io.InputStreamReader( - inputStream)); - var inputLine; - var result = new java.lang.StringBuffer(); - - while ((inputLine = inReader.readLine()) != null) { - result.append(inputLine); - } - inReader.close(); - return result.toString(); +function IsValidJSONString(str) { + try { + JSON.parse(str); + } catch (e) { + return false; } - /* Utility functions End */
\ No newline at end of file + return true; +} +/* Utility functions End */
\ No newline at end of file diff --git a/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js b/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js index 62c280531..86e4dfe1c 100644 --- a/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js +++ b/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js @@ -37,6 +37,8 @@ var requestID = clEvent.getRequestId(); var jsonObj; var aaiUpdateResult = true; +var wbClient = Java.type("org.onap.policy.apex.examples.bbs.WebClient"); +var client = new wbClient(); /* Get AAI URL from Configuration file. */ var AAI_URL = "localhost:8080"; @@ -50,15 +52,19 @@ var service_instance; try { var br = Files.newBufferedReader(Paths.get( "/home/apexuser/examples/config/ONAPBBS/config.txt")); - // read line by line var line; while ((line = br.readLine()) != null) { if (line.startsWith("AAI_URL")) { var str = line.split("="); AAI_URL = str[str.length - 1]; - break; + } else if (line.startsWith("AAI_USERNAME")) { + var str = line.split("="); + AAI_USERNAME = str[str.length - 1]; + } else if (line.startsWith("AAI_PASSWORD")) { + var str = line.split("="); + AAI_PASSWORD = str[str.length - 1]; + } } - } } catch (err) { executor.logger.info("Failed to retrieve data " + err); } @@ -73,7 +79,7 @@ try { executor.logger.info("Query url" + urlGet); result = httpGet(urlGet).data; - executor.logger.info("Data received From " + urlGet + " " + result.toString()); + executor.logger.info("Data received From " + urlGet + " " + result); jsonObj = JSON.parse(result); @@ -102,13 +108,11 @@ try { putUpddateServInstance, null, 4)); var urlPut = HTTP_PROTOCOL + AAI_URL + putUrl + "?resource_version=" + resource_version; - result = httpPut(urlPut, JSON.stringify(putUpddateServInstance)).data; - executor.logger.info("Data received From " + urlPut + " " + result.toString()); - jsonObj = JSON.parse(result); - executor.logger.info("After Parse " + JSON.stringify(jsonObj, null, 4)); - + result = client.httpsRequest(urlPut, "PUT", JSON.stringify(putUpddateServInstance), AAI_USERNAME, AAI_PASSWORD, + "application/json", true, true); + executor.logger.info("Data received From " + urlPut + " " + result); /* If failure to retrieve data proceed to Failure */ - if (result == "") { + if (result != "") { aaiUpdateResult = false; } } diff --git a/examples/examples-onap-bbs/src/main/resources/policy/NomadicONTPolicyModel.apex b/examples/examples-onap-bbs/src/main/resources/policy/NomadicONTPolicyModel.apex index 108459eca..242eed478 100644 --- a/examples/examples-onap-bbs/src/main/resources/policy/NomadicONTPolicyModel.apex +++ b/examples/examples-onap-bbs/src/main/resources/policy/NomadicONTPolicyModel.apex @@ -49,11 +49,13 @@ event parameter create name=AAI_SERVICE_ASSIGNED parName=attachmentPoint sch event parameter create name=AAI_SERVICE_ASSIGNED parName=serviceInstanceId schemaName=SimpleStringType optional=true event create name=SDNC_RESOURCE_UPDATE version=1.0.0 nameSpace=org.onap.policy.apex.onap.bbs source=APEX target=APEX +event parameter create name=SDNC_RESOURCE_UPDATE parName=result schemaName=SimpleStringType event parameter create name=SDNC_RESOURCE_UPDATE parName=requestID schemaName=UUIDType event parameter create name=SDNC_RESOURCE_UPDATE parName=attachmentPoint schemaName=SimpleStringType event parameter create name=SDNC_RESOURCE_UPDATE parName=serviceInstanceId schemaName=SimpleStringType optional=true event create name=AAI_SERVICE_CREATE version=1.0.0 nameSpace=org.onap.policy.apex.onap.bbs source=APEX target=APEX +event parameter create name=AAI_SERVICE_CREATE parName=result schemaName=SimpleStringType event parameter create name=AAI_SERVICE_CREATE parName=requestID schemaName=UUIDType event parameter create name=AAI_SERVICE_CREATE parName=attachmentPoint schemaName=SimpleStringType event parameter create name=AAI_SERVICE_CREATE parName=serviceInstanceId schemaName=SimpleStringType optional=true @@ -106,6 +108,7 @@ task inputfield create name=AAIServiceAssignedTask fieldName=serviceInstanceId task outputfield create name=AAIServiceAssignedTask fieldName=requestID schemaName=UUIDType task outputfield create name=AAIServiceAssignedTask fieldName=attachmentPoint schemaName=SimpleStringType task outputfield create name=AAIServiceAssignedTask fieldName=serviceInstanceId schemaName=SimpleStringType optional=true +task outputfield create name=AAIServiceAssignedTask fieldName=result schemaName=SimpleStringType task contextref create name=AAIServiceAssignedTask albumName=NomadicONTContextAlbum @@ -133,6 +136,7 @@ task inputfield create name=SdncResourceUpdateTask fieldName=serviceInstanceId task outputfield create name=SdncResourceUpdateTask fieldName=requestID schemaName=UUIDType task outputfield create name=SdncResourceUpdateTask fieldName=attachmentPoint schemaName=SimpleStringType task outputfield create name=SdncResourceUpdateTask fieldName=serviceInstanceId schemaName=SimpleStringType optional=true +task outputfield create name=SdncResourceUpdateTask fieldName=result schemaName=SimpleStringType task contextref create name=SdncResourceUpdateTask albumName=NomadicONTContextAlbum task logic create name=SdncResourceUpdateTask logicFlavour=JAVASCRIPT logic=LS |