aboutsummaryrefslogtreecommitdiffstats
path: root/services/services-engine
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 /services/services-engine
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 'services/services-engine')
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java40
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexPeriodicEventGenerator.java8
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverter.java8
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JsonEventConverter.java25
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/JsonEventProtocolParameters.java14
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/ApexEventTest.java23
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java5
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java8
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/Apex2ApexEventConverterTest.java25
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverterTest.java9
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.java9
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java4
12 files changed, 128 insertions, 50 deletions
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java
index 76a1c03a2..a8f13bbf6 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.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.
@@ -21,7 +22,9 @@
package org.onap.policy.apex.service.engine.event;
+import com.google.common.base.Strings;
import java.io.Serializable;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
@@ -30,7 +33,9 @@ import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
+import org.apache.commons.lang3.EnumUtils;
import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
+import org.onap.policy.apex.model.basicmodel.concepts.AxToscaPolicyProcessingStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -92,6 +97,14 @@ public class ApexEvent extends HashMap<String, Object> implements Serializable {
public static final String TARGET_HEADER_FIELD = "target";
/**
+ * The toscaPolicyState of Apex event, an optional field. It specifies the TOSCA Policy processing status
+ * on an Apex event, with possible values as enumerated in
+ * {@link org.onap.policy.apex.model.basicmodel.concepts.AxToscaPolicyProcessingStatus}.
+ * If no toscaPolicyState is specified, it indicates that the TOSCA Policy is under process.
+ */
+ public static final String TOSCA_POLICY_STATE_HEADER_FIELD = "toscaPolicyState";
+
+ /**
* The exception message field of an Apex event is an exception message indicating that an event
* failed.
*/
@@ -118,6 +131,7 @@ public class ApexEvent extends HashMap<String, Object> implements Serializable {
private final String nameSpace;
private final String source;
private final String target;
+ private final String toscaPolicyState;
// An identifier for the current event execution. The default value here will always be unique
// in a single JVM
@@ -143,14 +157,13 @@ public class ApexEvent extends HashMap<String, Object> implements Serializable {
* @throws ApexEventException thrown on validation errors on event names and versions
*/
public ApexEvent(final String name, final String version, final String nameSpace, final String source,
- final String target) throws ApexEventException {
- // @formatter:off
- this.name = validateField(NAME_HEADER_FIELD, name, NAME_REGEXP);
- this.version = validateField(VERSION_HEADER_FIELD, version, VERSION_REGEXP);
+ final String target, final String toscaPolicyState) throws ApexEventException {
+ this.name = validateField(NAME_HEADER_FIELD, name, NAME_REGEXP);
+ this.version = validateField(VERSION_HEADER_FIELD, version, VERSION_REGEXP);
this.nameSpace = validateField(NAMESPACE_HEADER_FIELD, nameSpace, NAMESPACE_REGEXP);
- this.source = validateField(SOURCE_HEADER_FIELD, source, SOURCE_REGEXP);
- this.target = validateField(TARGET_HEADER_FIELD, target, TARGET_REGEXP);
- // @formatter:on
+ this.source = validateField(SOURCE_HEADER_FIELD, source, SOURCE_REGEXP);
+ this.target = validateField(TARGET_HEADER_FIELD, target, TARGET_REGEXP);
+ this.toscaPolicyState = validateField(TOSCA_POLICY_STATE_HEADER_FIELD, toscaPolicyState, "");
}
/**
@@ -174,6 +187,17 @@ public class ApexEvent extends HashMap<String, Object> implements Serializable {
*/
private String validateField(final String fieldName, final String fieldValue, final String fieldRegexp)
throws ApexEventException {
+ if (fieldName.equals(TOSCA_POLICY_STATE_HEADER_FIELD) && !Strings.isNullOrEmpty(fieldValue)) {
+ if (EnumUtils.isValidEnum(AxToscaPolicyProcessingStatus.class, fieldValue)) {
+ return fieldValue;
+ } else {
+ String message = EVENT_PREAMBLE + name + ": field \"" + fieldName + "=" + fieldValue
+ + "\" is illegal. It doesn't match supported values '"
+ + Arrays.asList(AxToscaPolicyProcessingStatus.values()) + "'";
+ LOGGER.warn(message);
+ throw new ApexEventException(message);
+ }
+ }
if (fieldValue.matches(fieldRegexp)) {
return fieldValue;
} else {
@@ -243,4 +267,4 @@ public class ApexEvent extends HashMap<String, Object> implements Serializable {
// Go ahead and put everything
super.putAll(incomingMap);
}
-}
+} \ No newline at end of file
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexPeriodicEventGenerator.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexPeriodicEventGenerator.java
index 1300f2176..ea3cb4b29 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexPeriodicEventGenerator.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexPeriodicEventGenerator.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 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.
@@ -53,6 +54,9 @@ public class ApexPeriodicEventGenerator extends TimerTask {
/** The target of the periodic event. */
public static final String PERIODIC_EVENT_TARGET = PERIODIC_EVENT_SOURCE;
+ /** The status of the periodic event. */
+ public static final String PERIODIC_EVENT_STATUS = "";
+
/**
* The field name in the periodic event for the delay between occurrences of the periodic event.
*/
@@ -137,7 +141,7 @@ public class ApexPeriodicEventGenerator extends TimerTask {
// Send the periodic event
try {
final var periodicEvent = new ApexEvent(PERIODIC_EVENT_NAME, PERIODIC_EVENT_VERSION,
- PERIODIC_EVENT_NAMESPACE, PERIODIC_EVENT_SOURCE, PERIODIC_EVENT_TARGET);
+ PERIODIC_EVENT_NAMESPACE, PERIODIC_EVENT_SOURCE, PERIODIC_EVENT_TARGET, PERIODIC_EVENT_STATUS);
periodicEvent.putAll(periodicEventMap);
engineServiceEventInterface.sendEvent(periodicEvent);
} catch (final ApexEventException e) {
@@ -171,4 +175,4 @@ public class ApexPeriodicEventGenerator extends TimerTask {
return "ApexPeriodicEventGenerator [period=" + eventGeneratorPeriod + ", firstEventTime=" + firstEventTime
+ ", lastEventTime=" + lastEventTime + ", eventCount=" + eventCount + "]";
}
-}
+} \ No newline at end of file
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverter.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverter.java
index 27fa50988..3bbd3ab4f 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverter.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverter.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 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -72,12 +72,12 @@ public final class ApexEvent2EnEventConverter implements ApexEventConverter {
// Create the Apex event
final var axEvent = enEvent.getAxEvent();
final var apexEvent = new ApexEvent(axEvent.getKey().getName(), axEvent.getKey().getVersion(),
- axEvent.getNameSpace(), axEvent.getSource(), axEvent.getTarget());
+ axEvent.getNameSpace(), axEvent.getSource(), axEvent.getTarget(), axEvent.getToscaPolicyState());
apexEvent.setExecutionId(enEvent.getExecutionId());
apexEvent.setExecutionProperties(enEvent.getExecutionProperties());
- // Copy he exception message to the Apex event if it is set
+ // Copy the exception message to the Apex event if it is set
if (enEvent.getExceptionMessage() != null) {
apexEvent.setExceptionMessage(enEvent.getExceptionMessage());
}
@@ -119,4 +119,4 @@ public final class ApexEvent2EnEventConverter implements ApexEventConverter {
return enEvent;
}
-}
+} \ No newline at end of file
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JsonEventConverter.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JsonEventConverter.java
index 56f0d6ba8..976a3ae3d 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JsonEventConverter.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/Apex2JsonEventConverter.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.
@@ -188,6 +188,7 @@ public class Apex2JsonEventConverter implements ApexEventProtocolConverter {
jsonObject.addProperty(ApexEvent.NAMESPACE_HEADER_FIELD, apexEvent.getNameSpace());
jsonObject.addProperty(ApexEvent.SOURCE_HEADER_FIELD, apexEvent.getSource());
jsonObject.addProperty(ApexEvent.TARGET_HEADER_FIELD, apexEvent.getTarget());
+ jsonObject.addProperty(ApexEvent.TOSCA_POLICY_STATE_HEADER_FIELD, apexEvent.getToscaPolicyState());
if (apexEvent.getExceptionMessage() != null) {
jsonObject.addProperty(ApexEvent.EXCEPTION_MESSAGE_HEADER_FIELD, apexEvent.getExceptionMessage());
@@ -416,8 +417,9 @@ public class Apex2JsonEventConverter implements ApexEventProtocolConverter {
final String eventNamespace = getHeaderNamespace(jsonObject, eventName, eventDefinition);
final String eventSource = getHeaderSource(jsonObject, eventDefinition);
final String eventTarget = getHeaderTarget(jsonObject, eventDefinition);
+ final String eventStatus = getHeaderToscaPolicyState(jsonObject, eventDefinition);
- return new ApexEvent(eventName, eventVersion, eventNamespace, eventSource, eventTarget);
+ return new ApexEvent(eventName, eventVersion, eventNamespace, eventSource, eventTarget, eventStatus);
}
/**
@@ -521,6 +523,23 @@ public class Apex2JsonEventConverter implements ApexEventProtocolConverter {
}
/**
+ * Determine the status field of the event header.
+ *
+ * @param jsonObject the event in JSON format
+ * @param eventDefinition the definition of the event structure
+ * @return the event toscaPolicyState
+ */
+ private String getHeaderToscaPolicyState(final JsonObject jsonObject, final AxEvent eventDefinition) {
+ // For toscaPolicyState, use defined value from model only if value is not found on the incoming event
+ var toscaPolicyState = getJsonStringField(jsonObject, ApexEvent.TOSCA_POLICY_STATE_HEADER_FIELD,
+ jsonPars.getToscaPolicyStateAlias(), null, false);
+ if (toscaPolicyState == null) {
+ toscaPolicyState = eventDefinition.getToscaPolicyState();
+ }
+ return toscaPolicyState;
+ }
+
+ /**
* This method gets an event string field from a JSON object.
*
* @param jsonObject the JSON object containing the JSON representation of the incoming event
@@ -609,4 +628,4 @@ public class Apex2JsonEventConverter implements ApexEventProtocolConverter {
// check for the field
return jsonObject.has(fieldName);
}
-}
+} \ No newline at end of file
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/JsonEventProtocolParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/JsonEventProtocolParameters.java
index 51e9b6d40..397a56e78 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/JsonEventProtocolParameters.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/jsonprotocolplugin/JsonEventProtocolParameters.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,11 +62,12 @@ public class JsonEventProtocolParameters extends EventProtocolTextCharDelimitedP
// 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 nameAlias = null;
+ private String versionAlias = null;
+ private String nameSpaceAlias = null;
+ private String sourceAlias = null;
+ private String targetAlias = null;
+ private String toscaPolicyStateAlias = null;
// @formatter:on
// Flag indicating POJO decoding and encoding and parameter indicating the name of the Pojo field
@@ -104,4 +106,4 @@ public class JsonEventProtocolParameters extends EventProtocolTextCharDelimitedP
public String getName() {
return this.getLabel();
}
-}
+} \ No newline at end of file
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/ApexEventTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/ApexEventTest.java
index bb299a834..0f17bf193 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/ApexEventTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/ApexEventTest.java
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 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.
@@ -42,7 +43,7 @@ public class ApexEventTest {
@Before
public void setUp() throws Exception {
apexEvent =
- new ApexEvent("name", "version", "namespace", "source", "target");
+ new ApexEvent("name", "version", "namespace", "source", "target", "");
}
@@ -50,7 +51,7 @@ public class ApexEventTest {
public void invalidEventName() {
final String name = "++" + RandomStringUtils.randomAlphabetic(5);
Assertions.assertThatCode(() ->
- apexEvent = new ApexEvent(name, "version", "namespace", "source", "target"))
+ apexEvent = new ApexEvent(name, "version", "namespace", "source", "target", ""))
.isInstanceOf(ApexEventException.class);
}
@@ -58,7 +59,7 @@ public class ApexEventTest {
public void invalidEventVersion() {
final String version = "++" + RandomStringUtils.randomAlphabetic(5);
Assertions.assertThatCode(() ->
- apexEvent = new ApexEvent("name", version, "namespace", "source", "target"))
+ apexEvent = new ApexEvent("name", version, "namespace", "source", "target", ""))
.isInstanceOf(ApexEventException.class);
}
@@ -66,7 +67,7 @@ public class ApexEventTest {
public void invalidEventNamespace() {
final String namespace = "++" + RandomStringUtils.randomAlphabetic(5);
Assertions.assertThatCode(() ->
- apexEvent = new ApexEvent("name", "version", namespace, "source", "target"))
+ apexEvent = new ApexEvent("name", "version", namespace, "source", "target", ""))
.isInstanceOf(ApexEventException.class);
}
@@ -74,7 +75,7 @@ public class ApexEventTest {
public void invalidEventSource() {
final String source = "++" + RandomStringUtils.randomAlphabetic(5);
Assertions.assertThatCode(() ->
- apexEvent = new ApexEvent("name", "version", "namespace", source, "target"))
+ apexEvent = new ApexEvent("name", "version", "namespace", source, "target", ""))
.isInstanceOf(ApexEventException.class);
}
@@ -82,11 +83,19 @@ public class ApexEventTest {
public void invalidEventTarget() {
final String target = "++" + RandomStringUtils.randomAlphabetic(5);
Assertions.assertThatCode(() ->
- apexEvent = new ApexEvent("name", "version", "namespace", "source", target))
+ apexEvent = new ApexEvent("name", "version", "namespace", "source", target, ""))
.isInstanceOf(ApexEventException.class);
}
@Test
+ public void invalidEventStatus() {
+ final String toscaPolicyState = "INVALID_STATUS";
+ Assertions.assertThatCode(() ->
+ apexEvent = new ApexEvent("name", "version", "namespace", "source", "target", toscaPolicyState))
+ .isInstanceOf(ApexEventException.class);
+ }
+
+ @Test
public void setExecutionId() {
final int executionId = random.nextInt();
apexEvent.setExecutionId(executionId);
@@ -161,4 +170,4 @@ public class ApexEventTest {
assertThat(actual2).isNull();
assertThat(actual3).isNull();
}
-}
+} \ No newline at end of file
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java
index a7d08bb55..ed1e09b2a 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 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.
@@ -59,7 +60,7 @@ public class JsonEventConverterTest {
assertThatThrownBy(() -> converter.fromApexEvent(null))
.hasMessage("event processing failed, Apex event is null");
assertThatThrownBy(() -> converter.fromApexEvent(new ApexEvent("Event", "0.0.1", "a.name.space",
- "here", "there")))
+ "here", "there", "")))
.hasMessage("Model for org.onap.policy.apex.model.eventmodel.concepts.AxEvents not found in model service");
}
-}
+} \ No newline at end of file
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java
index fdb886e10..dd7acddaa 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 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.
@@ -38,6 +39,7 @@ import org.junit.Test;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.SchemaParameters;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.basicmodel.concepts.AxToscaPolicyProcessingStatus;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader;
import org.onap.policy.apex.model.basicmodel.service.ModelService;
@@ -250,7 +252,8 @@ public class JsonEventHandlerTest {
basicEventMap.put("intPar", 12345);
final ApexEvent basicEvent =
- new ApexEvent("BasicEvent", "0.0.1", "org.onap.policy.apex.events", "test", "apex");
+ new ApexEvent("BasicEvent", "0.0.1", "org.onap.policy.apex.events", "test", "apex",
+ AxToscaPolicyProcessingStatus.ENTRY.name());
basicEvent.putAll(basicEventMap);
final String apexEvent0000JsonString = (String) jsonEventConverter.fromApexEvent(basicEvent);
@@ -263,5 +266,6 @@ public class JsonEventHandlerTest {
assertTrue(apexEvent0000JsonString.contains("\"source\": \"test\""));
assertTrue(apexEvent0000JsonString.contains("\"target\": \"apex\""));
assertTrue(apexEvent0000JsonString.contains("\"intPar\": 12345"));
+ assertTrue(apexEvent0000JsonString.contains("\"toscaPolicyState\": \"ENTRY\""));
}
-}
+} \ No newline at end of file
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/Apex2ApexEventConverterTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/Apex2ApexEventConverterTest.java
index 04e87ee42..9a61f8739 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/Apex2ApexEventConverterTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/Apex2ApexEventConverterTest.java
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 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.
@@ -29,6 +30,7 @@ import java.util.List;
import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxToscaPolicyProcessingStatus;
import org.onap.policy.apex.service.engine.event.ApexEvent;
import org.onap.policy.apex.service.engine.event.ApexEventException;
import org.onap.policy.apex.service.engine.event.ApexEventList;
@@ -76,8 +78,9 @@ public class Apex2ApexEventConverterTest {
final String nameSpace = "a" + RandomStringUtils.randomAlphanumeric(7);
final String source = RandomStringUtils.randomAlphanumeric(8);
final String target = RandomStringUtils.randomAlphanumeric(9);
+ final String toscaPolicyState = AxToscaPolicyProcessingStatus.ENTRY.name();
- final ApexEvent event = new ApexEvent(name, version, nameSpace, source, target);
+ final ApexEvent event = new ApexEvent(name, version, nameSpace, source, target, toscaPolicyState);
final List<ApexEvent> result = converter.toApexEvent(eventName, event);
assertThat(result).isEmpty();
}
@@ -90,8 +93,9 @@ public class Apex2ApexEventConverterTest {
final String nameSpace1 = "a" + RandomStringUtils.randomAlphanumeric(7);
final String source1 = RandomStringUtils.randomAlphanumeric(8);
final String target1 = RandomStringUtils.randomAlphanumeric(9);
+ final String toscaPolicyState1 = AxToscaPolicyProcessingStatus.ENTRY.name();
- final ApexEvent event = new ApexEvent(name1, version1, nameSpace1, source1, target1);
+ final ApexEvent event = new ApexEvent(name1, version1, nameSpace1, source1, target1, toscaPolicyState1);
final String key = RandomStringUtils.randomAlphabetic(3);
event.put(key, new Object());
@@ -108,8 +112,9 @@ public class Apex2ApexEventConverterTest {
final String nameSpace1 = "a" + RandomStringUtils.randomAlphanumeric(7);
final String source1 = RandomStringUtils.randomAlphanumeric(8);
final String target1 = RandomStringUtils.randomAlphanumeric(9);
+ final String toscaPolicyState1 = AxToscaPolicyProcessingStatus.ENTRY.name();
- final ApexEvent event = new ApexEvent(name1, version1, nameSpace1, source1, target1);
+ final ApexEvent event = new ApexEvent(name1, version1, nameSpace1, source1, target1, toscaPolicyState1);
final ApexEventList eventList = new ApexEventList();
eventList.add(event);
@@ -119,8 +124,9 @@ public class Apex2ApexEventConverterTest {
final String nameSpace2 = "b" + RandomStringUtils.randomAlphanumeric(17);
final String source2 = RandomStringUtils.randomAlphanumeric(18);
final String target2 = RandomStringUtils.randomAlphanumeric(19);
+ final String toscaPolicyState2 = AxToscaPolicyProcessingStatus.EXIT_SUCCESS.name();
- final ApexEvent parentEvent = new ApexEvent(name2, version2, nameSpace2, source2, target2);
+ final ApexEvent parentEvent = new ApexEvent(name2, version2, nameSpace2, source2, target2, toscaPolicyState2);
final String key = RandomStringUtils.randomAlphabetic(3);
parentEvent.put(key, eventList);
final List<ApexEvent> result = converter.toApexEvent(eventName, parentEvent);
@@ -136,8 +142,9 @@ public class Apex2ApexEventConverterTest {
final String nameSpace1 = "a" + RandomStringUtils.randomAlphanumeric(7);
final String source1 = RandomStringUtils.randomAlphanumeric(8);
final String target1 = RandomStringUtils.randomAlphanumeric(9);
+ final String toscaPolicyState1 = AxToscaPolicyProcessingStatus.ENTRY.name();
- final ApexEvent event = new ApexEvent(name1, version1, nameSpace1, source1, target1);
+ final ApexEvent event = new ApexEvent(name1, version1, nameSpace1, source1, target1, toscaPolicyState1);
final ApexEventList eventList = new ApexEventList();
eventList.add(event);
@@ -147,8 +154,9 @@ public class Apex2ApexEventConverterTest {
final String nameSpace2 = "b" + RandomStringUtils.randomAlphanumeric(17);
final String source2 = RandomStringUtils.randomAlphanumeric(18);
final String target2 = RandomStringUtils.randomAlphanumeric(19);
+ final String toscaPolicyState2 = AxToscaPolicyProcessingStatus.EXIT_FAILURE.name();
- final ApexEvent parentEvent = new ApexEvent(name2, version2, nameSpace2, source2, target2);
+ final ApexEvent parentEvent = new ApexEvent(name2, version2, nameSpace2, source2, target2, toscaPolicyState2);
final String key1 = RandomStringUtils.randomAlphabetic(3);
final String key2 = RandomStringUtils.randomAlphabetic(2);
parentEvent.put(key1, eventList);
@@ -170,11 +178,12 @@ public class Apex2ApexEventConverterTest {
final String nameSpace1 = "a" + RandomStringUtils.randomAlphanumeric(7);
final String source1 = RandomStringUtils.randomAlphanumeric(8);
final String target1 = RandomStringUtils.randomAlphanumeric(9);
+ final String toscaPolicyState1 = AxToscaPolicyProcessingStatus.ENTRY.name();
- final ApexEvent event = new ApexEvent(name1, version1, nameSpace1, source1, target1);
+ final ApexEvent event = new ApexEvent(name1, version1, nameSpace1, source1, target1, toscaPolicyState1);
final Object actual = converter.fromApexEvent(event);
assertSame(event, actual);
}
-}
+} \ No newline at end of file
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverterTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverterTest.java
index 562760f69..4d36b7be4 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverterTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverterTest.java
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 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.
@@ -29,6 +30,7 @@ import org.junit.Before;
import org.junit.Test;
import org.onap.policy.apex.core.engine.event.EnEvent;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.basicmodel.concepts.AxToscaPolicyProcessingStatus;
import org.onap.policy.apex.model.eventmodel.concepts.AxEvent;
import org.onap.policy.apex.service.engine.event.ApexEvent;
import org.onap.policy.apex.service.engine.event.ApexEventException;
@@ -58,8 +60,9 @@ public class ApexEvent2EnEventConverterTest {
final String nameSpace = "a" + RandomStringUtils.randomAlphanumeric(7);
final String source = RandomStringUtils.randomAlphanumeric(8);
final String target = RandomStringUtils.randomAlphanumeric(9);
+ final String toscaPolicyState = AxToscaPolicyProcessingStatus.ENTRY.name();
- final ApexEvent event = new ApexEvent(name, version, nameSpace, source, target);
+ final ApexEvent event = new ApexEvent(name, version, nameSpace, source, target, toscaPolicyState);
assertThatThrownBy(() -> converter.toApexEvent(eventName, event))
.isInstanceOf(ApexEventRuntimeException.class);
@@ -73,6 +76,7 @@ public class ApexEvent2EnEventConverterTest {
final String nameSpace = "b" + RandomStringUtils.randomAlphabetic(7);
final String source = RandomStringUtils.randomAlphabetic(8);
final String target = RandomStringUtils.randomAlphabetic(9);
+ final String toscaPolicyState = AxToscaPolicyProcessingStatus.ENTRY.name();
final int executionId = random.nextInt(1000);
final String exceptionMessage = RandomStringUtils.randomAlphabetic(11);
@@ -83,12 +87,13 @@ public class ApexEvent2EnEventConverterTest {
axEvent.setNameSpace(nameSpace);
axEvent.setSource(source);
axEvent.setTarget(target);
+ axEvent.setToscaPolicyState(toscaPolicyState);
final EnEvent enEvent = new EnEvent(axEvent);
enEvent.setExecutionId(executionId);
enEvent.setExceptionMessage(exceptionMessage);
// prepare expected event
- final ApexEvent apexEvent = new ApexEvent(name, version, nameSpace, source, target);
+ final ApexEvent apexEvent = new ApexEvent(name, version, nameSpace, source, target, toscaPolicyState);
apexEvent.setExecutionId(executionId);
apexEvent.setExceptionMessage(exceptionMessage);
final Object[] expected = {apexEvent};
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.java
index ed1afe4da..0095c9630 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020-2021 Nordix Foundation.
- * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2020-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");
@@ -239,7 +239,7 @@ public class EngineServiceImplTest {
esImpl.stop();
esImpl.sendEvent(null);
- esImpl.sendEvent(new ApexEvent("SomeEvent", "0.0.1", "the.event.namespace", "EventSource", "EventTarget"));
+ esImpl.sendEvent(new ApexEvent("SomeEvent", "0.0.1", "the.event.namespace", "EventSource", "EventTarget", ""));
esImpl.startPeriodicEvents(100000);
@@ -381,7 +381,8 @@ public class EngineServiceImplTest {
}
try {
- esImpl.sendEvent(new ApexEvent("SomeEvent", "0.0.1", "the.event.namespace", "EventSource", "EventTarget"));
+ esImpl.sendEvent(new ApexEvent("SomeEvent", "0.0.1", "the.event.namespace", "EventSource", "EventTarget",
+ ""));
} catch (ApexException apEx) {
fail("test should not throw an exception");
}
@@ -420,4 +421,4 @@ public class EngineServiceImplTest {
fail("test should not throw an exception");
}
}
-}
+} \ No newline at end of file
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java
index 504e8df14..c95b465cf 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 Nordix Foundation.
- * Modifications Copyright (C) 2021 Bell Canada Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021-2022 Bell Canada Intellectual Property. 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.
@@ -348,7 +348,7 @@ public class EngineWorkerTest {
fail("test should not throw an exception");
}
- eventQueue.add(new ApexEvent("SomeEvent", "0.0.1", "the.event.namespace", "EventSource", "EventTarget"));
+ eventQueue.add(new ApexEvent("SomeEvent", "0.0.1", "the.event.namespace", "EventSource", "EventTarget", ""));
try {
worker.updateModel(worker.getKey(), differentModelString, false);