summaryrefslogtreecommitdiffstats
path: root/plugins
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
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')
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java15
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsObjectEventConverter.java7
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/Apex2XmlEventConverter.java7
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XmlEventHandlerTest.java9
-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
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java8
7 files changed, 58 insertions, 29 deletions
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java
index 708f29f4f..2f781689f 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Samsung. All rights reserved.
* Modifications Copyright (C) 2019-2021 Nordix Foundation.
+ * 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.
@@ -328,7 +329,7 @@ public class ApexJmsProducerTest {
// Prepare sendEvent
ApexEvent apexEvent = new ApexEvent("testEvent", "testVersion", "testNameSpace",
- "testSource", "testTarget");
+ "testSource", "testTarget", "");
Mockito.doThrow(JMSException.class).when(session).createObjectMessage(apexEvent);
final long executionId = random.nextLong();
@@ -367,7 +368,7 @@ public class ApexJmsProducerTest {
// Prepare sendEvent
final Message message = Mockito.mock(ObjectMessage.class);
ApexEvent apexEvent = new ApexEvent("testEvent", "testVersion", "testNameSpace",
- "testSource", "testTarget");
+ "testSource", "testTarget", "");
Mockito.doReturn(message).when(session).createObjectMessage(apexEvent);
Mockito.doThrow(JMSException.class).when(messageProducer).send(message);
@@ -410,7 +411,7 @@ public class ApexJmsProducerTest {
// Prepare sendEvent
final Message message = Mockito.mock(ObjectMessage.class);
ApexEvent apexEvent = new ApexEvent("testEvent", "testVersion", "testNameSpace",
- "testSource", "testTarget");
+ "testSource", "testTarget", "");
Mockito.doReturn(message).when(session).createObjectMessage(apexEvent);
Mockito.doNothing().when(messageProducer).send(message);
@@ -452,7 +453,7 @@ public class ApexJmsProducerTest {
// Prepare sendEvent
ApexEvent apexEvent = new ApexEvent("testEvent", "testVersion", "testNameSpace",
- "testSource", "testTarget");
+ "testSource", "testTarget", "");
Mockito.doThrow(JMSException.class).when(session).createTextMessage(apexEvent.toString());
@@ -495,7 +496,7 @@ public class ApexJmsProducerTest {
// Prepare sendEvent
final Message message = Mockito.mock(TextMessage.class);
ApexEvent apexEvent = new ApexEvent("testEvent", "testVersion", "testNameSpace",
- "testSource", "testTarget");
+ "testSource", "testTarget", "");
Mockito.doReturn(message).when(session).createTextMessage(apexEvent.toString());
Mockito.doThrow(JMSException.class).when(messageProducer).send(message);
@@ -539,7 +540,7 @@ public class ApexJmsProducerTest {
// Prepare sendEvent
final Message message = Mockito.mock(TextMessage.class);
ApexEvent apexEvent = new ApexEvent("testEvent", "testVersion", "testNameSpace",
- "testSource", "testTarget");
+ "testSource", "testTarget", "");
Mockito.doReturn(message).when(session).createTextMessage(apexEvent.toString());
Mockito.doNothing().when(messageProducer).send(message);
@@ -707,4 +708,4 @@ public class ApexJmsProducerTest {
// do the test
assertThatCode(apexJmsProducer::stop).doesNotThrowAnyException();
}
-}
+} \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsObjectEventConverter.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsObjectEventConverter.java
index cd14f4a3b..8d9416fb1 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsObjectEventConverter.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/java/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsObjectEventConverter.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.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -100,12 +100,13 @@ public final class Apex2JmsObjectEventConverter implements ApexEventProtocolConv
// Create the Apex event
// @formatter:off
+ // FIXME: Introduce new AxEvent field for APEX to Jms object conversion
final var apexEvent = new ApexEvent(
jmsIncomingObject.getClass().getSimpleName() + eventProtocolParameters.getIncomingEventSuffix(),
eventProtocolParameters.getIncomingEventVersion(),
jmsIncomingObject.toString().getClass().getPackage().getName(),
eventProtocolParameters.getIncomingEventSource(),
- eventProtocolParameters.getIncomingEventTarget());
+ eventProtocolParameters.getIncomingEventTarget(), "");
// @formatter:on
// Set the data on the apex event as the incoming object
@@ -137,4 +138,4 @@ public final class Apex2JmsObjectEventConverter implements ApexEventProtocolConv
// Return the single object from the Apex event message
return apexEvent.values().iterator().next();
}
-}
+} \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/Apex2XmlEventConverter.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/Apex2XmlEventConverter.java
index f601c4b6f..907d426e7 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/Apex2XmlEventConverter.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/main/java/org/onap/policy/apex/plugins/event/protocol/xml/Apex2XmlEventConverter.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -128,8 +128,9 @@ public final class Apex2XmlEventConverter implements ApexEventProtocolConverter
}
// Create the Apex event
+ // FIXME: Introduce new AxEvent field for APEX to Xml conversion
final var apexEvent = new ApexEvent(xmlApexEvent.getName(), xmlApexEvent.getVersion(),
- xmlApexEvent.getNameSpace(), xmlApexEvent.getSource(), xmlApexEvent.getTarget());
+ xmlApexEvent.getNameSpace(), xmlApexEvent.getSource(), xmlApexEvent.getTarget(), "");
// Set the data on the apex event
for (final XMLApexEventData xmlData : xmlApexEvent.getData()) {
@@ -184,4 +185,4 @@ public final class Apex2XmlEventConverter implements ApexEventProtocolConverter
throw new ApexEventException("Unable to unmarshal Apex event to XML\n" + apexEvent, e);
}
}
-}
+} \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XmlEventHandlerTest.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XmlEventHandlerTest.java
index 609b0471b..f8caf8c2f 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XmlEventHandlerTest.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-xml/src/test/java/org/onap/policy/apex/plugins/event/protocol/xml/XmlEventHandlerTest.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2022 Bell Canada.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -152,7 +153,7 @@ public class XmlEventHandlerTest {
event0000DataMap.put("NullValue", null);
final ApexEvent apexEvent0000 =
- new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.sample.events", "test", "apex");
+ new ApexEvent("Event0000", "0.0.1", "org.onap.policy.apex.sample.events", "test", "apex", "");
apexEvent0000.putAll(event0000DataMap);
final String apexEvent0000XmlString = xmlEventConverter.fromApexEvent(apexEvent0000);
@@ -182,8 +183,8 @@ public class XmlEventHandlerTest {
event0004DataMap.put("TestActCaseSelected", Integer.valueOf(2));
event0004DataMap.put("TestActStateTime", Long.valueOf(1434370506095L));
- final ApexEvent apexEvent0004 =
- new ApexEvent("Event0004", "0.0.1", "org.onap.policy.apex.domains.sample.events", "test", "apex");
+ final ApexEvent apexEvent0004 = new ApexEvent("Event0004", "0.0.1",
+ "org.onap.policy.apex.domains.sample.events", "test", "apex", "");
apexEvent0004.putAll(event0004DataMap);
final String apexEvent0004XmlString = xmlEventConverter.fromApexEvent(apexEvent0004);
@@ -201,4 +202,4 @@ public class XmlEventHandlerTest {
throw new ApexException("Exception reading Apex event xml file", e);
}
}
-}
+} \ 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/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
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java
index ab911499a..0d3d62382 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java
@@ -3,6 +3,7 @@
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 Nordix Foundation
* 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.
@@ -35,6 +36,7 @@ import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters;
import org.onap.policy.apex.context.parameters.SchemaParameters;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxToscaPolicyProcessingStatus;
import org.onap.policy.apex.model.basicmodel.service.ModelService;
import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
@@ -80,6 +82,7 @@ public class YamlPluginStabilityTest {
testEvent = new AxEvent(new AxArtifactKey("TestEvent", "0.0.1"));
testEvent.setNameSpace("org.onap.policy.apex.plugins.event.protocol.yaml");
+ testEvent.setToscaPolicyState(AxToscaPolicyProcessingStatus.ENTRY.name());
AxField teField0 = new AxField(new AxReferenceKey(testEvent.getKey(), "intValue"), simpleIntSchema.getKey());
testEvent.getParameterMap().put("intValue", teField0);
AxField teField1 = new AxField(new AxReferenceKey(testEvent.getKey(), "doubleValue"),
@@ -130,7 +133,8 @@ public class YamlPluginStabilityTest {
assertThatThrownBy(() -> converter.fromApexEvent(null))
.hasMessage("event processing failed, Apex event is null");
ApexEvent apexEvent = new ApexEvent(testEvent.getKey().getName(), testEvent.getKey().getVersion(),
- testEvent.getNameSpace(), testEvent.getSource(), testEvent.getTarget());
+ testEvent.getNameSpace(), testEvent.getSource(), testEvent.getTarget(),
+ testEvent.getToscaPolicyState());
apexEvent.put("doubleValue", 123.45);
apexEvent.put("intValue", 123);
apexEvent.put("stringValue", "123.45");
@@ -216,4 +220,4 @@ public class YamlPluginStabilityTest {
assertThatThrownBy(() -> converter.toApexEvent("TestEvent", "doubleValue: 123.45\n" + "intValue: ~\n"
+ "stringValue: MyString")).getCause().hasMessageStartingWith("mandatory field \"intValue\" is missing");
}
-}
+} \ No newline at end of file