summaryrefslogtreecommitdiffstats
path: root/services/services-engine/src/main
diff options
context:
space:
mode:
authora.sreekumar <ajith.sreekumar@bell.ca>2020-09-28 12:45:22 +0100
committera.sreekumar <ajith.sreekumar@bell.ca>2020-09-28 16:52:34 +0100
commite0d41e83dc9b5af7e0454e0133c8ddbb332f0c79 (patch)
tree0af0a707dc5e3fc774416482d657617306478e55 /services/services-engine/src/main
parent672ee6e4b2ca54d7872b2af556f3cf785a2ab10b (diff)
Fixing APEX eventName handling to avoid duplicate requests
Change-Id: I6ee50fb455424ae1f241b7a12d1cdbf0e6ee4011 Issue-ID: POLICY-2815 Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
Diffstat (limited to 'services/services-engine/src/main')
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java74
1 files changed, 48 insertions, 26 deletions
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java
index 8c2aee1f6..dc9854158 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexEventUnmarshaller.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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,6 +22,9 @@
package org.onap.policy.apex.service.engine.main;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.BlockingQueue;
@@ -214,40 +218,58 @@ public class ApexEventUnmarshaller implements ApexEventReceiver, Runnable {
}
// Convert the incoming events to Apex events
- try {
- final List<ApexEvent> apexEventList = converter.toApexEvent(consumerParameters.getEventName(), event);
+ List<ApexEvent> apexEventList = convertToApexEvents(event);
- for (final ApexEvent apexEvent : apexEventList) {
- isEventFilteredOut(apexEvent);
+ for (final ApexEvent apexEvent : apexEventList) {
+ // Check if this event is filtered out by the incoming filter
+ if (isEventFilteredOut(apexEvent)) {
+ // Ignore this event
+ continue;
+ }
- // Check if this event is filtered out by the incoming filter
- if (isEventFilteredOut(apexEvent)) {
- // Ignore this event
- continue;
- }
+ if (!generateExecutionId) {
+ apexEvent.setExecutionId(executionId);
+ }
- if (!generateExecutionId) {
- apexEvent.setExecutionId(executionId);
- }
+ apexEvent.setExecutionProperties(executionProperties);
- apexEvent.setExecutionProperties(executionProperties);
+ // Cache synchronized events that are sent
+ if (consumerParameters.isPeeredMode(EventHandlerPeeredMode.SYNCHRONOUS)) {
+ final SynchronousEventCache synchronousEventCache =
+ (SynchronousEventCache) consumer.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS);
+ synchronousEventCache.cacheSynchronizedEventToApex(apexEvent.getExecutionId(), apexEvent);
+ }
- // Cache synchronized events that are sent
- if (consumerParameters.isPeeredMode(EventHandlerPeeredMode.SYNCHRONOUS)) {
- final SynchronousEventCache synchronousEventCache =
- (SynchronousEventCache) consumer.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS);
- synchronousEventCache.cacheSynchronizedEventToApex(apexEvent.getExecutionId(), apexEvent);
- }
+ // Enqueue the event
+ queue.add(apexEvent);
+ }
+ }
- // Enqueue the event
- queue.add(apexEvent);
+ private List<ApexEvent> convertToApexEvents(final Object event) throws ApexEventException {
+ List<ApexEvent> apexEventList = null;
+ List<String> eventNamesList = null;
+ if (consumerParameters.getEventName() != null) {
+ eventNamesList = Arrays.asList(consumerParameters.getEventName().split("\\|"));
+ } else {
+ eventNamesList = Collections.singletonList(null);
+ }
+ Iterator<String> iterator = eventNamesList.iterator();
+ // Incoming events in an endpoint can have different structure , for e.g., success/failure response events
+ // Parse the incoming event into an APEX event defined with any one of the names specified in eventName field
+ while (iterator.hasNext()) {
+ try {
+ String eventName = iterator.next();
+ apexEventList = converter.toApexEvent(eventName, event);
+ break;
+ } catch (ApexException e) {
+ if (!iterator.hasNext()) {
+ final String errorMessage = "Error while converting event into an ApexEvent for " + name + ": "
+ + e.getMessage() + ", Event=" + event;
+ throw new ApexEventException(errorMessage, e);
+ }
}
- } catch (final ApexException e) {
- final String errorMessage = "Error while converting event into an ApexEvent for " + name + ": "
- + e.getMessage() + ", Event=" + event;
- LOGGER.warn(errorMessage, e);
- throw new ApexEventException(errorMessage, e);
}
+ return apexEventList;
}
/**