com.orbitz.consul
Class AgentClient

java.lang.Object
  extended by com.orbitz.consul.AgentClient

public class AgentClient
extends java.lang.Object

HTTP Client for /v1/agent/ endpoints.

See Also:
The Consul API Docs

Method Summary
 void check(java.lang.String checkId, State state, java.lang.String note)
          Checks in with Consul.
 void checkTtl(java.lang.String serviceId, State state, java.lang.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(java.lang.String serviceId)
          De-register a particular service from the Consul Agent.
 void deregisterCheck(java.lang.String checkId)
          De-registers a Health Check with the Agent
 void fail(java.lang.String serviceId)
          Sets a TTL service check to "critical" state.
 void fail(java.lang.String serviceId, java.lang.String note)
          Sets a TTL service check to "critical" state with a note.
 void failCheck(java.lang.String checkId)
          Sets a TTL check to "critical" state.
 void failCheck(java.lang.String checkId, java.lang.String note)
          Sets a TTL check to "critical" state with a note.
 void forceLeave(java.lang.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.
 java.util.Map<java.lang.String,HealthCheck> getChecks()
          Retrieves all checks registered with the Agent.
 java.util.List<Member> getMembers()
          Retrieves all members that the Agent can see in the gossip pool.
 java.util.Map<java.lang.String,Service> getServices()
          Retrieves all services registered with the Agent.
 boolean isRegistered(java.lang.String serviceId)
          Indicates whether or not a particular service is registered with the local Consul agent.
 boolean join(java.lang.String address)
          GET /v1/agent/join/{address} Instructs the agent to join a node.
 boolean join(java.lang.String address, boolean wan)
          GET /v1/agent/join/{address}?wan=1 Instructs the agent to join a node.
 void pass(java.lang.String serviceId)
          Sets a TTL service check to "passing" state
 void pass(java.lang.String serviceId, java.lang.String note)
          Sets a TTL service check to "passing" state with a note
 void passCheck(java.lang.String checkId)
          Sets a TTL check to "passing" state
 void passCheck(java.lang.String checkId, java.lang.String note)
          Sets a TTL check to "passing" state with a note
 void ping()
          Pings the Consul Agent.
 void register(int port, long ttl, java.lang.String name, java.lang.String id, java.lang.String... tags)
          Registers the client as a service with Consul.
 void register(int port, Registration.Check check, java.lang.String name, java.lang.String id, java.lang.String... tags)
          Registers the client as a service with Consul.
 void register(int port, java.lang.String script, long interval, java.lang.String name, java.lang.String id, java.lang.String... tags)
          Registers the client as a service with Consul.
 void register(int port, java.net.URL http, long interval, java.lang.String name, java.lang.String id, java.lang.String... tags)
          Registers the client as a service with Consul.
 void register(Registration registration)
          Registers the client as a service with Consul.
 void registerCheck(Check check)
          Registers a Health Check with the Agent.
 void registerCheck(java.lang.String checkId, java.lang.String name, long ttl)
          Registers a Health Check with the Agent.
 void registerCheck(java.lang.String checkId, java.lang.String name, long ttl, java.lang.String notes)
          Registers a Health Check with the Agent.
 void registerCheck(java.lang.String checkId, java.lang.String name, java.lang.String script, long interval)
          Registers a Health Check with the Agent.
 void registerCheck(java.lang.String checkId, java.lang.String name, java.lang.String script, long interval, java.lang.String notes)
          Registers a Health Check with the Agent.
 void registerCheck(java.lang.String checkId, java.lang.String name, java.net.URL http, long interval)
          Registers a Health Check with the Agent.
 void registerCheck(java.lang.String checkId, java.lang.String name, java.net.URL http, long interval, java.lang.String notes)
          Registers a Health Check with the Agent.
 void warn(java.lang.String serviceId)
          Sets a TTL service check to "warning" state.
 void warn(java.lang.String serviceId, java.lang.String note)
          Sets a TTL service check to "warning" state with a note.
 void warnCheck(java.lang.String checkId)
          Sets a TTL check to "warning" state.
 void warnCheck(java.lang.String checkId, java.lang.String note)
          Sets a TTL check to "warning" state with a note.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isRegistered

public boolean isRegistered(java.lang.String serviceId)
Indicates whether or not a particular service is registered with the local Consul agent.

Returns:
true if a particular service is registered with the local Consul agent, otherwise false.

ping

public void ping()
Pings the Consul Agent.


register

public void register(int port,
                     long ttl,
                     java.lang.String name,
                     java.lang.String id,
                     java.lang.String... tags)
Registers the client as a service with Consul. Registration enables the use of checks.

Parameters:
port - The public facing port of the service to register with Consul.
ttl - Time to live for the Consul dead man's switch.
name - Service name to register.
id - Service id to register.
tags - Tags to register with.

register

public void register(int port,
                     java.lang.String script,
                     long interval,
                     java.lang.String name,
                     java.lang.String id,
                     java.lang.String... tags)
Registers the client as a service with Consul. Registration enables the use of checks.

Parameters:
port - The public facing port of the service to register with Consul.
script - Health script for Consul to use.
interval - Health script run interval in seconds.
name - Service name to register.
id - Service id to register.
tags - Tags to register with.

register

public void register(int port,
                     java.net.URL http,
                     long interval,
                     java.lang.String name,
                     java.lang.String id,
                     java.lang.String... tags)
Registers the client as a service with Consul. Registration enables the use of checks.

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.

register

public void register(int port,
                     Registration.Check check,
                     java.lang.String name,
                     java.lang.String id,
                     java.lang.String... tags)
Registers the client as a service with Consul. Registration enables the use of checks.

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.

register

public void register(Registration registration)
Registers the client as a service with Consul. Registration enables the use of checks.

Parameters:
registration - The registration payload.

deregister

public void deregister(java.lang.String serviceId)
De-register a particular service from the Consul Agent.


registerCheck

public void registerCheck(java.lang.String checkId,
                          java.lang.String name,
                          java.lang.String script,
                          long interval)
Registers a 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

public void registerCheck(java.lang.String checkId,
                          java.lang.String name,
                          java.net.URL http,
                          long interval)
Registers a 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(java.lang.String checkId,
                          java.lang.String name,
                          java.lang.String script,
                          long interval,
                          java.lang.String notes)
Registers a 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.
notes - Human readable notes. Not used by Consul.

registerCheck

public void registerCheck(java.lang.String checkId,
                          java.lang.String name,
                          java.net.URL http,
                          long interval,
                          java.lang.String notes)
Registers a 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(java.lang.String checkId,
                          java.lang.String name,
                          long ttl)
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

public void registerCheck(java.lang.String checkId,
                          java.lang.String name,
                          long ttl,
                          java.lang.String notes)
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

public void registerCheck(Check check)
Registers a Health Check with the Agent.

Parameters:
check - The Check to register.

deregisterCheck

public void deregisterCheck(java.lang.String checkId)
De-registers a Health Check with the Agent

Parameters:
checkId - the id of the Check to deregister

getAgent

public Agent getAgent()
Retrieves the Agent's configuration and member information.

GET /v1/agent/self

Returns:
The Agent information.

getChecks

public java.util.Map<java.lang.String,HealthCheck> getChecks()
Retrieves all checks registered with the Agent.

GET /v1/agent/checks

Returns:
Map of Check ID to Checks.

getServices

public java.util.Map<java.lang.String,Service> getServices()
Retrieves all services registered with the Agent.

GET /v1/agent/services

Returns:
Map of Service ID to Services.

getMembers

public java.util.List<Member> getMembers()
Retrieves all members that the Agent can see in the gossip pool.

GET /v1/agent/members

Returns:
List of Members.

forceLeave

public void forceLeave(java.lang.String node)
GET /v1/agent/force-leave/{node}

Instructs the agent to force a node into the "left" state.

Parameters:
node -

check

public void check(java.lang.String checkId,
                  State state,
                  java.lang.String note)
           throws NotRegisteredException
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

checkTtl

public void checkTtl(java.lang.String serviceId,
                     State state,
                     java.lang.String note)
              throws NotRegisteredException
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.

Parameters:
serviceId -
state -
note -
Throws:
NotRegisteredException

pass

public void pass(java.lang.String serviceId)
          throws NotRegisteredException
Sets a TTL service check to "passing" state

Throws:
NotRegisteredException

pass

public void pass(java.lang.String serviceId,
                 java.lang.String note)
          throws NotRegisteredException
Sets a TTL service check to "passing" state with a note

Throws:
NotRegisteredException

warn

public void warn(java.lang.String serviceId)
          throws NotRegisteredException
Sets a TTL service check to "warning" state.

Throws:
NotRegisteredException

warn

public void warn(java.lang.String serviceId,
                 java.lang.String note)
          throws NotRegisteredException
Sets a TTL service check to "warning" state with a note.

Throws:
NotRegisteredException

fail

public void fail(java.lang.String serviceId)
          throws NotRegisteredException
Sets a TTL service check to "critical" state.

Throws:
NotRegisteredException

fail

public void fail(java.lang.String serviceId,
                 java.lang.String note)
          throws NotRegisteredException
Sets a TTL service check to "critical" state with a note.

Throws:
NotRegisteredException

passCheck

public void passCheck(java.lang.String checkId)
               throws NotRegisteredException
Sets a TTL check to "passing" state

Throws:
NotRegisteredException

passCheck

public void passCheck(java.lang.String checkId,
                      java.lang.String note)
               throws NotRegisteredException
Sets a TTL check to "passing" state with a note

Throws:
NotRegisteredException

warnCheck

public void warnCheck(java.lang.String checkId)
               throws NotRegisteredException
Sets a TTL check to "warning" state.

Throws:
NotRegisteredException

warnCheck

public void warnCheck(java.lang.String checkId,
                      java.lang.String note)
               throws NotRegisteredException
Sets a TTL check to "warning" state with a note.

Throws:
NotRegisteredException

failCheck

public void failCheck(java.lang.String checkId)
               throws NotRegisteredException
Sets a TTL check to "critical" state.

Throws:
NotRegisteredException

failCheck

public void failCheck(java.lang.String checkId,
                      java.lang.String note)
               throws NotRegisteredException
Sets a TTL check to "critical" state with a note.

Throws:
NotRegisteredException

join

public boolean join(java.lang.String address)
GET /v1/agent/join/{address} Instructs the agent to join a node.

Parameters:
address - The address to join.
Returns:
true if successful, otherwise false.

join

public boolean join(java.lang.String address,
                    boolean wan)
GET /v1/agent/join/{address}?wan=1 Instructs the agent to join a node.

Parameters:
address - The address to join.
wan - Use WAN pool.
Returns:
true if successful, otherwise false.