summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
Diffstat (limited to 'services')
-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;
}
/**