summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-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
-rw-r--r--examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestRestSimEndpoint.java2
-rw-r--r--examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java11
7 files changed, 42 insertions, 44 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
diff --git a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestRestSimEndpoint.java b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestRestSimEndpoint.java
index 4e88afe83..17b99c986 100644
--- a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestRestSimEndpoint.java
+++ b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/GrpcTestRestSimEndpoint.java
@@ -68,7 +68,7 @@ public class GrpcTestRestSimEndpoint {
public Response policyLogRequest(final String jsonString) {
LOGGER.info("\n*** POLICY LOG ENTRY START ***\n {} \n *** POLICY LOG ENTRY END ***", jsonString);
synchronized (lock) {
- loggedOutputEvent = jsonString;
+ loggedOutputEvent += jsonString + "\n";
}
return Response.status(200).build();
}
diff --git a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java
index 7f799c24f..a197432ba 100644
--- a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java
+++ b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix Foundation.
- * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2020-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.
@@ -21,8 +21,8 @@
package org.onap.policy.apex.examples.grpc;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
-import static org.junit.Assert.assertEquals;
import java.nio.file.Files;
import java.nio.file.Paths;
@@ -85,9 +85,12 @@ public class TestApexGrpcExample {
Response response = client.target(getLoggedEventUrl).request("application/json").get();
sim.tearDown();
String responseEntity = response.readEntity(String.class);
-
String expectedLoggedOutputEvent = Files
.readString(Paths.get("src/main/resources/examples/events/APEXgRPC/LogEvent.json")).replaceAll("\r", "");
- assertEquals(expectedLoggedOutputEvent, responseEntity);
+ String expectedStatusEvent =
+ Files.readString(Paths.get("src/main/resources/examples/events/APEXgRPC/CDSResponseStatusEvent.json"))
+ .replaceAll("\r", "");
+ // Both LogEvent and CDSResponseStatusEvent are generated from the final state in the policy
+ assertThat(responseEntity).contains(expectedStatusEvent + expectedLoggedOutputEvent);
}
}