e6019f73f040c6b818b64451d39f14b1bd43141b
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.mso.bpmn.infrastructure.pnf.dmaap;
22
23 import java.io.IOException;
24 import java.net.URI;
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;
30
31 public class PnfEventReadyConsumer {
32
33     private static final String JSON_PATH_CORRELATION_ID = "$.pnfRegistrationFields.correlationId";
34     private HttpClient httpClient;
35
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;
43
44     public PnfEventReadyConsumer() {
45         httpClient = HttpClientBuilder.create().build();
46     }
47
48     public void notifyWhenPnfReady(String correlationId)
49             throws IOException {
50         HttpGet getRequest = new HttpGet(buildURI(consumerGroup, consumerId));
51         HttpResponse response = httpClient.execute(getRequest);
52         checkIfResponseIsAccepted(response, correlationId);
53     }
54
55     private boolean checkIfResponseIsAccepted(HttpResponse response, String correlationId) {
56         // TODO parse response if contains proper correlationId
57         return false;
58     }
59
60     private URI buildURI(String consumerGroup, String consumerId) {
61         return UriBuilder.fromUri(dmaapUriPathPrefix)
62                 .scheme(dmaapProtocol)
63                 .host(dmaapHost)
64                 .port(dmaapPort).path(dmaapTopicName)
65                 .path(consumerGroup).path(consumerId).build();
66     }
67
68     public void setDmaapHost(String dmaapHost) {
69         this.dmaapHost = dmaapHost;
70     }
71
72     public void setDmaapPort(int dmaapPort) {
73         this.dmaapPort = dmaapPort;
74     }
75
76     public void setDmaapProtocol(String dmaapProtocol) {
77         this.dmaapProtocol = dmaapProtocol;
78     }
79
80     public void setDmaapUriPathPrefix(String dmaapUriPathPrefix) {
81         this.dmaapUriPathPrefix = dmaapUriPathPrefix;
82     }
83
84     public void setDmaapTopicName(String dmaapTopicName) {
85         this.dmaapTopicName = dmaapTopicName;
86     }
87
88     public void setConsumerId(String consumerId) {
89         this.consumerId = consumerId;
90     }
91
92     public void setConsumerGroup(String consumerGroup) {
93         this.consumerGroup = consumerGroup;
94     }
95
96 }