From 5262c350a449c02d91b558976c37850d6340ad81 Mon Sep 17 00:00:00 2001 From: s00370346 Date: Thu, 11 Apr 2019 00:14:39 +0530 Subject: ONAP BBS: Apex Nomadic ONT Policy Implementation Issue-ID: DCAEGEN2-1237 Change-Id: I81831f6498b6c47c0a43215e0445c791b12dac6e Signed-off-by: s00370346 --- .../ONAPBBS/NomadicONTPolicyModel_config.json | 77 ++++++ .../resources/examples/config/ONAPBBS/config.txt | 2 + .../examples/events/ONAPBBS/EventsIn.json.txt | 42 ++++ .../main/resources/logic/AAIServiceAssignedTask.js | 210 +++++++++++++++++ .../main/resources/logic/AAIServiceCreateTask.js | 158 +++++++++++++ .../logic/ErrorAAIServiceAssignedLogTask.js | 28 +++ .../logic/ErrorSdncResourceUpdateTaskLogTask.js | 28 +++ .../resources/logic/GetBBSCloseLoopEventTask.js | 99 ++++++++ .../resources/logic/NomadicEventSuccessTask.js | 46 ++++ .../main/resources/logic/RUorInitStateSelect.js | 43 ++++ .../main/resources/logic/SU2orInitStateSelect.js | 44 ++++ .../main/resources/logic/SdncResourceUpdateTask.js | 163 +++++++++++++ .../logic/ServiceUpdateStateCpeAuthTask.js | 155 ++++++++++++ .../resources/policy/NomadicONTPolicyModel.apex | 262 +++++++++++++++++++++ .../schemas/VCPEClosedLoopStatusType.avsc | 108 +++++++++ 15 files changed, 1465 insertions(+) create mode 100644 examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/NomadicONTPolicyModel_config.json create mode 100644 examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/config.txt create mode 100644 examples/examples-onap-bbs/src/main/resources/examples/events/ONAPBBS/EventsIn.json.txt create mode 100644 examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js create mode 100644 examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js create mode 100644 examples/examples-onap-bbs/src/main/resources/logic/ErrorAAIServiceAssignedLogTask.js create mode 100644 examples/examples-onap-bbs/src/main/resources/logic/ErrorSdncResourceUpdateTaskLogTask.js create mode 100644 examples/examples-onap-bbs/src/main/resources/logic/GetBBSCloseLoopEventTask.js create mode 100644 examples/examples-onap-bbs/src/main/resources/logic/NomadicEventSuccessTask.js create mode 100644 examples/examples-onap-bbs/src/main/resources/logic/RUorInitStateSelect.js create mode 100644 examples/examples-onap-bbs/src/main/resources/logic/SU2orInitStateSelect.js create mode 100644 examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js create mode 100644 examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js create mode 100644 examples/examples-onap-bbs/src/main/resources/policy/NomadicONTPolicyModel.apex create mode 100644 examples/examples-onap-bbs/src/main/resources/schemas/VCPEClosedLoopStatusType.avsc (limited to 'examples/examples-onap-bbs/src/main/resources') diff --git a/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/NomadicONTPolicyModel_config.json b/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/NomadicONTPolicyModel_config.json new file mode 100644 index 000000000..eef2d99a6 --- /dev/null +++ b/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/NomadicONTPolicyModel_config.json @@ -0,0 +1,77 @@ +{ + "engineServiceParameters": { + "name": "NomadicONTPolicyModelEngine", + "version": "0.0.1", + "id": 101, + "instanceCount": 4, + "deploymentPort": 12345, + "policyModelFileName": "/home/apexuser/examples/models/ONAPBBS/NomadicONTPolicyModel.json", + "engineParameters": { + "executorParameters": { + "MVEL": { + "parameterClassName": "org.onap.policy.apex.plugins.executor.mvel.MvelExecutorParameters" + }, + "JAVASCRIPT": { + "parameterClassName": "org.onap.policy.apex.plugins.executor.javascript.JavascriptExecutorParameters" + } + }, + "contextParameters": { + "parameterClassName": "org.onap.policy.apex.context.parameters.ContextParameters", + "schemaParameters": { + "Avro": { + "parameterClassName": "org.onap.policy.apex.plugins.context.schema.avro.AvroSchemaHelperParameters" + }, + "Java": { + "parameterClassName": "org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters", + "jsonAdapters": { + "Instant": { + "adaptedClass": "java.time.Instant", + "adaptorClass": "org.onap.policy.controlloop.util.Serialization$GsonInstantAdapter" + }, + "APPC_LCM_REQUEST": { + "adaptedClass": "org.onap.policy.appclcm.LcmRequest", + "adaptorClass": "org.onap.policy.appclcm.util.Serialization$RequestAdapter" + }, + "APPC_LCM_RESPONSE": { + "adaptedClass": "org.onap.policy.appclcm.LcmResponse", + "adaptorClass": "org.onap.policy.appclcm.util.Serialization$ResponseAdapter" + } + } + } + } + } + } + }, + "eventOutputParameters": { + "FirstProducer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "standardIo": true + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON" + } + } + }, + "eventInputParameters": { + "SecondConsumer": { + "carrierTechnologyParameters": { + "carrierTechnology": "FILE", + "parameters": { + "fileName": "examples/events/ONAPBBS/EventsIn.json.txt" + } + }, + "eventProtocolParameters": { + "eventProtocol": "JSON", + "parameters": { + "nameAlias": "policyName", + "versionAlias": "version", + "sourceAlias": "from", + "pojoField": "VirtualControlLoopEvent" + } + } + } + } +} 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 new file mode 100644 index 000000000..56b6821f7 --- /dev/null +++ b/examples/examples-onap-bbs/src/main/resources/examples/config/ONAPBBS/config.txt @@ -0,0 +1,2 @@ +AAI_URL=192.167.1.3:8080 +SDNC_URL=192.167.1.3:8080 \ No newline at end of file diff --git a/examples/examples-onap-bbs/src/main/resources/examples/events/ONAPBBS/EventsIn.json.txt b/examples/examples-onap-bbs/src/main/resources/examples/events/ONAPBBS/EventsIn.json.txt new file mode 100644 index 000000000..900bb0681 --- /dev/null +++ b/examples/examples-onap-bbs/src/main/resources/examples/events/ONAPBBS/EventsIn.json.txt @@ -0,0 +1,42 @@ +{ + "closedLoopEventClient":"DCAE.BBS_event_processor_mSInstance", + "policyVersion":"1.0.0.5", + "policyName":"Nomadic_ONT", + "policyScope":"reRegPolicyScope", + "target_type":"VM", + "AAI":{ + "attachmentPoint":"olt11-1-1", + "service-information.hsia-cfs-service-instance-id":"1923eaa8-8ab7-49ef-b4c2-e185efbbe832", + "cvlan":"1005", + "svlan":"100", + "remoteId":"some-remote-id" + }, + "closedLoopAlarmStart":1553067455, + "closedLoopEventStatus":"ONSET", + "closedLoopControlName":"reRegControlName", + "version":"1.0.0", + "target":"vserver.vserver-name", + "requestID":"407a6515-4b10-46ad-a249-efe529a36c69", + "from":"DCAE" +} +{ + "closedLoopEventClient":"DCAE.BBS_event_processor_mSInstance", + "policyVersion":"1.0.0.5", + "policyName":"CPE_Authentication", + "policyScope":"reRegPolicyScope", + "target_type":"VM", + "AAI":{ + "attachmentPoint":"olt11-1-1", + "service-information.hsia-cfs-service-instance-id":"1923eaa8-8ab7-49ef-b4c2-e185efbbe832", + "cvlan":"1005", + "svlan":"100", + "remoteId":"some-remote-id" + }, + "closedLoopAlarmStart":1553067455, + "closedLoopEventStatus":"ONSET", + "closedLoopControlName":"reRegControlName", + "version":"1.0.0", + "target":"vserver.vserver-name", + "requestID":"407a6515-4b10-46ad-a249-efe529a36c69", + "from":"DCAE" +} \ No newline at end of file diff --git a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js new file mode 100644 index 000000000..f488c27bf --- /dev/null +++ b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceAssignedTask.js @@ -0,0 +1,210 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Huawei. All rights reserved. + * ================================================================================ + * 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========================================================= + */ + +load("nashorn:mozilla_compat.js"); +importClass(org.apache.avro.Schema); +importClass(java.io.BufferedReader); +importClass(java.io.IOException); +importClass(java.nio.file.Files); +importClass(java.nio.file.Paths); + +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 vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get(attachmentPoint); +executor.logger.info(vcpeClosedLoopStatus); + +var jsonObj; +var aaiUpdateResult = true; + +/* Get AAI URL from Configuration file. */ +var AAI_URL = "localhost:8080"; +var CUSTOMER_ID = requestID; +var BBS_CFS_SERVICE_TYPE = "BBS-CFS-Access_Test"; +var SERVICE_INSTANCE_UUID = serviceInstanceId; +var service_instance_id; +var resource_version; +var relationship_list; +var orchStatus; +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; + } + } +} catch (err) { + executor.logger.info("Failed to retrieve data " + err); +} + +executor.logger.info("AAI_URL=>" + AAI_URL); + +/* Get service instance Id from AAI */ +try { + //var urlGet = "https://" + AAI_URL + "/aai/v14/business/customers/customer/" + CUSTOMER_ID + "/service-subscriptions/service-subscription/" + BBS_CFS_SERVICE_TYPE + "/service-instances/service-instance/" + SERVICE_INSTANCE_UUID + var urlGet = "http://" + AAI_URL + "/RestConfServer/rest/operations/policy/su1/getService"; + executor.logger.info("Query url" + urlGet); + + result = httpGet(urlGet).data; + executor.logger.info("Data received From " + urlGet + " " + result.toString()); + jsonObj = JSON.parse(result); + + + /* Retrieve the service instance id */ + service_instance_id = jsonObj['service-instance-id']; + resource_version = jsonObj['resource-version']; + relationship_list = jsonObj['relationship-list']; + executor.logger.info("After Parse " + JSON.stringify(jsonObj, null, 4)); + + if (result == "") { + aaiUpdateResult = false; + } +}catch (err) { + executor.logger.info("Failed to retrieve data " + err); + aaiUpdateResult = false; +} + +/* BBS Policy updates orchestration status of {{bbs-cfs-service-instance-UUID}} [ active --> assigned ] */ +orchStatus = { + "service-instance-id": service_instance_id, + "resource-version": resource_version, + "orchestration-status": "assigned", + "relationship-list": relationship_list + }; +try { + if (aaiUpdateResult == true) { + executor.logger.info("ready to putAfter Parse " + JSON.stringify(orchStatus, null, 4)); + + //var urlPut = "https://" + AAI_URL + "/aai/v14/business/customers/customer/" + CUSTOMER_ID + "/service-subscriptions/service-subscription/" + BBS_CFS_SERVICE_TYPE + "/service-instances/service-instance/" + SERVICE_INSTANCE_UUID; + var urlPut = "http://" + AAI_URL + "/RestConfServer/rest/operations/policy/su1/putOrchStatus"; + result = httpPut(urlPut, JSON.stringify(orchStatus)).data; + executor.logger.info("Data received From " + urlPut + " " +result.toString()); + jsonObj = JSON.parse(result); + executor.logger.info("After Parse " + JSON.stringify(jsonObj, null, 4)); + + /* If failure to retrieve data proceed to Failure */ + if (result == "") { + aaiUpdateResult = false; + } + } +}catch (err) { + executor.logger.info("Failed to retrieve data " + err); + aaiUpdateResult = false; +} + +/* BBS Policy fetches from AAI {{bbs-cfs-service-instance-UUID}} relationship-list, including: CPE PNF ID, AccessConnectivity VF ID, InternetProfile VF ID */ +try { + if (aaiUpdateResult == true) { + var urlGet2 = "http://" + AAI_URL + "/RestConfServer/rest/operations/policy/su1/getHsia"; + //var urlGet2 = "https://"+ AAI_URL + "/aai/v11/business/customers/customer/" + CUSTOMER_ID + "/service-subscriptions/service-subscription/" + BBS_CFS_SERVICE_TYPE +"/service-instances/service-instance/"+ SERVICE_INSTANCE_UUID + "?depth=all" + result = httpGet(urlGet2).data; + executor.logger.info("Data received From " + urlGet2 + " " +result.toString()); + jsonObj = JSON.parse(result); + executor.logger.info("After Parse " + JSON.stringify(jsonObj, null, 4)); + + /* If failure to retrieve data proceed to Failure */ + if ((result == "") || (jsonObj['orchestration-status'] != 'assigned')) { + executor.logger.info("Failed to get assigned status "); + aaiUpdateResult = false; + } + } +}catch (err) { + executor.logger.info("Failed to retrieve data " + err); + aaiUpdateResult = false; +} +/* If Success then Fill output schema */ +if (aaiUpdateResult === true) { + vcpeClosedLoopStatus.put("result", "SUCCESS"); + vcpeClosedLoopStatus.put("aai_message", JSON.stringify(orchStatus)); +} else { + vcpeClosedLoopStatus.put("result", "FAILURE"); +} + +executor.outFields.put("requestID", requestID); +executor.outFields.put("attachmentPoint", attachmentPoint); +executor.outFields.put("serviceInstanceId", executor.inFields.get("serviceInstanceId")); + +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); + } + inReader.close(); + return result.toString(); +} + +/* Utility functions End */ + diff --git a/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js new file mode 100644 index 000000000..e4f22369c --- /dev/null +++ b/examples/examples-onap-bbs/src/main/resources/logic/AAIServiceCreateTask.js @@ -0,0 +1,158 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Huawei. All rights reserved. + * ================================================================================ + * 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========================================================= + */ +load("nashorn:mozilla_compat.js"); +importClass(org.apache.avro.Schema); +importClass(java.io.BufferedReader); +importClass(java.io.IOException); +importClass(java.nio.file.Files); +importClass(java.nio.file.Paths); + +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"); + +//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; + +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; + } + + } +} catch (err) { + executor.logger.info("Failed to retrieve data " + err); +} +executor.logger.info("AAI_URL=>" + AAI_URL); + + +var attachmentPoint = executor.inFields.get("attachmentPoint"); +var requestID = executor.inFields.get("requestID"); +var serviceInstanceId = executor.inFields.get("serviceInstanceId"); + +var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get(attachmentPoint); +executor.logger.info(vcpeClosedLoopStatus); + +var jsonObj = JSON.parse(vcpeClosedLoopStatus.get("aai_message")); + +jsonObj['orchestration-status'] = "created"; +executor.logger.info(" string" + JSON.stringify(jsonObj, null, 4)); + +var aaiUpdateResult = true; + + +/*BBS Policy updates {{bbs-cfs-service-instance-UUID}} orchestration-status [ assigned --> created ]*/ +try { + //var urlPut = "https://" + AAI_URL + "/aai/v14/business/customers/customer/" + CUSTOMER_ID + "/service-subscriptions/service-subscription/" + BBS_CFS_SERVICE_TYPE + "/service-instances/service-instance/" + SERVICE_INSTANCE_UUID; + var urlPut = "http://" + AAI_URL + "/RestConfServer/rest/operations/policy/su2/aaiUpdate"; + result = httpPut(urlPut, JSON.stringify(jsonObj)).data; + executor.logger.info("Data received From " + urlPut + " " +result.toString()); + repos = JSON.parse(result); + executor.logger.info("After Parse " + result.toString()); + + if (result == "") { + aaiUpdateResult = false; + } +}catch (err) { + executor.logger.info("Failed to retrieve data " + err); + aaiUpdateResult = false; +} + +/* If Success then Fill output schema */ +if (aaiUpdateResult === true) { + vcpeClosedLoopStatus.put("result", "SUCCESS"); +} else { + vcpeClosedLoopStatus.put("result", "FAILURE"); +} + + +executor.outFields.put("requestID", requestID); +executor.outFields.put("attachmentPoint", attachmentPoint); +executor.outFields.put("serviceInstanceId", executor.inFields.get("serviceInstanceId")); + +var returnValue = executor.isTrue; +executor.logger.info("==========>" + executor.outFields); +executor.logger.info("End Execution AAIServiceCreateTask.js"); + + +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(); +} + + diff --git a/examples/examples-onap-bbs/src/main/resources/logic/ErrorAAIServiceAssignedLogTask.js b/examples/examples-onap-bbs/src/main/resources/logic/ErrorAAIServiceAssignedLogTask.js new file mode 100644 index 000000000..ee646fa36 --- /dev/null +++ b/examples/examples-onap-bbs/src/main/resources/logic/ErrorAAIServiceAssignedLogTask.js @@ -0,0 +1,28 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Huawei. All rights reserved. + * ================================================================================ + * 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); + +var returnValue = executor.isTrue; +executor.logger.info("Begin Execution ErrorServiceUpdateOneLogTask.js"); diff --git a/examples/examples-onap-bbs/src/main/resources/logic/ErrorSdncResourceUpdateTaskLogTask.js b/examples/examples-onap-bbs/src/main/resources/logic/ErrorSdncResourceUpdateTaskLogTask.js new file mode 100644 index 000000000..19a61cabd --- /dev/null +++ b/examples/examples-onap-bbs/src/main/resources/logic/ErrorSdncResourceUpdateTaskLogTask.js @@ -0,0 +1,28 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Huawei. All rights reserved. + * ================================================================================ + * 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(executor.outFields); + +var returnValue = executor.isTrue; +executor.logger.info("End Execution ErrorResourceUpdateLogTask.js"); diff --git a/examples/examples-onap-bbs/src/main/resources/logic/GetBBSCloseLoopEventTask.js b/examples/examples-onap-bbs/src/main/resources/logic/GetBBSCloseLoopEventTask.js new file mode 100644 index 000000000..06b11acd5 --- /dev/null +++ b/examples/examples-onap-bbs/src/main/resources/logic/GetBBSCloseLoopEventTask.js @@ -0,0 +1,99 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Huawei. All rights reserved. + * ================================================================================ + * 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========================================================= + */ + +load("nashorn:mozilla_compat.js"); + +executor.logger.info("Begin Execution GetBBSCloseLoopEventTask.js"); +executor.logger.info(executor.subject.id); +executor.logger.info(executor.inFields); +var returnValue = executor.isTrue; + +//**************************************************************************// + +var clEventType = Java.type("org.onap.policy.controlloop.VirtualControlLoopEvent"); +var 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 vcpeClosedLoopStatus = null; +var serviceInstanceId = null; + +if (clEvent.getAai().get("attachmentPoint") != null) { + attachmentPoint = clEvent.getAai().get("attachmentPoint"); + executor.logger.info("attachmentPoint = " + attachmentPoint); + vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get(attachmentPoint); + serviceInstanceId = clEvent.getAai().get("service-information.hsia-cfs-service-instance-id"); + executor.logger.info("serviceInstanceId = " + serviceInstanceId); + + if (vcpeClosedLoopStatus == null) { + executor.logger.info("Creating context information for new ONT Device \"" + attachmentPoint.toString() + "\""); + + vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").getSchemaHelper().createNewInstance(); + + vcpeClosedLoopStatus.put("closedLoopControlName", clEvent.getClosedLoopControlName()); + vcpeClosedLoopStatus.put("closedLoopAlarmStart", clEvent.getClosedLoopAlarmStart().toEpochMilli()); + vcpeClosedLoopStatus.put("closedLoopEventClient", clEvent.getClosedLoopEventClient()); + vcpeClosedLoopStatus.put("closedLoopEventStatus", clEvent.getClosedLoopEventStatus().toString()); + vcpeClosedLoopStatus.put("version", clEvent.getVersion()); + vcpeClosedLoopStatus.put("requestID", clEvent.getRequestId().toString()); + vcpeClosedLoopStatus.put("target_type", clEvent.getTargetType().toString()); + vcpeClosedLoopStatus.put("target", clEvent.getTarget()); + vcpeClosedLoopStatus.put("from", clEvent.getFrom()); + vcpeClosedLoopStatus.put("policyScope", "Nomadic ONT"); + vcpeClosedLoopStatus.put("policyName", clEvent.getPolicyName()); + vcpeClosedLoopStatus.put("policyVersion", "1.0.0"); + vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); + vcpeClosedLoopStatus.put("message", ""); + vcpeClosedLoopStatus.put("result", "SUCCESS"); + var aaiInfo = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").getSchemaHelper().createNewSubInstance("VCPE_AAI_Type"); + + aaiInfo.put("attachmentPoint", clEvent.getAai().get("attachmentPoint")); + aaiInfo.put("cvlan", clEvent.getAai().get("cvlan")); + aaiInfo.put("service_information_hsia_cfs_service_instance_id", clEvent.getAai().get("service-information.hsia-cfs-service-instance-id")); + aaiInfo.put("svlan", clEvent.getAai().get("svlan")); + aaiInfo.put("remoteId", clEvent.getAai().get("remoteId")); + + + vcpeClosedLoopStatus.put("AAI", aaiInfo); + + if (clEvent.getClosedLoopAlarmEnd() != null) { + vcpeClosedLoopStatus.put("closedLoopAlarmEnd", clEvent.getClosedLoopAlarmEnd().toEpochMilli()); + } else { + vcpeClosedLoopStatus.put("closedLoopAlarmEnd", java.lang.Long.valueOf(0)); + } + + executor.getContextAlbum("VCPEClosedLoopStatusAlbum").put(attachmentPoint.toString(), vcpeClosedLoopStatus); + executor.logger.info("Created context information for new vCPE VNF \"" + attachmentPoint.toString() + "\""); + } + + executor.outFields.put("requestID", requestID); + executor.outFields.put("attachmentPoint", attachmentPoint); + executor.outFields.put("serviceInstanceId", attachmentPoint); + executor.logger.info(executor.outFields); +} + +executor.logger.info("********************* Event Successfully Received and stored in album *********************"); + +//**************************************************************************// + + diff --git a/examples/examples-onap-bbs/src/main/resources/logic/NomadicEventSuccessTask.js b/examples/examples-onap-bbs/src/main/resources/logic/NomadicEventSuccessTask.js new file mode 100644 index 000000000..f6a7c4ce7 --- /dev/null +++ b/examples/examples-onap-bbs/src/main/resources/logic/NomadicEventSuccessTask.js @@ -0,0 +1,46 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Huawei. All rights reserved. + * ================================================================================ + * 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========================================================= + */ +load("nashorn:mozilla_compat.js"); +importClass(org.apache.avro.Schema); + +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 vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get(attachmentPoint); + +executor.logger.info("==========>" + executor.outFields); +executor.logger.info("==========>" + executor.inFields); + +result = vcpeClosedLoopStatus.get("result"); + +if (result === "SUCCESS") { + returnValue = executor.isTrue; + 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 = executor.isFalse; +} + +var returnValue = executor.isTrue; +executor.logger.info("End Execution NomadicEventSuccess.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 new file mode 100644 index 000000000..959eab772 --- /dev/null +++ b/examples/examples-onap-bbs/src/main/resources/logic/RUorInitStateSelect.js @@ -0,0 +1,43 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Huawei. All rights reserved. + * ================================================================================ + * 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 returnValue = executor.isTrue; +var result = null; + +var attachmentPoint = executor.inFields.get("attachmentPoint"); +var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get(attachmentPoint); + +executor.logger.info("==========>" + executor.outFields); +executor.logger.info("==========>" + executor.inFields); + +result = vcpeClosedLoopStatus.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"); diff --git a/examples/examples-onap-bbs/src/main/resources/logic/SU2orInitStateSelect.js b/examples/examples-onap-bbs/src/main/resources/logic/SU2orInitStateSelect.js new file mode 100644 index 000000000..6b4c4ff34 --- /dev/null +++ b/examples/examples-onap-bbs/src/main/resources/logic/SU2orInitStateSelect.js @@ -0,0 +1,44 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Huawei. All rights reserved. + * ================================================================================ + * 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 returnValue = executor.isTrue; +var result = null; + +var attachmentPoint = executor.inFields.get("attachmentPoint"); +var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get(attachmentPoint); + +executor.logger.info("==========>" + executor.outFields); +executor.logger.info("==========>" + executor.inFields); + +result = vcpeClosedLoopStatus.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 RUorInitStateSelect.js"); \ No newline at end of file diff --git a/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js b/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js new file mode 100644 index 000000000..6a302ea6a --- /dev/null +++ b/examples/examples-onap-bbs/src/main/resources/logic/SdncResourceUpdateTask.js @@ -0,0 +1,163 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Huawei. All rights reserved. + * ================================================================================ + * 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========================================================= + */ + +load("nashorn:mozilla_compat.js"); +importClass(org.apache.avro.Schema); +importClass(java.io.BufferedReader); +importClass(java.io.IOException); +importClass(java.nio.file.Files); +importClass(java.nio.file.Paths); +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 vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get(attachmentPoint); +executor.logger.info(vcpeClosedLoopStatus); +var jsonObj; +var aaiUpdateResult = true; +var SDNC_URL = "localhost:8080"; +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; + } + } +} catch (err) { + executor.logger.info("Failed to retrieve data " + err); +} +executor.logger.info("SDNC_URL=>" + SDNC_URL); + + +var result; +var jsonObj; +var aaiUpdateResult = true; + +/* BBS Policy calls SDN-C GR-API to delete AccessConnectivity VF ID */ +var json = {id: 1, someValue: "1234"}; +try { + var urlPost1 = "http://" + SDNC_URL + "/RestConfServer/rest/operations/policy/ru/createInstance"; + result = httpPost(urlPost1, JSON.stringify(json) ,"application/json").data; + executor.logger.info("Data received From " + urlPost1 + " " +result.toString()); + jsonObj = JSON.parse(result); + executor.logger.info("After Parse " + jsonObj.toString()); + + if (result == "") { + aaiUpdateResult = false; + } +}catch (err) { + executor.logger.info("Failed to retrieve data " + err); + aaiUpdateResult = false; +} +/* BBS Policy calls SDN-C GR-API to create new AccessConnectivity VF */ +try { + if (aaiUpdateResult == true) { + var json = {id: 2, someValue: "1234"}; + var urlPost2 = "http://" + SDNC_URL + "/RestConfServer/rest/operations/policy/ru/createInstance"; + result = httpPost(urlPost2, JSON.stringify(json), "application/json").data; + executor.logger.info("Data received From " + urlPost2 + " " +result.toString()); + jsonObj = JSON.parse(result); + executor.logger.info("After Parse " + jsonObj.toString()); + + if (result == "") { + } + } +}catch (err) { + executor.logger.info("Failed to retrieve data " + err); + aaiUpdateResult = false; +} + + +/* If Success then Fill output schema */ +if (aaiUpdateResult === true) { + vcpeClosedLoopStatus.put("result", "SUCCESS"); +} else { + vcpeClosedLoopStatus.put("result", "FAILURE"); +} + + +executor.outFields.put("requestID", requestID); +executor.outFields.put("attachmentPoint", attachmentPoint); +executor.outFields.put("serviceInstanceId", executor.inFields.get("serviceInstanceId")); + +var returnValue = executor.isTrue; +executor.logger.info("==========>" + executor.outFields); +executor.logger.info("End Execution SdncResourceUpdateTask.js"); + + +/* 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 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(); +} +/* Utility functions End */ diff --git a/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js b/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js new file mode 100644 index 000000000..9c48f0d52 --- /dev/null +++ b/examples/examples-onap-bbs/src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js @@ -0,0 +1,155 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Huawei. All rights reserved. + * ================================================================================ + * 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========================================================= + */ + +load("nashorn:mozilla_compat.js"); +importClass(java.io.BufferedReader); +importClass(java.io.IOException); +importClass(java.nio.file.Files); +importClass(java.nio.file.Paths); +executor.logger.info("Begin Execution ServiceUpdateStateCpeAuthTask.js"); +executor.logger.info(executor.subject.id); +executor.logger.info(executor.inFields); +var returnValue = executor.isTrue; + +//**************************************************************************// + +var clEventType = Java.type("org.onap.policy.controlloop.VirtualControlLoopEvent"); +var 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 serviceInstanceId = null; +var AAI_URL = "localhost:8080"; +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; + } + + } +} catch (err) { + executor.logger.info("Failed to retrieve data " + err); +} +executor.logger.info("AAI_URL=>" + AAI_URL); + +if (clEvent.getAai().get("attachmentPoint") != null) { + attachmentPoint = clEvent.getAai().get("attachmentPoint"); + executor.logger.info("attachmentPoint = " + attachmentPoint); + serviceInstanceId = clEvent.getAai().get("service-information.hsia-cfs-service-instance-id"); + executor.logger.info("serviceInstanceId = " + serviceInstanceId); + + var result; + var jsonObj; + var prevResult = true; + + + /*BBS Policy updates {{bbs-cfs-service-instance-UUID}} orchestration-status [ assigned --> created ]*/ + var json = {id: 1, someValue: "1234"}; + try { + var urlPut = "http://" + AAI_URL + "/RestConfServer/rest/operations/policy/cpe/cpeAuthUpdate"; + result = httpPut(urlPut, JSON.stringify(json)).data; + executor.logger.info("Data received From " + urlPut + " " +result.toString()); + repos = JSON.parse(result); + executor.logger.info("After Parse " + result.toString()); + + if (result == "") { + prevResult = false; + } + }catch (err) { + executor.logger.info("Failed to retrieve data " + err); + prevResult = false; + } + + /* If Success then Fill output schema */ + if (prevResult == true) { + executor.outFields.put("result", "SUCCCESS"); + } else { + executor.outFields.put("result", "FAILURE"); + } + + executor.outFields.put("requestID", requestID); + executor.outFields.put("attachmentPoint", attachmentPoint); + executor.outFields.put("serviceInstanceId", attachmentPoint); + executor.logger.info(executor.outFields); +} + + + +var returnValue = executor.isTrue; +executor.logger.info("End Execution ServiceUpdateStateCpeAuthTask.js"); + + +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(); +} diff --git a/examples/examples-onap-bbs/src/main/resources/policy/NomadicONTPolicyModel.apex b/examples/examples-onap-bbs/src/main/resources/policy/NomadicONTPolicyModel.apex new file mode 100644 index 000000000..e3f319661 --- /dev/null +++ b/examples/examples-onap-bbs/src/main/resources/policy/NomadicONTPolicyModel.apex @@ -0,0 +1,262 @@ +#------------------------------------------------------------------------------- +# ============LICENSE_START======================================================= +# Copyright (C) 2016-2019 Huawei. All rights reserved. +# ================================================================================ +# 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========================================================= +#------------------------------------------------------------------------------- + +#========> create Policy model +model create name=NomadicONTPolicyModel version=1.0.0 + + +#========> Define Schema and Data types +schema create name=SimpleStringType flavour=Java schema=java.lang.String +schema create name=SimpleLongType flavour=Java schema=java.lang.Long +schema create name=SimpleBooleanType flavour=Java schema=java.lang.Boolean +schema create name=UUIDType flavour=Java schema=java.util.UUID + +schema create name=VirtualControlLoopEventType flavour=Java schema=org.onap.policy.controlloop.VirtualControlLoopEvent + +schema create name=VCPEClosedLoopStatusType flavour=Avro schema=LS +#MACROFILE:"src/main/resources/schemas/VCPEClosedLoopStatusType.avsc" +LE + +#=======================> Create Albums +album create name=VCPEClosedLoopStatusAlbum scope=policy writable=true schemaName=VCPEClosedLoopStatusType + + +#===================================> Define Events +#=============>Nomadic ONT +event create name=Nomadic_ONT version=1.0.0 nameSpace=org.onap.policy.apex.onap.bbs source=DCAE target=APEX +event parameter create name=Nomadic_ONT parName=VirtualControlLoopEvent schemaName=VirtualControlLoopEventType + +event create name=AAI_SERVICE_ASSIGNED version=1.0.0 nameSpace=org.onap.policy.apex.onap.bbs source=APEX target=APEX +event parameter create name=AAI_SERVICE_ASSIGNED parName=requestID schemaName=UUIDType +event parameter create name=AAI_SERVICE_ASSIGNED parName=attachmentPoint schemaName=SimpleStringType +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=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=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 + +event create name=ERROR_LOG version=1.0.0 nameSpace=org.onap.policy.apex.onap.bbs source=APEX target=APEX +event parameter create name=ERROR_LOG parName=errorLogParam schemaName=SimpleStringType + +event create name=END_CONTROL_LOOP version=1.0.0 nameSpace=org.onap.policy.apex.onap.bbs source=APEX target=APEX +event parameter create name=END_CONTROL_LOOP parName=result schemaName=SimpleStringType +event parameter create name=END_CONTROL_LOOP parName=requestID schemaName=UUIDType +event parameter create name=END_CONTROL_LOOP parName=attachmentPoint schemaName=SimpleStringType +event parameter create name=END_CONTROL_LOOP parName=serviceInstanceId schemaName=SimpleStringType optional=true + + +event create name=END_EVENT version=1.0.0 nameSpace=org.onap.policy.apex.onap.bbs source=APEX target=DCAE +event parameter create name=END_EVENT parName=result schemaName=SimpleStringType optional=true +event parameter create name=END_EVENT parName=requestID schemaName=UUIDType +event parameter create name=END_EVENT parName=attachmentPoint schemaName=SimpleStringType +event parameter create name=END_EVENT parName=serviceInstanceId schemaName=SimpleStringType optional=true + +#=============>CPE Authentication +event create name=CPE_Authentication version=1.0.0 nameSpace=org.onap.policy.apex.onap.bbs source=DCAE target=APEX +event parameter create name=CPE_Authentication parName=VirtualControlLoopEvent schemaName=VirtualControlLoopEventType + +event create name=AAI_CPE_AUTH_UPDATE version=1.0.0 nameSpace=org.onap.policy.apex.onap.bbs source=APEX target=DCAE +event parameter create name=AAI_CPE_AUTH_UPDATE parName=result schemaName=SimpleStringType +event parameter create name=AAI_CPE_AUTH_UPDATE parName=requestID schemaName=UUIDType +event parameter create name=AAI_CPE_AUTH_UPDATE parName=attachmentPoint schemaName=SimpleStringType +event parameter create name=AAI_CPE_AUTH_UPDATE parName=serviceInstanceId schemaName=SimpleStringType optional=true + + +#========> Define Tasks (1) +task create name=GetBBSCloseLoopEventTask + +task inputfield create name=GetBBSCloseLoopEventTask fieldName=VirtualControlLoopEvent schemaName=VirtualControlLoopEventType +task outputfield create name=GetBBSCloseLoopEventTask fieldName=requestID schemaName=UUIDType +task outputfield create name=GetBBSCloseLoopEventTask fieldName=attachmentPoint schemaName=SimpleStringType +task outputfield create name=GetBBSCloseLoopEventTask fieldName=serviceInstanceId schemaName=SimpleStringType optional=true +task contextref create name=GetBBSCloseLoopEventTask albumName=VCPEClosedLoopStatusAlbum + +task logic create name=GetBBSCloseLoopEventTask logicFlavour=JAVASCRIPT logic=LS +#MACROFILE:"src/main/resources/logic/GetBBSCloseLoopEventTask.js" +LE + +#========> Define Tasks (2) +task create name=AAIServiceAssignedTask +task inputfield create name=AAIServiceAssignedTask fieldName=requestID schemaName=UUIDType +task inputfield create name=AAIServiceAssignedTask fieldName=attachmentPoint schemaName=SimpleStringType +task inputfield create name=AAIServiceAssignedTask fieldName=serviceInstanceId schemaName=SimpleStringType optional=true +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 contextref create name=AAIServiceAssignedTask albumName=VCPEClosedLoopStatusAlbum + +task logic create name=AAIServiceAssignedTask logicFlavour=JAVASCRIPT logic=LS +#MACROFILE:"src/main/resources/logic/AAIServiceAssignedTask.js" +LE + +#========> Define Tasks (3) +task create name=ErrorAAIServiceAssignedLogTask +task inputfield create name=ErrorAAIServiceAssignedLogTask fieldName=result schemaName=SimpleStringType +task inputfield create name=ErrorAAIServiceAssignedLogTask fieldName=requestID schemaName=UUIDType +task inputfield create name=ErrorAAIServiceAssignedLogTask fieldName=attachmentPoint schemaName=SimpleStringType +task inputfield create name=ErrorAAIServiceAssignedLogTask fieldName=serviceInstanceId schemaName=SimpleStringType optional=true +task outputfield create name=ErrorAAIServiceAssignedLogTask fieldName=errorLogParam schemaName=SimpleStringType + +task logic create name=ErrorAAIServiceAssignedLogTask logicFlavour=JAVASCRIPT logic=LS +#MACROFILE:"src/main/resources/logic/ErrorAAIServiceAssignedLogTask.js" +LE + +#========> Define Tasks (4) +task create name=SdncResourceUpdateTask +task inputfield create name=SdncResourceUpdateTask fieldName=requestID schemaName=UUIDType +task inputfield create name=SdncResourceUpdateTask fieldName=attachmentPoint schemaName=SimpleStringType +task inputfield create name=SdncResourceUpdateTask fieldName=serviceInstanceId schemaName=SimpleStringType optional=true +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 contextref create name=SdncResourceUpdateTask albumName=VCPEClosedLoopStatusAlbum + +task logic create name=SdncResourceUpdateTask logicFlavour=JAVASCRIPT logic=LS +#MACROFILE:"src/main/resources/logic/SdncResourceUpdateTask.js" +LE + +#========> Define Tasks (5) +task create name=ErrorSdncResourceUpdateTaskLogTask +task inputfield create name=ErrorSdncResourceUpdateTaskLogTask fieldName=result schemaName=SimpleStringType +task inputfield create name=ErrorSdncResourceUpdateTaskLogTask fieldName=requestID schemaName=UUIDType +task inputfield create name=ErrorSdncResourceUpdateTaskLogTask fieldName=attachmentPoint schemaName=SimpleStringType +task inputfield create name=ErrorSdncResourceUpdateTaskLogTask fieldName=serviceInstanceId schemaName=SimpleStringType optional=true +task outputfield create name=ErrorSdncResourceUpdateTaskLogTask fieldName=errorLogParam schemaName=SimpleStringType + +task logic create name=ErrorSdncResourceUpdateTaskLogTask logicFlavour=JAVASCRIPT logic=LS +#MACROFILE:"src/main/resources/logic/ErrorSdncResourceUpdateTaskLogTask.js" +LE + +#========> Define Tasks (6) +task create name=AAIServiceCreateTask +task inputfield create name=AAIServiceCreateTask fieldName=requestID schemaName=UUIDType +task inputfield create name=AAIServiceCreateTask fieldName=attachmentPoint schemaName=SimpleStringType +task inputfield create name=AAIServiceCreateTask fieldName=serviceInstanceId schemaName=SimpleStringType optional=true +task outputfield create name=AAIServiceCreateTask fieldName=requestID schemaName=UUIDType +task outputfield create name=AAIServiceCreateTask fieldName=attachmentPoint schemaName=SimpleStringType +task outputfield create name=AAIServiceCreateTask fieldName=serviceInstanceId schemaName=SimpleStringType optional=true +task outputfield create name=AAIServiceCreateTask fieldName=result schemaName=SimpleStringType +task contextref create name=AAIServiceCreateTask albumName=VCPEClosedLoopStatusAlbum + +task logic create name=AAIServiceCreateTask logicFlavour=JAVASCRIPT logic=LS +#MACROFILE:"src/main/resources/logic/AAIServiceCreateTask.js" +LE + +#========> Define Tasks (7) +task create name=NomadicEventSuccessTask +task inputfield create name=NomadicEventSuccessTask fieldName=requestID schemaName=UUIDType +task inputfield create name=NomadicEventSuccessTask fieldName=attachmentPoint schemaName=SimpleStringType +task inputfield create name=NomadicEventSuccessTask fieldName=serviceInstanceId schemaName=SimpleStringType optional=true +task outputfield create name=NomadicEventSuccessTask fieldName=result schemaName=SimpleStringType optional=true +task contextref create name=NomadicEventSuccessTask albumName=VCPEClosedLoopStatusAlbum + +task logic create name=NomadicEventSuccessTask logicFlavour=JAVASCRIPT logic=LS +#MACROFILE:"src/main/resources/logic/NomadicEventSuccessTask.js" +LE + + + +#========> Define Tasks (8) +task create name=ServiceUpdateStateCpeAuthTask +task inputfield create name=ServiceUpdateStateCpeAuthTask fieldName=VirtualControlLoopEvent schemaName=VirtualControlLoopEventType +task outputfield create name=ServiceUpdateStateCpeAuthTask fieldName=result schemaName=SimpleStringType +task outputfield create name=ServiceUpdateStateCpeAuthTask fieldName=requestID schemaName=UUIDType +task outputfield create name=ServiceUpdateStateCpeAuthTask fieldName=attachmentPoint schemaName=SimpleStringType +task outputfield create name=ServiceUpdateStateCpeAuthTask fieldName=serviceInstanceId schemaName=SimpleStringType optional=true +task contextref create name=ServiceUpdateStateCpeAuthTask albumName=VCPEClosedLoopStatusAlbum + +task logic create name=ServiceUpdateStateCpeAuthTask logicFlavour=JAVASCRIPT logic=LS +#MACROFILE:"src/main/resources/logic/ServiceUpdateStateCpeAuthTask.js" +LE + +#========> Create Policy (1) +policy create name=ONTRegistrationPolicy template=Freestyle firstState=INIT + +policy state create name=ONTRegistrationPolicy stateName=NOMADIC_ONT_REG_SUCCESS triggerName=END_CONTROL_LOOP defaultTaskName=NomadicEventSuccessTask +policy state output create name=ONTRegistrationPolicy stateName=NOMADIC_ONT_REG_SUCCESS outputName=NomadicEventSuccessOutPut eventName=END_EVENT +policy state taskref create name=ONTRegistrationPolicy stateName=NOMADIC_ONT_REG_SUCCESS taskName=NomadicEventSuccessTask outputType=DIRECT outputName=NomadicEventSuccessOutPut + +#========> Create State (1.4) +policy state create name=ONTRegistrationPolicy stateName=AAI_SERVICE_CREATE triggerName=AAI_SERVICE_CREATE defaultTaskName=AAIServiceCreateTask + +policy state output create name=ONTRegistrationPolicy stateName=AAI_SERVICE_CREATE outputName=AAIServiceCreateTaskOutput eventName=END_CONTROL_LOOP nextState=NOMADIC_ONT_REG_SUCCESS +policy state taskref create name=ONTRegistrationPolicy stateName=AAI_SERVICE_CREATE taskName=AAIServiceCreateTask outputType=DIRECT outputName=AAIServiceCreateTaskOutput + +policy state output create name=ONTRegistrationPolicy stateName=AAI_SERVICE_CREATE outputName=SdncResourceUpdateErrorLogOutput eventName=ERROR_LOG +policy state taskref create name=ONTRegistrationPolicy stateName=AAI_SERVICE_CREATE taskName=ErrorSdncResourceUpdateTaskLogTask outputType=DIRECT outputName=SdncResourceUpdateErrorLogOutput + +policy state contextref create name=ONTRegistrationPolicy stateName=AAI_SERVICE_CREATE albumName=VCPEClosedLoopStatusAlbum + +policy state selecttasklogic create name=ONTRegistrationPolicy stateName=AAI_SERVICE_CREATE logicFlavour=JAVASCRIPT logic=LS +#MACROFILE:"src/main/resources/logic/SU2orInitStateSelect.js" +LE + + +#========> Create State (1.3) +policy state create name=ONTRegistrationPolicy stateName=SDNC_RES_UPDATE triggerName=SDNC_RESOURCE_UPDATE defaultTaskName=SdncResourceUpdateTask + +policy state output create name=ONTRegistrationPolicy stateName=SDNC_RES_UPDATE outputName=SdncResourceUpdateOutput eventName=AAI_SERVICE_CREATE nextState=AAI_SERVICE_CREATE +policy state taskref create name=ONTRegistrationPolicy stateName=SDNC_RES_UPDATE taskName=SdncResourceUpdateTask outputType=DIRECT outputName=SdncResourceUpdateOutput + +policy state output create name=ONTRegistrationPolicy stateName=SDNC_RES_UPDATE outputName=AAIServiceAssignedErrorLogOutput eventName=ERROR_LOG +policy state taskref create name=ONTRegistrationPolicy stateName=SDNC_RES_UPDATE taskName=ErrorAAIServiceAssignedLogTask outputType=DIRECT outputName=AAIServiceAssignedErrorLogOutput + +policy state contextref create name=ONTRegistrationPolicy stateName=SDNC_RES_UPDATE albumName=VCPEClosedLoopStatusAlbum + +policy state selecttasklogic create name=ONTRegistrationPolicy stateName=SDNC_RES_UPDATE logicFlavour=JAVASCRIPT logic=LS +#MACROFILE:"src/main/resources/logic/RUorInitStateSelect.js" +LE + + + +#========> Create State (1.2) +policy state create name=ONTRegistrationPolicy stateName=AAI_SERVICE_ASSIGN triggerName=AAI_SERVICE_ASSIGNED defaultTaskName=AAIServiceAssignedTask + +policy state output create name=ONTRegistrationPolicy stateName=AAI_SERVICE_ASSIGN outputName=AAIServiceAssignedOutput eventName=SDNC_RESOURCE_UPDATE nextState=SDNC_RES_UPDATE +policy state taskref create name=ONTRegistrationPolicy stateName=AAI_SERVICE_ASSIGN taskName=AAIServiceAssignedTask outputType=DIRECT outputName=AAIServiceAssignedOutput + + + + + +#========> Create State (1.1) +policy state create name=ONTRegistrationPolicy stateName=INIT triggerName=Nomadic_ONT defaultTaskName=GetBBSCloseLoopEventTask +policy state output create name=ONTRegistrationPolicy stateName=INIT outputName=BBSCloseLoopEventOutPut eventName=AAI_SERVICE_ASSIGNED nextState=AAI_SERVICE_ASSIGN +policy state taskref create name=ONTRegistrationPolicy stateName=INIT taskName=GetBBSCloseLoopEventTask outputType=DIRECT outputName=BBSCloseLoopEventOutPut + + + +#========> Create Policy (2) +policy create name=CPEAuthenticationPolicy template=Freestyle firstState=INIT + + +#========> Create State (2.1) +policy state create name=CPEAuthenticationPolicy stateName=INIT triggerName=CPE_Authentication defaultTaskName=ServiceUpdateStateCpeAuthTask +policy state output create name=CPEAuthenticationPolicy stateName=INIT outputName=ServiceUpdateCpeAuthOutPut eventName=AAI_CPE_AUTH_UPDATE +policy state taskref create name=CPEAuthenticationPolicy stateName=INIT taskName=ServiceUpdateStateCpeAuthTask outputType=DIRECT outputName=ServiceUpdateCpeAuthOutPut + +validate diff --git a/examples/examples-onap-bbs/src/main/resources/schemas/VCPEClosedLoopStatusType.avsc b/examples/examples-onap-bbs/src/main/resources/schemas/VCPEClosedLoopStatusType.avsc new file mode 100644 index 000000000..5d1b317a8 --- /dev/null +++ b/examples/examples-onap-bbs/src/main/resources/schemas/VCPEClosedLoopStatusType.avsc @@ -0,0 +1,108 @@ +{ + "type": "record", + "name": "VCPEClosedLoopStatus", + "fields": [ + { + "name": "AAI", + "type": { + "type": "record", + "name": "VCPE_AAI_Type", + "namespace": "org.onap.policy.apex.onap.vcpe", + "fields": [ + { + "name": "attachmentPoint", + "type": "string" + }, + { + "name": "service_information_hsia_cfs_service_instance_id", + "type": "string" + }, + { + "name": "cvlan", + "type": "string" + }, + { + "name": "svlan", + "type": "string" + }, + { + "name": "remoteId", + "type": "string" + } + ] + } + }, + { + "name": "closedLoopAlarmStart", + "type": "long" + }, + { + "name": "closedLoopAlarmEnd", + "type": "long" + }, + { + "name": "closedLoopControlName", + "type": "string" + }, + { + "name": "version", + "type": "string" + }, + { + "name": "requestID", + "type": "string" + }, + { + "name": "closedLoopEventClient", + "type": "string" + }, + { + "name": "closedLoopEventStatus", + "type": "string" + }, + { + "name": "target_type", + "type": "string" + }, + { + "name": "target", + "type": "string" + }, + { + "name": "from", + "type": "string" + }, + { + "name": "policyScope", + "type": "string" + }, + { + "name": "policyName", + "type": "string" + }, + { + "name": "policyVersion", + "type": "string" + }, + { + "name": "notification", + "type": "string" + }, + { + "name": "notificationTime", + "type": "long" + }, + { + "name": "result", + "type": "string" + }, + { + "name": "message", + "type": "string" + }, + { + "name": "aai_message", + "type": "string" + } + ] +} \ No newline at end of file -- cgit 1.2.3-korg