public class AgentClient extends Object
Modifier and Type | Method and Description |
---|---|
void |
check(String checkId,
State state,
String note)
Checks in with Consul.
|
void |
checkTtl(String serviceId,
State state,
String note)
Prepends the default TTL prefix to the serviceId to produce a check id,
then delegates to check(String checkId, State state, String note)
This method only works with TTL checks that have not been given a custom
name.
|
void |
deregister(String serviceId)
De-register a particular service from the Consul Agent.
|
void |
deregister(String serviceId,
QueryOptions options)
De-register a particular service from the Consul Agent.
|
void |
deregisterCheck(String checkId)
De-registers a Health Check with the Agent
|
void |
fail(String serviceId)
Sets a TTL service check to "critical" state.
|
void |
fail(String serviceId,
String note)
Sets a TTL service check to "critical" state with a note.
|
void |
failCheck(String checkId)
Sets a TTL check to "critical" state.
|
void |
failCheck(String checkId,
String note)
Sets a TTL check to "critical" state with a note.
|
void |
forceLeave(String node)
GET /v1/agent/force-leave/{node}
Instructs the agent to force a node into the "left" state.
|
Agent |
getAgent()
Retrieves the Agent's configuration and member information.
|
Map<String,HealthCheck> |
getChecks()
Retrieves all checks registered with the Agent.
|
ClientConfig |
getConfig() |
ClientEventHandler |
getEventHandler() |
List<Member> |
getMembers()
Retrieves all members that the Agent can see in the gossip pool.
|
Map<String,Service> |
getServices()
Retrieves all services registered with the Agent.
|
boolean |
isRegistered(String serviceId)
Indicates whether or not a particular service is registered with
the local Consul agent.
|
boolean |
join(String address)
GET /v1/agent/join/{address}
Instructs the agent to join a node.
|
boolean |
join(String address,
boolean wan)
GET /v1/agent/join/{address}?wan=1
Instructs the agent to join a node.
|
void |
pass(String serviceId)
Sets a TTL service check to "passing" state
|
void |
pass(String serviceId,
String note)
Sets a TTL service check to "passing" state with a note
|
void |
passCheck(String checkId)
Sets a TTL check to "passing" state
|
void |
passCheck(String checkId,
String note)
Sets a TTL check to "passing" state with a note
|
void |
ping()
Pings the Consul Agent.
|
void |
register(int port,
com.google.common.net.HostAndPort tcp,
long interval,
String name,
String id,
List<String> tags,
Map<String,String> meta)
Registers the client as a service with Consul with a TCP based check
|
void |
register(int port,
List<Registration.RegCheck> checks,
String name,
String id,
List<String> tags,
Map<String,String> meta)
Registers the client as a service with Consul with multiple checks
|
void |
register(int port,
List<String> args,
long interval,
String name,
String id,
List<String> tags,
Map<String,String> meta)
Registers the client as a service with Consul with a script based check.
|
void |
register(int port,
long ttl,
String name,
String id,
List<String> tags,
Map<String,String> meta)
Registers the client as a service with Consul with a ttl check.
|
void |
register(int port,
Registration.RegCheck check,
String name,
String id,
List<String> tags,
Map<String,String> meta)
Registers the client as a service with Consul with an existing
Registration.RegCheck |
void |
register(int port,
String args,
long interval,
String name,
String id,
List<String> tags,
Map<String,String> meta)
Registers the client as a service with Consul with a script based check.
|
void |
register(int port,
URL http,
long interval,
String name,
String id,
List<String> tags,
Map<String,String> meta)
Registers the client as a service with Consul with an http based check
|
void |
register(Registration registration) |
void |
register(Registration registration,
QueryOptions options)
Registers the client as a service with Consul.
|
void |
registerCheck(Check check)
Registers a Health Check with the Agent.
|
void |
registerCheck(String checkId,
String name,
com.google.common.net.HostAndPort tcp,
long interval)
Registers a TCP Health Check with the Agent.
|
void |
registerCheck(String checkId,
String name,
com.google.common.net.HostAndPort tcp,
long interval,
String notes)
Registers a TCP Health Check with the Agent.
|
void |
registerCheck(String checkId,
String name,
List<String> args,
long interval,
String notes)
Registers a script Health Check with the Agent.
|
void |
registerCheck(String checkId,
String name,
long ttl)
Registers a Health Check with the Agent.
|
void |
registerCheck(String checkId,
String name,
long ttl,
String notes)
Registers a Health Check with the Agent.
|
void |
registerCheck(String checkId,
String name,
String script,
long interval)
Registers a script Health Check with the Agent.
|
void |
registerCheck(String checkId,
String name,
String args,
long interval,
String notes)
Registers a script Health Check with the Agent.
|
void |
registerCheck(String checkId,
String name,
URL http,
long interval)
Registers an HTTP Health Check with the Agent.
|
void |
registerCheck(String checkId,
String name,
URL http,
long interval,
String notes)
Registers a HTTP Health Check with the Agent.
|
void |
toggleMaintenanceMode(String serviceId,
boolean enable)
Toggles maintenance mode for a service ID.
|
void |
toggleMaintenanceMode(String serviceId,
boolean enable,
String reason)
Toggles maintenance mode for a service ID.
|
void |
warn(String serviceId)
Sets a TTL service check to "warning" state.
|
void |
warn(String serviceId,
String note)
Sets a TTL service check to "warning" state with a note.
|
void |
warnCheck(String checkId)
Sets a TTL check to "warning" state.
|
void |
warnCheck(String checkId,
String note)
Sets a TTL check to "warning" state with a note.
|
protected final Http http
public boolean isRegistered(String serviceId)
true
if a particular service is registered with
the local Consul agent, otherwise false
.public void ping()
public void register(int port, long ttl, String name, String id, List<String> tags, Map<String,String> meta)
port
- The public facing port of the service to register with Consul.ttl
- Time to live in seconds for the Consul dead man's switch.name
- Service name to register.id
- Service id to register.tags
- Tags to register with.meta
- Meta to register with.public void register(int port, String args, long interval, String name, String id, List<String> tags, Map<String,String> meta)
port
- The public facing port of the service to register with Consul.args
- Specifies command argument to run to update the status of the check..interval
- Health script run interval in seconds.name
- Service name to register.id
- Service id to register.tags
- Tags to register with.meta
- Meta to register with.public void register(int port, List<String> args, long interval, String name, String id, List<String> tags, Map<String,String> meta)
port
- The public facing port of the service to register with Consul.args
- Specifies command argument to run to update the status of the check..interval
- Health script run interval in seconds.name
- Service name to register.id
- Service id to register.tags
- Tags to register with.meta
- Meta to register with.public void register(int port, URL http, long interval, String name, String id, List<String> tags, Map<String,String> meta)
port
- The public facing port of the service to register with Consul.http
- Health check URL.interval
- Health script run interval in seconds.name
- Service name to register.id
- Service id to register.tags
- Tags to register with.meta
- Meta to register with.public void register(int port, com.google.common.net.HostAndPort tcp, long interval, String name, String id, List<String> tags, Map<String,String> meta)
port
- The public facing port of the service to register with Consul.tcp
- Health check TCP host and port.interval
- Health script run interval in seconds.name
- Service name to register.id
- Service id to register.tags
- Tags to register with.meta
- Meta to register with.public void register(int port, Registration.RegCheck check, String name, String id, List<String> tags, Map<String,String> meta)
Registration.RegCheck
port
- The public facing port of the service to register with Consul.check
- The health check to run periodically. Can be null.name
- Service name to register.id
- Service id to register.tags
- Tags to register with.meta
- Meta to register with.public void register(int port, List<Registration.RegCheck> checks, String name, String id, List<String> tags, Map<String,String> meta)
port
- The public facing port of the service to register with Consul.checks
- The health checks to run periodically.name
- Service name to register.id
- Service id to register.tags
- Tags to register with.meta
- Meta to register with.public void register(Registration registration, QueryOptions options)
registration
- The registration payload.options
- An optional QueryOptions instance.public void register(Registration registration)
public void deregister(String serviceId, QueryOptions options)
public void deregister(String serviceId)
public void registerCheck(String checkId, String name, String script, long interval)
checkId
- The Check ID to use. Must be unique for the Agent.name
- The Check Name.script
- Health script for Consul to use.interval
- Health script run interval in seconds.public void registerCheck(String checkId, String name, URL http, long interval)
checkId
- The Check ID to use. Must be unique for the Agent.name
- The Check Name.http
- Health check URL.interval
- Health script run interval in seconds.public void registerCheck(String checkId, String name, com.google.common.net.HostAndPort tcp, long interval)
checkId
- The Check ID to use. Must be unique for the Agent.name
- The Check Name.tcp
- Health check TCP host and port.interval
- Health script run interval in seconds.public void registerCheck(String checkId, String name, List<String> args, long interval, String notes)
checkId
- The Check ID to use. Must be unique for the Agent.name
- The Check Name.args
- Health script for Consul to use.interval
- Health script run interval in seconds.notes
- Human readable notes. Not used by Consul.public void registerCheck(String checkId, String name, String args, long interval, String notes)
checkId
- The Check ID to use. Must be unique for the Agent.name
- The Check Name.args
- Specifies command argument to run to update the status of the check.interval
- Health script run interval in seconds.notes
- Human readable notes. Not used by Consul.public void registerCheck(String checkId, String name, URL http, long interval, String notes)
checkId
- The Check ID to use. Must be unique for the Agent.name
- The Check Name.http
- Health check URL.interval
- Health script run interval in seconds.notes
- Human readable notes. Not used by Consul.public void registerCheck(String checkId, String name, com.google.common.net.HostAndPort tcp, long interval, String notes)
checkId
- The Check ID to use. Must be unique for the Agent.name
- The Check Name.tcp
- Health check TCP host and port.interval
- Health script run interval in seconds.notes
- Human readable notes. Not used by Consul.public void registerCheck(String checkId, String name, long ttl)
checkId
- The Check ID to use. Must be unique for the Agent.name
- The Check Name.ttl
- Time to live for the Consul dead man's switch.public void registerCheck(String checkId, String name, long ttl, String notes)
checkId
- The Check ID to use. Must be unique for the Agent.name
- The Check Name.ttl
- Time to live for the Consul dead man's switch.notes
- Human readable notes. Not used by Consul.public void registerCheck(Check check)
check
- The Check to register.public void deregisterCheck(String checkId)
checkId
- the id of the Check to deregisterpublic Agent getAgent()
public Map<String,HealthCheck> getChecks()
public Map<String,Service> getServices()
public List<Member> getMembers()
public void forceLeave(String node)
node
- public void check(String checkId, State state, String note) throws NotRegisteredException
checkId
- The Check ID to check in.state
- The current state of the Check.note
- Any note to associate with the Check.NotRegisteredException
public void checkTtl(String serviceId, State state, String note) throws NotRegisteredException
NotRegisteredException
public void pass(String serviceId) throws NotRegisteredException
NotRegisteredException
public void pass(String serviceId, String note) throws NotRegisteredException
NotRegisteredException
public void warn(String serviceId) throws NotRegisteredException
NotRegisteredException
public void warn(String serviceId, String note) throws NotRegisteredException
NotRegisteredException
public void fail(String serviceId) throws NotRegisteredException
NotRegisteredException
public void fail(String serviceId, String note) throws NotRegisteredException
NotRegisteredException
public void passCheck(String checkId) throws NotRegisteredException
NotRegisteredException
public void passCheck(String checkId, String note) throws NotRegisteredException
NotRegisteredException
public void warnCheck(String checkId) throws NotRegisteredException
NotRegisteredException
public void warnCheck(String checkId, String note) throws NotRegisteredException
NotRegisteredException
public void failCheck(String checkId) throws NotRegisteredException
NotRegisteredException
public void failCheck(String checkId, String note) throws NotRegisteredException
NotRegisteredException
public boolean join(String address)
address
- The address to join.true
if successful, otherwise false
.public boolean join(String address, boolean wan)
address
- The address to join.wan
- Use WAN pool.true
if successful, otherwise false
.public void toggleMaintenanceMode(String serviceId, boolean enable)
serviceId
- The service ID.enable
- true
if the service should be in
maintenance mode, otherwise false
.public void toggleMaintenanceMode(String serviceId, boolean enable, String reason)
serviceId
- The service ID.enable
- true
if the service should be in
maintenance mode, otherwise false
.reason
- The reason for maintenance mode.public ClientConfig getConfig()
public ClientEventHandler getEventHandler()
Copyright © 2018. All rights reserved.