From f69ffd9e6e0208c867d14b02e6a13d548bc5d18d Mon Sep 17 00:00:00 2001 From: Yi Deng Date: Fri, 12 Dec 2014 14:08:48 -0800 Subject: [PATCH] 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 --- .../org/apache/hadoop/hbase/ClusterManager.java | 46 +++++++--------------- .../apache/hadoop/hbase/HBaseClusterManager.java | 27 +++++++++++-- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/ClusterManager.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/ClusterManager.java index 836fbe8..2431109 100644 --- a/hbase-it/src/test/java/org/apache/hadoop/hbase/ClusterManager.java +++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/ClusterManager.java @@ -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,43 @@ 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 */ - public abstract void signal(ServiceType service, String signal, - String hostname) throws IOException; + void signal(ServiceType service, String signal, String hostname) throws IOException; /** - * Kill the service running on given host + * Kills the service running on the given host */ - public void kill(ServiceType service, String hostname) throws IOException { - signal(service, SIGKILL, hostname); - } + void kill(ServiceType service, String hostname) throws IOException; /** - * Suspend the service running on given host + * Suspends the service running on the given host */ - public void suspend(ServiceType service, String hostname) throws IOException { - signal(service, SIGSTOP, hostname); - } + void suspend(ServiceType service, String hostname) throws IOException; /** - * Resume the services running on given hosts + * Resumes the services running on the given host */ - 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: * diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/HBaseClusterManager.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/HBaseClusterManager.java index 8203088..0015e59 100644 --- a/hbase-it/src/test/java/org/apache/hadoop/hbase/HBaseClusterManager.java +++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/HBaseClusterManager.java @@ -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) { @@ -275,4 +282,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); + } } -- 1.9.3 (Apple Git-50)