2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.bpmn.infrastructure.pnf.dmaap;
23 import java.io.IOException;
25 import javax.ws.rs.core.UriBuilder;
26 import org.apache.http.HttpResponse;
27 import org.apache.http.client.HttpClient;
28 import org.apache.http.client.methods.HttpGet;
29 import org.apache.http.impl.client.HttpClientBuilder;
31 public class PnfEventReadyConsumer {
33 private static final String JSON_PATH_CORRELATION_ID = "$.pnfRegistrationFields.correlationId";
34 private HttpClient httpClient;
36 private String dmaapHost;
37 private int dmaapPort;
38 private String dmaapProtocol;
39 private String dmaapUriPathPrefix;
40 private String dmaapTopicName;
41 private String consumerId;
42 private String consumerGroup;
44 public PnfEventReadyConsumer() {
45 httpClient = HttpClientBuilder.create().build();
48 public void notifyWhenPnfReady(String correlationId)
50 HttpGet getRequest = new HttpGet(buildURI(consumerGroup, consumerId));
51 HttpResponse response = httpClient.execute(getRequest);
52 checkIfResponseIsAccepted(response, correlationId);
55 private boolean checkIfResponseIsAccepted(HttpResponse response, String correlationId) {
56 // TODO parse response if contains proper correlationId
60 private URI buildURI(String consumerGroup, String consumerId) {
61 return UriBuilder.fromUri(dmaapUriPathPrefix)
62 .scheme(dmaapProtocol)
64 .port(dmaapPort).path(dmaapTopicName)
65 .path(consumerGroup).path(consumerId).build();
68 public void setDmaapHost(String dmaapHost) {
69 this.dmaapHost = dmaapHost;
72 public void setDmaapPort(int dmaapPort) {
73 this.dmaapPort = dmaapPort;
76 public void setDmaapProtocol(String dmaapProtocol) {
77 this.dmaapProtocol = dmaapProtocol;
80 public void setDmaapUriPathPrefix(String dmaapUriPathPrefix) {
81 this.dmaapUriPathPrefix = dmaapUriPathPrefix;
84 public void setDmaapTopicName(String dmaapTopicName) {
85 this.dmaapTopicName = dmaapTopicName;
88 public void setConsumerId(String consumerId) {
89 this.consumerId = consumerId;
92 public void setConsumerGroup(String consumerGroup) {
93 this.consumerGroup = consumerGroup;