package com.ecwid.consul.v1;
import com.ecwid.consul.transport.TLSConfig;
import com.ecwid.consul.v1.acl.AclClient;
import com.ecwid.consul.v1.acl.AclConsulClient;
import com.ecwid.consul.v1.acl.model.Acl;
import com.ecwid.consul.v1.acl.model.NewAcl;
import com.ecwid.consul.v1.acl.model.UpdateAcl;
import com.ecwid.consul.v1.agent.AgentClient;
import com.ecwid.consul.v1.agent.AgentConsulClient;
import com.ecwid.consul.v1.agent.model.*;
import com.ecwid.consul.v1.catalog.*;
import com.ecwid.consul.v1.catalog.model.*;
import com.ecwid.consul.v1.coordinate.CoordinateClient;
import com.ecwid.consul.v1.coordinate.CoordinateConsulClient;
import com.ecwid.consul.v1.coordinate.model.Datacenter;
import com.ecwid.consul.v1.event.EventClient;
import com.ecwid.consul.v1.event.EventConsulClient;
import com.ecwid.consul.v1.event.EventListRequest;
import com.ecwid.consul.v1.event.model.Event;
import com.ecwid.consul.v1.event.model.EventParams;
import com.ecwid.consul.v1.health.HealthChecksForServiceRequest;
import com.ecwid.consul.v1.health.HealthClient;
import com.ecwid.consul.v1.health.HealthConsulClient;
import com.ecwid.consul.v1.health.HealthServicesRequest;
import com.ecwid.consul.v1.health.model.HealthService;
import com.ecwid.consul.v1.kv.KeyValueClient;
import com.ecwid.consul.v1.kv.KeyValueConsulClient;
import com.ecwid.consul.v1.kv.model.GetBinaryValue;
import com.ecwid.consul.v1.kv.model.GetValue;
import com.ecwid.consul.v1.kv.model.PutParams;
import com.ecwid.consul.v1.query.QueryClient;
import com.ecwid.consul.v1.query.QueryConsulClient;
import com.ecwid.consul.v1.query.model.QueryExecution;
import com.ecwid.consul.v1.session.SessionClient;
import com.ecwid.consul.v1.session.SessionConsulClient;
import com.ecwid.consul.v1.session.model.NewSession;
import com.ecwid.consul.v1.session.model.Session;
import com.ecwid.consul.v1.status.StatusClient;
import com.ecwid.consul.v1.status.StatusConsulClient;
import java.util.List;
import java.util.Map;
/**
* Full consul-api client with all supported methods.
* If you like to use more specific clients, please look at *Client classes (AclClient, AgentClient etc.)
*
* Implementation notes:
* Do not afraid of the class size :)
* There aren't any 'smart' or specific methods - all methods in this class are just delegates and auto-generated by IntelliJ IDEA
*
* @author Vasily Vasilkov ([email protected])
*/
public class ConsulClient implements
AclClient,
AgentClient,
CatalogClient,
CoordinateClient,
EventClient,
HealthClient,
KeyValueClient,
QueryClient,
SessionClient,
StatusClient {
private final AclClient aclClient;
private final AgentClient agentClient;
private final CatalogClient catalogClient;
private final CoordinateClient coordinateClient;
private final EventClient eventClient;
private final HealthClient healthClient;
private final KeyValueClient keyValueClient;
private final QueryClient queryClient;
private final SessionClient sessionClient;
private final StatusClient statusClient;
public ConsulClient(ConsulRawClient rawClient) {
aclClient = new AclConsulClient(rawClient);
agentClient = new AgentConsulClient(rawClient);
catalogClient = new CatalogConsulClient(rawClient);
coordinateClient = new CoordinateConsulClient(rawClient);
eventClient = new EventConsulClient(rawClient);
healthClient = new HealthConsulClient(rawClient);
keyValueClient = new KeyValueConsulClient(rawClient);
queryClient = new QueryConsulClient(rawClient);
sessionClient = new SessionConsulClient(rawClient);
statusClient = new StatusConsulClient(rawClient);
}
/**
* Consul client will connect to local consul agent on
* 'http://localhost:8500'
*/
public ConsulClient() {
this(new ConsulRawClient());
}
/**
* Consul client will connect to local consul agent on
* 'http://localhost:8500'
*
* @param tlsConfig TLS configuration
*/
public ConsulClient(TLSConfig tlsConfig) {
this(new ConsulRawClient(tlsConfig));
}
/**
* Connect to consul agent on specific address and default port (8500)
*
* @param agentHost Hostname or IP address of consul agent. You can specify scheme
* (HTTP/HTTPS) in address. If there is no scheme in address -
* client will use HTTP.
*/
public ConsulClient(String agentHost) {
this(new ConsulRawClient(agentHost));
}
/**
* Connect to consul agent on specific address and default port (8500)
*
* @param agentHost Hostname or IP address of consul agent. You can specify scheme
* (HTTP/HTTPS) in address. If there is no scheme in address -
* client will use HTTP.
* @param tlsConfig TLS configuration
*/
public ConsulClient(String agentHost, TLSConfig tlsConfig) {
this(new ConsulRawClient(agentHost, tlsConfig));
}
/**
* Connect to consul agent on specific address and port
*
* @param agentHost Hostname or IP address of consul agent. You can specify scheme
* (HTTP/HTTPS) in address. If there is no scheme in address -
* client will use HTTP.
* @param agentPort Consul agent port
*/
public ConsulClient(String agentHost, int agentPort) {
this(new ConsulRawClient(agentHost, agentPort));
}
/**
* Connect to consul agent on specific address and port
*
* @param agentHost Hostname or IP address of consul agent. You can specify scheme
* (HTTP/HTTPS) in address. If there is no scheme in address -
* client will use HTTP.
* @param agentPort Consul agent port
* @param tlsConfig TLS configuration
*/
public ConsulClient(String agentHost, int agentPort, TLSConfig tlsConfig) {
this(new ConsulRawClient(agentHost, agentPort, tlsConfig));
}
// -------------------------------------------------------------------------------------------
// ACL
@Override
public Response aclCreate(NewAcl newAcl, String token) {
return aclClient.aclCreate(newAcl, token);
}
@Override
public Response aclUpdate(UpdateAcl updateAcl, String token) {
return aclClient.aclUpdate(updateAcl, token);
}
@Override
public Response aclDestroy(String aclId, String token) {
return aclClient.aclDestroy(aclId, token);
}
@Override
public Response getAcl(String id) {
return aclClient.getAcl(id);
}
@Override
public Response aclClone(String aclId, String token) {
return aclClient.aclClone(aclId, token);
}
@Override
public Response> getAclList(String token) {
return aclClient.getAclList(token);
}
// -------------------------------------------------------------------------------------------
// Agent
@Override
public Response