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
Nested ClassesModifier and TypeClassDescriptionprivate static enumRepresents of the high-level health status of a subject in the cluster.private static enumprivate static enumRepresents the configured run state of a role.(package private) static enumNested classes/interfaces inherited from interface org.apache.hadoop.hbase.ClusterManager
ClusterManager.ServiceType -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate final org.apache.hbase.thirdparty.javax.ws.rs.client.Clientprivate Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate ClusterManagerprivate static final org.slf4j.Loggerprivate static final org.apache.hbase.thirdparty.com.google.gson.JsonParserprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate static final Stringprivate org.apache.hadoop.hbase.util.RetryCounterFactoryprivate static final Map<ClusterManager.ServiceType,RESTApiClusterManager.Service> private String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static Map<ClusterManager.ServiceType,RESTApiClusterManager.Service> private longdoRoleCommand(String serviceName, String roleName, RESTApiClusterManager.RoleCommand roleCommand) Issues a command (e.g.private <T> TexecuteWithRetries(Callable<T> callable) Helper method for executing retryable work.private Optional<org.apache.hbase.thirdparty.com.google.gson.JsonObject>getCommand(long commandId) private StringgetFromURIGet(URI uri) getHealthSummary(String serviceName, String roleType, String hostId) private Stringprivate StringgetRoleName(String serviceName, String roleType, String hostId) private StringgetRolePropertyValue(String serviceName, String roleType, String hostId, String property) private RESTApiClusterManager.RoleStategetRoleState(String serviceName, String roleType, String hostId) private RESTApiClusterManager.RoleStategetRoleState(ClusterManager.ServiceType service, String hostname) private Stringprivate booleanhasCommandCompleted(long commandId) Returntrueif thecommandIdhas finished processing.private booleanhasCommandCompletedSuccessfully(long commandId) Returntrueif thecommandIdhas finished successfully.booleanisRunning(ClusterManager.ServiceType service, String hostname, int port) Returns whether the service is running on the remote host.voidkill(ClusterManager.ServiceType service, String hostname, int port) Kills the service running on the given hostprivate voidperformClusterManagerCommand(ClusterManager.ServiceType role, String hostname, RESTApiClusterManager.RoleCommand command) voidrestart(ClusterManager.ServiceType service, String hostname, int port) Restart the service on the given hostvoidresume(ClusterManager.ServiceType service, String hostname, int port) Resumes the services running on the given hostvoidsetConf(org.apache.hadoop.conf.Configuration conf) voidstart(ClusterManager.ServiceType service, String hostname, int port) Start the service on the given hostvoidstop(ClusterManager.ServiceType service, String hostname, int port) Stop the service on the given hostvoidsuspend(ClusterManager.ServiceType service, String hostname, int port) Suspends the service running on the given hostprivate voidMethods inherited from class org.apache.hadoop.conf.Configured
getConfMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
setConfin interfaceorg.apache.hadoop.conf.Configurable- Overrides:
setConfin classorg.apache.hadoop.conf.Configured
-
start
Description copied from interface:ClusterManagerStart the service on the given host- Specified by:
startin interfaceClusterManager
-
stop
Description copied from interface:ClusterManagerStop the service on the given host- Specified by:
stopin interfaceClusterManager
-
restart
Description copied from interface:ClusterManagerRestart the service on the given host- Specified by:
restartin interfaceClusterManager
-
isRunning
Description copied from interface:ClusterManagerReturns whether the service is running on the remote host. This only checks whether the service still has a pid.- Specified by:
isRunningin interfaceClusterManager
-
kill
Description copied from interface:ClusterManagerKills the service running on the given host- Specified by:
killin interfaceClusterManager- Throws:
IOException
-
suspend
public void suspend(ClusterManager.ServiceType service, String hostname, int port) throws IOException Description copied from interface:ClusterManagerSuspends the service running on the given host- Specified by:
suspendin interfaceClusterManager- Throws:
IOException
-
resume
public void resume(ClusterManager.ServiceType service, String hostname, int port) throws IOException Description copied from interface:ClusterManagerResumes the services running on the given host- Specified by:
resumein 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
Returntrueif thecommandIdhas finished processing. -
hasCommandCompletedSuccessfully
Returntrueif thecommandIdhas finished successfully. -
executeWithRetries
Helper method for executing retryable work. -
waitFor
-
buildRoleServiceTypeMap
private static Map<ClusterManager.ServiceType,RESTApiClusterManager.Service> buildRoleServiceTypeMap()
-