summaryrefslogtreecommitdiffstats
path: root/plugins/plugins-event
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/plugins-event')
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/pom.xml76
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/main/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcConsumer.java72
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/main/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcProducer.java152
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/main/java/org/onap/policy/apex/plugins/event/carrier/grpc/GrpcCarrierTechnologyParameters.java90
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/main/java/org/onap/policy/apex/plugins/event/carrier/grpc/package-info.java21
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcConsumerTest.java93
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcProducerTest.java98
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/GrpcCarrierTechnologyParametersTest.java87
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/resources/executionServiceInputEvent.json25
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumer.java4
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducer.java8
-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.java7
-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.java27
-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.java41
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducer.java9
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/policymodels/RequestorModel.json2
-rw-r--r--plugins/plugins-event/plugins-event-carrier/pom.xml5
17 files changed, 760 insertions, 57 deletions
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/pom.xml b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/pom.xml
new file mode 100644
index 000000000..443f8f173
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/pom.xml
@@ -0,0 +1,76 @@
+<?xml version="1.0"?>
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 2020 Nordix Foundation.
+ ================================================================================
+ 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=========================================================
+-->
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-carrier</groupId>
+ <artifactId>plugins-event-carrier</artifactId>
+ <version>2.3.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>plugins-event-carrier-grpc</artifactId>
+ <name>${project.artifactId}</name>
+ <description>[${project.parent.artifactId}] Plugin for handling GRPC requests and responses</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
+ <artifactId>cds</artifactId>
+ <version>${version.policy.models}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.policy.models.policy-models-interactions.model-actors</groupId>
+ <artifactId>actor.cds</artifactId>
+ <version>${version.policy.models}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <profiles>
+ <profile>
+ <id>apexSite</id>
+ <activation>
+ <property>
+ <name>apexSite</name>
+ </property>
+ </activation>
+ <properties>
+ <adsite-plugins-event-carrier-grpc-dir>${project.basedir}/src</adsite-plugins-event-carrier-grpc-dir>
+ </properties>
+ <distributionManagement>
+ <site>
+ <id>${project.artifactId}-site</id>
+ <url>${apex.adsite.prefix}/modules/plugins/plugins-event/${project.parent.artifactId}/${project.artifactId}/</url>
+ </site>
+ </distributionManagement>
+ </profile>
+ </profiles>
+</project>
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/main/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcConsumer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/main/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcConsumer.java
new file mode 100644
index 000000000..7333c8a05
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/main/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcConsumer.java
@@ -0,0 +1,72 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.grpc;
+
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.engine.event.ApexEventReceiver;
+import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
+import org.onap.policy.apex.service.engine.event.ApexPluginsEventConsumer;
+import org.onap.policy.apex.service.engine.event.PeeredReference;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
+
+/**
+ * This class implements an Apex gRPC consumer. It is not expected to receive events using gRPC.
+ * So, initializing a gRPC consumer will result in error.
+ *
+ * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
+ */
+public class ApexGrpcConsumer extends ApexPluginsEventConsumer {
+
+ private static final String GRPC_CONSUMER_ERROR_MSG =
+ "A gRPC Consumer may not be specified. Only sending events is possible using gRPC";
+
+ @Override
+ public void init(final String consumerName, final EventHandlerParameters consumerParameters,
+ final ApexEventReceiver incomingEventReceiver) throws ApexEventException {
+ throw new ApexEventException(GRPC_CONSUMER_ERROR_MSG);
+ }
+
+ @Override
+ public void run() {
+ throw new ApexEventRuntimeException(GRPC_CONSUMER_ERROR_MSG);
+ }
+
+ @Override
+ public void start() {
+ throw new ApexEventRuntimeException(GRPC_CONSUMER_ERROR_MSG);
+ }
+
+ @Override
+ public void stop() {
+ throw new ApexEventRuntimeException(GRPC_CONSUMER_ERROR_MSG);
+ }
+
+ @Override
+ public PeeredReference getPeeredReference(EventHandlerPeeredMode peeredMode) {
+ throw new ApexEventRuntimeException(GRPC_CONSUMER_ERROR_MSG);
+ }
+
+ @Override
+ public void setPeeredReference(EventHandlerPeeredMode peeredMode, PeeredReference peeredReference) {
+ throw new ApexEventRuntimeException(GRPC_CONSUMER_ERROR_MSG);
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/main/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcProducer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/main/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcProducer.java
new file mode 100644
index 000000000..380ae1274
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/main/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcProducer.java
@@ -0,0 +1,152 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.grpc;
+
+import com.google.protobuf.InvalidProtocolBufferException;
+import com.google.protobuf.util.JsonFormat;
+import java.util.Properties;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType;
+import org.onap.ccsdk.cds.controllerblueprints.common.api.Status;
+import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput;
+import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput.Builder;
+import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput;
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
+import org.onap.policy.apex.service.engine.event.ApexPluginsEventProducer;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
+import org.onap.policy.cds.api.CdsProcessorListener;
+import org.onap.policy.cds.client.CdsProcessorGrpcClient;
+import org.onap.policy.cds.properties.CdsServerProperties;
+import org.onap.policy.controlloop.actor.cds.constants.CdsActorConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Concrete implementation of an Apex gRPC plugin that manages to send a GRPC request.
+ *
+ * @author Ajith Sreekumar(ajith.sreekumar@est.tech)
+ *
+ */
+public class ApexGrpcProducer extends ApexPluginsEventProducer implements CdsProcessorListener {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ApexGrpcProducer.class);
+
+ private CdsServerProperties props;
+ // The gRPC client
+ private CdsProcessorGrpcClient client;
+
+ private AtomicReference<ExecutionServiceOutput> cdsResponse = new AtomicReference<>();
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public void init(final String producerName, final EventHandlerParameters producerParameters)
+ throws ApexEventException {
+ this.name = producerName;
+
+ // Check and get the gRPC Properties
+ if (!(producerParameters.getCarrierTechnologyParameters() instanceof GrpcCarrierTechnologyParameters)) {
+ final String errorMessage =
+ "Specified producer properties are not applicable to gRPC producer (" + this.name + ")";
+ throw new ApexEventException(errorMessage);
+ }
+ GrpcCarrierTechnologyParameters grpcProducerProperties =
+ (GrpcCarrierTechnologyParameters) producerParameters.getCarrierTechnologyParameters();
+
+ client = makeGrpcClient(grpcProducerProperties);
+ }
+
+ private CdsProcessorGrpcClient makeGrpcClient(GrpcCarrierTechnologyParameters grpcProducerProperties) {
+ props = new CdsServerProperties();
+ props.setHost(grpcProducerProperties.getHost());
+ props.setPort(grpcProducerProperties.getPort());
+ props.setUsername(grpcProducerProperties.getUsername());
+ props.setPassword(grpcProducerProperties.getPassword());
+ props.setTimeout(grpcProducerProperties.getTimeout());
+
+ return new CdsProcessorGrpcClient(this, props);
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public void sendEvent(final long executionId, final Properties executionProperties, final String eventName,
+ final Object event) {
+
+ ExecutionServiceInput executionServiceInput;
+ Builder builder = ExecutionServiceInput.newBuilder();
+ try {
+ JsonFormat.parser().ignoringUnknownFields().merge((String) event, builder);
+ executionServiceInput = builder.build();
+ } catch (InvalidProtocolBufferException e) {
+ throw new ApexEventRuntimeException(
+ "Incoming Event cannot be converted to ExecutionServiceInput type for gRPC request." + e.getMessage());
+ }
+ try {
+ CountDownLatch countDownLatch = client.sendRequest(executionServiceInput);
+ if (!countDownLatch.await(props.getTimeout(), TimeUnit.SECONDS)) {
+ cdsResponse.set(ExecutionServiceOutput.newBuilder().setStatus(Status.newBuilder()
+ .setErrorMessage(CdsActorConstants.TIMED_OUT).setEventType(EventType.EVENT_COMPONENT_FAILURE))
+ .build());
+ LOGGER.error("gRPC Request timed out.");
+ }
+ } catch (InterruptedException e) {
+ LOGGER.error("gRPC request failed. {}", e.getMessage());
+ cdsResponse.set(ExecutionServiceOutput.newBuilder().setStatus(Status.newBuilder()
+ .setErrorMessage(CdsActorConstants.INTERRUPTED).setEventType(EventType.EVENT_COMPONENT_FAILURE))
+ .build());
+ Thread.currentThread().interrupt();
+ }
+
+ if (!EventType.EVENT_COMPONENT_EXECUTED.equals(cdsResponse.get().getStatus().getEventType())) {
+ String errorMessage = "Sending event \"" + eventName + "\" by " + this.name + " to CDS failed, "
+ + "response from CDS:\n" + cdsResponse.get();
+ throw new ApexEventRuntimeException(errorMessage);
+ }
+ }
+
+ /**
+ * {@inheritDoc}.
+ */
+ @Override
+ public void stop() {
+ client.close();
+ }
+
+ @Override
+ public void onMessage(ExecutionServiceOutput message) {
+ LOGGER.info("Received notification from CDS: {}", message);
+ cdsResponse.set(message);
+ }
+
+ @Override
+ public void onError(Throwable throwable) {
+ String errorMsg = throwable.getLocalizedMessage();
+ cdsResponse.set(ExecutionServiceOutput.newBuilder()
+ .setStatus(Status.newBuilder().setErrorMessage(errorMsg).setEventType(EventType.EVENT_COMPONENT_FAILURE))
+ .build());
+ LOGGER.error("Failed processing blueprint {} {}", errorMsg, throwable);
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/main/java/org/onap/policy/apex/plugins/event/carrier/grpc/GrpcCarrierTechnologyParameters.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/main/java/org/onap/policy/apex/plugins/event/carrier/grpc/GrpcCarrierTechnologyParameters.java
new file mode 100644
index 000000000..59db16743
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/main/java/org/onap/policy/apex/plugins/event/carrier/grpc/GrpcCarrierTechnologyParameters.java
@@ -0,0 +1,90 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.grpc;
+
+import lombok.Getter;
+import lombok.Setter;
+import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
+import org.onap.policy.common.parameters.annotations.Max;
+import org.onap.policy.common.parameters.annotations.Min;
+import org.onap.policy.common.parameters.annotations.NotNull;
+
+// @formatter:off
+/**
+ * Apex parameters for gRPC as an event carrier technology.
+ *
+ * <p>The parameters for this plugin are:
+ * <ol>
+ * <li>host: The host on which CDS is running. This parameter is mandatory
+ * <li>port: The port on the CDS host to connect to for CDS. This parameter is mandatory.
+ * <li>username: The username for basic authentication to connect to CDS. This parameter is mandatory.
+ * <li>password: The password for basic authentication to connect to CDS. This parameter is mandatory.
+ * <li>timeout: The timeout in seconds for CDS requests. This parameter is mandatory.
+ * </ol>
+ *
+ * @author Ajith Sreekumar(ajith.sreekumar@est.tech)
+ */
+//@formatter:on
+@Getter
+@Setter
+public class GrpcCarrierTechnologyParameters extends CarrierTechnologyParameters {
+ // @formatter:off
+ private static final int MIN_USER_PORT = 1024;
+ private static final int MAX_USER_PORT = 65535;
+
+ /** The label of this carrier technology. */
+ public static final String GRPC_CARRIER_TECHNOLOGY_LABEL = "GRPC";
+
+ /** The producer plugin class for the grpc carrier technology. */
+ public static final String GRPC_EVENT_PRODUCER_PLUGIN_CLASS = ApexGrpcProducer.class.getName();
+
+ /** The consumer plugin class for the gRPC carrier technology. */
+ public static final String GRPC_EVENT_CONSUMER_PLUGIN_CLASS = ApexGrpcConsumer.class.getName();
+
+ @Min(value = 1)
+ private int timeout;
+
+ @Min(value = MIN_USER_PORT)
+ @Max(value = MAX_USER_PORT)
+ private int port;
+
+ @NotNull
+ private String host;
+
+ @NotNull
+ private String username;
+
+ @NotNull
+ private String password;
+
+
+ /**
+ * Constructor to create a gRPC carrier technology parameters instance and register the instance with the
+ * parameter service.
+ */
+ public GrpcCarrierTechnologyParameters() {
+ super();
+ // Set the carrier technology properties for the gRPC carrier technology
+ this.setLabel(GRPC_CARRIER_TECHNOLOGY_LABEL);
+ this.setEventProducerPluginClass(GRPC_EVENT_PRODUCER_PLUGIN_CLASS);
+ this.setEventConsumerPluginClass(GRPC_EVENT_CONSUMER_PLUGIN_CLASS);
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/main/java/org/onap/policy/apex/plugins/event/carrier/grpc/package-info.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/main/java/org/onap/policy/apex/plugins/event/carrier/grpc/package-info.java
new file mode 100644
index 000000000..77d26266d
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/main/java/org/onap/policy/apex/plugins/event/carrier/grpc/package-info.java
@@ -0,0 +1,21 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.grpc;
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcConsumerTest.java
new file mode 100644
index 000000000..dc5cc3809
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcConsumerTest.java
@@ -0,0 +1,93 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.grpc;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.engine.event.ApexEventReceiver;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
+
+public class ApexGrpcConsumerTest {
+ ApexGrpcConsumer grpcConsumer = null;
+ EventHandlerParameters consumerParameters = null;
+ ApexEventReceiver incomingEventReceiver = null;
+
+ private static final String GRPC_CONSUMER_ERROR_MSG =
+ "A gRPC Consumer may not be specified. Only sending events is possible using gRPC";
+
+ /**
+ * Set up testing.
+ *
+ * @throws ApexEventException on test set up errors.
+ */
+ @Before
+ public void setUp() throws ApexEventException {
+ grpcConsumer = new ApexGrpcConsumer();
+ consumerParameters = new EventHandlerParameters();
+ consumerParameters.setCarrierTechnologyParameters(new GrpcCarrierTechnologyParameters() {});
+ }
+
+ @Test
+ public void testInit() {
+ assertThatThrownBy(() -> {
+ grpcConsumer.init("TestApexGrpcConsumer", consumerParameters, incomingEventReceiver);
+ }).hasMessage(GRPC_CONSUMER_ERROR_MSG);
+ }
+
+ @Test
+ public void testStart() {
+ assertThatThrownBy(() -> {
+ grpcConsumer.start();
+ }).hasMessage(GRPC_CONSUMER_ERROR_MSG);
+ }
+
+ @Test
+ public void testGetName() {
+ assertEquals(null, new ApexGrpcConsumer().getName());
+ }
+
+ @Test
+ public void testGetPeeredReference() {
+ assertThatThrownBy(() -> {
+ grpcConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR);
+ }).hasMessage(GRPC_CONSUMER_ERROR_MSG);
+ }
+
+ @Test
+ public void testSetPeeredReference() {
+ assertThatThrownBy(() -> {
+ grpcConsumer.setPeeredReference(null, null);
+ }).hasMessage(GRPC_CONSUMER_ERROR_MSG);
+ }
+
+ @Test()
+ public void testStop() {
+ assertThatThrownBy(() -> {
+ new ApexGrpcConsumer().stop();
+ }).hasMessage(GRPC_CONSUMER_ERROR_MSG);
+ }
+
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcProducerTest.java
new file mode 100644
index 000000000..53d191e14
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcProducerTest.java
@@ -0,0 +1,98 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.grpc;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.Mockito.spy;
+
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import org.assertj.core.api.Assertions;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
+import org.onap.policy.cds.client.CdsProcessorGrpcClient;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ApexGrpcProducerTest {
+ private static final String HOST = "localhost";
+ @Mock
+ private CdsProcessorGrpcClient grpcClient;
+ private ApexGrpcProducer apexGrpcProducer = spy(new ApexGrpcProducer());
+ @Mock
+ private EventHandlerParameters eventHandlerParameters;
+
+ /**
+ * Set up testing.
+ *
+ * @throws ApexEventException on test set up errors.
+ */
+ @Before
+ public void setUp() throws ApexEventException {
+ populateEventHandlerParameters(HOST, 5);
+ }
+
+ @Test(expected = ApexEventException.class)
+ public void testInit_fail() throws ApexEventException {
+ apexGrpcProducer.init("TestApexGrpcProducer", new EventHandlerParameters());
+ }
+
+ @Test
+ public void testInit_pass() {
+ // should not throw an exception
+ Assertions.assertThatCode(() -> apexGrpcProducer.init("TestApexGrpcProducer", eventHandlerParameters))
+ .doesNotThrowAnyException();
+ }
+
+ @Test
+ public void testStop() throws ApexEventException {
+ apexGrpcProducer.init("TestApexGrpcProducer", eventHandlerParameters);
+ // should not throw an exception
+ Assertions.assertThatCode(() -> apexGrpcProducer.stop()).doesNotThrowAnyException();
+ }
+
+ @Test
+ public void testSendEvent() throws ApexEventException {
+ apexGrpcProducer.init("TestApexGrpcProducer", eventHandlerParameters);
+ assertThatThrownBy(() -> {
+ apexGrpcProducer.sendEvent(123, null, "grpcEvent",
+ Files.readString(Paths.get("src/test/resources/executionServiceInputEvent.json")));
+ }).hasMessageContaining("UNAVAILABLE: io exception");
+ }
+
+ private void populateEventHandlerParameters(String host, int timeout) {
+ eventHandlerParameters = new EventHandlerParameters();
+ GrpcCarrierTechnologyParameters params = new GrpcCarrierTechnologyParameters();
+ params.setLabel("GRPC");
+ params.setEventProducerPluginClass(ApexGrpcProducer.class.getName());
+ params.setEventConsumerPluginClass(ApexGrpcConsumer.class.getName());
+ params.setHost(host);
+ params.setPort(3214);
+ params.setUsername("dummyUser");
+ params.setPassword("dummyPassword");
+ params.setTimeout(timeout);
+ eventHandlerParameters.setCarrierTechnologyParameters(params);
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/GrpcCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/GrpcCarrierTechnologyParametersTest.java
new file mode 100644
index 000000000..a3994c29e
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/GrpcCarrierTechnologyParametersTest.java
@@ -0,0 +1,87 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Nordix Foundation.
+ * ================================================================================
+ * 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.grpc;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.parameters.GroupValidationResult;
+
+public class GrpcCarrierTechnologyParametersTest {
+
+ private static final String USERNAME = "username";
+ private static final String PASSWORD = "password";
+ private static final String HOST = "localhost";
+
+ private GrpcCarrierTechnologyParameters params;
+
+ @Before
+ public void setUp() {
+ params = new GrpcCarrierTechnologyParameters();
+ }
+
+ @Test
+ public void testGrpcCarrierTechnologyParameters_invalid() {
+ GroupValidationResult result = params.validate();
+ assertFalse(result.isValid());
+ assertTrue(result.getResult().contains("field \"timeout\" type \"int\" value \"0\" INVALID, must be >= 1"));
+ assertTrue(result.getResult().contains("field \"port\" type \"int\" value \"0\" INVALID, must be >= 1024"));
+ assertTrue(
+ result.getResult().contains("field \"host\" type \"java.lang.String\" value \"null\" INVALID, is null"));
+ assertTrue(result.getResult()
+ .contains("field \"username\" type \"java.lang.String\" value \"null\" INVALID, is null"));
+ assertTrue(result.getResult()
+ .contains("field \"password\" type \"java.lang.String\" value \"null\" INVALID, is null"));
+ assertTrue(result.getResult().contains(""));
+ assertTrue(result.getResult().contains(""));
+ }
+
+ @Test
+ public void testGrpcCarrierTechnologyParameters_valid() {
+ assertEquals("GRPC", params.getName());
+ assertEquals(ApexGrpcConsumer.class.getName(), params.getEventConsumerPluginClass());
+ assertEquals(ApexGrpcProducer.class.getName(), params.getEventProducerPluginClass());
+
+ params.setHost(HOST);
+ params.setPassword(PASSWORD);
+ params.setPort(2233);
+ params.setTimeout(1000);
+ params.setUsername(USERNAME);
+ GroupValidationResult result = params.validate();
+ assertTrue(result.isValid());
+ }
+
+ @Test
+ public void testGrpcCarrierTechnologyParameters_invalid_values() {
+ params.setHost(HOST);
+ params.setPassword(PASSWORD);
+ params.setTimeout(1000);
+ params.setUsername(USERNAME);
+
+ params.setPort(23); // invalid value
+ GroupValidationResult result = params.validate();
+ assertFalse(result.isValid());
+ assertTrue(result.getResult().contains("field \"port\" type \"int\" value \"23\" INVALID, must be >= 1024"));
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/resources/executionServiceInputEvent.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/resources/executionServiceInputEvent.json
new file mode 100644
index 000000000..1054af14a
--- /dev/null
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/resources/executionServiceInputEvent.json
@@ -0,0 +1,25 @@
+{
+ "actionIdentifiers": {
+ "actionName": "actionName",
+ "blueprintName": "bluePrintName",
+ "blueprintVersion": "1.0.0",
+ "mode": "sync"
+ },
+ "commonHeader": {
+ "originatorId": "sdnc",
+ "requestId": "1234567",
+ "subRequestId": "subReqId"
+ },
+ "payload": {
+ "config-assign-request": {
+ "resolution-key": "RES-KEY",
+ "config-assign-properties": {
+ "service-instance-id": "sid12",
+ "pnf-id": "pnf-id",
+ "pnf-address": "1.2.3.4",
+ "service-uuid": "service-uuid",
+ "customization-uuid": "customization-uuid"
+ }
+ }
+ }
+}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumer.java
index ff300423f..f70a3c1ac 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumer.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumer.java
@@ -74,7 +74,6 @@ public class ApexJmsConsumer extends ApexPluginsEventConsumer implements Message
final String errorMessage = "specified consumer properties of type \""
+ consumerParameters.getCarrierTechnologyParameters().getClass().getName()
+ "\" are not applicable to a JMS consumer";
- LOGGER.warn(errorMessage);
throw new ApexEventException(errorMessage);
}
jmsConsumerProperties = (JmsCarrierTechnologyParameters) consumerParameters.getCarrierTechnologyParameters();
@@ -95,7 +94,6 @@ public class ApexJmsConsumer extends ApexPluginsEventConsumer implements Message
final String errorMessage = "lookup of JMS connection factory \""
+ jmsConsumerProperties.getConnectionFactory() + "\" failed for JMS consumer properties \""
+ jmsConsumerProperties.getJmsConsumerProperties() + "\"";
- LOGGER.warn(errorMessage, e);
throw new ApexEventException(errorMessage, e);
}
@@ -112,7 +110,6 @@ public class ApexJmsConsumer extends ApexPluginsEventConsumer implements Message
final String errorMessage = "lookup of JMS topic \"" + jmsConsumerProperties.getConsumerTopic()
+ "\" failed for JMS consumer properties \"" + jmsConsumerProperties.getJmsConsumerProperties()
+ "\"";
- LOGGER.warn(errorMessage, e);
throw new ApexEventException(errorMessage, e);
}
@@ -124,7 +121,6 @@ public class ApexJmsConsumer extends ApexPluginsEventConsumer implements Message
} catch (final Exception e) {
final String errorMessage = "connection to the JMS server failed for JMS properties \""
+ jmsConsumerProperties.getJmsConsumerProperties() + "\"";
- LOGGER.warn(errorMessage, e);
throw new ApexEventException(errorMessage, e);
}
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducer.java
index 46b503e04..393ea7310 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducer.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/main/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducer.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -88,7 +88,6 @@ public class ApexJmsProducer implements ApexEventProducer {
if (!(producerParameters.getCarrierTechnologyParameters() instanceof JmsCarrierTechnologyParameters)) {
final String errorMessage = "specified producer properties are not applicable to a JMS producer ("
+ this.name + ")";
- LOGGER.warn(errorMessage);
throw new ApexEventException(errorMessage);
}
jmsProducerProperties = (JmsCarrierTechnologyParameters) producerParameters.getCarrierTechnologyParameters();
@@ -110,7 +109,6 @@ public class ApexJmsProducer implements ApexEventProducer {
final String errorMessage = "lookup of JMS connection factory \""
+ jmsProducerProperties.getConnectionFactory() + "\" failed for JMS producer properties \""
+ jmsProducerProperties.getJmsConsumerProperties() + FOR_PRODUCER_TAG + this.name + ")";
- LOGGER.warn(errorMessage, e);
throw new ApexEventException(errorMessage, e);
}
@@ -128,7 +126,6 @@ public class ApexJmsProducer implements ApexEventProducer {
final String errorMessage = "lookup of JMS topic \"" + jmsProducerProperties.getProducerTopic()
+ "\" failed for JMS producer properties \""
+ jmsProducerProperties.getJmsProducerProperties() + FOR_PRODUCER_TAG + this.name + ")";
- LOGGER.warn(errorMessage, e);
throw new ApexEventException(errorMessage, e);
}
@@ -140,7 +137,6 @@ public class ApexJmsProducer implements ApexEventProducer {
} catch (final Exception e) {
final String errorMessage = "connection to JMS server failed for JMS properties \""
+ jmsProducerProperties.getJmsConsumerProperties() + FOR_PRODUCER_TAG + this.name + ")";
- LOGGER.warn(errorMessage, e);
throw new ApexEventException(errorMessage, e);
}
@@ -150,7 +146,6 @@ public class ApexJmsProducer implements ApexEventProducer {
} catch (final Exception e) {
final String errorMessage = "creation of session to JMS server failed for JMS properties \""
+ jmsProducerProperties.getJmsConsumerProperties() + FOR_PRODUCER_TAG + this.name + ")";
- LOGGER.warn(errorMessage, e);
throw new ApexEventException(errorMessage, e);
}
@@ -161,7 +156,6 @@ public class ApexJmsProducer implements ApexEventProducer {
final String errorMessage = "creation of producer for sending events "
+ "to JMS server failed for JMS properties \""
+ jmsProducerProperties.getJmsConsumerProperties() + "\"";
- LOGGER.warn(errorMessage, e);
throw new ApexEventException(errorMessage, e);
}
}
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 aa8185fdb..a3d273dfd 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
@@ -22,9 +22,9 @@
package org.onap.policy.apex.plugins.event.carrier.restclient;
import java.util.Properties;
-
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.Response;
@@ -35,6 +35,7 @@ import org.onap.policy.apex.service.engine.event.ApexEventException;
import org.onap.policy.apex.service.engine.event.ApexEventReceiver;
import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
import org.onap.policy.apex.service.engine.event.ApexPluginsEventConsumer;
+import org.onap.policy.apex.service.parameters.carriertechnology.RestPluginCarrierTechnologyParameters;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -86,10 +87,10 @@ public class ApexRestClientConsumer extends ApexPluginsEventConsumer {
// Check if the HTTP method has been set
if (restConsumerProperties.getHttpMethod() == null) {
- restConsumerProperties.setHttpMethod(RestClientCarrierTechnologyParameters.HttpMethod.GET);
+ restConsumerProperties.setHttpMethod(RestPluginCarrierTechnologyParameters.HttpMethod.GET);
}
- if (!RestClientCarrierTechnologyParameters.HttpMethod.GET.equals(restConsumerProperties.getHttpMethod())) {
+ if (!RestPluginCarrierTechnologyParameters.HttpMethod.GET.equals(restConsumerProperties.getHttpMethod())) {
final String errorMessage = "specified HTTP method of \"" + restConsumerProperties.getHttpMethod()
+ "\" is invalid, only HTTP method \"GET\" "
+ "is supported for event reception on REST client consumer (" + this.name + ")";
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 3506ace3c..cf3500065 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
@@ -21,8 +21,6 @@
package org.onap.policy.apex.plugins.event.carrier.restclient;
-import java.util.EnumMap;
-import java.util.Map;
import java.util.Optional;
import java.util.Properties;
import java.util.Set;
@@ -33,12 +31,10 @@ import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Response;
import org.onap.policy.apex.service.engine.event.ApexEventException;
-import org.onap.policy.apex.service.engine.event.ApexPluginsEventProducer;
import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
-import org.onap.policy.apex.service.engine.event.PeeredReference;
-import org.onap.policy.apex.service.engine.event.SynchronousEventCache;
+import org.onap.policy.apex.service.engine.event.ApexPluginsEventProducer;
+import org.onap.policy.apex.service.parameters.carriertechnology.RestPluginCarrierTechnologyParameters;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
-import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -77,14 +73,14 @@ public class ApexRestClientProducer extends ApexPluginsEventProducer {
// Check if the HTTP method has been set
if (restProducerProperties.getHttpMethod() == null) {
- restProducerProperties.setHttpMethod(RestClientCarrierTechnologyParameters.HttpMethod.POST);
+ restProducerProperties.setHttpMethod(RestPluginCarrierTechnologyParameters.HttpMethod.POST);
}
- if (!RestClientCarrierTechnologyParameters.HttpMethod.POST.equals(restProducerProperties.getHttpMethod())
- && !RestClientCarrierTechnologyParameters.HttpMethod.PUT
+ if (!RestPluginCarrierTechnologyParameters.HttpMethod.POST.equals(restProducerProperties.getHttpMethod())
+ && !RestPluginCarrierTechnologyParameters.HttpMethod.PUT
.equals(restProducerProperties.getHttpMethod())) {
final String errorMessage = "specified HTTP method of \"" + restProducerProperties.getHttpMethod()
- + "\" is invalid, only HTTP methods \"POST\" and \"PUT\" are supproted "
+ + "\" is invalid, only HTTP methods \"POST\" and \"PUT\" are supported "
+ "for event sending on REST client producer (" + this.name + ")";
LOGGER.warn(errorMessage);
throw new ApexEventException(errorMessage);
@@ -97,6 +93,7 @@ public class ApexRestClientProducer extends ApexPluginsEventProducer {
/**
* {@inheritDoc}.
*/
+ @Override
public void sendEvent(final long executionId, final Properties executionProperties, final String eventName,
final Object event) {
super.sendEvent(executionId, executionProperties, eventName, event);
@@ -106,15 +103,17 @@ public class ApexRestClientProducer extends ApexPluginsEventProducer {
Set<String> names = restProducerProperties.getKeysFromUrl();
Set<String> inputProperty = executionProperties.stringPropertyNames();
+ // @formatter:off
names.stream().map(Optional::of).forEach(op ->
op.filter(inputProperty::contains)
.orElseThrow(() -> new ApexEventRuntimeException(
- "key\"" + op.get() + "\"specified on url \"" + restProducerProperties.getUrl()
- + "\"not found in execution properties passed by the current policy"))
+ "key \"" + op.get() + "\" specified on url \"" + restProducerProperties.getUrl()
+ + "\" not found in execution properties passed by the current policy"))
);
untaggedUrl = names.stream().reduce(untaggedUrl,
(acc, str) -> acc.replace("{" + str + "}", (String) executionProperties.get(str)));
+ // @formatter:on
}
// Send the event as a REST request
@@ -131,7 +130,7 @@ public class ApexRestClientProducer extends ApexPluginsEventProducer {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("event sent from engine using {} to URL {} with HTTP {} : {} and response {} ", this.name,
- untaggedUrl, restProducerProperties.getHttpMethod(), event, response);
+ untaggedUrl, restProducerProperties.getHttpMethod(), event, response);
}
}
@@ -152,7 +151,7 @@ public class ApexRestClientProducer extends ApexPluginsEventProducer {
*/
private Response sendEventAsRestRequest(final String untaggedUrl, final String event) {
// We have already checked that it is a PUT or POST request
- if (RestClientCarrierTechnologyParameters.HttpMethod.POST.equals(restProducerProperties.getHttpMethod())) {
+ if (RestPluginCarrierTechnologyParameters.HttpMethod.POST.equals(restProducerProperties.getHttpMethod())) {
return client.target(untaggedUrl).request("application/json")
.headers(restProducerProperties.getHttpHeadersAsMultivaluedMap()).post(Entity.json(event));
} else {
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 b67a339aa..ce688d62d 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
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,8 +25,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
-import ch.qos.logback.classic.Level;
-
import java.util.Properties;
import javax.ws.rs.client.Client;
@@ -47,6 +45,8 @@ import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMo
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import ch.qos.logback.classic.Level;
+
/**
* Test the ApexRestClientProducer class.
*
@@ -77,8 +77,8 @@ public class ApexRestClientProducerTest {
fail("test should throw an exception here");
} catch (ApexEventException e) {
assertEquals(
- "specified producer properties are not applicable to REST client producer (RestClientProducer)",
- e.getMessage());
+ "specified producer properties are not applicable to REST client producer (RestClientProducer)",
+ e.getMessage());
}
RestClientCarrierTechnologyParameters rcctp = new RestClientCarrierTechnologyParameters();
@@ -89,8 +89,10 @@ public class ApexRestClientProducerTest {
assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.GET, rcctp.getHttpMethod());
fail("test should throw an exception here");
} catch (ApexEventException e) {
- assertEquals("specified HTTP method of \"DELETE\" is invalid, only HTTP methods \"POST\" and \"PUT\" "
- + "are supproted for event sending on REST client producer (RestClientConsumer)", e.getMessage());
+ assertEquals(
+ "specified HTTP method of \"DELETE\" is invalid, only HTTP methods \"POST\" and \"PUT\" "
+ + "are supported for event sending on REST client producer (RestClientConsumer)",
+ e.getMessage());
}
rcctp.setHttpMethod(null);
@@ -109,7 +111,6 @@ public class ApexRestClientProducerTest {
assertEquals(null, arcp.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
arcp.stop();
-
rcctp.setHttpMethod(RestClientCarrierTechnologyParameters.HttpMethod.PUT);
arcp.init("RestClientConsumer", producerParameters);
assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.PUT, rcctp.getHttpMethod());
@@ -171,7 +172,7 @@ public class ApexRestClientProducerTest {
Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl());
arcp.setClient(httpClientMock);
- //test property not found
+ // test property not found
rcctp.setUrl("http://some.place2.that.{key}.not/{tag}and.again.{tag}");
Properties properties = new Properties();
properties.put("tag", "exist");
@@ -180,11 +181,9 @@ public class ApexRestClientProducerTest {
arcp.stop();
fail("test should throw an exception");
} catch (Exception e) {
- assertEquals(
- "key\"key\"specified on url "
- + "\"http://some.place2.that.{key}.not/{tag}and.again.{tag}\"not found "
- + "in execution properties passed by the current policy",
- e.getMessage());
+ assertEquals("key \"key\" specified on url "
+ + "\"http://some.place2.that.{key}.not/{tag}and.again.{tag}\" not found "
+ + "in execution properties passed by the current policy", e.getMessage());
}
}
@@ -234,8 +233,8 @@ public class ApexRestClientProducerTest {
rcctp.setHttpMethod(RestClientCarrierTechnologyParameters.HttpMethod.POST);
ApexEventConsumer consumer = new ApexFileEventConsumer();
- SynchronousEventCache cache = new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS, consumer, arcp,
- 1000);
+ SynchronousEventCache cache =
+ new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS, consumer, arcp, 1000);
arcp.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, cache);
assertEquals(cache, arcp.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
arcp.init("RestClientConsumer", producerParameters);
@@ -271,8 +270,8 @@ public class ApexRestClientProducerTest {
rcctp.setHttpMethod(RestClientCarrierTechnologyParameters.HttpMethod.POST);
ApexEventConsumer consumer = new ApexFileEventConsumer();
- SynchronousEventCache cache = new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS, consumer, arcp,
- 1000);
+ SynchronousEventCache cache =
+ new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS, consumer, arcp, 1000);
arcp.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, cache);
assertEquals(cache, arcp.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
arcp.init("RestClientConsumer", producerParameters);
@@ -320,9 +319,9 @@ public class ApexRestClientProducerTest {
fail("test should throw an exception here");
} catch (Exception e) {
assertEquals(
- "send of event to URL \"http://some.place.that.does.not/exist\" using HTTP \"POST\" "
- + "failed with status code 400 and message \"null\", event:\n" + "This is an Event",
- e.getMessage());
+ "send of event to URL \"http://some.place.that.does.not/exist\" using HTTP \"POST\" "
+ + "failed with status code 400 and message \"null\", event:\n" + "This is an Event",
+ e.getMessage());
}
}
} \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducer.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducer.java
index 3e2cd5a94..e166bdc1f 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducer.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/main/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducer.java
@@ -21,16 +21,13 @@
package org.onap.policy.apex.plugins.event.carrier.restrequestor;
-import java.util.EnumMap;
-import java.util.Map;
import java.util.Properties;
import org.onap.policy.apex.service.engine.event.ApexEventConsumer;
import org.onap.policy.apex.service.engine.event.ApexEventException;
-import org.onap.policy.apex.service.engine.event.ApexPluginsEventProducer;
import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
+import org.onap.policy.apex.service.engine.event.ApexPluginsEventProducer;
import org.onap.policy.apex.service.engine.event.PeeredReference;
-import org.onap.policy.apex.service.engine.event.SynchronousEventCache;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
import org.slf4j.Logger;
@@ -125,8 +122,8 @@ public class ApexRestRequestorProducer extends ApexPluginsEventProducer {
// Use the consumer to handle this event
final ApexRestRequestorConsumer restRequstConsumer = (ApexRestRequestorConsumer) consumer;
- restRequstConsumer.processRestRequest(new ApexRestRequest(
- executionId, executionProperties, eventName, event));
+ restRequstConsumer
+ .processRestRequest(new ApexRestRequest(executionId, executionProperties, eventName, event));
eventsSent++;
} else {
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/policymodels/RequestorModel.json b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/policymodels/RequestorModel.json
index b6fdc617b..98510d2a5 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/policymodels/RequestorModel.json
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/resources/policymodels/RequestorModel.json
@@ -460,7 +460,7 @@
"taskLogic" : {
"key" : "TaskLogic",
"logicFlavour" : "JAVASCRIPT",
- "logic" : "executor.logger.debug(executor.subject.id);\nvar gc = executor.getContextAlbum(\"BasicContextAlbum\");\nexecutor.logger.debug(gc.name);\nexecutor.logger.debug(executor.inFields);\n\nexecutor.logger.debug(executor.eo);\n\nvar returnValue = executor.isTrue;"
+ "logic" : "executor.logger.debug(executor.subject.getId());\nvar gc = executor.getContextAlbum(\"BasicContextAlbum\");\nexecutor.logger.debug(gc.getName());\nvar returnValue = executor.isTrue;"
}
}
} ]
diff --git a/plugins/plugins-event/plugins-event-carrier/pom.xml b/plugins/plugins-event/plugins-event-carrier/pom.xml
index cd48929d3..3127c2a77 100644
--- a/plugins/plugins-event/plugins-event-carrier/pom.xml
+++ b/plugins/plugins-event/plugins-event-carrier/pom.xml
@@ -1,6 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
<!--
============LICENSE_START=======================================================
Copyright (C) 2018 Ericsson. All rights reserved.
+ Modifications Copyright (C) 2020 Nordix Foundation.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -39,7 +41,8 @@
<module>plugins-event-carrier-restclient</module>
<module>plugins-event-carrier-restserver</module>
<module>plugins-event-carrier-restrequestor</module>
- </modules>
+ <module>plugins-event-carrier-grpc</module>
+ </modules>
<profiles>
<profile>