accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject [2/3] accumulo git commit: ACCUMULO-3666 sudo to user running accumulo before start/stop
Date Thu, 19 Mar 2015 20:08:07 GMT
ACCUMULO-3666 sudo to user running accumulo before start/stop

On a system where the test is running as a user other than
the user running Accumulo, we need to sudo to the Accumulo user.


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/7edfaf79
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/7edfaf79
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/7edfaf79

Branch: refs/heads/master
Commit: 7edfaf79f8a8a7f2d099d996b82fd94e233517d3
Parents: 838a5fc
Author: Josh Elser <elserj@apache.org>
Authored: Thu Mar 19 12:07:30 2015 -0400
Committer: Josh Elser <elserj@apache.org>
Committed: Thu Mar 19 16:04:41 2015 -0400

----------------------------------------------------------------------
 TESTING.md                                         |  1 +
 .../standalone/StandaloneAccumuloCluster.java      | 10 ++++++----
 .../standalone/StandaloneClusterControl.java       | 17 ++++++++++-------
 .../apache/accumulo/harness/AccumuloClusterIT.java |  2 +-
 .../StandaloneAccumuloClusterConfiguration.java    | 16 ++++++++++++++++
 5 files changed, 34 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/7edfaf79/TESTING.md
----------------------------------------------------------------------
diff --git a/TESTING.md b/TESTING.md
index acde744..de484ee 100644
--- a/TESTING.md
+++ b/TESTING.md
@@ -88,6 +88,7 @@ The following properties can be used to configure a standalone cluster:
 - `accumulo.it.cluster.standalone.hadoop.conf`, Required: `HADOOP_CONF_DIR`
 - `accumulo.it.cluster.standalone.home`, Optional: `ACCUMULO_HOME`
 - `accumulo.it.cluster.standalone.conf`, Optional: `ACCUMULO_CONF_DIR`
+- `accumulo.it.cluster.standalone.server.user`, Optional: The user Accumulo is running as
(used to sudo when starting/stopping Accumulo). Default "accumulo"
 
 Additionally, when running with Kerberos enabled, it is required that Kerberos principals
already exist
 for the tests to use. As such, a number of properties exist to allow users to be passed down
for tests

http://git-wip-us.apache.org/repos/asf/accumulo/blob/7edfaf79/minicluster/src/main/java/org/apache/accumulo/cluster/standalone/StandaloneAccumuloCluster.java
----------------------------------------------------------------------
diff --git a/minicluster/src/main/java/org/apache/accumulo/cluster/standalone/StandaloneAccumuloCluster.java
b/minicluster/src/main/java/org/apache/accumulo/cluster/standalone/StandaloneAccumuloCluster.java
index 69a11df..dc0bc18 100644
--- a/minicluster/src/main/java/org/apache/accumulo/cluster/standalone/StandaloneAccumuloCluster.java
+++ b/minicluster/src/main/java/org/apache/accumulo/cluster/standalone/StandaloneAccumuloCluster.java
@@ -52,16 +52,18 @@ public class StandaloneAccumuloCluster implements AccumuloCluster {
   private String accumuloHome, accumuloConfDir, hadoopConfDir;
   private Path tmp;
   private List<ClusterUser> users;
+  private String serverUser;
 
-  public StandaloneAccumuloCluster(ClientConfiguration clientConf, Path tmp, List<ClusterUser>
users) {
-    this(new ZooKeeperInstance(clientConf), clientConf, tmp, users);
+  public StandaloneAccumuloCluster(ClientConfiguration clientConf, Path tmp, List<ClusterUser>
users, String serverUser) {
+    this(new ZooKeeperInstance(clientConf), clientConf, tmp, users, serverUser);
   }
 
-  public StandaloneAccumuloCluster(Instance instance, ClientConfiguration clientConf, Path
tmp, List<ClusterUser> users) {
+  public StandaloneAccumuloCluster(Instance instance, ClientConfiguration clientConf, Path
tmp, List<ClusterUser> users, String serverUser) {
     this.instance = instance;
     this.clientConf = clientConf;
     this.tmp = tmp;
     this.users = users;
+    this.serverUser = serverUser;
   }
 
   public String getAccumuloHome() {
@@ -116,7 +118,7 @@ public class StandaloneAccumuloCluster implements AccumuloCluster {
 
   @Override
   public StandaloneClusterControl getClusterControl() {
-    return new StandaloneClusterControl(null == accumuloHome ? System.getenv("ACCUMULO_HOME")
: accumuloHome,
+    return new StandaloneClusterControl(serverUser, null == accumuloHome ? System.getenv("ACCUMULO_HOME")
: accumuloHome,
         null == accumuloConfDir ? System.getenv("ACCUMULO_CONF_DIR") : accumuloConfDir);
   }
 

http://git-wip-us.apache.org/repos/asf/accumulo/blob/7edfaf79/minicluster/src/main/java/org/apache/accumulo/cluster/standalone/StandaloneClusterControl.java
----------------------------------------------------------------------
diff --git a/minicluster/src/main/java/org/apache/accumulo/cluster/standalone/StandaloneClusterControl.java
b/minicluster/src/main/java/org/apache/accumulo/cluster/standalone/StandaloneClusterControl.java
index 7cc80c0..ebc6143 100644
--- a/minicluster/src/main/java/org/apache/accumulo/cluster/standalone/StandaloneClusterControl.java
+++ b/minicluster/src/main/java/org/apache/accumulo/cluster/standalone/StandaloneClusterControl.java
@@ -45,20 +45,23 @@ import com.google.common.collect.Maps;
 public class StandaloneClusterControl implements ClusterControl {
   private static final Logger log = LoggerFactory.getLogger(StandaloneClusterControl.class);
 
+  private static final String SUDO_CMD = "sudo";
   private static final String START_SERVER_SCRIPT = "start-server.sh", ACCUMULO_SCRIPT =
"accumulo", TOOL_SCRIPT = "tool.sh";
   private static final String MASTER_HOSTS_FILE = "masters", GC_HOSTS_FILE = "gc", TSERVER_HOSTS_FILE
= "slaves", TRACER_HOSTS_FILE = "tracers",
       MONITOR_HOSTS_FILE = "monitor";
 
+  protected String user;
   protected String accumuloHome, accumuloConfDir;
   protected RemoteShellOptions options;
 
   protected String startServerPath, accumuloPath, toolPath;
 
-  public StandaloneClusterControl() {
-    this(System.getenv("ACCUMULO_HOME"), System.getenv("ACCUMULO_CONF_DIR"));
+  public StandaloneClusterControl(String user) {
+    this(user, System.getenv("ACCUMULO_HOME"), System.getenv("ACCUMULO_CONF_DIR"));
   }
 
-  public StandaloneClusterControl(String accumuloHome, String accumuloConfDir) {
+  public StandaloneClusterControl(String user, String accumuloHome, String accumuloConfDir)
{
+    this.user = user;
     this.options = new RemoteShellOptions();
     this.accumuloHome = accumuloHome;
     this.accumuloConfDir = accumuloConfDir;
@@ -132,7 +135,7 @@ public class StandaloneClusterControl implements ClusterControl {
   public void adminStopAll() throws IOException {
     File confDir = getConfDir();
     String master = getHosts(new File(confDir, "masters")).get(0);
-    String[] cmd = new String[] {accumuloPath, Admin.class.getName(), "stopAll"};
+    String[] cmd = new String[] {SUDO_CMD, "-u", user, accumuloPath, Admin.class.getName(),
"stopAll"};
     Entry<Integer,String> pair = exec(master, cmd);
     if (0 != pair.getKey().intValue()) {
       throw new IOException("stopAll did not finish successfully, retcode=" + pair.getKey()
+ ", stdout=" + pair.getValue());
@@ -185,7 +188,7 @@ public class StandaloneClusterControl implements ClusterControl {
 
   @Override
   public void start(ServerType server, String hostname) throws IOException {
-    String[] cmd = new String[] {startServerPath, hostname, getProcessString(server)};
+    String[] cmd = new String[] {SUDO_CMD, "-u", user, startServerPath, hostname, getProcessString(server)};
     Entry<Integer,String> pair = exec(hostname, cmd);
     if (0 != pair.getKey()) {
       throw new IOException("Start " + server + " on " + hostname + " failed for execute
successfully");
@@ -252,9 +255,9 @@ public class StandaloneClusterControl implements ClusterControl {
 
     String[] stopCmd;
     if (isSignalNumber) {
-      stopCmd = new String[] {"kill", "-" + signal, pid};
+      stopCmd = new String[] {SUDO_CMD, "-u", user, "kill", "-" + signal, pid};
     } else {
-      stopCmd = new String[] {"kill", "-s", signal, pid};
+      stopCmd = new String[] {SUDO_CMD, "-u", user, "kill", "-s", signal, pid};
     }
 
     Entry<Integer,String> pair = exec(hostname, stopCmd);

http://git-wip-us.apache.org/repos/asf/accumulo/blob/7edfaf79/test/src/test/java/org/apache/accumulo/harness/AccumuloClusterIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/harness/AccumuloClusterIT.java b/test/src/test/java/org/apache/accumulo/harness/AccumuloClusterIT.java
index 930b275..250e01e 100644
--- a/test/src/test/java/org/apache/accumulo/harness/AccumuloClusterIT.java
+++ b/test/src/test/java/org/apache/accumulo/harness/AccumuloClusterIT.java
@@ -129,7 +129,7 @@ public abstract class AccumuloClusterIT extends AccumuloIT implements
MiniCluste
       case STANDALONE:
         StandaloneAccumuloClusterConfiguration conf = (StandaloneAccumuloClusterConfiguration)
clusterConf;
         ClientConfiguration clientConf = conf.getClientConf();
-        StandaloneAccumuloCluster standaloneCluster = new StandaloneAccumuloCluster(conf.getInstance(),
clientConf, conf.getTmpDirectory(), conf.getUsers());
+        StandaloneAccumuloCluster standaloneCluster = new StandaloneAccumuloCluster(conf.getInstance(),
clientConf, conf.getTmpDirectory(), conf.getUsers(), conf.getAccumuloServerUser());
         // If these are provided in the configuration, pass them into the cluster
         standaloneCluster.setAccumuloHome(conf.getAccumuloHome());
         standaloneCluster.setAccumuloConfDir(conf.getAccumuloConfDir());

http://git-wip-us.apache.org/repos/asf/accumulo/blob/7edfaf79/test/src/test/java/org/apache/accumulo/harness/conf/StandaloneAccumuloClusterConfiguration.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/harness/conf/StandaloneAccumuloClusterConfiguration.java
b/test/src/test/java/org/apache/accumulo/harness/conf/StandaloneAccumuloClusterConfiguration.java
index 49fbc28..aed0a21 100644
--- a/test/src/test/java/org/apache/accumulo/harness/conf/StandaloneAccumuloClusterConfiguration.java
+++ b/test/src/test/java/org/apache/accumulo/harness/conf/StandaloneAccumuloClusterConfiguration.java
@@ -58,6 +58,8 @@ public class StandaloneAccumuloClusterConfiguration extends AccumuloClusterPrope
   public static final String ACCUMULO_STANDALONE_INSTANCE_NAME_DEFAULT = "accumulo";
   public static final String ACCUMULO_STANDALONE_TMP_DIR_KEY = ACCUMULO_STANDALONE_PREFIX
+ "tmpdir";
   public static final String ACCUMULO_STANDALONE_TMP_DIR_DEFAULT = "/tmp";
+  public static final String ACCUMULO_STANDALONE_SERVER_USER = ACCUMULO_STANDALONE_PREFIX
+ "server.user";
+  public static final String ACCUMULO_STANDALONE_SERVER_USER_DEFAULT = "accumulo";
 
   // A set of users we can use to connect to this instances
   public static final String ACCUMULO_STANDALONE_USER_KEY = ACCUMULO_STANDALONE_PREFIX +
"users.";
@@ -71,6 +73,7 @@ public class StandaloneAccumuloClusterConfiguration extends AccumuloClusterPrope
   public static final String ACCUMULO_STANDALONE_HADOOP_CONF = ACCUMULO_STANDALONE_PREFIX
+ "hadoop.conf";
 
   private Map<String,String> conf;
+  private String serverUser;
   private File clientConfFile;
   private ClientConfiguration clientConf;
   private List<ClusterUser> clusterUsers;
@@ -98,6 +101,12 @@ public class StandaloneAccumuloClusterConfiguration extends AccumuloClusterPrope
       clientConf.withZkHosts(getZooKeepers());
     }
 
+    // The user Accumulo is running as
+    serverUser = conf.get(ACCUMULO_STANDALONE_SERVER_USER);
+    if (null == serverUser) {
+      serverUser = ACCUMULO_STANDALONE_SERVER_USER_DEFAULT;
+    }
+
     clusterUsers = new ArrayList<>();
     for (Entry<String,String> entry : conf.entrySet()) {
       String key = entry.getKey();
@@ -230,4 +239,11 @@ public class StandaloneAccumuloClusterConfiguration extends AccumuloClusterPrope
   public List<ClusterUser> getUsers() {
     return Collections.unmodifiableList(clusterUsers);
   }
+
+  /**
+   * @return The user Accumulo is running as
+   */
+  public String getAccumuloServerUser() {
+    return serverUser;
+  }
 }


Mime
View raw message