summaryrefslogtreecommitdiffstats
path: root/examples/examples-grpc/src/main/resources
diff options
context:
space:
mode:
authora.sreekumar <ajith.sreekumar@bell.ca>2021-06-22 15:55:46 +0100
committera.sreekumar <ajith.sreekumar@bell.ca>2021-06-28 10:36:48 +0100
commit926646d8e5e86e680a119360f93d7bdb46c89435 (patch)
tree7ff431e59672b19f658faed87c80b4d147253c9c /examples/examples-grpc/src/main/resources
parent63637d939697451d3ac63216d938780a157ff895 (diff)
Changes to support multiple outputs from a state
This review addresses two main changes: 1) inputFields and outputFields are not tied to task definition anymore. Instead inputEvent and outputEvents associated to a task is populated as part of the policy state definition, as the state definition have the information anyway. - Clean up of the usage of inputFields and outputFields in task definition will happen in a future review - inputFields and outputFields defined in task definition in policies until honolulu will not make the policy invalid as the changes are done in backward compatible way. 2) Multiple output events can come out of a final state now. - Define another policy state output with the relevant eventName in the command file - In the task logic, create a map to store the fields of the relevant outputEvent, and then just call "executor.addFieldsToOutput(<the_map_of_fields>)" These 2 steps are enough to send multiple events to relevant components as per the apex configuration. Change-Id: Id88ca402704106404f529e595e1a76f6bf167876 Issue-ID: POLICY-3336 Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
Diffstat (limited to 'examples/examples-grpc/src/main/resources')
-rw-r--r--examples/examples-grpc/src/main/resources/examples/config/APEXgRPC/ApexConfig.json4
-rw-r--r--examples/examples-grpc/src/main/resources/examples/events/APEXgRPC/CDSResponseStatusEvent.json13
-rw-r--r--examples/examples-grpc/src/main/resources/examples/events/APEXgRPC/LogEvent.json12
-rw-r--r--examples/examples-grpc/src/main/resources/logic/ResponseTask.js11
-rw-r--r--examples/examples-grpc/src/main/resources/policy/APEXgRPCPolicy.apex33
5 files changed, 34 insertions, 39 deletions
diff --git a/examples/examples-grpc/src/main/resources/examples/config/APEXgRPC/ApexConfig.json b/examples/examples-grpc/src/main/resources/examples/config/APEXgRPC/ApexConfig.json
index fb1c38014..c34f9e33f 100644
--- a/examples/examples-grpc/src/main/resources/examples/config/APEXgRPC/ApexConfig.json
+++ b/examples/examples-grpc/src/main/resources/examples/config/APEXgRPC/ApexConfig.json
@@ -106,7 +106,7 @@
"eventProtocolParameters": {
"eventProtocol": "JSON"
},
- "eventNameFilter": "CDSResponseStatusEvent"
+ "eventNameFilter": "(LogEvent|CDSResponseStatusEvent)"
}
}
-} \ No newline at end of file
+}
diff --git a/examples/examples-grpc/src/main/resources/examples/events/APEXgRPC/CDSResponseStatusEvent.json b/examples/examples-grpc/src/main/resources/examples/events/APEXgRPC/CDSResponseStatusEvent.json
new file mode 100644
index 000000000..938983362
--- /dev/null
+++ b/examples/examples-grpc/src/main/resources/examples/events/APEXgRPC/CDSResponseStatusEvent.json
@@ -0,0 +1,13 @@
+{
+ "name": "CDSResponseStatusEvent",
+ "version": "0.0.1",
+ "nameSpace": "org.onap.policy.apex.onap.pmcontrol",
+ "source": "APEX",
+ "target": "DCAE",
+ "status": {
+ "subscriptionName": "testPolicyB",
+ "nfName": "pnf300",
+ "changeType": "CREATE",
+ "message": "success"
+ }
+}
diff --git a/examples/examples-grpc/src/main/resources/examples/events/APEXgRPC/LogEvent.json b/examples/examples-grpc/src/main/resources/examples/events/APEXgRPC/LogEvent.json
index a86ccd1d7..e227b6699 100644
--- a/examples/examples-grpc/src/main/resources/examples/events/APEXgRPC/LogEvent.json
+++ b/examples/examples-grpc/src/main/resources/examples/events/APEXgRPC/LogEvent.json
@@ -1,13 +1,9 @@
{
- "name": "CDSResponseStatusEvent",
+ "name": "LogEvent",
"version": "0.0.1",
"nameSpace": "org.onap.policy.apex.onap.pmcontrol",
"source": "APEX",
"target": "DCAE",
- "status": {
- "subscriptionName": "testPolicyB",
- "nfName": "pnf300",
- "changeType": "CREATE",
- "message": "success"
- }
-} \ No newline at end of file
+ "final_status": "FINAL_SUCCESS",
+ "message": "Operation successfully completed."
+}
diff --git a/examples/examples-grpc/src/main/resources/logic/ResponseTask.js b/examples/examples-grpc/src/main/resources/logic/ResponseTask.js
index 04517763a..dc4948990 100644
--- a/examples/examples-grpc/src/main/resources/logic/ResponseTask.js
+++ b/examples/examples-grpc/src/main/resources/logic/ResponseTask.js
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix. All rights reserved.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
@@ -25,7 +26,7 @@ var albumID = uuidType.fromString("d0050623-18e5-46c9-9298-9a567990cd7c");
var pmSubscriptionInfo = executor.getContextAlbum("PMSubscriptionAlbum").get(albumID.toString());
-var responseStatus = executor.subject.getOutFieldSchemaHelper("status").createNewInstance();
+var responseStatus = executor.subject.getOutFieldSchemaHelper("CDSResponseStatusEvent", "status").createNewInstance();
responseStatus.put("subscriptionName", pmSubscriptionInfo.get("subscription").get("subscriptionName"))
responseStatus.put("nfName", pmSubscriptionInfo.get("nfName"))
@@ -39,6 +40,12 @@ if ("failure".equals(response.get("create_DasH_subscription_DasH_response").get(
responseStatus.put("message", "success")
}
-executor.outFields.put("status", responseStatus)
+var cdsResponseEventFields = java.util.HashMap();
+cdsResponseEventFields.put("status", responseStatus);
+executor.addFieldsToOutput(cdsResponseEventFields);
+var logEventFields = java.util.HashMap();
+logEventFields.put("final_status", "FINAL_SUCCESS");
+logEventFields.put("message", "Operation successfully completed.");
+executor.addFieldsToOutput(logEventFields);
true;
diff --git a/examples/examples-grpc/src/main/resources/policy/APEXgRPCPolicy.apex b/examples/examples-grpc/src/main/resources/policy/APEXgRPCPolicy.apex
index b0cbcb7c0..636c74b80 100644
--- a/examples/examples-grpc/src/main/resources/policy/APEXgRPCPolicy.apex
+++ b/examples/examples-grpc/src/main/resources/policy/APEXgRPCPolicy.apex
@@ -1,6 +1,7 @@
#-------------------------------------------------------------------------------
# ============LICENSE_START=======================================================
# Copyright (C) 2020 Nordix Foundation.
+# Modifications Copyright (C) 2021 Bell Canada. 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.
@@ -111,69 +112,46 @@ event parameter create name=CDSResponseEvent parName=payload schemaName=CDSRespo
event create name=CDSResponseStatusEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=DCAE
event parameter create name=CDSResponseStatusEvent parName=status schemaName=SubscriptionStatusType
+event create name=LogEvent nameSpace=org.onap.policy.apex.onap.pmcontrol source=APEX target=DCAE
+event parameter create name=LogEvent parName=final_status schemaName=SimpleStringType
+event parameter create name=LogEvent parName=message schemaName=SimpleStringType
+
##
## TASKS
##
task create name=ReceivePMSubscriptionTask
-task inputfield create name=ReceivePMSubscriptionTask fieldName=subscription schemaName=SubscriptionType
-task inputfield create name=ReceivePMSubscriptionTask fieldName=nfName schemaName=SimpleStringType
-task inputfield create name=ReceivePMSubscriptionTask fieldName=policyName schemaName=SimpleStringType
-task inputfield create name=ReceivePMSubscriptionTask fieldName=changeType schemaName=SimpleStringType
-task inputfield create name=ReceivePMSubscriptionTask fieldName=closedLoopControlName schemaName=SimpleStringType
-task outputfield create name=ReceivePMSubscriptionTask fieldName=albumID schemaName=UUIDType
task contextref create name=ReceivePMSubscriptionTask albumName=PMSubscriptionAlbum
task logic create name=ReceivePMSubscriptionTask logicFlavour=JAVASCRIPT logic=LS
#MACROFILE:"src/main/resources/logic/ReceivePMSubscriptionTask.js"
LE
task create name=CreateSubscriptionPayloadTask
-task inputfield create name=CreateSubscriptionPayloadTask fieldName=albumID schemaName=UUIDType
-task outputfield create name=CreateSubscriptionPayloadTask fieldName=payload schemaName=CDSCreateSubscriptionPayloadType
-task outputfield create name=CreateSubscriptionPayloadTask fieldName=albumID schemaName=UUIDType
task contextref create name=CreateSubscriptionPayloadTask albumName=PMSubscriptionAlbum
task logic create name=CreateSubscriptionPayloadTask logicFlavour=JAVASCRIPT logic=LS
#MACROFILE:"src/main/resources/logic/CreateSubscriptionPayloadTask.js"
LE
task create name=DeleteSubscriptionPayloadTask
-task inputfield create name=DeleteSubscriptionPayloadTask fieldName=albumID schemaName=UUIDType
-task outputfield create name=DeleteSubscriptionPayloadTask fieldName=payload schemaName=CDSDeleteSubscriptionPayloadType
-task outputfield create name=DeleteSubscriptionPayloadTask fieldName=albumID schemaName=UUIDType
task contextref create name=DeleteSubscriptionPayloadTask albumName=PMSubscriptionAlbum
task logic create name=DeleteSubscriptionPayloadTask logicFlavour=JAVASCRIPT logic=LS
#MACROFILE:"src/main/resources/logic/DeleteSubscriptionPayloadTask.js"
LE
task create name=CreateSubscriptionRequestTask
-task inputfield create name=CreateSubscriptionRequestTask fieldName=albumID schemaName=UUIDType
-task inputfield create name=CreateSubscriptionRequestTask fieldName=payload schemaName=CDSCreateSubscriptionPayloadType
-task outputfield create name=CreateSubscriptionRequestTask fieldName=commonHeader schemaName=CDSRequestCommonHeaderType
-task outputfield create name=CreateSubscriptionRequestTask fieldName=actionIdentifiers schemaName=CDSActionIdentifiersType
-task outputfield create name=CreateSubscriptionRequestTask fieldName=payload schemaName=CDSCreateSubscriptionPayloadType
task contextref create name=CreateSubscriptionRequestTask albumName=PMSubscriptionAlbum
task logic create name=CreateSubscriptionRequestTask logicFlavour=JAVASCRIPT logic=LS
#MACROFILE:"src/main/resources/logic/CreateSubscriptionRequestTask.js"
LE
task create name=DeleteSubscriptionRequestTask
-task inputfield create name=DeleteSubscriptionRequestTask fieldName=albumID schemaName=UUIDType
-task inputfield create name=DeleteSubscriptionRequestTask fieldName=payload schemaName=CDSDeleteSubscriptionPayloadType
-task outputfield create name=DeleteSubscriptionRequestTask fieldName=commonHeader schemaName=CDSRequestCommonHeaderType
-task outputfield create name=DeleteSubscriptionRequestTask fieldName=actionIdentifiers schemaName=CDSActionIdentifiersType
-task outputfield create name=DeleteSubscriptionRequestTask fieldName=payload schemaName=CDSDeleteSubscriptionPayloadType
task contextref create name=DeleteSubscriptionRequestTask albumName=PMSubscriptionAlbum
task logic create name=DeleteSubscriptionRequestTask logicFlavour=JAVASCRIPT logic=LS
#MACROFILE:"src/main/resources/logic/DeleteSubscriptionRequestTask.js"
LE
task create name=CDSResponseTask
-task inputfield create name=CDSResponseTask fieldName=commonHeader schemaName=CDSResponseCommonHeaderType
-task inputfield create name=CDSResponseTask fieldName=actionIdentifiers schemaName=CDSActionIdentifiersType
-task inputfield create name=CDSResponseTask fieldName=status schemaName=CDSResponseStatusType
-task inputfield create name=CDSResponseTask fieldName=payload schemaName=CDSResponsePayloadType
-task outputfield create name=CDSResponseTask fieldName=status schemaName=SubscriptionStatusType
task contextref create name=CDSResponseTask albumName=PMSubscriptionAlbum
task logic create name=CDSResponseTask logicFlavour=JAVASCRIPT logic=LS
#MACROFILE:"src/main/resources/logic/ResponseTask.js"
@@ -227,6 +205,7 @@ policy create name=CDSResponsePolicy template=Freestyle firstState=CDSResponseSt
# State CDSResponseState
policy state create name=CDSResponsePolicy stateName=CDSResponseState triggerName=CDSResponseEvent defaultTaskName=CDSResponseTask
policy state output create name=CDSResponsePolicy stateName=CDSResponseState outputName=ResponseOutput eventName=CDSResponseStatusEvent
+policy state output create name=CDSResponsePolicy stateName=CDSResponseState outputName=ResponseOutput eventName=LogEvent
policy state taskref create name=CDSResponsePolicy stateName=CDSResponseState taskName=CDSResponseTask outputType=DIRECT outputName=ResponseOutput
validate \ No newline at end of file