From 8e3ee2eab19c9b2db2423567418ab28b65ff8aec Mon Sep 17 00:00:00 2001 From: Lukasz Muszkieta Date: Fri, 6 Apr 2018 14:50:21 +0200 Subject: PnfReadyEventConsumer implementation Change-Id: Ia4d9fedb023ef6893e887ff6b5802623649aeeba Issue-ID: SO-466 Signed-off-by: Lukasz Muszkieta --- .../scripts/PnfReadyEventHandler.java | 28 ------- .../pnf/dmaap/PnfEventReadyConsumer.java | 96 ++++++++++++++++++++++ .../src/main/resources/dmaap.properties | 7 ++ .../src/main/resources/processengine.properties | 20 ----- .../src/main/webapp/WEB-INF/applicationContext.xml | 14 ++++ 5 files changed, 117 insertions(+), 48 deletions(-) delete mode 100644 bpmn/MSOInfrastructureBPMN/src/main/groovy/org/openecomp/mso/bpmn/infrastructure/scripts/PnfReadyEventHandler.java create mode 100644 bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/dmaap/PnfEventReadyConsumer.java create mode 100644 bpmn/MSOInfrastructureBPMN/src/main/resources/dmaap.properties delete mode 100644 bpmn/MSOInfrastructureBPMN/src/main/resources/processengine.properties (limited to 'bpmn/MSOInfrastructureBPMN/src/main') 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 @@ + + + + + + + + + + + + + + -- cgit 1.2.3-korg