2 * Copyright 2016-2017 ZTE, Inc. and others.
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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
14 package org.onap.msb.sdclient.wrapper.consul;
16 import static org.onap.msb.sdclient.wrapper.consul.util.ClientUtil.response;
18 import java.util.List;
20 import javax.ws.rs.client.WebTarget;
21 import javax.ws.rs.core.GenericType;
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;
30 * HTTP Client for /v1/health/ endpoints.
32 public class HealthClient {
35 private static final GenericType<List<ServiceHealth>> TYPE_SERVICE_HEALTH_LIST =
36 new GenericType<List<ServiceHealth>>() {};
38 private final WebTarget webTarget;
41 * Constructs an instance of this class.
43 * @param webTarget The {@link javax.ws.rs.client.WebTarget} to base requests from.
45 HealthClient(WebTarget webTarget) {
46 this.webTarget = webTarget;
52 * Retrieves the healthchecks for all healthy service instances.
54 * GET /v1/health/service/{service}?passing
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.
60 public ConsulResponse<List<ServiceHealth>> getHealthyServiceInstances(String service) {
61 return getHealthyServiceInstances(service, null, QueryOptions.BLANK);
65 * Retrieves the healthchecks for all healthy service instances in a given datacenter.
67 * GET /v1/health/service/{service}?dc={datacenter}&passing
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.
74 public ConsulResponse<List<ServiceHealth>> getHealthyServiceInstances(String service,
75 CatalogOptions catalogOptions) {
76 return getHealthyServiceInstances(service, catalogOptions, QueryOptions.BLANK);
80 * Retrieves the healthchecks for all healthy service instances with
81 * {@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
88 * of {@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
104 * of {@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"), catalogOptions,
109 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, 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);
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}.
135 * GET /v1/health/service/{service}?dc={datacenter}&passing
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.
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);
150 * Retrieves the healthchecks for all nodes.
152 * GET /v1/health/service/{service}
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.
158 public ConsulResponse<List<ServiceHealth>> getAllServiceInstances(String service) {
159 return getAllServiceInstances(service, null, QueryOptions.BLANK);
163 * Retrieves the healthchecks for all nodes in a given datacenter.
165 * GET /v1/health/service/{service}?dc={datacenter}
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.
172 public ConsulResponse<List<ServiceHealth>> getAllServiceInstances(String service, CatalogOptions catalogOptions) {
173 return getAllServiceInstances(service, catalogOptions, QueryOptions.BLANK);
177 * Retrieves the healthchecks for all nodes with
178 * {@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
185 * of {@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
201 * of {@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 datacenter with
211 * {@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, QueryOptions queryOptions,
223 ConsulResponseCallback<List<ServiceHealth>> callback) {
224 response(webTarget.path("service").path(service), catalogOptions, queryOptions, TYPE_SERVICE_HEALTH_LIST,
229 * Asynchronously retrieves the healthchecks for all nodes in a given datacenter with
230 * {@link org.onap.msb.sdclient.wrapper.consul.option.QueryOptions}.
232 * GET /v1/health/service/{service}?dc={datacenter}
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.
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,