summaryrefslogtreecommitdiffstats
path: root/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java
diff options
context:
space:
mode:
authorRashmi Pujar <rashmi.pujar1@bell.ca>2022-01-22 00:37:28 -0500
committerRashmi Pujar <rashmi.pujar1@bell.ca>2022-01-24 14:06:57 -0500
commit632899642b6a1d1489a0b96932c9c38863a53a26 (patch)
treeab9665853aa637ab1d76d7c25523c77835d3ca3e /plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java
parentc719ee941bd4202b617544e351a11a35b20b8a6a (diff)
Add TOSCA policy status header field to APEX event create CLI
In order to expose the processing status of a TOSCA policy to APEX-PDP, a new header field for APEX concept "event" has been introduced to track this within an APEX policy implementation. This field will be leveraged to extract the TOSCA policy execution metrics. Note, that the field is marked as optional for backward compatibility. Unit tests have been augmented to test for the field wherever applicable and the default empty value is retained for the others. "example-grpc" module has been updated to include this field. Exposing the TOSCA policy execution metrics is outside the scope of this patch since the current changes are already very large owing to the atomic nature of the change introduced. Issue-ID: POLICY-3845 Signed-off-by: Rashmi Pujar <rashmi.pujar1@bell.ca> Change-Id: Ief6d70f9abcfc8414e10aa51a27815ee9028e4c8
Diffstat (limited to 'plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java')
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/Apex2YamlEventConverter.java25
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolParameters.java16
2 files changed, 31 insertions, 10 deletions
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/Apex2YamlEventConverter.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/Apex2YamlEventConverter.java
index 9359e4ef9..731d3519a 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/Apex2YamlEventConverter.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/Apex2YamlEventConverter.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2021 Nordix Foundation.
- * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2021-2022 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.
@@ -257,7 +257,9 @@ public class Apex2YamlEventConverter implements ApexEventProtocolConverter {
String target = getHeaderTarget(yamlMap, eventDefinition);
- return new ApexEvent(name, version, namespace, source, target);
+ String toscaPolicyState = getHeaderToscaPolicyState(yamlMap, eventDefinition);
+
+ return new ApexEvent(name, version, namespace, source, target, toscaPolicyState);
}
/**
@@ -318,6 +320,23 @@ public class Apex2YamlEventConverter implements ApexEventProtocolConverter {
}
/**
+ * Get the event header toscaPolicyState field.
+ *
+ * @param yamlMap the YAML map to read from
+ * @param eventDefinition the event definition
+ * @return the event header toscaPolicyState field
+ */
+ private String getHeaderToscaPolicyState(final Map<?, ?> yamlMap, final AxEvent eventDefinition) {
+ // For toscaPolicyState, use the defined value only if not found on the incoming event
+ var toscaPolicyState = getYamlStringField(yamlMap, ApexEvent.TOSCA_POLICY_STATE_HEADER_FIELD,
+ yamlPars.getToscaPolicyStateAlias(), null, false);
+ if (toscaPolicyState == null) {
+ toscaPolicyState = eventDefinition.getTarget();
+ }
+ return toscaPolicyState;
+ }
+
+ /**
* This method gets an event string field from a JSON object.
*
* @param yamlMap the YAML containing the YAML representation of the incoming event
@@ -391,4 +410,4 @@ public class Apex2YamlEventConverter implements ApexEventProtocolConverter {
return eventElement;
}
-}
+} \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolParameters.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolParameters.java
index e5539cd04..120104460 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolParameters.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/main/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolParameters.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2022 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.
@@ -61,12 +62,13 @@ public class YamlEventProtocolParameters extends EventProtocolTextTokenDelimited
// Aliases for Apex event header fields
// @formatter:off
- private String nameAlias = null;
- private String versionAlias = null;
- private String nameSpaceAlias = null;
- private String sourceAlias = null;
- private String targetAlias = null;
- private String yamlFieldName = DEFAULT_YAML_FIELD_NAME;
+ private String nameAlias = null;
+ private String versionAlias = null;
+ private String nameSpaceAlias = null;
+ private String sourceAlias = null;
+ private String targetAlias = null;
+ private String toscaPolicyStateAlias = null;
+ private String yamlFieldName = DEFAULT_YAML_FIELD_NAME;
// @formatter:on
/**
@@ -96,4 +98,4 @@ public class YamlEventProtocolParameters extends EventProtocolTextTokenDelimited
// Set the event protocol plugin class
this.setEventProtocolPluginClass(Apex2YamlEventConverter.class.getName());
}
-}
+} \ No newline at end of file