From ce9d82d2c0e863597d84cc8909955e398405f45a Mon Sep 17 00:00:00 2001 From: liamfallon Date: Wed, 26 Jun 2019 15:40:41 +0000 Subject: Add passthrough properties for APEX engine APEX event receiver and sender plugins sometimes need to exchange information with tasks, especially in the case of REST communication. This change enables passthrough of Properties from the event carrier technology plugins to APEX task, task selection, and state finalizer logics. Apologies for the size of the review but this change involves passinng the properties through all the APEX components, hence the large number of small changes. Issue-ID: POLICY-1742 Change-Id: I219fd69550f06702ef64adbb165fe7baac422e96 Signed-off-by: liamfallon --- .../carrier/websocket/ApexWebSocketConsumer.java | 4 ++-- .../carrier/websocket/ApexWebSocketProducer.java | 20 +++++++++++--------- .../carrier/websocket/ApexWebSocketProducerTest.java | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) (limited to 'plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket') diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketConsumer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketConsumer.java index 17955c3be..f6ed6895d 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketConsumer.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketConsumer.java @@ -80,7 +80,7 @@ public class ApexWebSocketConsumer implements ApexEventConsumer, WsStringMessage LOGGER.warn("specified consumer properties are not applicable to a web socket consumer"); throw new ApexEventException("specified consumer properties are not applicable to a web socket consumer"); } - + // The Web Socket properties WebSocketCarrierTechnologyParameters webSocketConsumerProperties = (WebSocketCarrierTechnologyParameters) consumerParameters.getCarrierTechnologyParameters(); @@ -183,7 +183,7 @@ public class ApexWebSocketConsumer implements ApexEventConsumer, WsStringMessage @Override public void receiveString(final String eventString) { try { - eventReceiver.receiveEvent(eventString); + eventReceiver.receiveEvent(null, eventString); eventsRead++; } catch (final Exception e) { final String errorMessage = "Error sending event " + name + '_' + eventsRead + ", " + e.getMessage() diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketProducer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketProducer.java index 6f04024b4..07b6d42e6 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketProducer.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/main/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketProducer.java @@ -22,6 +22,7 @@ package org.onap.policy.apex.plugins.event.carrier.websocket; import java.util.EnumMap; import java.util.Map; +import java.util.Properties; import org.onap.policy.apex.core.infrastructure.messaging.MessagingException; import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageClient; @@ -57,25 +58,25 @@ public class ApexWebSocketProducer implements ApexEventProducer, WsStringMessage @Override public void init(final String producerName, final EventHandlerParameters producerParameters) - throws ApexEventException { + throws ApexEventException { this.name = producerName; // Check and get the web socket Properties if (!(producerParameters.getCarrierTechnologyParameters() instanceof WebSocketCarrierTechnologyParameters)) { - String message = "specified producer properties for " + this.name - + "are not applicable to a web socket producer"; + String message = + "specified producer properties for " + this.name + "are not applicable to a web socket producer"; LOGGER.warn(message); throw new ApexEventException("specified producer properties are not applicable to a web socket producer"); } // The Web Socket properties WebSocketCarrierTechnologyParameters webSocketProducerProperties = - (WebSocketCarrierTechnologyParameters) producerParameters.getCarrierTechnologyParameters(); + (WebSocketCarrierTechnologyParameters) producerParameters.getCarrierTechnologyParameters(); // Check if this is a server or a client Web Socket if (webSocketProducerProperties.isWsClient()) { // Create a WS client wsStringMessager = new WsStringMessageClient(webSocketProducerProperties.getHost(), - webSocketProducerProperties.getPort()); + webSocketProducerProperties.getPort()); } else { wsStringMessager = new WsStringMessageServer(webSocketProducerProperties.getPort()); } @@ -128,10 +129,11 @@ public class ApexWebSocketProducer implements ApexEventProducer, WsStringMessage * java.lang.Object) */ @Override - public void sendEvent(final long executionId, final String eventName, final Object event) { + public void sendEvent(final long executionId, final Properties executionProperties, final String eventName, + final Object event) { // Check if this is a synchronized event, if so we have received a reply - final SynchronousEventCache synchronousEventCache = (SynchronousEventCache) peerReferenceMap - .get(EventHandlerPeeredMode.SYNCHRONOUS); + final SynchronousEventCache synchronousEventCache = + (SynchronousEventCache) peerReferenceMap.get(EventHandlerPeeredMode.SYNCHRONOUS); if (synchronousEventCache != null) { synchronousEventCache.removeCachedEventToApexIfExists(executionId); } @@ -161,7 +163,7 @@ public class ApexWebSocketProducer implements ApexEventProducer, WsStringMessage @Override public void receiveString(final String messageString) { String message = "received message \"" + messageString + "\" on web socket producer (" + this.name - + ") , no messages should be received on a web socket producer"; + + ") , no messages should be received on a web socket producer"; LOGGER.warn(message); } } diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketProducerTest.java index b97f42ffb..d4b3114d5 100644 --- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketProducerTest.java +++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-websocket/src/test/java/org/onap/policy/apex/plugins/event/carrier/websocket/ApexWebSocketProducerTest.java @@ -107,7 +107,7 @@ public class ApexWebSocketProducerTest { apexWebSocketConsumer, apexWebSocketProducer, DEFAULT_SYNCHRONOUS_EVENT_TIMEOUT); apexWebSocketProducer.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, synchronousEventCache); - apexWebSocketProducer.sendEvent(1000L, "TestApexWebSocketProducer", "apexEvent"); + apexWebSocketProducer.sendEvent(1000L, null, "TestApexWebSocketProducer", "apexEvent"); } @Test -- cgit 1.2.3-korg