From f46af3394f85598eaa718f22312f9b7a6485c636 Mon Sep 17 00:00:00 2001 From: "a.sreekumar" Date: Fri, 20 Mar 2020 18:30:43 +0000 Subject: Adding example for APEX gRPC plugin for CDS interaction Change-Id: I8361eb0cbe74c3548ca98f3005bc37f5a1f91747 Issue-ID: POLICY-2436 Signed-off-by: a.sreekumar --- .../main/resources/logic/CreateOrDeleteStateTSL.js | 33 +++++++++++++++ .../logic/CreateSubscriptionPayloadTask.js | 45 ++++++++++++++++++++ .../logic/CreateSubscriptionRequestTask.js | 44 ++++++++++++++++++++ .../logic/DeleteSubscriptionPayloadTask.js | 45 ++++++++++++++++++++ .../logic/DeleteSubscriptionRequestTask.js | 44 ++++++++++++++++++++ .../resources/logic/ReceivePMSubscriptionTask.js | 48 ++++++++++++++++++++++ .../src/main/resources/logic/ResponseTask.js | 44 ++++++++++++++++++++ 7 files changed, 303 insertions(+) create mode 100644 examples/examples-grpc/src/main/resources/logic/CreateOrDeleteStateTSL.js create mode 100644 examples/examples-grpc/src/main/resources/logic/CreateSubscriptionPayloadTask.js create mode 100644 examples/examples-grpc/src/main/resources/logic/CreateSubscriptionRequestTask.js create mode 100644 examples/examples-grpc/src/main/resources/logic/DeleteSubscriptionPayloadTask.js create mode 100644 examples/examples-grpc/src/main/resources/logic/DeleteSubscriptionRequestTask.js create mode 100644 examples/examples-grpc/src/main/resources/logic/ReceivePMSubscriptionTask.js create mode 100644 examples/examples-grpc/src/main/resources/logic/ResponseTask.js (limited to 'examples/examples-grpc/src/main/resources/logic') diff --git a/examples/examples-grpc/src/main/resources/logic/CreateOrDeleteStateTSL.js b/examples/examples-grpc/src/main/resources/logic/CreateOrDeleteStateTSL.js new file mode 100644 index 000000000..010a71dff --- /dev/null +++ b/examples/examples-grpc/src/main/resources/logic/CreateOrDeleteStateTSL.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); + +var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString()) +var changeType = pmSubscriptionInfo.get("changeType").toString() + +if ("CREATE".equals(changeType)) { + executor.subject.getTaskKey("CreateSubscriptionPayloadTask").copyTo(executor.selectedTask); +} +else if ("DELETE".equals(changeType)) { + executor.subject.getTaskKey("DeleteSubscriptionPayloadTask").copyTo(executor.selectedTask); +} + +true; \ No newline at end of file diff --git a/examples/examples-grpc/src/main/resources/logic/CreateSubscriptionPayloadTask.js b/examples/examples-grpc/src/main/resources/logic/CreateSubscriptionPayloadTask.js new file mode 100644 index 000000000..48f31847b --- /dev/null +++ b/examples/examples-grpc/src/main/resources/logic/CreateSubscriptionPayloadTask.js @@ -0,0 +1,45 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix. 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); + +var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString()) + +var payloadProperties = executor.subject.getOutFieldSchemaHelper("payload").createNewSubInstance("create_DasH_subscription_DasH_properties_record"); + +payloadProperties.put("nfName", pmSubscriptionInfo.get("nfName")) +payloadProperties.put("subscriptionName", pmSubscriptionInfo.get("subscription").get("subscriptionName")) +payloadProperties.put("administrativeState", pmSubscriptionInfo.get("subscription").get("administrativeState")) +payloadProperties.put("fileBasedGP", pmSubscriptionInfo.get("subscription").get("fileBasedGP").toString()) +payloadProperties.put("fileLocation", pmSubscriptionInfo.get("subscription").get("fileLocation")) +payloadProperties.put("measurementGroups", pmSubscriptionInfo.get("subscription").get("measurementGroups")) + +var payloadEntry = executor.subject.getOutFieldSchemaHelper("payload").createNewSubInstance("CDSRequestPayloadEntry"); +payloadEntry.put("create_DasH_subscription_DasH_properties", payloadProperties) + +var payload = executor.subject.getOutFieldSchemaHelper("payload").createNewInstance(); +payload.put("create_DasH_subscription_DasH_request", payloadEntry); + +executor.outFields.put("albumID", executor.inFields.get("albumID")) +executor.outFields.put("payload", payload); + +executor.logger.info("Sending Create Subscription Event to CDS") + +true; diff --git a/examples/examples-grpc/src/main/resources/logic/CreateSubscriptionRequestTask.js b/examples/examples-grpc/src/main/resources/logic/CreateSubscriptionRequestTask.js new file mode 100644 index 000000000..638429817 --- /dev/null +++ b/examples/examples-grpc/src/main/resources/logic/CreateSubscriptionRequestTask.js @@ -0,0 +1,44 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix. 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); + +var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString()) +var payload = executor.inFields.get("payload") +var actionName = "create-subscription" + +var commonHeader = executor.subject.getOutFieldSchemaHelper("commonHeader").createNewInstance(); +commonHeader.put("originatorId", "sdnc"); +commonHeader.put("requestId", "123456-1000"); +commonHeader.put("subRequestId", "sub-123456-1000"); + +var actionIdentifiers = executor.subject.getOutFieldSchemaHelper("actionIdentifiers").createNewInstance(); +actionIdentifiers.put("actionName", actionName); +actionIdentifiers.put("blueprintName", "pm_control"); +actionIdentifiers.put("blueprintVersion", "1.0.0"); +actionIdentifiers.put("mode", "sync"); + +executor.outFields.put("commonHeader", commonHeader); +executor.outFields.put("actionIdentifiers", actionIdentifiers); +executor.outFields.put("payload", payload); + +executor.logger.info("Sending Activate Subscription Event to CDS") + +true; \ No newline at end of file diff --git a/examples/examples-grpc/src/main/resources/logic/DeleteSubscriptionPayloadTask.js b/examples/examples-grpc/src/main/resources/logic/DeleteSubscriptionPayloadTask.js new file mode 100644 index 000000000..180dcba71 --- /dev/null +++ b/examples/examples-grpc/src/main/resources/logic/DeleteSubscriptionPayloadTask.js @@ -0,0 +1,45 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix. 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); + +var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString()) + +var payloadProperties = executor.subject.getOutFieldSchemaHelper("payload").createNewSubInstance("delete_DasH_subscription_DasH_properties_record"); + +payloadProperties.put("nfName", pmSubscriptionInfo.get("nfName")) +payloadProperties.put("subscriptionName", pmSubscriptionInfo.get("subscription").get("subscriptionName")) +payloadProperties.put("administrativeState", pmSubscriptionInfo.get("subscription").get("administrativeState")) +payloadProperties.put("fileBasedGP", pmSubscriptionInfo.get("subscription").get("fileBasedGP").toString()) +payloadProperties.put("fileLocation", pmSubscriptionInfo.get("subscription").get("fileLocation")) +payloadProperties.put("measurementGroups", pmSubscriptionInfo.get("subscription").get("measurementGroups")) + +var payloadEntry = executor.subject.getOutFieldSchemaHelper("payload").createNewSubInstance("CDSRequestPayloadEntry"); +payloadEntry.put("delete_DasH_subscription_DasH_properties", payloadProperties) + +var payload = executor.subject.getOutFieldSchemaHelper("payload").createNewInstance(); +payload.put("delete_DasH_subscription_DasH_request", payloadEntry); + +executor.outFields.put("albumID", executor.inFields.get("albumID")) +executor.outFields.put("payload", payload); + +executor.logger.info("Sending delete Subscription Event to CDS") + +true; diff --git a/examples/examples-grpc/src/main/resources/logic/DeleteSubscriptionRequestTask.js b/examples/examples-grpc/src/main/resources/logic/DeleteSubscriptionRequestTask.js new file mode 100644 index 000000000..9ec2a119b --- /dev/null +++ b/examples/examples-grpc/src/main/resources/logic/DeleteSubscriptionRequestTask.js @@ -0,0 +1,44 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix. 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); + +var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(executor.inFields.get("albumID").toString()) +var payload = executor.inFields.get("payload") +var actionName = "delete-subscription" + +var commonHeader = executor.subject.getOutFieldSchemaHelper("commonHeader").createNewInstance(); +commonHeader.put("originatorId", "sdnc"); +commonHeader.put("requestId", "123456-1000"); +commonHeader.put("subRequestId", "sub-123456-1000"); + +var actionIdentifiers = executor.subject.getOutFieldSchemaHelper("actionIdentifiers").createNewInstance(); +actionIdentifiers.put("actionName", actionName); +actionIdentifiers.put("blueprintName", "pm_control"); +actionIdentifiers.put("blueprintVersion", "1.0.0"); +actionIdentifiers.put("mode", "sync"); + +executor.outFields.put("commonHeader", commonHeader); +executor.outFields.put("actionIdentifiers", actionIdentifiers); +executor.outFields.put("payload", payload); + +executor.logger.info("Sending Deactivate Subscription Event to CDS") + +true; \ No newline at end of file diff --git a/examples/examples-grpc/src/main/resources/logic/ReceivePMSubscriptionTask.js b/examples/examples-grpc/src/main/resources/logic/ReceivePMSubscriptionTask.js new file mode 100644 index 000000000..bc4028a32 --- /dev/null +++ b/examples/examples-grpc/src/main/resources/logic/ReceivePMSubscriptionTask.js @@ -0,0 +1,48 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix. 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========================================================= + */ +var uuidType = java.util.UUID; + + +//albumID will be used to fetch info from our album later +var albumID = uuidType.fromString("d0050623-18e5-46c9-9298-9a567990cd7c"); +var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").getSchemaHelper().createNewInstance(); +var returnValue = true;; + +if(executor.inFields.get("policyName") != null) { + var changeType = executor.inFields.get("changeType") + var nfName = executor.inFields.get("nfName") + var policyName = executor.inFields.get("policyName") + var closedLoopControlName = executor.inFields.get("closedLoopControlName") + var subscription = executor.inFields.get("subscription") + + pmSubscriptionInfo.put("nfName", executor.inFields.get("nfName")); + pmSubscriptionInfo.put("changeType", executor.inFields.get("changeType")) + pmSubscriptionInfo.put("policyName", executor.inFields.get("policyName")) + pmSubscriptionInfo.put("closedLoopControlName", executor.inFields.get("closedLoopControlName")) + pmSubscriptionInfo.put("subscription", subscription) + + executor.getContextAlbum("PMSubscriptionAlbum").put(albumID.toString(), pmSubscriptionInfo); + + executor.outFields.put("albumID", albumID) +} else { + executor.message = "Received invalid event" + returnValue = false; +} +returnValue; \ No newline at end of file diff --git a/examples/examples-grpc/src/main/resources/logic/ResponseTask.js b/examples/examples-grpc/src/main/resources/logic/ResponseTask.js new file mode 100644 index 000000000..04517763a --- /dev/null +++ b/examples/examples-grpc/src/main/resources/logic/ResponseTask.js @@ -0,0 +1,44 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Nordix. 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========================================================= + */ + + +var uuidType = java.util.UUID; + +var albumID = uuidType.fromString("d0050623-18e5-46c9-9298-9a567990cd7c"); + +var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(albumID.toString()); + +var responseStatus = executor.subject.getOutFieldSchemaHelper("status").createNewInstance(); + +responseStatus.put("subscriptionName", pmSubscriptionInfo.get("subscription").get("subscriptionName")) +responseStatus.put("nfName", pmSubscriptionInfo.get("nfName")) +responseStatus.put("changeType", pmSubscriptionInfo.get("changeType")) + +var response = executor.inFields.get("payload") + +if ("failure".equals(response.get("create_DasH_subscription_DasH_response").get("odl_DasH_response").get("status"))) { + responseStatus.put("message", "failed") +} else { + responseStatus.put("message", "success") +} + +executor.outFields.put("status", responseStatus) + +true; -- cgit 1.2.3-korg