Package org.apache.hadoop.hbase
Class RESTApiClusterManager
java.lang.Object
org.apache.hadoop.conf.Configured
org.apache.hadoop.hbase.RESTApiClusterManager
- All Implemented Interfaces:
org.apache.hadoop.conf.Configurable
,ClusterManager
public class RESTApiClusterManager
extends org.apache.hadoop.conf.Configured
implements ClusterManager
A ClusterManager implementation designed to control Cloudera Manager (http://www.cloudera.com)
clusters via REST API. This API uses HTTP GET requests against the cluster manager server to
retrieve information and POST/PUT requests to perform actions. As a simple example, to retrieve a
list of hosts from a CM server with login credentials admin:admin, a simple curl command would be
curl -X POST -H "Content-Type:application/json" -u admin:admin \
"http://this.is.my.server.com:7180/api/v8/hosts" This command would return a JSON result, which
would need to be parsed to retrieve relevant information. This action and many others are covered
by this class. A note on nomenclature: while the ClusterManager interface uses a ServiceType enum
when referring to things like RegionServers and DataNodes, cluster managers often use different
terminology. As an example, Cloudera Manager (http://www.cloudera.com) would refer to a
RegionServer as a "role" of the HBase "service." It would further refer to "hbase" as the
"serviceType." Apache Ambari (http://ambari.apache.org) would call the RegionServer a "component"
of the HBase "service." This class will defer to the ClusterManager terminology in methods that
it implements from that interface, but uses Cloudera Manager's terminology when dealing with its
API directly. DEBUG-level logging gives more details of the actions this class takes as they
happen. Log at TRACE-level to see the API requests and responses. TRACE-level logging on
RetryCounter displays wait times, so that can be helpful too.
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate static enum
Represents of the high-level health status of a subject in the cluster.private static enum
private static enum
Represents the configured run state of a role.(package private) static enum
Nested classes/interfaces inherited from interface org.apache.hadoop.hbase.ClusterManager
ClusterManager.ServiceType
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final String
private final org.apache.hbase.thirdparty.javax.ws.rs.client.Client
private String
private static final String
private static final String
private static final String
private static final String
private ClusterManager
private static final org.slf4j.Logger
private static final org.apache.hbase.thirdparty.com.google.gson.JsonParser
private static final String
private static final String
private static final String
private static final String
private static final String
private org.apache.hadoop.hbase.util.RetryCounterFactory
private static final Map<ClusterManager.ServiceType,
RESTApiClusterManager.Service> private String
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate static Map<ClusterManager.ServiceType,
RESTApiClusterManager.Service> private long
doRoleCommand
(String serviceName, String roleName, RESTApiClusterManager.RoleCommand roleCommand) Issues a command (e.g.private <T> T
executeWithRetries
(Callable<T> callable) Helper method for executing retryable work.private Optional<org.apache.hbase.thirdparty.com.google.gson.JsonObject>
getCommand
(long commandId) private String
getFromURIGet
(URI uri) getHealthSummary
(String serviceName, String roleType, String hostId) private String
private String
getRoleName
(String serviceName, String roleType, String hostId) private String
getRolePropertyValue
(String serviceName, String roleType, String hostId, String property) private RESTApiClusterManager.RoleState
getRoleState
(String serviceName, String roleType, String hostId) private RESTApiClusterManager.RoleState
getRoleState
(ClusterManager.ServiceType service, String hostname) private String
private boolean
hasCommandCompleted
(long commandId) Returntrue
if thecommandId
has finished processing.private boolean
hasCommandCompletedSuccessfully
(long commandId) Returntrue
if thecommandId
has finished successfully.boolean
isRunning
(ClusterManager.ServiceType service, String hostname, int port) Returns whether the service is running on the remote host.void
kill
(ClusterManager.ServiceType service, String hostname, int port) Kills the service running on the given hostprivate void
performClusterManagerCommand
(ClusterManager.ServiceType role, String hostname, RESTApiClusterManager.RoleCommand command) void
restart
(ClusterManager.ServiceType service, String hostname, int port) Restart the service on the given hostvoid
resume
(ClusterManager.ServiceType service, String hostname, int port) Resumes the services running on the given hostvoid
setConf
(org.apache.hadoop.conf.Configuration conf) void
start
(ClusterManager.ServiceType service, String hostname, int port) Start the service on the given hostvoid
stop
(ClusterManager.ServiceType service, String hostname, int port) Stop the service on the given hostvoid
suspend
(ClusterManager.ServiceType service, String hostname, int port) Suspends the service running on the given hostprivate void
Methods inherited from class org.apache.hadoop.conf.Configured
getConf
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.hadoop.conf.Configurable
getConf
-
Field Details
-
REST_API_CLUSTER_MANAGER_HOSTNAME
- See Also:
-
REST_API_CLUSTER_MANAGER_USERNAME
- See Also:
-
REST_API_CLUSTER_MANAGER_PASSWORD
- See Also:
-
REST_API_CLUSTER_MANAGER_CLUSTER_NAME
- See Also:
-
REST_API_DELEGATE_CLUSTER_MANAGER
- See Also:
-
parser
-
DEFAULT_SERVER_HOSTNAME
- See Also:
-
DEFAULT_SERVER_USERNAME
- See Also:
-
DEFAULT_SERVER_PASSWORD
- See Also:
-
DEFAULT_CLUSTER_NAME
- See Also:
-
serverHostname
-
clusterName
-
API_VERSION
- See Also:
-
client
-
hBaseClusterManager
-
retryCounterFactory
-
LOG
-
roleServiceType
-
-
Constructor Details
-
RESTApiClusterManager
-
-
Method Details
-
setConf
- Specified by:
setConf
in interfaceorg.apache.hadoop.conf.Configurable
- Overrides:
setConf
in classorg.apache.hadoop.conf.Configured
-
start
Description copied from interface:ClusterManager
Start the service on the given host- Specified by:
start
in interfaceClusterManager
-
stop
Description copied from interface:ClusterManager
Stop the service on the given host- Specified by:
stop
in interfaceClusterManager
-
restart
Description copied from interface:ClusterManager
Restart the service on the given host- Specified by:
restart
in interfaceClusterManager
-
isRunning
Description copied from interface:ClusterManager
Returns whether the service is running on the remote host. This only checks whether the service still has a pid.- Specified by:
isRunning
in interfaceClusterManager
-
kill
Description copied from interface:ClusterManager
Kills the service running on the given host- Specified by:
kill
in interfaceClusterManager
- Throws:
IOException
-
suspend
public void suspend(ClusterManager.ServiceType service, String hostname, int port) throws IOException Description copied from interface:ClusterManager
Suspends the service running on the given host- Specified by:
suspend
in interfaceClusterManager
- Throws:
IOException
-
resume
public void resume(ClusterManager.ServiceType service, String hostname, int port) throws IOException Description copied from interface:ClusterManager
Resumes the services running on the given host- Specified by:
resume
in interfaceClusterManager
- Throws:
IOException
-
performClusterManagerCommand
private void performClusterManagerCommand(ClusterManager.ServiceType role, String hostname, RESTApiClusterManager.RoleCommand command) -
doRoleCommand
private long doRoleCommand(String serviceName, String roleName, RESTApiClusterManager.RoleCommand roleCommand) Issues a command (e.g. starting or stopping a role).- Returns:
- the commandId of a successfully submitted asynchronous command.
-
getHealthSummary
private RESTApiClusterManager.HealthSummary getHealthSummary(String serviceName, String roleType, String hostId) -
getHostId
-
getFromURIGet
-
getRoleName
-
getRolePropertyValue
-
getRoleState
private RESTApiClusterManager.RoleState getRoleState(ClusterManager.ServiceType service, String hostname) -
getRoleState
private RESTApiClusterManager.RoleState getRoleState(String serviceName, String roleType, String hostId) -
getServiceName
-
getCommand
-
hasCommandCompleted
Returntrue
if thecommandId
has finished processing. -
hasCommandCompletedSuccessfully
Returntrue
if thecommandId
has finished successfully. -
executeWithRetries
Helper method for executing retryable work. -
waitFor
-
buildRoleServiceTypeMap
private static Map<ClusterManager.ServiceType,RESTApiClusterManager.Service> buildRoleServiceTypeMap()
-