HBASE-12680 Move signal related code from ClusterManager to HBaseClusterManager and change ClusterManager to an interface

Summary: The reason of this change is to make us write implementation of ClusterManager not using ssh/unix signals.

Test Plan: The compilation is OK.

Reviewers: eclark, manukranthk

Differential Revision: https://reviews.facebook.net/D30201

Signed-off-by: Elliott Clark <eclark@apache.org>
This commit is contained in:
Yi Deng 2014-12-12 14:08:48 -08:00 committed by Elliott Clark
parent ae684cac87
commit 555d14ed45
2 changed files with 37 additions and 40 deletions

View File

@ -20,10 +20,8 @@ package org.apache.hadoop.hbase;
import java.io.IOException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.conf.Configured;
/**
@ -32,16 +30,7 @@ import org.apache.hadoop.conf.Configured;
* functionality for carrying out deployment-specific tasks.
*/
@InterfaceAudience.Private
public abstract class ClusterManager extends Configured {
protected static final Log LOG = LogFactory.getLog(ClusterManager.class);
private static final String SIGKILL = "SIGKILL";
private static final String SIGSTOP = "SIGSTOP";
private static final String SIGCONT = "SIGCONT";
public ClusterManager() {
}
interface ClusterManager extends Configurable {
/**
* Type of the service daemon
*/
@ -72,50 +61,38 @@ public abstract class ClusterManager extends Configured {
/**
* Start the service on the given host
*/
public abstract void start(ServiceType service, String hostname) throws IOException;
void start(ServiceType service, String hostname) throws IOException;
/**
* Stop the service on the given host
*/
public abstract void stop(ServiceType service, String hostname) throws IOException;
void stop(ServiceType service, String hostname) throws IOException;
/**
* Restart the service on the given host
* Restarts the service on the given host
*/
public abstract void restart(ServiceType service, String hostname) throws IOException;
void restart(ServiceType service, String hostname) throws IOException;
/**
* Send the given posix signal to the service
* Kills the service running on the given host
*/
public abstract void signal(ServiceType service, String signal,
String hostname) throws IOException;
void kill(ServiceType service, String hostname) throws IOException;
/**
* Kill the service running on given host
* Suspends the service running on the given host
*/
public void kill(ServiceType service, String hostname) throws IOException {
signal(service, SIGKILL, hostname);
}
void suspend(ServiceType service, String hostname) throws IOException;
/**
* Suspend the service running on given host
* Resumes the services running on the given host
*/
public void suspend(ServiceType service, String hostname) throws IOException {
signal(service, SIGSTOP, hostname);
}
/**
* Resume the services running on given hosts
*/
public void resume(ServiceType service, String hostname) throws IOException {
signal(service, SIGCONT, hostname);
}
void resume(ServiceType service, String hostname) throws IOException;
/**
* Returns whether the service is running on the remote host. This only checks whether the
* service still has a pid.
*/
public abstract boolean isRunning(ServiceType service, String hostname) throws IOException;
boolean isRunning(ServiceType service, String hostname) throws IOException;
/* TODO: further API ideas:
*

View File

@ -24,7 +24,10 @@ import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.hbase.HBaseClusterManager.CommandProvider.Operation;
import org.apache.hadoop.hbase.util.Pair;
import org.apache.hadoop.hbase.util.RetryCounter;
@ -37,10 +40,15 @@ import org.apache.hadoop.util.Shell;
* to manage the cluster. Assumes Unix-like commands are available like 'ps',
* 'kill', etc. Also assumes the user running the test has enough "power" to start & stop
* servers on the remote machines (for example, the test user could be the same user as the
* user the daemon isrunning as)
* user the daemon is running as)
*/
@InterfaceAudience.Private
public class HBaseClusterManager extends ClusterManager {
public class HBaseClusterManager extends Configured implements ClusterManager {
private static final String SIGKILL = "SIGKILL";
private static final String SIGSTOP = "SIGSTOP";
private static final String SIGCONT = "SIGCONT";
protected static final Log LOG = LogFactory.getLog(HBaseClusterManager.class);
private String sshUserName;
private String sshOptions;
@ -181,7 +189,6 @@ public class HBaseClusterManager extends ClusterManager {
}
public HBaseClusterManager() {
super();
}
protected CommandProvider getCommandProvider(ServiceType service) {
@ -263,7 +270,6 @@ public class HBaseClusterManager extends ClusterManager {
exec(hostname, service, Operation.RESTART);
}
@Override
public void signal(ServiceType service, String signal, String hostname) throws IOException {
execWithRetries(hostname, getCommandProvider(service).signalCommand(service, signal));
}
@ -275,4 +281,18 @@ public class HBaseClusterManager extends ClusterManager {
return ret.length() > 0;
}
@Override
public void kill(ServiceType service, String hostname) throws IOException {
signal(service, SIGKILL, hostname);
}
@Override
public void suspend(ServiceType service, String hostname) throws IOException {
signal(service, SIGSTOP, hostname);
}
@Override
public void resume(ServiceType service, String hostname) throws IOException {
signal(service, SIGCONT, hostname);
}
}