Fix java check style issue
[msb/discovery.git] / sdclient / discovery-service / src / main / java / org / onap / msb / sdclient / wrapper / consul / HealthClient.java
1 /**
2  * Copyright 2016-2017 ZTE, Inc. and others.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 package org.onap.msb.sdclient.wrapper.consul;
15
16 import static org.onap.msb.sdclient.wrapper.consul.util.ClientUtil.response;
17
18 import java.util.List;
19
20 import javax.ws.rs.client.WebTarget;
21 import javax.ws.rs.core.GenericType;
22
23 import org.onap.msb.sdclient.wrapper.consul.async.ConsulResponseCallback;
24 import org.onap.msb.sdclient.wrapper.consul.model.ConsulResponse;
25 import org.onap.msb.sdclient.wrapper.consul.model.health.ServiceHealth;
26 import org.onap.msb.sdclient.wrapper.consul.option.CatalogOptions;
27 import org.onap.msb.sdclient.wrapper.consul.option.QueryOptions;
28
29 /**
30  * HTTP Client for /v1/health/ endpoints.
31  */
32 public class HealthClient {
33
34
35     private static final GenericType<List<ServiceHealth>> TYPE_SERVICE_HEALTH_LIST =
36                     new GenericType<List<ServiceHealth>>() {};
37
38     private final WebTarget webTarget;
39
40     /**
41      * Constructs an instance of this class.
42      *
43      * @param webTarget The {@link javax.ws.rs.client.WebTarget} to base requests from.
44      */
45     HealthClient(WebTarget webTarget) {
46         this.webTarget = webTarget;
47     }
48
49
50
51     /**
52      * Retrieves the healthchecks for all healthy service instances.
53      * 
54      * GET /v1/health/service/{service}?passing
55      *
56      * @param service The service to query.
57      * @return A {@link org.onap.msb.sdclient.wrapper.consul.model.ConsulResponse} containing a list
58      *         of {@link com.orbitz.consul.model.health.HealthCheck} objects.
59      */
60     public ConsulResponse<List<ServiceHealth>> getHealthyServiceInstances(String service) {
61         return getHealthyServiceInstances(service, null, QueryOptions.BLANK);
62     }
63
64     /**
65      * Retrieves the healthchecks for all healthy service instances in a given datacenter.
66      * 
67      * GET /v1/health/service/{service}?dc={datacenter}&amp;passing
68      *
69      * @param service The service to query.
70      * @param catalogOptions The catalog specific options to use.
71      * @return A {@link org.onap.msb.sdclient.wrapper.consul.model.ConsulResponse} containing a list
72      *         of {@link com.orbitz.consul.model.health.HealthCheck} objects.
73      */
74     public ConsulResponse<List<ServiceHealth>> getHealthyServiceInstances(String service,
75                     CatalogOptions catalogOptions) {
76         return getHealthyServiceInstances(service, catalogOptions, QueryOptions.BLANK);
77     }
78
79     /**
80      * Retrieves the healthchecks for all healthy service instances with
81      * {@link org.onap.msb.sdclient.wrapper.consul.option.QueryOptions}.
82      * 
83      * GET /v1/health/service/{service}?passing
84      *
85      * @param service The service to query.
86      * @param queryOptions The Query Options to use.
87      * @return A {@link org.onap.msb.sdclient.wrapper.consul.model.ConsulResponse} containing a list
88      *         of {@link com.orbitz.consul.model.health.HealthCheck} objects.
89      */
90     public ConsulResponse<List<ServiceHealth>> getHealthyServiceInstances(String service, QueryOptions queryOptions) {
91         return getHealthyServiceInstances(service, null, queryOptions);
92     }
93
94     /**
95      * Retrieves the healthchecks for all healthy service instances in a given datacenter with
96      * {@link org.onap.msb.sdclient.wrapper.consul.option.QueryOptions}.
97      * 
98      * GET /v1/health/service/{service}?dc={datacenter}&amp;passing
99      *
100      * @param service The service to query.
101      * @param catalogOptions The catalog specific options to use.
102      * @param queryOptions The Query Options to use.
103      * @return A {@link org.onap.msb.sdclient.wrapper.consul.model.ConsulResponse} containing a list
104      *         of {@link com.orbitz.consul.model.health.HealthCheck} objects.
105      */
106     public ConsulResponse<List<ServiceHealth>> getHealthyServiceInstances(String service, CatalogOptions catalogOptions,
107                     QueryOptions queryOptions) {
108         return response(webTarget.path("service").path(service).queryParam("passing", "true"), catalogOptions,
109                         queryOptions, TYPE_SERVICE_HEALTH_LIST);
110     }
111
112     /**
113      * Asynchronously retrieves the healthchecks for all healthy service instances in a given
114      * datacenter with {@link org.onap.msb.sdclient.wrapper.consul.option.QueryOptions}.
115      * 
116      * GET /v1/health/service/{service}?dc={datacenter}&amp;passing
117      * 
118      * Experimental.
119      *
120      * @param service The service to query.
121      * @param catalogOptions The catalog specific options to use.
122      * @param queryOptions The Query Options to use.
123      * @param callback Callback implemented by callee to handle results.
124      */
125     public void getHealthyServiceInstances(String service, CatalogOptions catalogOptions, QueryOptions queryOptions,
126                     ConsulResponseCallback<List<ServiceHealth>> callback) {
127         response(webTarget.path("service").path(service).queryParam("passing", "true"), catalogOptions, queryOptions,
128                         TYPE_SERVICE_HEALTH_LIST, callback);
129     }
130
131     /**
132      * Asynchronously retrieves the healthchecks for all healthy service instances in a given
133      * datacenter with {@link org.onap.msb.sdclient.wrapper.consul.option.QueryOptions}.
134      * 
135      * GET /v1/health/service/{service}?dc={datacenter}&amp;passing
136      * 
137      * Experimental.
138      *
139      * @param service The service to query.
140      * @param queryOptions The Query Options to use.
141      * @param callback Callback implemented by callee to handle results.
142      */
143     public void getHealthyServiceInstances(String service, QueryOptions queryOptions,
144                     ConsulResponseCallback<List<ServiceHealth>> callback) {
145         response(webTarget.path("service").path(service).queryParam("passing", "true"), CatalogOptions.BLANK,
146                         queryOptions, TYPE_SERVICE_HEALTH_LIST, callback);
147     }
148
149     /**
150      * Retrieves the healthchecks for all nodes.
151      * 
152      * GET /v1/health/service/{service}
153      *
154      * @param service The service to query.
155      * @return A {@link org.onap.msb.sdclient.wrapper.consul.model.ConsulResponse} containing a list
156      *         of {@link com.orbitz.consul.model.health.HealthCheck} objects.
157      */
158     public ConsulResponse<List<ServiceHealth>> getAllServiceInstances(String service) {
159         return getAllServiceInstances(service, null, QueryOptions.BLANK);
160     }
161
162     /**
163      * Retrieves the healthchecks for all nodes in a given datacenter.
164      * 
165      * GET /v1/health/service/{service}?dc={datacenter}
166      *
167      * @param service The service to query.
168      * @param catalogOptions The catalog specific options to use.
169      * @return A {@link org.onap.msb.sdclient.wrapper.consul.model.ConsulResponse} containing a list
170      *         of {@link com.orbitz.consul.model.health.HealthCheck} objects.
171      */
172     public ConsulResponse<List<ServiceHealth>> getAllServiceInstances(String service, CatalogOptions catalogOptions) {
173         return getAllServiceInstances(service, catalogOptions, QueryOptions.BLANK);
174     }
175
176     /**
177      * Retrieves the healthchecks for all nodes with
178      * {@link org.onap.msb.sdclient.wrapper.consul.option.QueryOptions}.
179      * 
180      * GET /v1/health/service/{service}
181      *
182      * @param service The service to query.
183      * @param queryOptions The Query Options to use.
184      * @return A {@link org.onap.msb.sdclient.wrapper.consul.model.ConsulResponse} containing a list
185      *         of {@link com.orbitz.consul.model.health.HealthCheck} objects.
186      */
187     public ConsulResponse<List<ServiceHealth>> getAllServiceInstances(String service, QueryOptions queryOptions) {
188         return getAllServiceInstances(service, null, queryOptions);
189     }
190
191     /**
192      * Retrieves the healthchecks for all nodes in a given datacenter with
193      * {@link org.onap.msb.sdclient.wrapper.consul.option.QueryOptions}.
194      * 
195      * GET /v1/health/service/{service}?dc={datacenter}
196      *
197      * @param service The service to query.
198      * @param catalogOptions The catalog specific options to use.
199      * @param queryOptions The Query Options to use.
200      * @return A {@link org.onap.msb.sdclient.wrapper.consul.model.ConsulResponse} containing a list
201      *         of {@link com.orbitz.consul.model.health.HealthCheck} objects.
202      */
203     public ConsulResponse<List<ServiceHealth>> getAllServiceInstances(String service, CatalogOptions catalogOptions,
204                     QueryOptions queryOptions) {
205         return response(webTarget.path("service").path(service), catalogOptions, queryOptions,
206                         TYPE_SERVICE_HEALTH_LIST);
207     }
208
209     /**
210      * Asynchronously retrieves the healthchecks for all nodes in a given datacenter with
211      * {@link org.onap.msb.sdclient.wrapper.consul.option.QueryOptions}.
212      * 
213      * GET /v1/health/service/{service}?dc={datacenter}
214      * 
215      * Experimental.
216      *
217      * @param service The service to query.
218      * @param catalogOptions The catalog specific options to use.
219      * @param queryOptions The Query Options to use.
220      * @param callback Callback implemented by callee to handle results.
221      */
222     public void getAllServiceInstances(String service, CatalogOptions catalogOptions, QueryOptions queryOptions,
223                     ConsulResponseCallback<List<ServiceHealth>> callback) {
224         response(webTarget.path("service").path(service), catalogOptions, queryOptions, TYPE_SERVICE_HEALTH_LIST,
225                         callback);
226     }
227
228     /**
229      * Asynchronously retrieves the healthchecks for all nodes in a given datacenter with
230      * {@link org.onap.msb.sdclient.wrapper.consul.option.QueryOptions}.
231      * 
232      * GET /v1/health/service/{service}?dc={datacenter}
233      * 
234      * Experimental.
235      *
236      * @param service The service to query.
237      * @param queryOptions The Query Options to use.
238      * @param callback Callback implemented by callee to handle results.
239      */
240     public void getAllServiceInstances(String service, QueryOptions queryOptions,
241                     ConsulResponseCallback<List<ServiceHealth>> callback) {
242         response(webTarget.path("service").path(service), CatalogOptions.BLANK, queryOptions, TYPE_SERVICE_HEALTH_LIST,
243                         callback);
244     }
245 }