Create entities and classes
[holmes/common.git] / holmes-actions / src / main / java / org / onap / holmes / common / dmaap / Subscriber.java
1 /*\r
2  * Copyright 2017 ZTE Corporation.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  * http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 package org.onap.holmes.common.dmaap;\r
18 \r
19 import java.util.Collections;\r
20 import java.util.List;\r
21 import javax.ws.rs.client.Client;\r
22 import javax.ws.rs.client.ClientBuilder;\r
23 import javax.ws.rs.client.WebTarget;\r
24 import javax.ws.rs.core.Response;\r
25 import lombok.Getter;\r
26 import lombok.Setter;\r
27 import org.glassfish.jersey.client.ClientConfig;\r
28 import org.onap.holmes.common.dmaap.entity.VesAlarm;\r
29 import org.onap.holmes.common.exception.CorrelationException;\r
30 \r
31 @Getter\r
32 @Setter\r
33 public class Subscriber {\r
34     /**\r
35      * The number of milliseconds to wait for messages if none are immediately\r
36      * available. This should normally be used, and set at 15000 or higher.\r
37      */\r
38     private int timeout = 15000;\r
39 \r
40     /**\r
41      * The maximum number of messages to return\r
42      */\r
43     private int limit = 100;\r
44 \r
45     private boolean secure;\r
46     private String topic;\r
47     private String url;\r
48     private String consumerGroup = "g0";\r
49     private String consumer = "u1";\r
50     private String authInfo;\r
51     private String authExpDate;\r
52 \r
53     List<VesAlarm> subscribe() throws CorrelationException {\r
54         Client client = ClientBuilder.newClient(new ClientConfig());\r
55         WebTarget webTarget = client.target(url);\r
56         Response response = webTarget.path(topic).path(consumerGroup).path(consumer).request().get();\r
57 \r
58         try {\r
59             return extractAlarms(response);\r
60         }\r
61         catch (Exception e) {\r
62             throw new CorrelationException("Failed to convert the response data to VES alarms.", e);\r
63         }\r
64     }\r
65 \r
66     private List<VesAlarm> extractAlarms(Response response) {\r
67         return Collections.emptyList();\r
68     }\r
69 }\r