From 7a8e49a16020f7d04724803659f365236987c5ed Mon Sep 17 00:00:00 2001 From: liamfallon Date: Thu, 19 Dec 2019 21:42:34 -0600 Subject: Update vCPE example to use Avro schemas THis change updates the vCPE example to show how the example can work towards the APPC using Avro schemas only. This means that Policies can be adapted to changes in controller APIs using Avro alone. This example works with the old and new format policy-models. Issue-ID: POLICY-2043 Change-Id: I42ac0eac5203eaa37316cf6c460c67f7e8d6deb2 Signed-off-by: liamfallon --- .../src/main/resources/logic/AAILookupTask.js | 85 ----------- .../resources/logic/APPCRestartVNFRequestTask.js | 67 --------- .../resources/logic/APPCRestartVNFResponseTask.js | 88 ------------ .../src/main/resources/logic/AbatedTask.js | 41 ------ .../src/main/resources/logic/ControlLoopLogTask.js | 72 ---------- .../src/main/resources/logic/DeniedTask.js | 32 ----- .../src/main/resources/logic/GetVCPEStateTask.js | 149 ------------------- .../src/main/resources/logic/GuardRequestTask.js | 44 ------ .../src/main/resources/logic/GuardResponseTask.js | 50 ------- .../src/main/resources/logic/NoAAILookupTask.js | 26 ---- .../main/resources/logic/OnsetOrAbatedStateTSL.js | 51 ------- .../RestartAPPCRequestPolicyPermitOrDenyTSL.js | 37 ----- .../resources/logic/definitive/AAILookupTask.js | 85 +++++++++++ .../logic/definitive/APPCRestartVNFRequestTask.js | 67 +++++++++ .../logic/definitive/APPCRestartVNFResponseTask.js | 88 ++++++++++++ .../main/resources/logic/definitive/AbatedTask.js | 41 ++++++ .../logic/definitive/ControlLoopLogTask.js | 73 ++++++++++ .../main/resources/logic/definitive/DeniedTask.js | 32 +++++ .../resources/logic/definitive/GetVCPEStateTask.js | 149 +++++++++++++++++++ .../resources/logic/definitive/GuardRequestTask.js | 44 ++++++ .../logic/definitive/GuardResponseTask.js | 50 +++++++ .../resources/logic/definitive/NoAAILookupTask.js | 26 ++++ .../logic/definitive/OnsetOrAbatedStateTSL.js | 51 +++++++ .../RestartAPPCRequestPolicyPermitOrDenyTSL.js | 37 +++++ .../logic/standalone/CheckServiceIdTask.js | 46 ++++++ .../resources/logic/standalone/CheckVNFIdTask.js | 45 ++++++ .../logic/standalone/CheckVServerIdTask.js | 46 ++++++ .../standalone/ConfigureBlackWhiteListTask.js | 49 +++++++ .../logic/standalone/ControlLoopLogTask.js | 75 ++++++++++ .../logic/standalone/ControllerRequestTask.js | 71 ++++++++++ .../logic/standalone/ControllerResponseTask.js | 90 ++++++++++++ .../standalone/DoControllerRequestActionTask.js | 27 ++++ .../resources/logic/standalone/DoLogActionTask.js | 28 ++++ .../ExecuteActionsPolicyActionStateTSL.js | 33 +++++ .../logic/standalone/GetEntityStateTask.js | 157 +++++++++++++++++++++ .../logic/standalone/InitiateActionsTask.js | 54 +++++++ .../ReceiveEventPolicyExecuteOrLogStateTSL.js | 55 ++++++++ .../resources/logic/standalone/StopAndLogTask.js | 47 ++++++ 38 files changed, 1566 insertions(+), 742 deletions(-) delete mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/AAILookupTask.js delete mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/APPCRestartVNFRequestTask.js delete mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/APPCRestartVNFResponseTask.js delete mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/AbatedTask.js delete mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/ControlLoopLogTask.js delete mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/DeniedTask.js delete mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/GetVCPEStateTask.js delete mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/GuardRequestTask.js delete mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/GuardResponseTask.js delete mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/NoAAILookupTask.js delete mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/OnsetOrAbatedStateTSL.js delete mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/RestartAPPCRequestPolicyPermitOrDenyTSL.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/definitive/AAILookupTask.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/definitive/APPCRestartVNFRequestTask.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/definitive/APPCRestartVNFResponseTask.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/definitive/AbatedTask.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/definitive/ControlLoopLogTask.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/definitive/DeniedTask.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/definitive/GetVCPEStateTask.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/definitive/GuardRequestTask.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/definitive/GuardResponseTask.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/definitive/NoAAILookupTask.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/definitive/OnsetOrAbatedStateTSL.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/definitive/RestartAPPCRequestPolicyPermitOrDenyTSL.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckServiceIdTask.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckVNFIdTask.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckVServerIdTask.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/standalone/ConfigureBlackWhiteListTask.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControlLoopLogTask.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControllerRequestTask.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControllerResponseTask.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/standalone/DoControllerRequestActionTask.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/standalone/DoLogActionTask.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/standalone/ExecuteActionsPolicyActionStateTSL.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/standalone/GetEntityStateTask.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/standalone/InitiateActionsTask.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/standalone/ReceiveEventPolicyExecuteOrLogStateTSL.js create mode 100644 examples/examples-onap-vcpe/src/main/resources/logic/standalone/StopAndLogTask.js (limited to 'examples/examples-onap-vcpe/src/main/resources/logic') diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/AAILookupTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/AAILookupTask.js deleted file mode 100644 index fcb39052d..000000000 --- a/examples/examples-onap-vcpe/src/main/resources/logic/AAILookupTask.js +++ /dev/null @@ -1,85 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. 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(executor.subject.id); -executor.logger.info(executor.inFields); - -var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get( - executor.inFields.get("vnfID").toString()); - -executor.logger.info("Executing A&AI Lookup"); -executor.logger.info(vcpeClosedLoopStatus); - -var aaiInfo = vcpeClosedLoopStatus.get("AAI"); - -if (aaiInfo.get("vserverName") == null) { - executor.message = "the field vserver.vserver-name must exist in the onset control loop event"; - executor.logger.warn(executor.message); - var returnValue = executor.isFalse; -} -else if (aaiInfo.get("genericVnfVnfId") == null && aaiInfo.get("genericVnfVnfName") == null) { - executor.message = "either the field generic-vnf.vnf-id or generic-vnf.vnf-name must exist" - + " in the onset control loop event"; - executor.logger.warn(executor.message); - var returnValue = executor.isFalse; -} -else { - var restManager = new org.onap.policy.rest.RestManager; - var aaiManager = new org.onap.policy.aai.AaiManager(restManager); - - // We need to instantiate the type in order to trigger the static JAXB handling - // in the AaiCqResponse class - var aaiCqResponseType = Java.type("org.onap.policy.aai.AaiCqResponse"); - - var aaiResponse = aaiManager.getCustomQueryResponse( - "http://localhost:54321/OnapVCpeSim/sim", - "aai.username", - "aai.password", - executor.inFields.get("requestID"), - vcpeClosedLoopStatus.get("AAI").get("vserverName") - ); - - var genericVnf; - - if (aaiInfo.get("genericVnfVnfId") != null) { - genericVnf = aaiResponse.getGenericVnfByModelInvariantId(aaiInfo.get("genericVnfVnfId")); - } - else { - genericVnf = aaiResponse.getGenericVnfByVnfName(aaiInfo.get("genericVnfVnfId")); - } - - aaiInfo.put("genericVnfResourceVersion", genericVnf.getResourceVersion()); - aaiInfo.put("genericVnfVnfName", genericVnf.getVnfName()); - aaiInfo.put("genericVnfProvStatus", genericVnf.getProvStatus()); - aaiInfo.put("genericVnfIsClosedLoopDisabled", genericVnf.isIsClosedLoopDisabled().toString()); - aaiInfo.put("genericVnfVnfType", genericVnf.getVnfType()); - aaiInfo.put("genericVnfInMaint", genericVnf.isInMaint().toString()); - aaiInfo.put("genericVnfServiceId", genericVnf.getServiceId()); - aaiInfo.put("genericVnfVnfId", genericVnf.getVnfId()); - aaiInfo.put("genericVnfOrchestrationStatus", - genericVnf.getVfModules().getVfModule().get(0).getOrchestrationStatus()); - - executor.outFields.put("requestID", executor.inFields.get("requestID")); - executor.outFields.put("vnfID", executor.inFields.get("vnfID")); - - executor.logger.info(executor.outFields); - - var returnValue = executor.isTrue; -} diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/APPCRestartVNFRequestTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/APPCRestartVNFRequestTask.js deleted file mode 100644 index dd69dcb1d..000000000 --- a/examples/examples-onap-vcpe/src/main/resources/logic/APPCRestartVNFRequestTask.js +++ /dev/null @@ -1,67 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. 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(executor.subject.id); -executor.logger.info(executor.inFields); - -var appcRequest = new org.onap.policy.appclcm.AppcLcmDmaapWrapper; -appcRequest.setBody(new org.onap.policy.appclcm.AppcLcmBody); -appcRequest.getBody().setInput(new org.onap.policy.appclcm.AppcLcmInput); -appcRequest.getBody().getInput().setCommonHeader( - new org.onap.policy.appclcm.AppcLcmCommonHeader); - -appcRequest.setVersion("2.0.0"); -appcRequest.setRpcName("restart"); -appcRequest.setCorrelationId(executor.inFields.get("requestID")); -appcRequest.setType("request"); - -var vcpeClosedLoopStatus = executor - .getContextAlbum("VCPEClosedLoopStatusAlbum").get( - executor.inFields.get("vnfID").toString()); - -appcRequest.getBody().getInput().getCommonHeader().setTimeStamp(java.time.Instant.now()); -appcRequest.getBody().getInput().getCommonHeader().setApiVer("2.00"); -appcRequest.getBody().getInput().getCommonHeader().setOriginatorId( - executor.inFields.get("requestID").toString()); -appcRequest.getBody().getInput().getCommonHeader().setRequestId( - executor.inFields.get("requestID")); -appcRequest.getBody().getInput().getCommonHeader().setSubRequestId("1"); -appcRequest.getBody().getInput().getCommonHeader().getFlags().put("ttl", "10000"); -appcRequest.getBody().getInput().getCommonHeader().getFlags().put("force", "TRUE"); -appcRequest.getBody().getInput().getCommonHeader().getFlags().put("mode", "EXCLUSIVE"); - -appcRequest.getBody().getInput().setAction("Restart"); -appcRequest.getBody().getInput().setActionIdentifiers(new java.util.HashMap()); -appcRequest.getBody().getInput().getActionIdentifiers().put("vnf-id", - executor.inFields.get("vnfID").toString()); - -executor.getContextAlbum("RequestIDVNFIDAlbum").put( - executor.inFields.get("requestID").toString(), - executor.inFields.get("vnfID")); - -vcpeClosedLoopStatus.put("notification", "OPERATION"); -vcpeClosedLoopStatus.put("notificationTime", java.lang.System - .currentTimeMillis()); - -executor.outFields.put("APPCLCMRequestEvent", appcRequest); - -executor.logger.info(executor.outFields); - -var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/APPCRestartVNFResponseTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/APPCRestartVNFResponseTask.js deleted file mode 100644 index 75ab6a3af..000000000 --- a/examples/examples-onap-vcpe/src/main/resources/logic/APPCRestartVNFResponseTask.js +++ /dev/null @@ -1,88 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. 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. - * - * APPC LCM Response code: 100 ACCEPTED - * 200 ERROR UNEXPECTED ERROR means failure - * 312 REJECTED DUPLICATE REQUEST - * 400 SUCCESS - * - * Note: Sometimes the corelationId has a -1 at the tail, need to get rid of it when present. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -executor.logger.info(executor.subject.id); -executor.logger.info(executor.inFields); - -var appcResponse = executor.inFields.get("APPCLCMResponseEvent"); - -var requestIDString = appcResponse.getCorrelationId().substr(0, 36); -executor.logger.info("requestIDString = " + requestIDString); -var vnfID = executor.getContextAlbum("RequestIDVNFIDAlbum") - .get(requestIDString); -executor.logger.info("Size of RequestIDVNFIDAlbum = " - + executor.getContextAlbum("RequestIDVNFIDAlbum").size()); -executor.logger.info("vnfID = " + vnfID); - -var returnValue = executor.isTrue; - -if (vnfID != null) { - var vcpeClosedLoopStatus = executor.getContextAlbum( - "VCPEClosedLoopStatusAlbum").get(vnfID.toString()); - var requestId = java.util.UUID.fromString(vcpeClosedLoopStatus - .get("requestID")); - - vcpeClosedLoopStatus.put("notificationTime", java.lang.System - .currentTimeMillis()); - - executor.logger.info("Got from APPC code: " - + org.onap.policy.appclcm.AppcLcmResponseCode - .toResponseValue(appcResponse.getBody().getOutput() - .getStatus().getCode())); - - if (org.onap.policy.appclcm.AppcLcmResponseCode - .toResponseValue(appcResponse.getBody().getOutput().getStatus() - .getCode()) == org.onap.policy.appclcm.AppcLcmResponseCode.SUCCESS) { - vcpeClosedLoopStatus.put("notification", "OPERATION_SUCCESS"); - vcpeClosedLoopStatus.put("message", "vCPE restarted"); - executor.getContextAlbum("RequestIDVNFIDAlbum").remove(requestIDString); - } else if (org.onap.policy.appclcm.AppcLcmResponseCode - .toResponseValue(appcResponse.getBody().getOutput().getStatus() - .getCode()) == "ACCEPTED" - || org.onap.policy.appclcm.AppcLcmResponseCode - .toResponseValue(appcResponse.getBody().getOutput() - .getStatus().getCode()) == "REJECT") { - executor.logger - .info("Got ACCEPTED 100 or REJECT 312, keep the context, wait for next response. Code is: " - + org.onap.policy.appclcm.AppcLcmResponseCode - .toResponseValue(appcResponse.getBody() - .getOutput().getStatus().getCode())); - } else { - executor.getContextAlbum("RequestIDVNFIDAlbum").remove(requestIDString); - vcpeClosedLoopStatus.put("notification", "OPERATION_FAILURE"); - vcpeClosedLoopStatus.put("message", "vCPE restart failed"); - } - - executor.outFields.put("requestID", requestId); - executor.outFields.put("vnfID", vnfID); -} else { - executor.message = "VNF ID not found in context album for request ID " - + requestIDString; - returnValue = executor.isFalse; -} - -executor.logger.info(executor.outFields); diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/AbatedTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/AbatedTask.js deleted file mode 100644 index f37b6f1b5..000000000 --- a/examples/examples-onap-vcpe/src/main/resources/logic/AbatedTask.js +++ /dev/null @@ -1,41 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. 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(executor.subject.id); -executor.logger.info(executor.inFields); - -var vcpeClosedLoopStatus = null; -if( executor.inFields.get("vnfID") == null) { - executor.logger.info("AbatedTask: vnfID is null"); - var vnfName = executor.inFields.get("vnfName"); - vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get( - executor.inFields.get("vnfName")); -} else { - vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get( - executor.inFields.get("vnfID").toString()); -} - -vcpeClosedLoopStatus.put("notification", "FINAL_SUCCESS"); -vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); -vcpeClosedLoopStatus.put("message", "situation has been abated"); - -executor.logger.info(executor.outFields); - -var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/ControlLoopLogTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/ControlLoopLogTask.js deleted file mode 100644 index aa816ca95..000000000 --- a/examples/examples-onap-vcpe/src/main/resources/logic/ControlLoopLogTask.js +++ /dev/null @@ -1,72 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. 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(executor.subject.id); -executor.logger.info(executor.inFields); - -var vnfID = executor.inFields.get("vnfID"); -if(vnfID == null) { - vnfID = executor.inFields.get("vnfName"); -} -executor.logger.info("vnfID=" + vnfID); - -var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get(vnfID.toString()); - -executor.logger.info("Logging context information for VNF \"" + vnfID + "\""); - -var clNotification = new org.onap.policy.controlloop.VirtualControlLoopNotification(); - -clNotification.setClosedLoopControlName(vcpeClosedLoopStatus.get("closedLoopControlName")); -clNotification.setClosedLoopAlarmStart(java.time.Instant.ofEpochMilli(vcpeClosedLoopStatus.get("closedLoopAlarmStart"))); -clNotification.setClosedLoopAlarmEnd(java.time.Instant.ofEpochMilli(vcpeClosedLoopStatus.get("closedLoopAlarmEnd"))); -clNotification.setClosedLoopEventClient(vcpeClosedLoopStatus.get("closedLoopEventClient")); -clNotification.setVersion(vcpeClosedLoopStatus.get("version")); -clNotification.setRequestId(java.util.UUID.fromString(vcpeClosedLoopStatus.get("requestID"))); -clNotification.setTargetType(vcpeClosedLoopStatus.get("target_type")); -clNotification.setTarget(org.onap.policy.controlloop.ControlLoopEventStatus.toStatus(vcpeClosedLoopStatus.get("target"))); -clNotification.setFrom(vcpeClosedLoopStatus.get("from")); -clNotification.setPolicyScope(vcpeClosedLoopStatus.get("policyScope")); -clNotification.setPolicyName(vcpeClosedLoopStatus.get("policyName")); -clNotification.setPolicyVersion(vcpeClosedLoopStatus.get("policyVersion")); -clNotification.setNotification(org.onap.policy.controlloop.ControlLoopNotificationType.toType(vcpeClosedLoopStatus.get("notification"))); -clNotification.setMessage(vcpeClosedLoopStatus.get("message")); - -var notificationInstant = java.time.Instant.ofEpochSecond(vcpeClosedLoopStatus.get("notificationTime")); -var notificationTime = java.time.ZonedDateTime.ofInstant(notificationInstant, java.time.ZoneOffset.UTC); -clNotification.setNotificationTime(notificationTime); - -var aaiInfo = vcpeClosedLoopStatus.get("AAI"); - -clNotification.getAai().put("generic-vnf.resource-version", aaiInfo.get("genericVnfResourceVersion")); -clNotification.getAai().put("generic-vnf.vnf-name", aaiInfo.get("genericVnfVnfName")); -clNotification.getAai().put("generic-vnf.prov-status", aaiInfo.get("genericVnfProvStatus")); -clNotification.getAai().put("generic-vnf.is-closed-loop-disabled", aaiInfo.get("genericVnfIsClosedLoopDisabled")); -clNotification.getAai().put("generic-vnf.orchestration-status", aaiInfo.get("genericVnfOrchestrationStatus")); -clNotification.getAai().put("generic-vnf.vnf-type", aaiInfo.get("genericVnfVnfType")); -clNotification.getAai().put("generic-vnf.in-maint", aaiInfo.get("genericVnfInMaint")); -clNotification.getAai().put("generic-vnf.service-id", aaiInfo.get("genericVnfServiceId")); -if(vnfID != null) { - clNotification.getAai().put("generic-vnf.vnf-id", aaiInfo.get("genericVnfVnfId")); -} -executor.outFields.put("VirtualControlLoopNotification", clNotification); - -executor.logger.info(executor.outFields); - -var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/DeniedTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/DeniedTask.js deleted file mode 100644 index 353c21ef6..000000000 --- a/examples/examples-onap-vcpe/src/main/resources/logic/DeniedTask.js +++ /dev/null @@ -1,32 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. 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(executor.subject.id); -executor.logger.info(executor.inFields); - -var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get( - executor.inFields.get("vnfID").toString()); - -vcpeClosedLoopStatus.put("notification", "REJECTED"); -vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); - -executor.logger.info(executor.outFields); - -var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/GetVCPEStateTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/GetVCPEStateTask.js deleted file mode 100644 index f4f6d908d..000000000 --- a/examples/examples-onap-vcpe/src/main/resources/logic/GetVCPEStateTask.js +++ /dev/null @@ -1,149 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. 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. - * - * Note: The incoming closedloop message can be ONSET with both VNF-name and VNF-ID - * or ABATED with only VNF-name. So need to handle differently. For ABATED case, - * since we still keep the RequireIDVNFID context album, we can get it from there. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -executor.logger.info(executor.subject.id); -executor.logger.info(executor.inFields); - -var clEventType = Java.type("org.onap.policy.controlloop.VirtualControlLoopEvent"); -var longType = Java.type("java.lang.Long"); -var uuidType = Java.type("java.util.UUID"); - -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 vnfID = null; -var vcpeClosedLoopStatus = null; - -if (clEvent.getAai().get("generic-vnf.vnf-id") != null) { - vnfID = uuidType.fromString(clEvent.getAai().get("generic-vnf.vnf-id")); - executor.logger.info("vnfID = " + vnfID); - vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get(vnfID); - - if (vcpeClosedLoopStatus == null) { - executor.logger.info("Creating context information for new vCPE VNF \"" + vnfID.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", "vCPE"); - vcpeClosedLoopStatus.put("policyName", "ONAPvCPEPolicyModel"); - vcpeClosedLoopStatus.put("policyVersion", "0.0.1"); - vcpeClosedLoopStatus.put("notification", "ACTIVE"); - vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); - vcpeClosedLoopStatus.put("message", ""); - - var aaiInfo = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").getSchemaHelper().createNewSubInstance("VCPE_AAI_Type"); - - aaiInfo.put("genericVnfResourceVersion", clEvent.getAai().get("generic-vnf.resource-version")); - aaiInfo.put("genericVnfVnfName", clEvent.getAai().get("generic-vnf.vnf-name")); - aaiInfo.put("genericVnfProvStatus", clEvent.getAai().get("generic-vnf.prov-status")); - aaiInfo.put("genericVnfIsClosedLoopDisabled", clEvent.getAai().get("generic-vnf.is-closed-loop-disabled")); - aaiInfo.put("genericVnfOrchestrationStatus", clEvent.getAai().get("generic-vnf.orchestration-status")); - aaiInfo.put("genericVnfVnfType", clEvent.getAai().get("generic-vnf.vnf-type")); - aaiInfo.put("genericVnfInMaint", clEvent.getAai().get("generic-vnf.in-maint")); - aaiInfo.put("genericVnfServiceId", clEvent.getAai().get("generic-vnf.service-id")); - aaiInfo.put("genericVnfVnfId", clEvent.getAai().get("generic-vnf.vnf-id")); - aaiInfo.put("vserverIsClosedLoopDisabled", clEvent.getAai().get("vserver.is-closed-loop-disabled")); - aaiInfo.put("vserverProvStatus", clEvent.getAai().get("vserver.prov-status")); - aaiInfo.put("vserverName", clEvent.getAai().get("vserver.vserver-name")); - - 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(vnfID.toString(), vcpeClosedLoopStatus); - - executor.logger.info("Created context information for new vCPE VNF \"" + vnfID.toString() + "\""); - } - - executor.outFields.put("requestID", requestID); - executor.outFields.put("vnfID", vnfID); - - executor.logger.info(executor.outFields); -} -else { - executor.logger.info("No vnf-id in VirtualControlLoopEvent, status:" + clEvent.getClosedLoopEventStatus().toString()); - var vnfName = clEvent.getAai().get("generic-vnf.vnf-name"); - executor.logger.info("No vnf-id in VirtualControlLoopEvent for " + vnfName); - - vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get(vnfName.toString()); - - if (vcpeClosedLoopStatus == null) { - executor.logger.info("Creating context information for new vCPE VNF \"" + vnfName.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", "vCPE"); - vcpeClosedLoopStatus.put("policyName", "ONAPvCPEPolicyModel"); - vcpeClosedLoopStatus.put("policyVersion", "0.0.1"); - vcpeClosedLoopStatus.put("notification", "ACTIVE"); - vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); - vcpeClosedLoopStatus.put("message", ""); - - var aaiInfo = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").getSchemaHelper().createNewSubInstance("VCPE_AAI_Type"); - - aaiInfo.put("genericVnfVnfName", clEvent.getAai().get("generic-vnf.vnf-name")); - 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(vnfName.toString(), vcpeClosedLoopStatus); - - executor.logger.info("Created context information for new vCPE VNF \"" + vnfName.toString() + "\""); - } - executor.outFields.put("requestID", requestID); - executor.outFields.put("vnfName", vnfName); - executor.logger.info(executor.outFields); -} - -returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/GuardRequestTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/GuardRequestTask.js deleted file mode 100644 index d247f8a65..000000000 --- a/examples/examples-onap-vcpe/src/main/resources/logic/GuardRequestTask.js +++ /dev/null @@ -1,44 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. 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(executor.subject.id); -executor.logger.info(executor.inFields); - -var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get( - executor.inFields.get("vnfID").toString()); - -var guardDecisionAttributes = executor.subject.getOutFieldSchemaHelper("decisionAttributes").createNewInstance(); - -guardDecisionAttributes.put("actor", "APPC"); -guardDecisionAttributes.put("recipe", "Restart"); -guardDecisionAttributes.put("target", executor.inFields.get("vnfID").toString()); -guardDecisionAttributes.put("clname", "APEXvCPEImplementation"); - -executor.logger.info(guardDecisionAttributes); - -executor.outFields.put("decisionAttributes", guardDecisionAttributes); -executor.outFields.put("onapName", "PDPD"); - -executor.getContextAlbum("ControlLoopExecutionIDAlbum").put(executor.executionId.toString(), - executor.inFields.get("vnfID")); - -executor.logger.info(executor.outFields); - -var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/GuardResponseTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/GuardResponseTask.js deleted file mode 100644 index 2a9100b7f..000000000 --- a/examples/examples-onap-vcpe/src/main/resources/logic/GuardResponseTask.js +++ /dev/null @@ -1,50 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. 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(executor.subject.id); -executor.logger.info(executor.inFields); - -var vnfID = executor.getContextAlbum("ControlLoopExecutionIDAlbum").remove(executor.executionId.toString()); - -executor.logger.info("Continuing execution with VNF ID: " + vnfID); - -var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get(vnfID.toString()); -executor.logger.info(vcpeClosedLoopStatus); - -var guardResult = executor.inFields.get("decision"); - -if (guardResult === "PERMIT") { - vcpeClosedLoopStatus.put("notification", "OPERATION: GUARD_PERMIT"); -} else if (guardResult === "DENY") { - vcpeClosedLoopStatus.put("notification", "OPERATION: GUARD_DENY"); -} else { - executor.message = "guard result must be either \"PERMIT\" or \"DENY\""; - returnValue = executor.FALSE; -} - -var uuidType = Java.type("java.util.UUID"); -var requestID = uuidType.fromString(vcpeClosedLoopStatus.get("requestID")); - -executor.outFields.put("requestID", requestID); -executor.outFields.put("vnfID", vnfID); - -executor.logger.info(executor.outFields); - -var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/NoAAILookupTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/NoAAILookupTask.js deleted file mode 100644 index ebc0e6387..000000000 --- a/examples/examples-onap-vcpe/src/main/resources/logic/NoAAILookupTask.js +++ /dev/null @@ -1,26 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. 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(executor.subject.id); -executor.logger.info(executor.inFields); - -executor.logger.info(executor.outFields); - -var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/OnsetOrAbatedStateTSL.js b/examples/examples-onap-vcpe/src/main/resources/logic/OnsetOrAbatedStateTSL.js deleted file mode 100644 index c8a3bfba8..000000000 --- a/examples/examples-onap-vcpe/src/main/resources/logic/OnsetOrAbatedStateTSL.js +++ /dev/null @@ -1,51 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. 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(executor.subject.id); -executor.logger.info(executor.inFields); - -var returnValue = executor.isTrue; -var status = null; - -if( executor.inFields.get("vnfID") == null) { - executor.logger.info("OnsetOrAbatedStateTSL: vnfID is null"); - var vnfName = executor.inFields.get("vnfName"); - var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get( - executor.inFields.get("vnfName")); - status = vcpeClosedLoopStatus.get("closedLoopEventStatus").toString(); -} else { - var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get( - executor.inFields.get("vnfID").toString()); - status = vcpeClosedLoopStatus.get("closedLoopEventStatus").toString(); -} - -var returnValue = executor.isTrue; - -if (status === "ONSET") { - executor.subject.getTaskKey("GuardRequestTask").copyTo(executor.selectedTask); -} else if (status === "ABATED") { - executor.subject.getTaskKey("AbatedTask").copyTo(executor.selectedTask); - onsetFlag = executor.isFalse; -} else { - executor.message = "closedLoopEventStatus is \"" + status + "\", it must be either \"ONSET\" or \"ABATED\""; - returnValue = executor.isFalse; -} - -executor.logger.info("ReceiveEventPolicyOnsetOrAbatedStateTSL State Selected Task:" + executor.selectedTask); diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/RestartAPPCRequestPolicyPermitOrDenyTSL.js b/examples/examples-onap-vcpe/src/main/resources/logic/RestartAPPCRequestPolicyPermitOrDenyTSL.js deleted file mode 100644 index a1bac6546..000000000 --- a/examples/examples-onap-vcpe/src/main/resources/logic/RestartAPPCRequestPolicyPermitOrDenyTSL.js +++ /dev/null @@ -1,37 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. 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(executor.subject.id); -executor.logger.info(executor.inFields); - -var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get( - executor.inFields.get("vnfID").toString()); - -var guardResult = vcpeClosedLoopStatus.get("notification"); - -if (guardResult === "OPERATION: GUARD_PERMIT") { - executor.subject.getTaskKey("APPCRestartVNFRequestTask").copyTo(executor.selectedTask); -} else { - executor.subject.getTaskKey("DeniedTask").copyTo(executor.selectedTask); -} - -executor.logger.info("RestartAPPCRequestPolicyPermitOrDenyTSL State Selected Task:" + executor.selectedTask); - -var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/AAILookupTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/AAILookupTask.js new file mode 100644 index 000000000..fcb39052d --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/AAILookupTask.js @@ -0,0 +1,85 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. 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(executor.subject.id); +executor.logger.info(executor.inFields); + +var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get( + executor.inFields.get("vnfID").toString()); + +executor.logger.info("Executing A&AI Lookup"); +executor.logger.info(vcpeClosedLoopStatus); + +var aaiInfo = vcpeClosedLoopStatus.get("AAI"); + +if (aaiInfo.get("vserverName") == null) { + executor.message = "the field vserver.vserver-name must exist in the onset control loop event"; + executor.logger.warn(executor.message); + var returnValue = executor.isFalse; +} +else if (aaiInfo.get("genericVnfVnfId") == null && aaiInfo.get("genericVnfVnfName") == null) { + executor.message = "either the field generic-vnf.vnf-id or generic-vnf.vnf-name must exist" + + " in the onset control loop event"; + executor.logger.warn(executor.message); + var returnValue = executor.isFalse; +} +else { + var restManager = new org.onap.policy.rest.RestManager; + var aaiManager = new org.onap.policy.aai.AaiManager(restManager); + + // We need to instantiate the type in order to trigger the static JAXB handling + // in the AaiCqResponse class + var aaiCqResponseType = Java.type("org.onap.policy.aai.AaiCqResponse"); + + var aaiResponse = aaiManager.getCustomQueryResponse( + "http://localhost:54321/OnapVCpeSim/sim", + "aai.username", + "aai.password", + executor.inFields.get("requestID"), + vcpeClosedLoopStatus.get("AAI").get("vserverName") + ); + + var genericVnf; + + if (aaiInfo.get("genericVnfVnfId") != null) { + genericVnf = aaiResponse.getGenericVnfByModelInvariantId(aaiInfo.get("genericVnfVnfId")); + } + else { + genericVnf = aaiResponse.getGenericVnfByVnfName(aaiInfo.get("genericVnfVnfId")); + } + + aaiInfo.put("genericVnfResourceVersion", genericVnf.getResourceVersion()); + aaiInfo.put("genericVnfVnfName", genericVnf.getVnfName()); + aaiInfo.put("genericVnfProvStatus", genericVnf.getProvStatus()); + aaiInfo.put("genericVnfIsClosedLoopDisabled", genericVnf.isIsClosedLoopDisabled().toString()); + aaiInfo.put("genericVnfVnfType", genericVnf.getVnfType()); + aaiInfo.put("genericVnfInMaint", genericVnf.isInMaint().toString()); + aaiInfo.put("genericVnfServiceId", genericVnf.getServiceId()); + aaiInfo.put("genericVnfVnfId", genericVnf.getVnfId()); + aaiInfo.put("genericVnfOrchestrationStatus", + genericVnf.getVfModules().getVfModule().get(0).getOrchestrationStatus()); + + executor.outFields.put("requestID", executor.inFields.get("requestID")); + executor.outFields.put("vnfID", executor.inFields.get("vnfID")); + + executor.logger.info(executor.outFields); + + var returnValue = executor.isTrue; +} diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/APPCRestartVNFRequestTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/APPCRestartVNFRequestTask.js new file mode 100644 index 000000000..dd69dcb1d --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/APPCRestartVNFRequestTask.js @@ -0,0 +1,67 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. 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(executor.subject.id); +executor.logger.info(executor.inFields); + +var appcRequest = new org.onap.policy.appclcm.AppcLcmDmaapWrapper; +appcRequest.setBody(new org.onap.policy.appclcm.AppcLcmBody); +appcRequest.getBody().setInput(new org.onap.policy.appclcm.AppcLcmInput); +appcRequest.getBody().getInput().setCommonHeader( + new org.onap.policy.appclcm.AppcLcmCommonHeader); + +appcRequest.setVersion("2.0.0"); +appcRequest.setRpcName("restart"); +appcRequest.setCorrelationId(executor.inFields.get("requestID")); +appcRequest.setType("request"); + +var vcpeClosedLoopStatus = executor + .getContextAlbum("VCPEClosedLoopStatusAlbum").get( + executor.inFields.get("vnfID").toString()); + +appcRequest.getBody().getInput().getCommonHeader().setTimeStamp(java.time.Instant.now()); +appcRequest.getBody().getInput().getCommonHeader().setApiVer("2.00"); +appcRequest.getBody().getInput().getCommonHeader().setOriginatorId( + executor.inFields.get("requestID").toString()); +appcRequest.getBody().getInput().getCommonHeader().setRequestId( + executor.inFields.get("requestID")); +appcRequest.getBody().getInput().getCommonHeader().setSubRequestId("1"); +appcRequest.getBody().getInput().getCommonHeader().getFlags().put("ttl", "10000"); +appcRequest.getBody().getInput().getCommonHeader().getFlags().put("force", "TRUE"); +appcRequest.getBody().getInput().getCommonHeader().getFlags().put("mode", "EXCLUSIVE"); + +appcRequest.getBody().getInput().setAction("Restart"); +appcRequest.getBody().getInput().setActionIdentifiers(new java.util.HashMap()); +appcRequest.getBody().getInput().getActionIdentifiers().put("vnf-id", + executor.inFields.get("vnfID").toString()); + +executor.getContextAlbum("RequestIDVNFIDAlbum").put( + executor.inFields.get("requestID").toString(), + executor.inFields.get("vnfID")); + +vcpeClosedLoopStatus.put("notification", "OPERATION"); +vcpeClosedLoopStatus.put("notificationTime", java.lang.System + .currentTimeMillis()); + +executor.outFields.put("APPCLCMRequestEvent", appcRequest); + +executor.logger.info(executor.outFields); + +var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/APPCRestartVNFResponseTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/APPCRestartVNFResponseTask.js new file mode 100644 index 000000000..75ab6a3af --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/APPCRestartVNFResponseTask.js @@ -0,0 +1,88 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. 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. + * + * APPC LCM Response code: 100 ACCEPTED + * 200 ERROR UNEXPECTED ERROR means failure + * 312 REJECTED DUPLICATE REQUEST + * 400 SUCCESS + * + * Note: Sometimes the corelationId has a -1 at the tail, need to get rid of it when present. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info(executor.subject.id); +executor.logger.info(executor.inFields); + +var appcResponse = executor.inFields.get("APPCLCMResponseEvent"); + +var requestIDString = appcResponse.getCorrelationId().substr(0, 36); +executor.logger.info("requestIDString = " + requestIDString); +var vnfID = executor.getContextAlbum("RequestIDVNFIDAlbum") + .get(requestIDString); +executor.logger.info("Size of RequestIDVNFIDAlbum = " + + executor.getContextAlbum("RequestIDVNFIDAlbum").size()); +executor.logger.info("vnfID = " + vnfID); + +var returnValue = executor.isTrue; + +if (vnfID != null) { + var vcpeClosedLoopStatus = executor.getContextAlbum( + "VCPEClosedLoopStatusAlbum").get(vnfID.toString()); + var requestId = java.util.UUID.fromString(vcpeClosedLoopStatus + .get("requestID")); + + vcpeClosedLoopStatus.put("notificationTime", java.lang.System + .currentTimeMillis()); + + executor.logger.info("Got from APPC code: " + + org.onap.policy.appclcm.AppcLcmResponseCode + .toResponseValue(appcResponse.getBody().getOutput() + .getStatus().getCode())); + + if (org.onap.policy.appclcm.AppcLcmResponseCode + .toResponseValue(appcResponse.getBody().getOutput().getStatus() + .getCode()) == org.onap.policy.appclcm.AppcLcmResponseCode.SUCCESS) { + vcpeClosedLoopStatus.put("notification", "OPERATION_SUCCESS"); + vcpeClosedLoopStatus.put("message", "vCPE restarted"); + executor.getContextAlbum("RequestIDVNFIDAlbum").remove(requestIDString); + } else if (org.onap.policy.appclcm.AppcLcmResponseCode + .toResponseValue(appcResponse.getBody().getOutput().getStatus() + .getCode()) == "ACCEPTED" + || org.onap.policy.appclcm.AppcLcmResponseCode + .toResponseValue(appcResponse.getBody().getOutput() + .getStatus().getCode()) == "REJECT") { + executor.logger + .info("Got ACCEPTED 100 or REJECT 312, keep the context, wait for next response. Code is: " + + org.onap.policy.appclcm.AppcLcmResponseCode + .toResponseValue(appcResponse.getBody() + .getOutput().getStatus().getCode())); + } else { + executor.getContextAlbum("RequestIDVNFIDAlbum").remove(requestIDString); + vcpeClosedLoopStatus.put("notification", "OPERATION_FAILURE"); + vcpeClosedLoopStatus.put("message", "vCPE restart failed"); + } + + executor.outFields.put("requestID", requestId); + executor.outFields.put("vnfID", vnfID); +} else { + executor.message = "VNF ID not found in context album for request ID " + + requestIDString; + returnValue = executor.isFalse; +} + +executor.logger.info(executor.outFields); diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/AbatedTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/AbatedTask.js new file mode 100644 index 000000000..f37b6f1b5 --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/AbatedTask.js @@ -0,0 +1,41 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. 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(executor.subject.id); +executor.logger.info(executor.inFields); + +var vcpeClosedLoopStatus = null; +if( executor.inFields.get("vnfID") == null) { + executor.logger.info("AbatedTask: vnfID is null"); + var vnfName = executor.inFields.get("vnfName"); + vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get( + executor.inFields.get("vnfName")); +} else { + vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get( + executor.inFields.get("vnfID").toString()); +} + +vcpeClosedLoopStatus.put("notification", "FINAL_SUCCESS"); +vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); +vcpeClosedLoopStatus.put("message", "situation has been abated"); + +executor.logger.info(executor.outFields); + +var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/ControlLoopLogTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/ControlLoopLogTask.js new file mode 100644 index 000000000..a5a692cbc --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/ControlLoopLogTask.js @@ -0,0 +1,73 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info(executor.subject.id); +executor.logger.info(executor.inFields); + +var vnfID = executor.inFields.get("vnfID"); +if(vnfID == null) { + vnfID = executor.inFields.get("vnfName"); +} +executor.logger.info("vnfID=" + vnfID); + +var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get(vnfID.toString()); + +executor.logger.info("Logging context information for VNF \"" + vnfID + "\""); + +var clNotification = new org.onap.policy.controlloop.VirtualControlLoopNotification(); + +clNotification.setClosedLoopControlName(vcpeClosedLoopStatus.get("closedLoopControlName")); +clNotification.setClosedLoopAlarmStart(java.time.Instant.ofEpochMilli(vcpeClosedLoopStatus.get("closedLoopAlarmStart"))); +clNotification.setClosedLoopAlarmEnd(java.time.Instant.ofEpochMilli(vcpeClosedLoopStatus.get("closedLoopAlarmEnd"))); +clNotification.setClosedLoopEventClient(vcpeClosedLoopStatus.get("closedLoopEventClient")); +clNotification.setVersion(vcpeClosedLoopStatus.get("version")); +clNotification.setRequestId(java.util.UUID.fromString(vcpeClosedLoopStatus.get("requestID"))); +clNotification.setTargetType(vcpeClosedLoopStatus.get("target_type")); +clNotification.setTarget(vcpeClosedLoopStatus.get("target")); +clNotification.setFrom(vcpeClosedLoopStatus.get("from")); +clNotification.setPolicyScope(vcpeClosedLoopStatus.get("policyScope")); +clNotification.setPolicyName(vcpeClosedLoopStatus.get("policyName")); +clNotification.setPolicyVersion(vcpeClosedLoopStatus.get("policyVersion")); +clNotification.setNotification(org.onap.policy.controlloop.ControlLoopNotificationType.toType(vcpeClosedLoopStatus.get("notification"))); +clNotification.setMessage(vcpeClosedLoopStatus.get("message")); + +var notificationInstant = java.time.Instant.ofEpochSecond(vcpeClosedLoopStatus.get("notificationTime")); +var notificationTime = java.time.ZonedDateTime.ofInstant(notificationInstant, java.time.ZoneOffset.UTC); +clNotification.setNotificationTime(notificationTime); + +var aaiInfo = vcpeClosedLoopStatus.get("AAI"); + +clNotification.getAai().put("generic-vnf.resource-version", aaiInfo.get("genericVnfResourceVersion")); +clNotification.getAai().put("generic-vnf.vnf-name", aaiInfo.get("genericVnfVnfName")); +clNotification.getAai().put("generic-vnf.prov-status", aaiInfo.get("genericVnfProvStatus")); +clNotification.getAai().put("generic-vnf.is-closed-loop-disabled", aaiInfo.get("genericVnfIsClosedLoopDisabled")); +clNotification.getAai().put("generic-vnf.orchestration-status", aaiInfo.get("genericVnfOrchestrationStatus")); +clNotification.getAai().put("generic-vnf.vnf-type", aaiInfo.get("genericVnfVnfType")); +clNotification.getAai().put("generic-vnf.in-maint", aaiInfo.get("genericVnfInMaint")); +clNotification.getAai().put("generic-vnf.service-id", aaiInfo.get("genericVnfServiceId")); +if(vnfID != null) { + clNotification.getAai().put("generic-vnf.vnf-id", aaiInfo.get("genericVnfVnfId")); +} +executor.outFields.put("VirtualControlLoopNotification", clNotification); + +executor.logger.info(executor.outFields); + +var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/DeniedTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/DeniedTask.js new file mode 100644 index 000000000..353c21ef6 --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/DeniedTask.js @@ -0,0 +1,32 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. 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(executor.subject.id); +executor.logger.info(executor.inFields); + +var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get( + executor.inFields.get("vnfID").toString()); + +vcpeClosedLoopStatus.put("notification", "REJECTED"); +vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); + +executor.logger.info(executor.outFields); + +var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/GetVCPEStateTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/GetVCPEStateTask.js new file mode 100644 index 000000000..f4f6d908d --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/GetVCPEStateTask.js @@ -0,0 +1,149 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. 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. + * + * Note: The incoming closedloop message can be ONSET with both VNF-name and VNF-ID + * or ABATED with only VNF-name. So need to handle differently. For ABATED case, + * since we still keep the RequireIDVNFID context album, we can get it from there. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info(executor.subject.id); +executor.logger.info(executor.inFields); + +var clEventType = Java.type("org.onap.policy.controlloop.VirtualControlLoopEvent"); +var longType = Java.type("java.lang.Long"); +var uuidType = Java.type("java.util.UUID"); + +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 vnfID = null; +var vcpeClosedLoopStatus = null; + +if (clEvent.getAai().get("generic-vnf.vnf-id") != null) { + vnfID = uuidType.fromString(clEvent.getAai().get("generic-vnf.vnf-id")); + executor.logger.info("vnfID = " + vnfID); + vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get(vnfID); + + if (vcpeClosedLoopStatus == null) { + executor.logger.info("Creating context information for new vCPE VNF \"" + vnfID.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", "vCPE"); + vcpeClosedLoopStatus.put("policyName", "ONAPvCPEPolicyModel"); + vcpeClosedLoopStatus.put("policyVersion", "0.0.1"); + vcpeClosedLoopStatus.put("notification", "ACTIVE"); + vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); + vcpeClosedLoopStatus.put("message", ""); + + var aaiInfo = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").getSchemaHelper().createNewSubInstance("VCPE_AAI_Type"); + + aaiInfo.put("genericVnfResourceVersion", clEvent.getAai().get("generic-vnf.resource-version")); + aaiInfo.put("genericVnfVnfName", clEvent.getAai().get("generic-vnf.vnf-name")); + aaiInfo.put("genericVnfProvStatus", clEvent.getAai().get("generic-vnf.prov-status")); + aaiInfo.put("genericVnfIsClosedLoopDisabled", clEvent.getAai().get("generic-vnf.is-closed-loop-disabled")); + aaiInfo.put("genericVnfOrchestrationStatus", clEvent.getAai().get("generic-vnf.orchestration-status")); + aaiInfo.put("genericVnfVnfType", clEvent.getAai().get("generic-vnf.vnf-type")); + aaiInfo.put("genericVnfInMaint", clEvent.getAai().get("generic-vnf.in-maint")); + aaiInfo.put("genericVnfServiceId", clEvent.getAai().get("generic-vnf.service-id")); + aaiInfo.put("genericVnfVnfId", clEvent.getAai().get("generic-vnf.vnf-id")); + aaiInfo.put("vserverIsClosedLoopDisabled", clEvent.getAai().get("vserver.is-closed-loop-disabled")); + aaiInfo.put("vserverProvStatus", clEvent.getAai().get("vserver.prov-status")); + aaiInfo.put("vserverName", clEvent.getAai().get("vserver.vserver-name")); + + 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(vnfID.toString(), vcpeClosedLoopStatus); + + executor.logger.info("Created context information for new vCPE VNF \"" + vnfID.toString() + "\""); + } + + executor.outFields.put("requestID", requestID); + executor.outFields.put("vnfID", vnfID); + + executor.logger.info(executor.outFields); +} +else { + executor.logger.info("No vnf-id in VirtualControlLoopEvent, status:" + clEvent.getClosedLoopEventStatus().toString()); + var vnfName = clEvent.getAai().get("generic-vnf.vnf-name"); + executor.logger.info("No vnf-id in VirtualControlLoopEvent for " + vnfName); + + vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get(vnfName.toString()); + + if (vcpeClosedLoopStatus == null) { + executor.logger.info("Creating context information for new vCPE VNF \"" + vnfName.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", "vCPE"); + vcpeClosedLoopStatus.put("policyName", "ONAPvCPEPolicyModel"); + vcpeClosedLoopStatus.put("policyVersion", "0.0.1"); + vcpeClosedLoopStatus.put("notification", "ACTIVE"); + vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); + vcpeClosedLoopStatus.put("message", ""); + + var aaiInfo = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").getSchemaHelper().createNewSubInstance("VCPE_AAI_Type"); + + aaiInfo.put("genericVnfVnfName", clEvent.getAai().get("generic-vnf.vnf-name")); + 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(vnfName.toString(), vcpeClosedLoopStatus); + + executor.logger.info("Created context information for new vCPE VNF \"" + vnfName.toString() + "\""); + } + executor.outFields.put("requestID", requestID); + executor.outFields.put("vnfName", vnfName); + executor.logger.info(executor.outFields); +} + +returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/GuardRequestTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/GuardRequestTask.js new file mode 100644 index 000000000..d247f8a65 --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/GuardRequestTask.js @@ -0,0 +1,44 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. 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(executor.subject.id); +executor.logger.info(executor.inFields); + +var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get( + executor.inFields.get("vnfID").toString()); + +var guardDecisionAttributes = executor.subject.getOutFieldSchemaHelper("decisionAttributes").createNewInstance(); + +guardDecisionAttributes.put("actor", "APPC"); +guardDecisionAttributes.put("recipe", "Restart"); +guardDecisionAttributes.put("target", executor.inFields.get("vnfID").toString()); +guardDecisionAttributes.put("clname", "APEXvCPEImplementation"); + +executor.logger.info(guardDecisionAttributes); + +executor.outFields.put("decisionAttributes", guardDecisionAttributes); +executor.outFields.put("onapName", "PDPD"); + +executor.getContextAlbum("ControlLoopExecutionIDAlbum").put(executor.executionId.toString(), + executor.inFields.get("vnfID")); + +executor.logger.info(executor.outFields); + +var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/GuardResponseTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/GuardResponseTask.js new file mode 100644 index 000000000..2a9100b7f --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/GuardResponseTask.js @@ -0,0 +1,50 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. 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(executor.subject.id); +executor.logger.info(executor.inFields); + +var vnfID = executor.getContextAlbum("ControlLoopExecutionIDAlbum").remove(executor.executionId.toString()); + +executor.logger.info("Continuing execution with VNF ID: " + vnfID); + +var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get(vnfID.toString()); +executor.logger.info(vcpeClosedLoopStatus); + +var guardResult = executor.inFields.get("decision"); + +if (guardResult === "PERMIT") { + vcpeClosedLoopStatus.put("notification", "OPERATION: GUARD_PERMIT"); +} else if (guardResult === "DENY") { + vcpeClosedLoopStatus.put("notification", "OPERATION: GUARD_DENY"); +} else { + executor.message = "guard result must be either \"PERMIT\" or \"DENY\""; + returnValue = executor.FALSE; +} + +var uuidType = Java.type("java.util.UUID"); +var requestID = uuidType.fromString(vcpeClosedLoopStatus.get("requestID")); + +executor.outFields.put("requestID", requestID); +executor.outFields.put("vnfID", vnfID); + +executor.logger.info(executor.outFields); + +var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/NoAAILookupTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/NoAAILookupTask.js new file mode 100644 index 000000000..ebc0e6387 --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/NoAAILookupTask.js @@ -0,0 +1,26 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. 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(executor.subject.id); +executor.logger.info(executor.inFields); + +executor.logger.info(executor.outFields); + +var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/OnsetOrAbatedStateTSL.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/OnsetOrAbatedStateTSL.js new file mode 100644 index 000000000..c8a3bfba8 --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/OnsetOrAbatedStateTSL.js @@ -0,0 +1,51 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. 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(executor.subject.id); +executor.logger.info(executor.inFields); + +var returnValue = executor.isTrue; +var status = null; + +if( executor.inFields.get("vnfID") == null) { + executor.logger.info("OnsetOrAbatedStateTSL: vnfID is null"); + var vnfName = executor.inFields.get("vnfName"); + var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get( + executor.inFields.get("vnfName")); + status = vcpeClosedLoopStatus.get("closedLoopEventStatus").toString(); +} else { + var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get( + executor.inFields.get("vnfID").toString()); + status = vcpeClosedLoopStatus.get("closedLoopEventStatus").toString(); +} + +var returnValue = executor.isTrue; + +if (status === "ONSET") { + executor.subject.getTaskKey("GuardRequestTask").copyTo(executor.selectedTask); +} else if (status === "ABATED") { + executor.subject.getTaskKey("AbatedTask").copyTo(executor.selectedTask); + onsetFlag = executor.isFalse; +} else { + executor.message = "closedLoopEventStatus is \"" + status + "\", it must be either \"ONSET\" or \"ABATED\""; + returnValue = executor.isFalse; +} + +executor.logger.info("ReceiveEventPolicyOnsetOrAbatedStateTSL State Selected Task:" + executor.selectedTask); diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/definitive/RestartAPPCRequestPolicyPermitOrDenyTSL.js b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/RestartAPPCRequestPolicyPermitOrDenyTSL.js new file mode 100644 index 000000000..a1bac6546 --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/definitive/RestartAPPCRequestPolicyPermitOrDenyTSL.js @@ -0,0 +1,37 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. 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(executor.subject.id); +executor.logger.info(executor.inFields); + +var vcpeClosedLoopStatus = executor.getContextAlbum("VCPEClosedLoopStatusAlbum").get( + executor.inFields.get("vnfID").toString()); + +var guardResult = vcpeClosedLoopStatus.get("notification"); + +if (guardResult === "OPERATION: GUARD_PERMIT") { + executor.subject.getTaskKey("APPCRestartVNFRequestTask").copyTo(executor.selectedTask); +} else { + executor.subject.getTaskKey("DeniedTask").copyTo(executor.selectedTask); +} + +executor.logger.info("RestartAPPCRequestPolicyPermitOrDenyTSL State Selected Task:" + executor.selectedTask); + +var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckServiceIdTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckServiceIdTask.js new file mode 100644 index 000000000..88bf72671 --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckServiceIdTask.js @@ -0,0 +1,46 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info(executor.subject.id); +executor.logger.info(executor.inFields); + +var vnfId = executor.inFields.get("vnfID").toString(); +var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfId); +var serviceId = vcpeClosedLoopStatus.get("AAI").get("genericVnfServiceId"); +var blackFlag = executor.getContextAlbum("ServiceIdWhiteBlackListAlbum").get(serviceId.toString()); + +executor.logger.info("vnfId=" + vnfId + ", serviceId=" + serviceId + ", blackFlag=" + blackFlag); + +if (blackFlag != null && blackFlag === true) { + vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); + vcpeClosedLoopStatus.put("notification", "BLACKLIST"); + var message = vcpeClosedLoopStatus.get("message"); + + if (message != null) { + vcpeClosedLoopStatus.put("message", message + ":Service ID blacklisted"); + } + else { + vcpeClosedLoopStatus.put("message", "Service ID blacklisted"); + } +} + +executor.logger.info(executor.outFields); + +var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckVNFIdTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckVNFIdTask.js new file mode 100644 index 000000000..d4e3f30dc --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckVNFIdTask.js @@ -0,0 +1,45 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info(executor.subject.id); +executor.logger.info(executor.inFields); + +var vnfId = executor.inFields.get("vnfID").toString(); +var blackFlag = executor.getContextAlbum("VnfIdWhiteBlackListAlbum").get(vnfId); + +executor.logger.info("vnfId=" + vnfId + ", blackFlag=" + blackFlag); + +if (blackFlag != null && blackFlag === true) { + var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfId); + vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); + vcpeClosedLoopStatus.put("notification", "BLACKLIST"); + var message = vcpeClosedLoopStatus.get("message"); + + if (message != null) { + vcpeClosedLoopStatus.put("message", message + ":VNF ID blacklisted"); + } + else { + vcpeClosedLoopStatus.put("message", "VNF ID blacklisted"); + } +} + +executor.logger.info(executor.outFields); + +var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckVServerIdTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckVServerIdTask.js new file mode 100644 index 000000000..785d93f25 --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/CheckVServerIdTask.js @@ -0,0 +1,46 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info(executor.subject.id); +executor.logger.info(executor.inFields); + +var vnfId = executor.inFields.get("vnfID").toString(); +var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfId); +var vServerId = vcpeClosedLoopStatus.get("AAI").get("vserverName"); +var blackFlag = executor.getContextAlbum("VServerIdWhiteBlackListAlbum").get(vServerId.toString()); + +executor.logger.info("vnfId=" + vnfId + ", vServerId=" + vServerId + ", blackFlag=" + blackFlag); + +if (blackFlag != null && blackFlag === true) { + vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); + vcpeClosedLoopStatus.put("notification", "BLACKLIST"); + var message = vcpeClosedLoopStatus.get("message"); + + if (message != null) { + vcpeClosedLoopStatus.put("message", message + ":VServer ID blacklisted"); + } + else { + vcpeClosedLoopStatus.put("message", "VServer ID blacklisted"); + } +} + +executor.logger.info(executor.outFields); + +var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ConfigureBlackWhiteListTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ConfigureBlackWhiteListTask.js new file mode 100644 index 000000000..2d41e5f90 --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ConfigureBlackWhiteListTask.js @@ -0,0 +1,49 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info(executor.subject.id); +executor.logger.info(executor.inFields); + +// Pass through to the log state + +executor.logger.info(executor.outFields); + +var targetType = executor.inFields.get("targetType"); +var target = executor.inFields.get("target"); +var black = executor.inFields.get("black"); + +var returnValue = executor.isTrue; + +if (targetType === "VNF") { + executor.getContextAlbum("VnfIdWhiteBlackListAlbum").put(target, black); + executor.logger.info("added VNF ID \"" + target + "\" with black flag \"" + black + "\" to VNF ID list"); +} +else if (targetType === "Service") { + executor.getContextAlbum("ServiceIdWhiteBlackListAlbum").put(target, black); + executor.logger.info("added Service ID \"" + target + "\" with black flag \"" + black + "\" to Service ID list"); +} +else if (targetType === "VServer") { + executor.getContextAlbum("VServerIdWhiteBlackListAlbum").put(target, black); + executor.logger.info("added VServer ID \"" + target + "\" with black flag \"" + black + "\" to VServer ID list"); +} +else { + executor.logger.warn("unknown target type \"" + targetType + "\" specified"); + returnValue = executor.isFalse; +} diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControlLoopLogTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControlLoopLogTask.js new file mode 100644 index 000000000..ca2166c75 --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControlLoopLogTask.js @@ -0,0 +1,75 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info(executor.subject.id); +executor.logger.info(executor.inFields); + +var vnfID = executor.inFields.get("vnfID"); +if (vnfID == null) { + vnfID = executor.inFields.get("vnfName"); +} +executor.logger.info("vnfID=" + vnfID); + +var controlLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfID.toString()); + +executor.logger.info("Logging context information for VNF \"" + vnfID + "\""); + +var clNotification = executor.subject.getOutFieldSchemaHelper("VirtualControlLoopNotification").createNewInstance(); + +clNotification.put("requestID", executor.inFields.get("requestID").toString()); +clNotification.put("closedLoopControlName", controlLoopStatus.get("closedLoopControlName")); +clNotification.put("closedLoopAlarmStart", controlLoopStatus.get("closedLoopAlarmStart")); +clNotification.put("closedLoopAlarmEnd", controlLoopStatus.get("closedLoopAlarmEnd")); +clNotification.put("closedLoopEventClient", controlLoopStatus.get("closedLoopEventClient")); +clNotification.put("version", controlLoopStatus.get("version")); +clNotification.put("targetType", controlLoopStatus.get("target_type")); +clNotification.put("target", controlLoopStatus.get("target")); +clNotification.put("from", controlLoopStatus.get("from")); +clNotification.put("policyScope", controlLoopStatus.get("policyScope")); +clNotification.put("policyName", controlLoopStatus.get("policyName")); +clNotification.put("policyVersion", controlLoopStatus.get("policyVersion")); +clNotification.put("notification", controlLoopStatus.get("notification")); +clNotification.put("message", controlLoopStatus.get("message")); +clNotification.put("notificationTime", controlLoopStatus.get("notificationTime")); +clNotification.put("opsClTimer", 0); + +var aaiInfo = controlLoopStatus.get("AAI"); + +var aaiInfoOut = new java.util.HashMap(); + +aaiInfoOut.put("generic-vnf.resource-version", aaiInfo.get("genericVnfResourceVersion")); +aaiInfoOut.put("generic-vnf.vnf-name", aaiInfo.get("genericVnfVnfName")); +aaiInfoOut.put("generic-vnf.prov-status", aaiInfo.get("genericVnfProvStatus")); +aaiInfoOut.put("generic-vnf.is-closed-loop-disabled", aaiInfo.get("genericVnfIsClosedLoopDisabled")); +aaiInfoOut.put("generic-vnf.orchestration-status", aaiInfo.get("genericVnfOrchestrationStatus")); +aaiInfoOut.put("generic-vnf.vnf-type", aaiInfo.get("genericVnfVnfType")); +aaiInfoOut.put("generic-vnf.in-maint", aaiInfo.get("genericVnfInMaint")); +aaiInfoOut.put("generic-vnf.service-id", aaiInfo.get("genericVnfServiceId")); +if (vnfID != null) { + aaiInfoOut.put("generic-vnf.vnf-id", aaiInfo.get("genericVnfVnfId")); +} + +clNotification.put("AAI", aaiInfoOut); + +executor.outFields.put("VirtualControlLoopNotification", clNotification); + +executor.logger.info(executor.outFields); + +var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControllerRequestTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControllerRequestTask.js new file mode 100644 index 000000000..b6d4cae38 --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControllerRequestTask.js @@ -0,0 +1,71 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info(executor.subject.id); +executor.logger.info(executor.inFields); + +var controllerRequest = executor.subject.getOutFieldSchemaHelper("ControllerRequest").createNewInstance(); + +var controllerRequestBody = executor.subject.getOutFieldSchemaHelper("ControllerRequest").createNewSubInstance( + "Controller_Body_Type"); + +var controllerRequestBodyInput = executor.subject.getOutFieldSchemaHelper("ControllerRequest").createNewSubInstance( + "Controller_Body_Type_Input"); + +var controllerRequestBodyInputCommonHeader = executor.subject.getOutFieldSchemaHelper("ControllerRequest") + .createNewSubInstance("Controller_Body_Type_Common_Header"); + +var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get( + executor.inFields.get("vnfID").toString()); + +controllerRequest.put("version", "2.0.0"); +controllerRequest.put("rpc_DasH_name", "restart"); +controllerRequest.put("correlation_DasH_id", executor.inFields.get("requestID").toString()); +controllerRequest.put("type", "request"); + +controllerRequestBodyInput.put("action", "Restart"); +controllerRequestBodyInput.put("action_DasH_identifiers", new java.util.HashMap()); +controllerRequestBodyInput.get("action_DasH_identifiers").put("vnf-id", executor.inFields.get("vnfID").toString()); + +controllerRequestBodyInputCommonHeader.put("timestamp", java.lang.System.currentTimeMillis()); +controllerRequestBodyInputCommonHeader.put("api_DasH_ver", "2.00"); +controllerRequestBodyInputCommonHeader.put("originator_DasH_id", executor.inFields.get("requestID").toString()); +controllerRequestBodyInputCommonHeader.put("request_DasH_id", executor.inFields.get("requestID").toString()); +controllerRequestBodyInputCommonHeader.put("sub_DasH_request_DasH_id", "1"); +controllerRequestBodyInputCommonHeader.put("flags", new java.util.HashMap()); +controllerRequestBodyInputCommonHeader.get("flags").put("ttl", "10000"); +controllerRequestBodyInputCommonHeader.get("flags").put("force", "TRUE"); +controllerRequestBodyInputCommonHeader.get("flags").put("mode", "EXCLUSIVE"); + +controllerRequestBodyInput.put("common_DasH_header", controllerRequestBodyInputCommonHeader); +controllerRequestBody.put("input", controllerRequestBodyInput); +controllerRequest.put("body", controllerRequestBody); + +executor.getContextAlbum("RequestIDVNFIDAlbum").put(executor.inFields.get("requestID").toString(), + executor.inFields.get("vnfID")); + +vcpeClosedLoopStatus.put("notification", "OPERATION"); +vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); + +executor.outFields.put("ControllerRequest", controllerRequest); + +executor.logger.info(executor.outFields); + +var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControllerResponseTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControllerResponseTask.js new file mode 100644 index 000000000..5a8703780 --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ControllerResponseTask.js @@ -0,0 +1,90 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * APPC LCM Response code: 100 ACCEPTED + * 200 ERROR UNEXPECTED ERROR means failure + * 312 REJECTED DUPLICATE REQUEST + * 400 SUCCESS + * + * Note: Sometimes the corelationId has a -1 at the tail, need to get rid of it when present. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info(executor.subject.id); +executor.logger.info(executor.inFields); + +var controllerResponse = executor.inFields.get("ControllerResponse"); + +var requestIDString = new java.lang.String(controllerResponse.get("correlation_DasH_id")); +executor.logger.info("requestIDString =\"" + requestIDString + "\""); +var vnfID = executor.getContextAlbum("RequestIDVNFIDAlbum").get(requestIDString); +executor.logger.info("vnfID = " + vnfID); + +var returnValue = executor.isTrue; + +if (vnfID != null) { + var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfID.toString()); + var requestId = java.util.UUID.fromString(vcpeClosedLoopStatus.get("requestID")); + + vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); + + var returnedCode = controllerResponse.get("body").get("output").get("status").get("code"); + var responseStatus = null; + + if (returnedCode == 100) { + responseStatus = "ACCEPTED"; + } else if (returnedCode == 200) { + responseStatus = "ERROR"; + } else if (returnedCode >= 300 && returnedCode <= 316) { + responseStatus = "REJECT"; + } else if (returnedCode == 400) { + responseStatus = "SUCCESS"; + } else if (returnedCode == 450 || (returnedCode >= 401 && returnedCode <= 406)) { + responseStatus = "FAILURE"; + } else if (returnedCode == 500) { + responseStatus = "PARTIAL_SUCCESS"; + } else if (returnedCode >= 501 && returnedCode <= 599) { + responseStatus = "PARTIAL_FAILURE"; + } else { + responseStatus = "SYSTEM_ERROR"; + } + + executor.logger.info("Got from APPC code: " + responseStatus); + + if (responseStatus === "SUCCESS") { + vcpeClosedLoopStatus.put("notification", "OPERATION_SUCCESS"); + vcpeClosedLoopStatus.put("message", "vCPE restarted"); + executor.getContextAlbum("RequestIDVNFIDAlbum").remove(requestIDString); + } else if (responseStatus === "ACCEPTED" || responseStatus === "REJECT") { + executor.logger.info("Got ACCEPTED 100 or REJECT 312, keep the context, wait for next response. Code is: " + + responseStatus); + } else { + executor.getContextAlbum("RequestIDVNFIDAlbum").remove(requestIDString); + vcpeClosedLoopStatus.put("notification", "OPERATION_FAILURE"); + vcpeClosedLoopStatus.put("message", "vCPE restart failed, code is " + responseStatus + ", message is " + + controllerResponse.get("body").get("output").get("status").get("message")); + } + + executor.outFields.put("requestID", requestId); + executor.outFields.put("vnfID", vnfID); +} else { + executor.message = "VNF ID not found in context album for request ID " + requestIDString; + returnValue = executor.isFalse; +} + +executor.logger.info(executor.outFields); diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/DoControllerRequestActionTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/DoControllerRequestActionTask.js new file mode 100644 index 000000000..c24e76523 --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/DoControllerRequestActionTask.js @@ -0,0 +1,27 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +executor.logger.info(executor.subject.id); +executor.logger.info(executor.inFields); + +// Pass through to the log state + +executor.logger.info(executor.outFields); + +var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/DoLogActionTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/DoLogActionTask.js new file mode 100644 index 000000000..003942e22 --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/DoLogActionTask.js @@ -0,0 +1,28 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info(executor.subject.id); +executor.logger.info(executor.inFields); + +// Pass through to the log state + +executor.logger.info(executor.outFields); + +var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ExecuteActionsPolicyActionStateTSL.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ExecuteActionsPolicyActionStateTSL.js new file mode 100644 index 000000000..a8bb40c80 --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ExecuteActionsPolicyActionStateTSL.js @@ -0,0 +1,33 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info(executor.subject.id); +executor.logger.info(executor.inFields); + +var returnValue = executor.isTrue; +var status = null; + +if (executor.inFields.get("action") === "ControllerRequestAction") { + executor.subject.getTaskKey("DoControllerRequestActionTask").copyTo(executor.selectedTask); +} else { + executor.subject.getTaskKey("DoLogActionTask").copyTo(executor.selectedTask); +} + +executor.logger.info("ReceiveEventPolicyOnsetOrAbatedStateTSL State Selected Task:" + executor.selectedTask); diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/GetEntityStateTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/GetEntityStateTask.js new file mode 100644 index 000000000..1567608bb --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/GetEntityStateTask.js @@ -0,0 +1,157 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Note: The incoming closedloop message can be ONSET with both VNF-name and VNF-ID + * or ABATED with only VNF-name. So need to handle differently. For ABATED case, + * since we still keep the RequireIDVNFID context album, we can get it from there. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info(executor.subject.id); +executor.logger.info(executor.inFields); + +var utf8Type = Java.type("org.apache.avro.util.Utf8"); +var uuidType = Java.type("java.util.UUID"); + +var clEvent = executor.inFields.get("VirtualControlLoopEvent"); + +executor.logger.info(clEvent.toString()); +executor.logger.info(clEvent.get("closedLoopControlName")); + +var requestID = uuidType.fromString(clEvent.get("requestID")); +executor.logger.info("requestID = " + requestID); +var vnfID = null; +var vcpeClosedLoopStatus = null; + +if (clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_id")) != null) { + vnfID = uuidType.fromString(clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_id"))); + executor.logger.info("vnfID = " + vnfID); + vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfID); + + if (vcpeClosedLoopStatus == null) { + executor.logger.info("Creating context information for new vCPE VNF \"" + vnfID.toString() + "\""); + + vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").getSchemaHelper().createNewInstance(); + + vcpeClosedLoopStatus.put("closedLoopControlName", clEvent.get("closedLoopControlName")); + vcpeClosedLoopStatus.put("closedLoopAlarmStart", clEvent.get("closedLoopAlarmStart")); + vcpeClosedLoopStatus.put("closedLoopEventClient", clEvent.get("closedLoopEventClient")); + vcpeClosedLoopStatus.put("closedLoopEventStatus", clEvent.get("closedLoopEventStatus")); + vcpeClosedLoopStatus.put("version", clEvent.get("version")); + vcpeClosedLoopStatus.put("requestID", clEvent.get("requestID")); + vcpeClosedLoopStatus.put("target_type", clEvent.get("target_type")); + vcpeClosedLoopStatus.put("target", clEvent.get("target")); + vcpeClosedLoopStatus.put("from", clEvent.get("from")); + vcpeClosedLoopStatus.put("policyScope", "vCPE"); + vcpeClosedLoopStatus.put("policyName", "ONAPvCPEPolicyModel"); + vcpeClosedLoopStatus.put("policyVersion", "0.0.1"); + vcpeClosedLoopStatus.put("notification", "ACTIVE"); + vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); + vcpeClosedLoopStatus.put("message", ""); + + var aaiInfo = executor.getContextAlbum("ControlLoopStatusAlbum").getSchemaHelper().createNewSubInstance( + "VCPE_AAI_Type"); + + aaiInfo.put("genericVnfResourceVersion", clEvent.get("AAI").get( + new utf8Type("generic_DasH_vnf_DoT_resource_DasH_version"))); + aaiInfo.put("genericVnfVnfName", clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_name"))); + aaiInfo.put("genericVnfProvStatus", clEvent.get("AAI").get( + new utf8Type("generic_DasH_vnf_DoT_prov_DasH_status"))); + aaiInfo.put("genericVnfIsClosedLoopDisabled", clEvent.get("AAI").get( + new utf8Type("generic_DasH_vnf_DoT_is_DasH_closed_DasH_loop_DasH_disabled"))); + aaiInfo.put("genericVnfOrchestrationStatus", clEvent.get("AAI").get( + new utf8Type("generic_DasH_vnf_DoT_orchestration_DasH_status"))); + aaiInfo.put("genericVnfVnfType", clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_type"))); + aaiInfo.put("genericVnfInMaint", clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_in_DasH_maint"))); + aaiInfo + .put("genericVnfServiceId", clEvent.get("AAI") + .get(new utf8Type("generic_DasH_vnf_DoT_service_DasH_id"))); + aaiInfo.put("genericVnfVnfId", clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_id"))); + aaiInfo.put("vserverIsClosedLoopDisabled", clEvent.get("AAI").get( + new utf8Type("vserver_DoT_is_DasH_closed_DasH_loop_DasH_disabled"))); + aaiInfo.put("vserverProvStatus", clEvent.get("AAI").get(new utf8Type("vserver_DoT_prov_DasH_status"))); + aaiInfo.put("vserverName", clEvent.get("AAI").get(new utf8Type("vserver_DoT_vserver_DasH_name"))); + + vcpeClosedLoopStatus.put("AAI", aaiInfo); + + if (clEvent.get("closedLoopAlarmEnd") != null) { + vcpeClosedLoopStatus.put("closedLoopAlarmEnd", clEvent.get("closedLoopAlarmEnd")); + } else { + vcpeClosedLoopStatus.put("closedLoopAlarmEnd", java.lang.Long.valueOf(0)); + } + + executor.getContextAlbum("ControlLoopStatusAlbum").put(vnfID.toString(), vcpeClosedLoopStatus); + + executor.logger.info("Created context information for new vCPE VNF \"" + vnfID.toString() + "\""); + } + + executor.outFields.put("requestID", requestID); + executor.outFields.put("vnfID", vnfID); + + executor.logger.info(executor.outFields); +} else { + executor.logger.info("No vnf-id in VirtualControlLoopEvent, status:" + + clEvent.get("closedLoopEventStatus").toString()); + var vnfName = clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_name")); + executor.logger.info("No vnf-id in VirtualControlLoopEvent for " + vnfName); + + vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get(vnfName); + + if (vcpeClosedLoopStatus == null) { + executor.logger.info("Creating context information for new vCPE VNF \"" + vnfName + "\""); + + vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").getSchemaHelper().createNewInstance(); + + vcpeClosedLoopStatus.put("closedLoopControlName", clEvent.get("closedLoopControlName")); + vcpeClosedLoopStatus.put("closedLoopAlarmStart", clEvent.get("closedLoopAlarmStart")); + vcpeClosedLoopStatus.put("closedLoopEventClient", clEvent.get("closedLoopEventClient")); + vcpeClosedLoopStatus.put("closedLoopEventStatus", clEvent.get("closedLoopEventStatus(")); + vcpeClosedLoopStatus.put("version", clEvent.get("version")); + vcpeClosedLoopStatus.put("requestID", clEvent.get("requestID")); + vcpeClosedLoopStatus.put("target_type", clEvent.get("targetType")); + vcpeClosedLoopStatus.put("target", clEvent.get("target")); + vcpeClosedLoopStatus.put("from", clEvent.get("from")); + vcpeClosedLoopStatus.put("policyScope", "vCPE"); + vcpeClosedLoopStatus.put("policyName", "ONAPvCPEPolicyModel"); + vcpeClosedLoopStatus.put("policyVersion", "0.0.1"); + vcpeClosedLoopStatus.put("notification", "ACTIVE"); + vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); + vcpeClosedLoopStatus.put("message", ""); + + var aaiInfo = executor.getContextAlbum("ControlLoopStatusAlbum").getSchemaHelper().createNewSubInstance( + "VCPE_AAI_Type"); + + aaiInfo.put("genericVnfVnfName", clEvent.get("AAI").get(new utf8Type("generic_DasH_vnf_DoT_vnf_DasH_name"))); + vcpeClosedLoopStatus.put("AAI", aaiInfo); + + if (clEvent.get("closedLoopAlarmEnd") != null) { + vcpeClosedLoopStatus.put("closedLoopAlarmEnd", clEvent.get("closedLoopAlarmEnd")); + } else { + vcpeClosedLoopStatus.put("closedLoopAlarmEnd", java.lang.Long.valueOf(0)); + } + + executor.getContextAlbum("ControlLoopStatusAlbum").put(vnfName, vcpeClosedLoopStatus); + + executor.logger.info("Created context information for new vCPE VNF \"" + vnfName + "\""); + } + executor.outFields.put("requestID", requestID); + executor.outFields.put("vnfName", vnfName); + executor.logger.info(executor.outFields); +} + +var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/InitiateActionsTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/InitiateActionsTask.js new file mode 100644 index 000000000..0303bc9a4 --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/InitiateActionsTask.js @@ -0,0 +1,54 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info(executor.subject.id); +executor.logger.info(executor.inFields); + +var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get( + executor.inFields.get("vnfID").toString()); + +var eventList = executor.subject.getOutFieldSchemaHelper("ActionEventList").createNewInstance(); + +var eventType = Java.type("org.onap.policy.apex.service.engine.event.ApexEvent"); + +var controllerRequestActionEvent = new eventType("ActionEvent", "0.0.1", "org.onap.policy.apex.onap.vcpe", "APEX", + "APEX"); + +controllerRequestActionEvent.put("action", "ControllerRequestAction"); +controllerRequestActionEvent.put("requestID", executor.inFields.get("requestID")); +controllerRequestActionEvent.put("vnfID", executor.inFields.get("vnfID")); +controllerRequestActionEvent.put("vnfName", executor.inFields.get("vnfName")); + +eventList.add(controllerRequestActionEvent); + +var logActionEvent = new eventType("ActionEvent", "0.0.1", "org.onap.policy.apex.onap.vcpe", "APEX", "APEX"); + +logActionEvent.put("action", "LogAction"); +logActionEvent.put("requestID", executor.inFields.get("requestID")); +logActionEvent.put("vnfID", executor.inFields.get("vnfID")); +logActionEvent.put("vnfName", executor.inFields.get("vnfName")); + +eventList.add(logActionEvent); + +executor.outFields.put("ActionEventList", eventList); + +executor.logger.info(executor.outFields); + +var returnValue = executor.isTrue; diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ReceiveEventPolicyExecuteOrLogStateTSL.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ReceiveEventPolicyExecuteOrLogStateTSL.js new file mode 100644 index 000000000..46a65add3 --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/ReceiveEventPolicyExecuteOrLogStateTSL.js @@ -0,0 +1,55 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info(executor.subject.id); +executor.logger.info(executor.inFields); + +var returnValue = executor.isTrue; + +if( executor.inFields.get("vnfID") == null) { + executor.logger.info("ControlLoopStatusAlbum: vnfID is null"); + var vnfName = executor.inFields.get("vnfName"); + var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get( + executor.inFields.get("vnfName")); +} else { + var vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum").get( + executor.inFields.get("vnfID").toString()); +} + +var status = vcpeClosedLoopStatus.get("closedLoopEventStatus").toString(); +var notification = vcpeClosedLoopStatus.get("notification"); + +var returnValue = executor.isTrue; + +if (notification != null && notification === "BLACKLIST") { + executor.subject.getTaskKey("StopAndLogTask").copyTo(executor.selectedTask); +} +else { + if (status === "ONSET") { + executor.subject.getTaskKey("InitiateActionsTask").copyTo(executor.selectedTask); + } else if (status === "ABATED") { + executor.subject.getTaskKey("StopAndLogTask").copyTo(executor.selectedTask); + } else { + executor.message = "closedLoopEventStatus is \"" + status + "\", it must be either \"ONSET\" or \"ABATED\""; + returnValue = executor.isFalse; + } +} + +executor.logger.info("ReceiveEventPolicyOnsetOrAbatedStateTSL State Selected Task:" + executor.selectedTask); diff --git a/examples/examples-onap-vcpe/src/main/resources/logic/standalone/StopAndLogTask.js b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/StopAndLogTask.js new file mode 100644 index 000000000..af57bf1f7 --- /dev/null +++ b/examples/examples-onap-vcpe/src/main/resources/logic/standalone/StopAndLogTask.js @@ -0,0 +1,47 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +executor.logger.info(executor.subject.id); +executor.logger.info(executor.inFields); + +var vcpeClosedLoopStatus = null; +if (executor.inFields.get("vnfID") == null) { + executor.logger.info("AbatedTask: vnfID is null"); + var vnfName = executor.inFields.get("vnfName"); + vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum") + .get(executor.inFields.get("vnfName")); +} else { + vcpeClosedLoopStatus = executor.getContextAlbum("ControlLoopStatusAlbum") + .get(executor.inFields.get("vnfID").toString()); +} + +vcpeClosedLoopStatus.put("notificationTime", java.lang.System.currentTimeMillis()); + +var message = vcpeClosedLoopStatus.get("message"); +if (message == null || message === "") { + vcpeClosedLoopStatus.put("message", "situation has been abated"); +} +else { + vcpeClosedLoopStatus.put("notification", "FINAL_FAILURE"); +} + +executor.logger.info(executor.outFields); + +var returnValue = executor.isTrue; -- cgit 1.2.3-korg