Package org.kiwiproject.consul
Class AgentClient
java.lang.Object
org.kiwiproject.consul.AgentClient
HTTP Client for /v1/agent/ endpoints.
- See Also:
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidChecks in with Consul.voidPrepends the default TTL prefix to the serviceId to produce a check id, then delegates tocheck(String, State, String).voidderegister(String serviceId) De-register a particular service from the Consul Agent.voidderegister(String serviceId, QueryOptions options) De-register a particular service from the Consul Agent.voidderegisterCheck(String checkId) De-registers a Health Check with the AgentvoidSets a TTL service check to "critical" state.voidSets a TTL service check to "critical" state with a note.voidSets a TTL check to "critical" state.voidSets a TTL check to "critical" state with a note.voidforceLeave(String node) GET /v1/agent/force-leave/{node}voidforceLeave(String node, QueryParameterOptions queryParameterOptions) GET /v1/agent/force-leave/{node}getAgent()Retrieves the Agent's configuration and member information.Retrieves all checks registered with the Agent.getChecks(QueryOptions queryOptions) Retrieves all checks registered with the Agent.Retrieves all members that the Agent can see in the gossip pool.getMembers(QueryOptions queryOptions) Retrieves all members that the Agent can see in the gossip pool.getService(String id, QueryOptions queryOptions) Retrieves all information about a service.voidgetService(String id, QueryOptions queryOptions, ConsulResponseCallback<FullService> callback) Retrieves all information about a service.Retrieves all services registered with the Agent.getServices(QueryOptions queryOptions) Retrieves all services registered with the Agent.booleanisRegistered(String serviceId) Indicates whether a particular service is registered with the local Consul agent.booleanGET /v1/agent/join/{address}booleanGET /v1/agent/join/{address}?wan=wanbooleanjoin(String address, QueryOptions queryOptions) GET /v1/agent/join/{address}?queryOptionsvoidSets a TTL service check to "passing" statevoidSets a TTL service check to "passing" state with a notevoidSets a TTL check to "passing" statevoidSets a TTL check to "passing" state with a notevoidping()Pings the Consul Agent.voidRegisters the client as a service with Consul with a ttl check.voidregister(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 checkvoidregister(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.voidregister(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 checkvoidregister(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.voidregister(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 checksvoidregister(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 existingRegistration.RegCheckvoidregister(Registration registration) voidregister(Registration registration, QueryOptions options) voidregister(Registration registration, QueryOptions options, QueryParameterOptions queryParameterOptions) Registers the client as a service with Consul.voidregisterCheck(String checkId, String name, long ttl) Registers a Health Check with the Agent.voidregisterCheck(String checkId, String name, long ttl, String notes) Registers a Health Check with the Agent.voidregisterCheck(String checkId, String name, com.google.common.net.HostAndPort tcp, long interval) Registers a TCP Health Check with the Agent.voidregisterCheck(String checkId, String name, com.google.common.net.HostAndPort tcp, long interval, String notes) Registers a TCP Health Check with the Agent.voidregisterCheck(String checkId, String name, String script, long interval) Registers a script Health Check with the Agent.voidregisterCheck(String checkId, String name, String args, long interval, String notes) Registers a script Health Check with the Agent.voidregisterCheck(String checkId, String name, URL http, long interval) Registers an HTTP Health Check with the Agent.voidregisterCheck(String checkId, String name, URL http, long interval, String notes) Registers an HTTP Health Check with the Agent.voidRegisters a script Health Check with the Agent.voidregisterCheck(Check check) Registers a Health Check with the Agent.voidtoggleMaintenanceMode(String serviceId, boolean enable) Toggles maintenance mode for a service ID.voidtoggleMaintenanceMode(String serviceId, boolean enable, String reason) Toggles maintenance mode for a service ID.voidtoggleMaintenanceMode(String serviceId, QueryOptions queryOptions) Toggles maintenance mode for a service ID.voidSets a TTL service check to "warning" state.voidSets a TTL service check to "warning" state with a note.voidSets a TTL check to "warning" state.voidSets a TTL check to "warning" state with a note.
-
Field Details
-
http
-
-
Method Details
-
isRegistered
Indicates whether a particular service is registered with the local Consul agent.- Parameters:
serviceId- the ID of the service to check- Returns:
trueif a particular service is registered with the local Consul agent, otherwisefalse.
-
ping
public void ping()Pings the Consul Agent. -
register
public 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.- Parameters:
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.
-
register
public 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.- Parameters:
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.
-
register
public 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.- Parameters:
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.
-
register
public 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- Parameters:
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.
-
register
public 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- Parameters:
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.
-
register
public 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 existingRegistration.RegCheck- Parameters:
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.
-
register
public 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- Parameters:
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.
-
register
public void register(Registration registration, QueryOptions options, QueryParameterOptions queryParameterOptions) Registers the client as a service with Consul. Registration enables the use of checks.- Parameters:
registration- The registration payload.options- An optional QueryOptions instance.queryParameterOptions- The Query Parameter Options to use.
-
register
-
register
-
deregister
De-register a particular service from the Consul Agent.- Parameters:
serviceId- the ID of the service to deregisteroptions- the query options to use
-
deregister
De-register a particular service from the Consul Agent.- Parameters:
serviceId- the ID of the service to deregister
-
registerCheck
Registers a script Health Check with the Agent.- Parameters:
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.
-
registerCheck
Registers an HTTP Health Check with the Agent.- Parameters:
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.
-
registerCheck
public void registerCheck(String checkId, String name, com.google.common.net.HostAndPort tcp, long interval) Registers a TCP Health Check with the Agent.- Parameters:
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.
-
registerCheck
public void registerCheck(String checkId, String name, List<String> args, long interval, String notes) Registers a script Health Check with the Agent.- Parameters:
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.
-
registerCheck
Registers a script Health Check with the Agent.- Parameters:
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.
-
registerCheck
Registers an HTTP Health Check with the Agent.- Parameters:
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.
-
registerCheck
public void registerCheck(String checkId, String name, com.google.common.net.HostAndPort tcp, long interval, String notes) Registers a TCP Health Check with the Agent.- Parameters:
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.
-
registerCheck
Registers a Health Check with the Agent.- Parameters:
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.
-
registerCheck
Registers a Health Check with the Agent.- Parameters:
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.
-
registerCheck
Registers a Health Check with the Agent.- Parameters:
check- The Check to register.
-
deregisterCheck
De-registers a Health Check with the Agent- Parameters:
checkId- the id of the Check to deregister
-
getAgent
Retrieves the Agent's configuration and member information.GET /v1/agent/self
- Returns:
- The Agent information.
-
getChecks
Retrieves all checks registered with the Agent.GET /v1/agent/checks
- Returns:
- Map of Check ID to Checks.
-
getChecks
Retrieves all checks registered with the Agent.GET /v1/agent/checks
- Parameters:
queryOptions- The Query Options to use.- Returns:
- Map of Check ID to Checks.
-
getServices
Retrieves all services registered with the Agent.GET /v1/agent/services
- Returns:
- Map of Service ID to Services.
-
getServices
Retrieves all services registered with the Agent.GET /v1/agent/services
- Parameters:
queryOptions- The Query Options to use.- Returns:
- Map of Service ID to Services.
-
getService
public ConsulResponse<FullService> getService(String id, QueryOptions queryOptions) throws NotRegisteredException Retrieves all information about a service.GET /v1/agent/service/:service_id
- Parameters:
id- The service id.queryOptions- The Query Options to use.- Returns:
- A
ConsulResponsecontainingFullServiceobject. - Throws:
NotRegisteredException- if the service is not registered
-
getService
public void getService(String id, QueryOptions queryOptions, ConsulResponseCallback<FullService> callback) Retrieves all information about a service.GET /v1/agent/service/:service_id
- Parameters:
id- The service id.queryOptions- The Query Options to use.callback- Callback implemented by callee to handle results.
-
getMembers
Retrieves all members that the Agent can see in the gossip pool.GET /v1/agent/members
- Returns:
- List of Members.
-
getMembers
Retrieves all members that the Agent can see in the gossip pool.GET /v1/agent/members
- Parameters:
queryOptions- The Query Options to use.- Returns:
- List of Members.
-
forceLeave
GET /v1/agent/force-leave/{node}Instructs the agent to force a node into the "left" state.
- Parameters:
node- Node name
-
forceLeave
GET /v1/agent/force-leave/{node}Instructs the agent to force a node into the "left" state.
- Parameters:
node- Node namequeryParameterOptions- The Query Parameters Options to use.
-
check
Checks in with Consul.- Parameters:
checkId- The Check ID to check in.state- The current state of the Check.note- Any note to associate with the Check.- Throws:
NotRegisteredException- if the service has not registered
-
checkTtl
Prepends the default TTL prefix to the serviceId to produce a check id, then delegates tocheck(String, State, String).This method only works with TTL checks that have not been given a custom name.
- Parameters:
serviceId- the ID of the service to checkstate- the state to use in the check-innote- the note to add to the check-in- Throws:
NotRegisteredException- if the service has not registered
-
pass
Sets a TTL service check to "passing" state- Parameters:
serviceId- the ID of the service to set as passing- Throws:
NotRegisteredException- if the service has not registered
-
pass
Sets a TTL service check to "passing" state with a note- Parameters:
serviceId- the ID of the service to set as passingnote- the note to set on the check- Throws:
NotRegisteredException- if the service has not registered
-
warn
Sets a TTL service check to "warning" state.- Parameters:
serviceId- serviceId the ID of the service to set as warn- Throws:
NotRegisteredException- if the service has not registered
-
warn
Sets a TTL service check to "warning" state with a note.- Parameters:
serviceId- serviceId the ID of the service to set as warnnote- the note to set on the check- Throws:
NotRegisteredException- if the service has not registered
-
fail
Sets a TTL service check to "critical" state.- Parameters:
serviceId- serviceId the ID of the service to set as critical/fail- Throws:
NotRegisteredException- if the service has not registered
-
fail
Sets a TTL service check to "critical" state with a note.- Parameters:
serviceId- serviceId the ID of the service to set as critical/failnote- the note to set on the check- Throws:
NotRegisteredException- if the service has not registered
-
passCheck
Sets a TTL check to "passing" state- Parameters:
checkId- the ID of the check to set as passing- Throws:
NotRegisteredException- if the service has not registered
-
passCheck
Sets a TTL check to "passing" state with a note- Parameters:
checkId- the ID of the check to set as passingnote- the note to set on the check- Throws:
NotRegisteredException- if the service has not registered
-
warnCheck
Sets a TTL check to "warning" state.- Parameters:
checkId- the ID of the check to set as "warning"- Throws:
NotRegisteredException- if the service has not registered
-
warnCheck
Sets a TTL check to "warning" state with a note.- Parameters:
checkId- the ID of the check to set as "warning"note- the note to set on the check- Throws:
NotRegisteredException- if the service has not registered
-
failCheck
Sets a TTL check to "critical" state.- Parameters:
checkId- the ID of the check to set as critical/fail- Throws:
NotRegisteredException- if the service has not registered
-
failCheck
Sets a TTL check to "critical" state with a note.- Parameters:
checkId- the ID of the check to set as critical/failnote- the note to set on the check- Throws:
NotRegisteredException- if the service has not registered
-
join
GET /v1/agent/join/{address}Instructs the agent to join a node.
- Parameters:
address- The address to join.- Returns:
trueif successful, otherwisefalse.
-
join
GET /v1/agent/join/{address}?wan=wanInstructs the agent to join a node.
- Parameters:
address- The address to join.wan- Use WAN pool.- Returns:
trueif successful, otherwisefalse.
-
join
GET /v1/agent/join/{address}?queryOptionsInstructs the agent to join a node.
- Parameters:
address- The address to join.queryOptions- The Query Options to use.- Returns:
trueif successful, otherwisefalse.
-
toggleMaintenanceMode
Toggles maintenance mode for a service ID.- Parameters:
serviceId- The service ID.enable-trueif the service should be in maintenance mode, otherwisefalse.
-
toggleMaintenanceMode
Toggles maintenance mode for a service ID.- Parameters:
serviceId- The service ID.enable-trueif the service should be in maintenance mode, otherwisefalse.reason- The reason for maintenance mode.
-
toggleMaintenanceMode
Toggles maintenance mode for a service ID.- Parameters:
serviceId- The service ID.queryOptions- The Query Options to use.
-
getConfig
-
getEventHandler
-