summaryrefslogtreecommitdiffstats
path: root/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2019-06-26 15:40:41 +0000
committerliamfallon <liam.fallon@est.tech>2019-06-26 15:40:41 +0000
commitce9d82d2c0e863597d84cc8909955e398405f45a (patch)
tree8ebb853119bdf673cf6f9516d428d4cc00080aeb /plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient
parent5f029543f1e673655af2d2974113069df0b6def0 (diff)
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 <liam.fallon@est.tech>
Diffstat (limited to 'plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient')
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumer.java4
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducer.java37
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java16
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/SupportApexEventReceiver.java23
4 files changed, 45 insertions, 35 deletions
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumer.java
index ddd000dd9..39389c297 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumer.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumer.java
@@ -223,7 +223,7 @@ public class ApexRestClientConsumer implements ApexEventConsumer, Runnable {
}
// Send the event into Apex
- eventReceiver.receiveEvent(eventJsonString);
+ eventReceiver.receiveEvent(null, eventJsonString);
} catch (final Exception e) {
LOGGER.warn("error receiving events on thread {}", consumerThread.getName(), e);
}
@@ -232,7 +232,7 @@ public class ApexRestClientConsumer implements ApexEventConsumer, Runnable {
/**
* Hook for unit test mocking of HTTP client.
- *
+ *
* @param client the mocked client
*/
protected void setClient(final Client client) {
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducer.java
index 4113cea4b..275f5a8c2 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducer.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/main/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducer.java
@@ -22,6 +22,7 @@ package org.onap.policy.apex.plugins.event.carrier.restclient;
import java.util.EnumMap;
import java.util.Map;
+import java.util.Properties;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
@@ -67,18 +68,18 @@ public class ApexRestClientProducer implements ApexEventProducer {
*/
@Override
public void init(final String producerName, final EventHandlerParameters producerParameters)
- throws ApexEventException {
+ throws ApexEventException {
this.name = producerName;
// Check and get the REST Properties
if (!(producerParameters.getCarrierTechnologyParameters() instanceof RestClientCarrierTechnologyParameters)) {
- final String errorMessage = "specified producer properties are not applicable to REST client producer ("
- + this.name + ")";
+ final String errorMessage =
+ "specified producer properties are not applicable to REST client producer (" + this.name + ")";
LOGGER.warn(errorMessage);
throw new ApexEventException(errorMessage);
}
- restProducerProperties = (RestClientCarrierTechnologyParameters) producerParameters
- .getCarrierTechnologyParameters();
+ restProducerProperties =
+ (RestClientCarrierTechnologyParameters) producerParameters.getCarrierTechnologyParameters();
// Check if the HTTP method has been set
if (restProducerProperties.getHttpMethod() == null) {
@@ -86,10 +87,11 @@ public class ApexRestClientProducer implements ApexEventProducer {
}
if (!RestClientCarrierTechnologyParameters.HttpMethod.POST.equals(restProducerProperties.getHttpMethod())
- && !RestClientCarrierTechnologyParameters.HttpMethod.PUT.equals(restProducerProperties.getHttpMethod())) {
+ && !RestClientCarrierTechnologyParameters.HttpMethod.PUT
+ .equals(restProducerProperties.getHttpMethod())) {
final String errorMessage = "specified HTTP method of \"" + restProducerProperties.getHttpMethod()
- + "\" is invalid, only HTTP methods \"POST\" and \"PUT\" are supproted "
- + "for event sending on REST client producer (" + this.name + ")";
+ + "\" is invalid, only HTTP methods \"POST\" and \"PUT\" are supproted "
+ + "for event sending on REST client producer (" + this.name + ")";
LOGGER.warn(errorMessage);
throw new ApexEventException(errorMessage);
}
@@ -137,10 +139,11 @@ public class ApexRestClientProducer implements ApexEventProducer {
* 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);
}
@@ -151,15 +154,15 @@ public class ApexRestClientProducer implements ApexEventProducer {
// Check that the request worked
if (response.getStatus() != Response.Status.OK.getStatusCode()) {
final String errorMessage = "send of event to URL \"" + restProducerProperties.getUrl() + "\" using HTTP \""
- + restProducerProperties.getHttpMethod() + "\" failed with status code " + response.getStatus()
- + " and message \"" + response.readEntity(String.class) + "\", event:\n" + event;
+ + restProducerProperties.getHttpMethod() + "\" failed with status code " + response.getStatus()
+ + " and message \"" + response.readEntity(String.class) + "\", event:\n" + event;
LOGGER.warn(errorMessage);
throw new ApexEventRuntimeException(errorMessage);
}
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("event sent from engine using {} to URL {} with HTTP {} : {} and response {} ", this.name,
- restProducerProperties.getUrl(), restProducerProperties.getHttpMethod(), event, response);
+ restProducerProperties.getUrl(), restProducerProperties.getHttpMethod(), event, response);
}
}
@@ -184,16 +187,16 @@ public class ApexRestClientProducer implements ApexEventProducer {
// We have already checked that it is a PUT or POST request
if (RestClientCarrierTechnologyParameters.HttpMethod.POST.equals(restProducerProperties.getHttpMethod())) {
return client.target(restProducerProperties.getUrl()).request("application/json")
- .headers(restProducerProperties.getHttpHeadersAsMultivaluedMap()).post(Entity.json(event));
+ .headers(restProducerProperties.getHttpHeadersAsMultivaluedMap()).post(Entity.json(event));
} else {
return client.target(restProducerProperties.getUrl()).request("application/json")
- .headers(restProducerProperties.getHttpHeadersAsMultivaluedMap()).put(Entity.json(event));
+ .headers(restProducerProperties.getHttpHeadersAsMultivaluedMap()).put(Entity.json(event));
}
}
/**
* Hook for unit test mocking of HTTP client.
- *
+ *
* @param client the mocked client
*/
protected void setClient(final Client client) {
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java
index 8f0e0940b..8ef0ec95c 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java
@@ -5,15 +5,15 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -166,7 +166,7 @@ public class ApexRestClientProducerTest {
arcp.setClient(httpClientMock);
try {
- arcp.sendEvent(123, "EventName", "This is an Event");
+ arcp.sendEvent(123, null, "EventName", "This is an Event");
arcp.stop();
} catch (Exception ex) {
fail("test should not throw an exception");
@@ -203,7 +203,7 @@ public class ApexRestClientProducerTest {
arcp.setClient(httpClientMock);
try {
- arcp.sendEvent(123, "EventName", "This is an Event");
+ arcp.sendEvent(123, null, "EventName", "This is an Event");
arcp.stop();
} catch (Exception e) {
fail("test should not throw an exception");
@@ -246,7 +246,7 @@ public class ApexRestClientProducerTest {
arcp.setClient(httpClientMock);
try {
- arcp.sendEvent(123, "EventName", "This is an Event");
+ arcp.sendEvent(123, null, "EventName", "This is an Event");
arcp.stop();
} catch (Exception e) {
fail("test should not throw an exception");
@@ -292,7 +292,7 @@ public class ApexRestClientProducerTest {
arcp.setClient(httpClientMock);
try {
- arcp.sendEvent(123, "EventName", "This is an Event");
+ arcp.sendEvent(123, null, "EventName", "This is an Event");
arcp.stop();
} catch (Exception e) {
fail("test should not throw an exception");
@@ -329,7 +329,7 @@ public class ApexRestClientProducerTest {
arcp.setClient(httpClientMock);
try {
- arcp.sendEvent(123, "EventName", "This is an Event");
+ arcp.sendEvent(123, null, "EventName", "This is an Event");
fail("test should throw an exception here");
} catch (Exception e) {
assertEquals(
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/SupportApexEventReceiver.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/SupportApexEventReceiver.java
index d3f8b9e82..5459310fa 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/SupportApexEventReceiver.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/SupportApexEventReceiver.java
@@ -5,21 +5,23 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.apex.plugins.event.carrier.restclient;
+import java.util.Properties;
+
import org.onap.policy.apex.service.engine.event.ApexEventException;
import org.onap.policy.apex.service.engine.event.ApexEventReceiver;
@@ -32,21 +34,26 @@ public class SupportApexEventReceiver implements ApexEventReceiver {
private Object lastEvent;
private int eventCount;
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.onap.policy.apex.service.engine.event.ApexEventReceiver#receiveEvent(long, java.lang.Object)
*/
@Override
- public void receiveEvent(long executionId, Object event) throws ApexEventException {
+ public void receiveEvent(final long executionId, final Properties executionProperties, final Object event)
+ throws ApexEventException {
this.lastExecutionId = executionId;
this.lastEvent = event;
this.eventCount++;
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.onap.policy.apex.service.engine.event.ApexEventReceiver#receiveEvent(java.lang.Object)
*/
@Override
- public void receiveEvent(Object event) throws ApexEventException {
+ public void receiveEvent(final Properties executionProperties, final Object event) throws ApexEventException {
this.lastEvent = event;
this.eventCount++;
}
@@ -61,7 +68,7 @@ public class SupportApexEventReceiver implements ApexEventReceiver {
/**
* Get the number of events received.
- *
+ *
* @return the number of events received
*/
public int getEventCount() {