2 * Copyright 2016 ZTE, Inc. and others.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.msb.sdclient.wrapper.consul;
18 import static org.onap.msb.sdclient.wrapper.consul.util.ClientUtil.response;
20 import java.util.List;
22 import javax.ws.rs.client.WebTarget;
23 import javax.ws.rs.core.GenericType;
25 import org.onap.msb.sdclient.wrapper.consul.async.ConsulResponseCallback;
26 import org.onap.msb.sdclient.wrapper.consul.model.ConsulResponse;
27 import org.onap.msb.sdclient.wrapper.consul.model.health.ServiceHealth;
28 import org.onap.msb.sdclient.wrapper.consul.option.CatalogOptions;
29 import org.onap.msb.sdclient.wrapper.consul.option.QueryOptions;
32 * HTTP Client for /v1/health/ endpoints.
34 public class HealthClient {
37 private static final GenericType<List<ServiceHealth>> TYPE_SERVICE_HEALTH_LIST =
38 new GenericType<List<ServiceHealth>>() {};
40 private final WebTarget webTarget;
43 * Constructs an instance of this class.
45 * @param webTarget The {@link javax.ws.rs.client.WebTarget} to base requests from.
47 HealthClient(WebTarget webTarget) {
48 this.webTarget = webTarget;
54 * Retrieves the healthchecks for all healthy service instances.
56 * GET /v1/health/service/{service}?passing
58 * @param service The service to query.
59 * @return A {@link org.onap.msb.sdclient.wrapper.consul.model.ConsulResponse} containing a list of
60 * {@link com.orbitz.consul.model.health.HealthCheck} objects.
62 public ConsulResponse<List<ServiceHealth>> getHealthyServiceInstances(String service) {
63 return getHealthyServiceInstances(service, null, QueryOptions.BLANK);
67 * Retrieves the healthchecks for all healthy service instances in a given datacenter.
69 * GET /v1/health/service/{service}?dc={datacenter}&passing
71 * @param service The service to query.
72 * @param catalogOptions The catalog specific options to use.
73 * @return A {@link org.onap.msb.sdclient.wrapper.consul.model.ConsulResponse} containing a list of
74 * {@link com.orbitz.consul.model.health.HealthCheck} objects.
76 public ConsulResponse<List<ServiceHealth>> getHealthyServiceInstances(String service, CatalogOptions catalogOptions) {
77 return getHealthyServiceInstances(service, catalogOptions, QueryOptions.BLANK);
81 * Retrieves the healthchecks for all healthy service instances with {@link org.onap.msb.sdclient.wrapper.consul.option.QueryOptions}.
83 * GET /v1/health/service/{service}?passing
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 of
88 * {@link com.orbitz.consul.model.health.HealthCheck} objects.
90 public ConsulResponse<List<ServiceHealth>> getHealthyServiceInstances(String service, QueryOptions queryOptions) {
91 return getHealthyServiceInstances(service, null, queryOptions);
95 * Retrieves the healthchecks for all healthy service instances in a given datacenter with
96 * {@link org.onap.msb.sdclient.wrapper.consul.option.QueryOptions}.
98 * GET /v1/health/service/{service}?dc={datacenter}&passing
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 of
104 * {@link com.orbitz.consul.model.health.HealthCheck} objects.
106 public ConsulResponse<List<ServiceHealth>> getHealthyServiceInstances(String service, CatalogOptions catalogOptions,
107 QueryOptions queryOptions) {
108 return response(webTarget.path("service").path(service).queryParam("passing", "true"),
109 catalogOptions, queryOptions, TYPE_SERVICE_HEALTH_LIST);
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}.
116 * GET /v1/health/service/{service}?dc={datacenter}&passing
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.
125 public void getHealthyServiceInstances(String service, CatalogOptions catalogOptions,
126 QueryOptions queryOptions,
127 ConsulResponseCallback<List<ServiceHealth>> callback) {
128 response(webTarget.path("service").path(service).queryParam("passing", "true"),
129 catalogOptions, queryOptions, TYPE_SERVICE_HEALTH_LIST, callback);
133 * Asynchronously retrieves the healthchecks for all healthy service instances in a given
134 * datacenter with {@link org.onap.msb.sdclient.wrapper.consul.option.QueryOptions}.
136 * GET /v1/health/service/{service}?dc={datacenter}&passing
140 * @param service The service to query.
141 * @param queryOptions The Query Options to use.
142 * @param callback Callback implemented by callee to handle results.
144 public void getHealthyServiceInstances(String service, QueryOptions queryOptions,
145 ConsulResponseCallback<List<ServiceHealth>> callback) {
146 response(webTarget.path("service").path(service).queryParam("passing", "true"),
147 CatalogOptions.BLANK, queryOptions, TYPE_SERVICE_HEALTH_LIST, callback);
151 * Retrieves the healthchecks for all nodes.
153 * GET /v1/health/service/{service}
155 * @param service The service to query.
156 * @return A {@link org.onap.msb.sdclient.wrapper.consul.model.ConsulResponse} containing a list of
157 * {@link com.orbitz.consul.model.health.HealthCheck} objects.
159 public ConsulResponse<List<ServiceHealth>> getAllServiceInstances(String service) {
160 return getAllServiceInstances(service, null, QueryOptions.BLANK);
164 * Retrieves the healthchecks for all nodes in a given datacenter.
166 * GET /v1/health/service/{service}?dc={datacenter}
168 * @param service The service to query.
169 * @param catalogOptions The catalog specific options to use.
170 * @return A {@link org.onap.msb.sdclient.wrapper.consul.model.ConsulResponse} containing a list of
171 * {@link com.orbitz.consul.model.health.HealthCheck} objects.
173 public ConsulResponse<List<ServiceHealth>> getAllServiceInstances(String service, CatalogOptions catalogOptions) {
174 return getAllServiceInstances(service, catalogOptions, QueryOptions.BLANK);
178 * Retrieves the healthchecks for all nodes with {@link org.onap.msb.sdclient.wrapper.consul.option.QueryOptions}.
180 * GET /v1/health/service/{service}
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 of
185 * {@link com.orbitz.consul.model.health.HealthCheck} objects.
187 public ConsulResponse<List<ServiceHealth>> getAllServiceInstances(String service, QueryOptions queryOptions) {
188 return getAllServiceInstances(service, null, queryOptions);
192 * Retrieves the healthchecks for all nodes in a given datacenter with
193 * {@link org.onap.msb.sdclient.wrapper.consul.option.QueryOptions}.
195 * GET /v1/health/service/{service}?dc={datacenter}
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 of
201 * {@link com.orbitz.consul.model.health.HealthCheck} objects.
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);
210 * Asynchronously retrieves the healthchecks for all nodes in a given
211 * datacenter with {@link org.onap.msb.sdclient.wrapper.consul.option.QueryOptions}.
213 * GET /v1/health/service/{service}?dc={datacenter}
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.
222 public void getAllServiceInstances(String service, CatalogOptions catalogOptions,
223 QueryOptions queryOptions,
224 ConsulResponseCallback<List<ServiceHealth>> callback) {
225 response(webTarget.path("service").path(service), catalogOptions, queryOptions,
226 TYPE_SERVICE_HEALTH_LIST, callback);
230 * Asynchronously retrieves the healthchecks for all nodes in a given
231 * datacenter with {@link org.onap.msb.sdclient.wrapper.consul.option.QueryOptions}.
233 * GET /v1/health/service/{service}?dc={datacenter}
237 * @param service The service to query.
238 * @param queryOptions The Query Options to use.
239 * @param callback Callback implemented by callee to handle results.
241 public void getAllServiceInstances(String service, QueryOptions queryOptions,
242 ConsulResponseCallback<List<ServiceHealth>> callback) {
243 response(webTarget.path("service").path(service), CatalogOptions.BLANK,
244 queryOptions, TYPE_SERVICE_HEALTH_LIST, callback);