summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeshu Kumar M <seshu.kumar.m@huawei.com>2018-04-10 08:48:01 +0000
committerGerrit Code Review <gerrit@onap.org>2018-04-10 08:48:01 +0000
commitf115334f0e8711e36dd43bc79335f2c98c77723f (patch)
tree10d7e2f3b4c47d1f92815c503dc7c85e1efb206f
parentc89d0d7d347c96bcfd84971214ab2e4cfe4546ae (diff)
parent8e3ee2eab19c9b2db2423567418ab28b65ff8aec (diff)
Merge "PnfReadyEventConsumer implementation"
-rw-r--r--bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/PnfReadyEventHandler.java28
-rw-r--r--bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumer.java96
-rw-r--r--bpmn/MSOInfrastructureBPMN/src/main/resources/dmaap.properties7
-rw-r--r--bpmn/MSOInfrastructureBPMN/src/main/resources/processengine.properties20
-rw-r--r--bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml14
-rw-r--r--bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumerTest.java68
-rw-r--r--bpmn/MSOInfrastructureBPMN/src/test/resources/dmaapTest.properties7
-rw-r--r--bpmn/MSOInfrastructureBPMN/src/test/resources/springConfig_PnfEventReadyConsumer.xml19
-rw-r--r--common/src/main/java/org/openecomp/mso/client/sdno/dmaap/PnfReadyEventConsumer.java93
-rw-r--r--common/src/test/java/org/openecomp/mso/client/dmaap/PnfReadyEventConsumerTest.java85
10 files changed, 211 insertions, 226 deletions
diff --git a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/PnfReadyEventHandler.java b/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/PnfReadyEventHandler.java
deleted file mode 100644
index f89b6a7a58..0000000000
--- a/bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/PnfReadyEventHandler.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.openecomp.mso.bpmn.infrastructure.scripts;
-
-import org.camunda.bpm.engine.delegate.DelegateExecution;
-import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil;
-import org.openecomp.mso.client.dmaap.DmaapConsumer;
-import org.openecomp.mso.client.sdno.dmaap.PnfReadyEventConsumer;
-
-public class PnfReadyEventHandler {
-
- private ExceptionUtil exceptionUtil;
-
- private static final String TOPIC_NAME = "VES event";
-
- public PnfReadyEventHandler() {
- exceptionUtil = new ExceptionUtil();
- }
-
- public void getPnfReadyEventFromDmaap (DelegateExecution execution) throws Exception {
- Object correlationIdVar = execution.getVariable("correlationId");
- if (!(correlationIdVar instanceof String)) {
- exceptionUtil.buildAndThrowWorkflowException(execution, 500, "correlationId variable is not String type");
- }
- String correlationId = (String) correlationIdVar;
- DmaapConsumer dmaapConsumer = new PnfReadyEventConsumer(correlationId);
- dmaapConsumer.consume();
- // TODO inform camunda process that event has been received
- }
-}
diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumer.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumer.java
new file mode 100644
index 0000000000..e6019f73f0
--- /dev/null
+++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumer.java
@@ -0,0 +1,96 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.bpmn.infrastructure.pnf.dmaap;
+
+import java.io.IOException;
+import java.net.URI;
+import javax.ws.rs.core.UriBuilder;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.HttpClientBuilder;
+
+public class PnfEventReadyConsumer {
+
+ private static final String JSON_PATH_CORRELATION_ID = "$.pnfRegistrationFields.correlationId";
+ private HttpClient httpClient;
+
+ private String dmaapHost;
+ private int dmaapPort;
+ private String dmaapProtocol;
+ private String dmaapUriPathPrefix;
+ private String dmaapTopicName;
+ private String consumerId;
+ private String consumerGroup;
+
+ public PnfEventReadyConsumer() {
+ httpClient = HttpClientBuilder.create().build();
+ }
+
+ public void notifyWhenPnfReady(String correlationId)
+ throws IOException {
+ HttpGet getRequest = new HttpGet(buildURI(consumerGroup, consumerId));
+ HttpResponse response = httpClient.execute(getRequest);
+ checkIfResponseIsAccepted(response, correlationId);
+ }
+
+ private boolean checkIfResponseIsAccepted(HttpResponse response, String correlationId) {
+ // TODO parse response if contains proper correlationId
+ return false;
+ }
+
+ private URI buildURI(String consumerGroup, String consumerId) {
+ return UriBuilder.fromUri(dmaapUriPathPrefix)
+ .scheme(dmaapProtocol)
+ .host(dmaapHost)
+ .port(dmaapPort).path(dmaapTopicName)
+ .path(consumerGroup).path(consumerId).build();
+ }
+
+ public void setDmaapHost(String dmaapHost) {
+ this.dmaapHost = dmaapHost;
+ }
+
+ public void setDmaapPort(int dmaapPort) {
+ this.dmaapPort = dmaapPort;
+ }
+
+ public void setDmaapProtocol(String dmaapProtocol) {
+ this.dmaapProtocol = dmaapProtocol;
+ }
+
+ public void setDmaapUriPathPrefix(String dmaapUriPathPrefix) {
+ this.dmaapUriPathPrefix = dmaapUriPathPrefix;
+ }
+
+ public void setDmaapTopicName(String dmaapTopicName) {
+ this.dmaapTopicName = dmaapTopicName;
+ }
+
+ public void setConsumerId(String consumerId) {
+ this.consumerId = consumerId;
+ }
+
+ public void setConsumerGroup(String consumerGroup) {
+ this.consumerGroup = consumerGroup;
+ }
+
+}
diff --git a/bpmn/MSOInfrastructureBPMN/src/main/resources/dmaap.properties b/bpmn/MSOInfrastructureBPMN/src/main/resources/dmaap.properties
new file mode 100644
index 0000000000..3c4dca49cf
--- /dev/null
+++ b/bpmn/MSOInfrastructureBPMN/src/main/resources/dmaap.properties
@@ -0,0 +1,7 @@
+dmaapHost=HOSTNAME
+dmaapPort=3905
+dmaapProtocol=http
+dmaapUriPathPrefix = events
+eventReadyTopicName=pnfEventReady
+consumerId=consumerId
+consumerGroup=group
diff --git a/bpmn/MSOInfrastructureBPMN/src/main/resources/processengine.properties b/bpmn/MSOInfrastructureBPMN/src/main/resources/processengine.properties
deleted file mode 100644
index d071fdabf8..0000000000
--- a/bpmn/MSOInfrastructureBPMN/src/main/resources/processengine.properties
+++ /dev/null
@@ -1,20 +0,0 @@
-###
-# ============LICENSE_START=======================================================
-# ECOMP MSO
-# ================================================================================
-# Copyright (C) 2017 AT&T Intellectual Property. 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.
-# 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.
-# ============LICENSE_END=========================================================
-###
-processEngineName=infrastructure
diff --git a/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml b/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml
index 46cea5da63..f46cd065ed 100644
--- a/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml
+++ b/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml
@@ -14,4 +14,18 @@
<property name="aaiConnection" ref="aaiConnection"/>
</bean>
+ <bean id="pnfEventReadyConsumer" class="org.openecomp.mso.bpmn.infrastructure.pnf.dmaap.PnfEventReadyConsumer">
+ <property name="dmaapHost" value="${dmaapHost}" />
+ <property name="dmaapPort" value="${dmaapPort}"/>
+ <property name="dmaapProtocol" value="${dmaapProtocol}"/>
+ <property name="dmaapUriPathPrefix" value="${dmaapUriPathPrefix}"/>
+ <property name="dmaapTopicName" value="${eventReadyTopicName}"/>
+ <property name= "consumerGroup" value="${consumerGroup}"/>
+ <property name="consumerId" value="${consumerId}"/>
+ </bean>
+
+ <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
+ <property name="locations" value="classpath:dmaap.properties"/>
+ </bean>
+
</beans>
diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumerTest.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumerTest.java
new file mode 100644
index 0000000000..2f6a00db66
--- /dev/null
+++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumerTest.java
@@ -0,0 +1,68 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. 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.
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.bpmn.infrastructure.pnf.dmaap;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import java.lang.reflect.Field;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringRunner;
+
+@RunWith(SpringRunner.class)
+@ContextConfiguration({"classpath:springConfig_PnfEventReadyConsumer.xml"})
+public class PnfEventReadyConsumerTest {
+
+ @Autowired
+ private PnfEventReadyConsumer pnfEventReadyConsumer;
+
+ private HttpClient httpClientMock;
+
+ @Before
+ public void init() throws NoSuchFieldException, IllegalAccessException {
+ httpClientMock = mock(HttpClient.class);
+ setPrivateField();
+ }
+
+ @Test
+ public void restClientInvokesWithProperURI() throws Exception {
+ ArgumentCaptor<HttpGet> captor1 = ArgumentCaptor.forClass(HttpGet.class);
+ pnfEventReadyConsumer.notifyWhenPnfReady("correlationId");
+ verify(httpClientMock).execute(captor1.capture());
+ assertThat(captor1.getValue().getURI()).hasHost("hostTest").hasPort(1234).hasScheme("http")
+ .hasPath("/eventsForTesting/eventTopicTest/consumerGroupTest/consumerTestId");
+ }
+
+ private void setPrivateField() throws NoSuchFieldException, IllegalAccessException {
+ Field field = pnfEventReadyConsumer.getClass().getDeclaredField("httpClient");
+ field.setAccessible(true);
+ field.set(pnfEventReadyConsumer, httpClientMock);
+ }
+
+}
diff --git a/bpmn/MSOInfrastructureBPMN/src/test/resources/dmaapTest.properties b/bpmn/MSOInfrastructureBPMN/src/test/resources/dmaapTest.properties
new file mode 100644
index 0000000000..a8df15c5df
--- /dev/null
+++ b/bpmn/MSOInfrastructureBPMN/src/test/resources/dmaapTest.properties
@@ -0,0 +1,7 @@
+dmaapHost=hostTest
+dmaapPort=1234
+dmaapProtocol=http
+dmaapUriPathPrefix = eventsForTesting
+eventReadyTopicName=eventTopicTest
+consumerId=consumerTestId
+consumerGroup=consumerGroupTest \ No newline at end of file
diff --git a/bpmn/MSOInfrastructureBPMN/src/test/resources/springConfig_PnfEventReadyConsumer.xml b/bpmn/MSOInfrastructureBPMN/src/test/resources/springConfig_PnfEventReadyConsumer.xml
new file mode 100644
index 0000000000..5abee9dfd9
--- /dev/null
+++ b/bpmn/MSOInfrastructureBPMN/src/test/resources/springConfig_PnfEventReadyConsumer.xml
@@ -0,0 +1,19 @@
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans.xsd">
+ <bean id="pnfEventReadyConsumer" class="org.openecomp.mso.bpmn.infrastructure.pnf.dmaap.PnfEventReadyConsumer">
+ <property name="dmaapHost" value="${dmaapHost}" />
+ <property name="dmaapPort" value="${dmaapPort}"/>
+ <property name="dmaapProtocol" value="${dmaapProtocol}"/>
+ <property name="dmaapUriPathPrefix" value="${dmaapUriPathPrefix}"/>
+ <property name="dmaapTopicName" value="${eventReadyTopicName}"/>
+ <property name= "consumerGroup" value="${consumerGroup}"/>
+ <property name="consumerId" value="${consumerId}"/>
+ </bean>
+
+ <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
+ <property name="locations" value="classpath:dmaapTest.properties"/>
+ </bean>
+
+</beans>
diff --git a/common/src/main/java/org/openecomp/mso/client/sdno/dmaap/PnfReadyEventConsumer.java b/common/src/main/java/org/openecomp/mso/client/sdno/dmaap/PnfReadyEventConsumer.java
deleted file mode 100644
index 08e35f62f8..0000000000
--- a/common/src/main/java/org/openecomp/mso/client/sdno/dmaap/PnfReadyEventConsumer.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. 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.
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.mso.client.sdno.dmaap;
-
-import java.io.IOException;
-import java.util.Optional;
-import javax.ws.rs.NotSupportedException;
-import org.openecomp.mso.client.dmaap.DmaapConsumer;
-import org.openecomp.mso.jsonpath.JsonPathUtil;
-
-public class PnfReadyEventConsumer extends DmaapConsumer {
-
- private static final String JSON_PATH_CORRELATION_ID = "$.pnfRegistrationFields.correlationId";
-
- private boolean continuePolling = true;
- private String correlationId;
-
- public PnfReadyEventConsumer(String correlationId) throws IOException {
- this.correlationId = correlationId;
- }
-
- @Override
- public boolean continuePolling() {
- return continuePolling;
- }
-
- @Override
- public void processMessage(String message) {
- }
-
- @Override
- public boolean isAccepted(String message) {
- Optional<String> correlationIdOpt = JsonPathUtil.getInstance().locateResult(message, JSON_PATH_CORRELATION_ID);
- if (correlationIdOpt.isPresent()) {
- continuePolling = false;
- return correlationIdOpt.get().equals(correlationId);
- }
- return false;
- }
-
- @Override
- public boolean isFailure(String message) {
- throw new NotSupportedException();
- }
-
- @Override
- public void stopProcessingMessages() {
- continuePolling = false;
- }
-
- @Override
- public String getRequestId() {
- throw new NotSupportedException();
- }
-
- @Override
- public String getUserName() {
- throw new NotSupportedException();
- }
-
- @Override
- public String getPassword() {
- throw new NotSupportedException();
- }
-
- @Override
- public String getTopic() {
- throw new NotSupportedException();
- }
-
- @Override
- public Optional<String> getHost() {
- throw new NotSupportedException();
- }
-}
diff --git a/common/src/test/java/org/openecomp/mso/client/dmaap/PnfReadyEventConsumerTest.java b/common/src/test/java/org/openecomp/mso/client/dmaap/PnfReadyEventConsumerTest.java
deleted file mode 100644
index 1561f75140..0000000000
--- a/common/src/test/java/org/openecomp/mso/client/dmaap/PnfReadyEventConsumerTest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2018 Huawei Intellectual Property. 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.
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.mso.client.dmaap;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.when;
-
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Optional;
-import org.junit.Test;
-import org.openecomp.mso.client.sdno.dmaap.PnfReadyEventConsumer;
-
-public class PnfReadyEventConsumerTest {
-
- private static final String CORRELATION_ID = "correlation_id_test";
-
- private static final String JSON_WITH_CORRELATION_ID = " {\"pnfRegistrationFields\": {\n"
- + " \"correlationId\": \"correlation_id_test\"\n"
- + " }}";
-
- @Test
- public void eventIsFoundForGivenCorrelationId2() throws Exception {
- PnfReadyEventConsumerForTesting testedObjectSpy = spy(new PnfReadyEventConsumerForTesting(CORRELATION_ID));
- Consumer consumerMock = mock(Consumer.class);
- when(testedObjectSpy.getConsumer()).thenReturn(consumerMock);
- when(consumerMock.fetch()).thenReturn(Arrays.asList(JSON_WITH_CORRELATION_ID));
- testedObjectSpy.consume();
- assertThat(testedObjectSpy.continuePolling()).isFalse();
- }
-
- // TODO this is temporary class, when methods are defined, it will be deleted
- private class PnfReadyEventConsumerForTesting extends PnfReadyEventConsumer {
-
- public PnfReadyEventConsumerForTesting(String correlationId) throws IOException {
- super(correlationId);
- }
-
- @Override
- public String getUserName(){
- return "userNameTest";
- }
- @Override
- public String getPassword(){
- return "passTest";
- }
- @Override
- public String getTopic(){
- return "topicTest";
- }
- @Override
- public Optional<String> getHost(){
- return Optional.of("http://localhost");
- }
- @Override
- public boolean isFailure(String message) {
- return false;
- }
- @Override
- public String getRequestId() {
- return "requestTest";
- }
- }
-
-}