com.ecwid.consul.v1.coordinate.CoordinateConsulClient Maven / Gradle / Ivy
package com.ecwid.consul.v1.coordinate;
import com.ecwid.consul.json.GsonFactory;
import com.ecwid.consul.transport.HttpResponse;
import com.ecwid.consul.v1.ConsulRawClient;
import com.ecwid.consul.v1.OperationException;
import com.ecwid.consul.v1.QueryParams;
import com.ecwid.consul.v1.Response;
import com.ecwid.consul.v1.coordinate.model.Datacenter;
import com.ecwid.consul.v1.coordinate.model.Node;
import com.google.gson.reflect.TypeToken;
import java.util.List;
/**
* @author Vasily Vasilkov ([email protected])
*/
public class CoordinateConsulClient implements CoordinateClient {
private final ConsulRawClient rawClient;
public CoordinateConsulClient(ConsulRawClient rawClient) {
this.rawClient = rawClient;
}
@Override
public Response> getDatacenters() {
HttpResponse httpResponse = rawClient.makeGetRequest("/v1/coordinate/datacenters");
if (httpResponse.getStatusCode() == 200) {
List value = GsonFactory.getGson().fromJson(httpResponse.getContent(), new TypeToken>() {
}.getType());
return new Response>(value, httpResponse);
} else {
throw new OperationException(httpResponse);
}
}
@Override
public Response> getNodes(QueryParams queryParams) {
HttpResponse httpResponse = rawClient.makeGetRequest("/v1/coordinate/nodes", queryParams);
if (httpResponse.getStatusCode() == 200) {
List value = GsonFactory.getGson().fromJson(httpResponse.getContent(), new TypeToken>() {
}.getType());
return new Response>(value, httpResponse);
} else {
throw new OperationException(httpResponse);
}
}
}