accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [15/16] accumulo git commit: Merge branch '1.7'
Date Wed, 03 Feb 2016 17:54:08 GMT
http://git-wip-us.apache.org/repos/asf/accumulo/blob/dc087b12/test/src/main/java/org/apache/accumulo/harness/AccumuloClusterHarness.java
----------------------------------------------------------------------
diff --cc test/src/main/java/org/apache/accumulo/harness/AccumuloClusterHarness.java
index 30058db,0000000..ba95f2b
mode 100644,000000..100644
--- a/test/src/main/java/org/apache/accumulo/harness/AccumuloClusterHarness.java
+++ b/test/src/main/java/org/apache/accumulo/harness/AccumuloClusterHarness.java
@@@ -1,338 -1,0 +1,337 @@@
 +/*
 + * Licensed to the Apache Software Foundation (ASF) under one or more
 + * contributor license agreements.  See the NOTICE file distributed with
 + * this work for additional information regarding copyright ownership.
 + * The ASF licenses this file to You under the Apache License, Version 2.0
 + * (the "License"); you may not use this file except in compliance with
 + * the License.  You may obtain a copy of the License at
 + *
 + *     http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +package org.apache.accumulo.harness;
 +
++import static com.google.common.base.Preconditions.checkState;
 +import static java.nio.charset.StandardCharsets.UTF_8;
 +import static org.junit.Assert.fail;
 +
 +import java.io.IOException;
 +
 +import org.apache.accumulo.cluster.AccumuloCluster;
 +import org.apache.accumulo.cluster.ClusterControl;
 +import org.apache.accumulo.cluster.ClusterUser;
 +import org.apache.accumulo.cluster.ClusterUsers;
 +import org.apache.accumulo.cluster.standalone.StandaloneAccumuloCluster;
 +import org.apache.accumulo.core.client.ClientConfiguration;
 +import org.apache.accumulo.core.client.ClientConfiguration.ClientProperty;
 +import org.apache.accumulo.core.client.Connector;
 +import org.apache.accumulo.core.client.admin.SecurityOperations;
 +import org.apache.accumulo.core.client.admin.TableOperations;
 +import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
 +import org.apache.accumulo.core.client.security.tokens.KerberosToken;
 +import org.apache.accumulo.core.client.security.tokens.PasswordToken;
 +import org.apache.accumulo.core.conf.Property;
 +import org.apache.accumulo.core.security.TablePermission;
 +import org.apache.accumulo.harness.conf.AccumuloClusterConfiguration;
 +import org.apache.accumulo.harness.conf.AccumuloClusterPropertyConfiguration;
 +import org.apache.accumulo.harness.conf.AccumuloMiniClusterConfiguration;
 +import org.apache.accumulo.harness.conf.StandaloneAccumuloClusterConfiguration;
 +import org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl;
 +import org.apache.accumulo.minicluster.impl.MiniAccumuloConfigImpl;
 +import org.apache.hadoop.conf.Configuration;
 +import org.apache.hadoop.fs.FileSystem;
 +import org.apache.hadoop.fs.Path;
 +import org.apache.hadoop.security.UserGroupInformation;
 +import org.junit.After;
 +import org.junit.AfterClass;
 +import org.junit.Assume;
 +import org.junit.Before;
 +import org.junit.BeforeClass;
 +import org.slf4j.Logger;
 +import org.slf4j.LoggerFactory;
 +
- import com.google.common.base.Preconditions;
- 
 +/**
 + * General Integration-Test base class that provides access to an Accumulo instance for testing. This instance could be MAC or a standalone instance.
 + */
 +public abstract class AccumuloClusterHarness extends AccumuloITBase implements MiniClusterConfigurationCallback, ClusterUsers {
 +  private static final Logger log = LoggerFactory.getLogger(AccumuloClusterHarness.class);
 +  private static final String TRUE = Boolean.toString(true);
 +
 +  public static enum ClusterType {
 +    MINI, STANDALONE;
 +
 +    public boolean isDynamic() {
 +      return this == MINI;
 +    }
 +  }
 +
 +  private static boolean initialized = false;
 +
 +  protected static AccumuloCluster cluster;
 +  protected static ClusterType type;
 +  protected static AccumuloClusterPropertyConfiguration clusterConf;
 +  protected static TestingKdc krb;
 +
 +  @BeforeClass
 +  public static void setUp() throws Exception {
 +    clusterConf = AccumuloClusterPropertyConfiguration.get();
 +    type = clusterConf.getClusterType();
 +
 +    if (ClusterType.MINI == type && TRUE.equals(System.getProperty(MiniClusterHarness.USE_KERBEROS_FOR_IT_OPTION))) {
 +      krb = new TestingKdc();
 +      krb.start();
 +      log.info("MiniKdc started");
 +    }
 +
 +    initialized = true;
 +  }
 +
 +  @AfterClass
 +  public static void tearDownKdc() throws Exception {
 +    if (null != krb) {
 +      krb.stop();
 +    }
 +  }
 +
 +  /**
 +   * The {@link TestingKdc} used for this {@link AccumuloCluster}. Might be null.
 +   */
 +  public static TestingKdc getKdc() {
 +    return krb;
 +  }
 +
 +  @Before
 +  public void setupCluster() throws Exception {
 +    // Before we try to instantiate the cluster, check to see if the test even wants to run against this type of cluster
 +    Assume.assumeTrue(canRunTest(type));
 +
 +    switch (type) {
 +      case MINI:
 +        MiniClusterHarness miniClusterHarness = new MiniClusterHarness();
 +        // Intrinsically performs the callback to let tests alter MiniAccumuloConfig and core-site.xml
 +        MiniAccumuloClusterImpl impl = miniClusterHarness.create(this, getAdminToken(), krb);
 +        cluster = impl;
 +        // MAC makes a ClientConf for us, just set it
 +        ((AccumuloMiniClusterConfiguration) clusterConf).setClientConf(impl.getClientConfig());
 +        // Login as the "root" user
 +        if (null != krb) {
 +          ClusterUser rootUser = krb.getRootUser();
 +          // Log in the 'client' user
 +          UserGroupInformation.loginUserFromKeytab(rootUser.getPrincipal(), rootUser.getKeytab().getAbsolutePath());
 +        }
 +        break;
 +      case STANDALONE:
 +        StandaloneAccumuloClusterConfiguration conf = (StandaloneAccumuloClusterConfiguration) clusterConf;
 +        ClientConfiguration clientConf = conf.getClientConf();
 +        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.setClientAccumuloConfDir(conf.getClientAccumuloConfDir());
 +        standaloneCluster.setServerAccumuloConfDir(conf.getServerAccumuloConfDir());
 +        standaloneCluster.setHadoopConfDir(conf.getHadoopConfDir());
 +
 +        // For SASL, we need to get the Hadoop configuration files as well otherwise UGI will log in as SIMPLE instead of KERBEROS
 +        Configuration hadoopConfiguration = standaloneCluster.getHadoopConfiguration();
 +        if (clientConf.getBoolean(ClientProperty.INSTANCE_RPC_SASL_ENABLED.getKey(), false)) {
 +          UserGroupInformation.setConfiguration(hadoopConfiguration);
 +          // Login as the admin user to start the tests
 +          UserGroupInformation.loginUserFromKeytab(conf.getAdminPrincipal(), conf.getAdminKeytab().getAbsolutePath());
 +        }
 +
 +        // Set the implementation
 +        cluster = standaloneCluster;
 +        break;
 +      default:
 +        throw new RuntimeException("Unhandled type");
 +    }
 +
 +    if (type.isDynamic()) {
 +      cluster.start();
 +    } else {
 +      log.info("Removing tables which appear to be from a previous test run");
 +      cleanupTables();
 +      log.info("Removing users which appear to be from a previous test run");
 +      cleanupUsers();
 +    }
 +
 +    switch (type) {
 +      case MINI:
 +        if (null != krb) {
 +          final String traceTable = Property.TRACE_TABLE.getDefaultValue();
 +          final ClusterUser systemUser = krb.getAccumuloServerUser(), rootUser = krb.getRootUser();
 +
 +          // Login as the trace user
 +          UserGroupInformation.loginUserFromKeytab(systemUser.getPrincipal(), systemUser.getKeytab().getAbsolutePath());
 +
 +          // Open a connector as the system user (ensures the user will exist for us to assign permissions to)
 +          Connector conn = cluster.getConnector(systemUser.getPrincipal(), new KerberosToken(systemUser.getPrincipal(), systemUser.getKeytab(), true));
 +
 +          // Then, log back in as the "root" user and do the grant
 +          UserGroupInformation.loginUserFromKeytab(rootUser.getPrincipal(), rootUser.getKeytab().getAbsolutePath());
 +          conn = getConnector();
 +
 +          // Create the trace table
 +          conn.tableOperations().create(traceTable);
 +
 +          // Trace user (which is the same kerberos principal as the system user, but using a normal KerberosToken) needs
 +          // to have the ability to read, write and alter the trace table
 +          conn.securityOperations().grantTablePermission(systemUser.getPrincipal(), traceTable, TablePermission.READ);
 +          conn.securityOperations().grantTablePermission(systemUser.getPrincipal(), traceTable, TablePermission.WRITE);
 +          conn.securityOperations().grantTablePermission(systemUser.getPrincipal(), traceTable, TablePermission.ALTER_TABLE);
 +        }
 +        break;
 +      default:
 +        // do nothing
 +    }
 +  }
 +
 +  public void cleanupTables() throws Exception {
 +    final String tablePrefix = this.getClass().getSimpleName() + "_";
 +    final TableOperations tops = getConnector().tableOperations();
 +    for (String table : tops.list()) {
 +      if (table.startsWith(tablePrefix)) {
 +        log.debug("Removing table {}", table);
 +        tops.delete(table);
 +      }
 +    }
 +  }
 +
 +  public void cleanupUsers() throws Exception {
 +    final String userPrefix = this.getClass().getSimpleName();
 +    final SecurityOperations secOps = getConnector().securityOperations();
 +    for (String user : secOps.listLocalUsers()) {
 +      if (user.startsWith(userPrefix)) {
 +        log.info("Dropping local user {}", user);
 +        secOps.dropLocalUser(user);
 +      }
 +    }
 +  }
 +
 +  @After
 +  public void teardownCluster() throws Exception {
 +    if (null != cluster) {
 +      if (type.isDynamic()) {
 +        cluster.stop();
 +      } else {
 +        log.info("Removing tables which appear to be from the current test");
 +        cleanupTables();
 +        log.info("Removing users which appear to be from the current test");
 +        cleanupUsers();
 +      }
 +    }
 +  }
 +
 +  public static AccumuloCluster getCluster() {
-     Preconditions.checkState(initialized);
++    checkState(initialized);
 +    return cluster;
 +  }
 +
 +  public static ClusterControl getClusterControl() {
-     Preconditions.checkState(initialized);
++    checkState(initialized);
 +    return cluster.getClusterControl();
 +  }
 +
 +  public static ClusterType getClusterType() {
-     Preconditions.checkState(initialized);
++    checkState(initialized);
 +    return type;
 +  }
 +
 +  public static String getAdminPrincipal() {
-     Preconditions.checkState(initialized);
++    checkState(initialized);
 +    return clusterConf.getAdminPrincipal();
 +  }
 +
 +  public static AuthenticationToken getAdminToken() {
-     Preconditions.checkState(initialized);
++    checkState(initialized);
 +    return clusterConf.getAdminToken();
 +  }
 +
 +  @Override
 +  public ClusterUser getAdminUser() {
 +    switch (type) {
 +      case MINI:
 +        if (null == krb) {
 +          PasswordToken passwordToken = (PasswordToken) getAdminToken();
 +          return new ClusterUser(getAdminPrincipal(), new String(passwordToken.getPassword(), UTF_8));
 +        }
 +        return krb.getRootUser();
 +      case STANDALONE:
 +        return new ClusterUser(getAdminPrincipal(), ((StandaloneAccumuloClusterConfiguration) clusterConf).getAdminKeytab());
 +      default:
 +        throw new RuntimeException("Unknown cluster type");
 +    }
 +  }
 +
 +  @Override
 +  public ClusterUser getUser(int offset) {
 +    switch (type) {
 +      case MINI:
 +        if (null != krb) {
 +          // Defer to the TestingKdc when kerberos is on so we can get the keytab instead of a password
 +          return krb.getClientPrincipal(offset);
 +        } else {
 +          // Come up with a mostly unique name
 +          String principal = getClass().getSimpleName() + "_" + testName.getMethodName() + "_" + offset;
 +          // Username and password are the same
 +          return new ClusterUser(principal, principal);
 +        }
 +      case STANDALONE:
 +        return ((StandaloneAccumuloCluster) cluster).getUser(offset);
 +      default:
 +        throw new RuntimeException("Unknown cluster type");
 +    }
 +  }
 +
 +  public static FileSystem getFileSystem() throws IOException {
-     Preconditions.checkState(initialized);
++    checkState(initialized);
 +    return cluster.getFileSystem();
 +  }
 +
 +  public static AccumuloClusterConfiguration getClusterConfiguration() {
-     Preconditions.checkState(initialized);
++    checkState(initialized);
 +    return clusterConf;
 +  }
 +
 +  public Connector getConnector() {
 +    try {
 +      String princ = getAdminPrincipal();
 +      AuthenticationToken token = getAdminToken();
 +      log.debug("Creating connector as {} with {}", princ, token);
 +      return cluster.getConnector(princ, token);
 +    } catch (Exception e) {
 +      log.error("Could not connect to Accumulo", e);
 +      fail("Could not connect to Accumulo: " + e.getMessage());
 +
 +      throw new RuntimeException("Could not connect to Accumulo", e);
 +    }
 +  }
 +
 +  // TODO Really don't want this here. Will ultimately need to abstract configuration method away from MAConfig
 +  // and change over to something more generic
 +  @Override
 +  public void configureMiniCluster(MiniAccumuloConfigImpl cfg, Configuration hadoopCoreSite) {}
 +
 +  /**
 +   * A test may not be capable of running against a given AccumuloCluster. Implementations can override this method to advertise that they cannot (or perhaps do
 +   * not) want to run the test.
 +   */
 +  public boolean canRunTest(ClusterType type) {
 +    return true;
 +  }
 +
 +  /**
 +   * Tries to give a reasonable directory which can be used to create temporary files for the test. Makes a basic attempt to create the directory if it does not
 +   * already exist.
 +   *
 +   * @return A directory which can be expected to exist on the Cluster's FileSystem
 +   */
 +  public Path getUsableDir() throws IllegalArgumentException, IOException {
 +    return cluster.getTemporaryPath();
 +  }
 +}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dc087b12/test/src/main/java/org/apache/accumulo/harness/MiniClusterHarness.java
----------------------------------------------------------------------
diff --cc test/src/main/java/org/apache/accumulo/harness/MiniClusterHarness.java
index f021e32,0000000..e1df97e
mode 100644,000000..100644
--- a/test/src/main/java/org/apache/accumulo/harness/MiniClusterHarness.java
+++ b/test/src/main/java/org/apache/accumulo/harness/MiniClusterHarness.java
@@@ -1,242 -1,0 +1,242 @@@
 +/*
 + * Licensed to the Apache Software Foundation (ASF) under one or more
 + * contributor license agreements.  See the NOTICE file distributed with
 + * this work for additional information regarding copyright ownership.
 + * The ASF licenses this file to You under the Apache License, Version 2.0
 + * (the "License"); you may not use this file except in compliance with
 + * the License.  You may obtain a copy of the License at
 + *
 + *     http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +package org.apache.accumulo.harness;
 +
++import static com.google.common.base.Preconditions.checkArgument;
 +import static java.nio.charset.StandardCharsets.UTF_8;
++import static java.util.Objects.requireNonNull;
 +import static org.junit.Assert.assertTrue;
 +
 +import java.io.BufferedOutputStream;
 +import java.io.File;
 +import java.io.FileOutputStream;
 +import java.io.OutputStream;
 +import java.util.Map;
 +import java.util.UUID;
 +import java.util.concurrent.atomic.AtomicLong;
 +
 +import org.apache.accumulo.cluster.ClusterUser;
 +import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
 +import org.apache.accumulo.core.client.security.tokens.KerberosToken;
 +import org.apache.accumulo.core.client.security.tokens.PasswordToken;
 +import org.apache.accumulo.core.conf.Property;
 +import org.apache.accumulo.minicluster.impl.MiniAccumuloClusterImpl;
 +import org.apache.accumulo.minicluster.impl.MiniAccumuloConfigImpl;
 +import org.apache.accumulo.server.security.handler.KerberosAuthenticator;
 +import org.apache.accumulo.server.security.handler.KerberosAuthorizor;
 +import org.apache.accumulo.server.security.handler.KerberosPermissionHandler;
 +import org.apache.accumulo.test.functional.NativeMapIT;
 +import org.apache.accumulo.test.util.CertUtils;
 +import org.apache.hadoop.conf.Configuration;
 +import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
 +import org.slf4j.Logger;
 +import org.slf4j.LoggerFactory;
 +
- import com.google.common.base.Preconditions;
- 
 +/**
 + * Harness that sets up a MiniAccumuloCluster in a manner expected for Accumulo integration tests.
 + */
 +public class MiniClusterHarness {
 +  private static final Logger log = LoggerFactory.getLogger(MiniClusterHarness.class);
 +
 +  private static final AtomicLong COUNTER = new AtomicLong(0);
 +
 +  public static final String USE_SSL_FOR_IT_OPTION = "org.apache.accumulo.test.functional.useSslForIT",
 +      USE_CRED_PROVIDER_FOR_IT_OPTION = "org.apache.accumulo.test.functional.useCredProviderForIT",
 +      USE_KERBEROS_FOR_IT_OPTION = "org.apache.accumulo.test.functional.useKrbForIT", TRUE = Boolean.toString(true);
 +
 +  // TODO These are defined in MiniKdc >= 2.6.0. Can be removed when minimum Hadoop dependency is increased to that.
 +  public static final String JAVA_SECURITY_KRB5_CONF = "java.security.krb5.conf", SUN_SECURITY_KRB5_DEBUG = "sun.security.krb5.debug";
 +
 +  /**
 +   * Create a MiniAccumuloCluster using the given Token as the credentials for the root user.
 +   */
 +  public MiniAccumuloClusterImpl create(AuthenticationToken token) throws Exception {
 +    return create(MiniClusterHarness.class.getName(), Long.toString(COUNTER.incrementAndGet()), token);
 +  }
 +
 +  public MiniAccumuloClusterImpl create(AuthenticationToken token, TestingKdc kdc) throws Exception {
 +    return create(MiniClusterHarness.class.getName(), Long.toString(COUNTER.incrementAndGet()), token, kdc);
 +  }
 +
 +  public MiniAccumuloClusterImpl create(AccumuloITBase testBase, AuthenticationToken token) throws Exception {
 +    return create(testBase.getClass().getName(), testBase.testName.getMethodName(), token);
 +  }
 +
 +  public MiniAccumuloClusterImpl create(AccumuloITBase testBase, AuthenticationToken token, TestingKdc kdc) throws Exception {
 +    return create(testBase, token, kdc, MiniClusterConfigurationCallback.NO_CALLBACK);
 +  }
 +
 +  public MiniAccumuloClusterImpl create(AccumuloITBase testBase, AuthenticationToken token, TestingKdc kdc, MiniClusterConfigurationCallback configCallback)
 +      throws Exception {
 +    return create(testBase.getClass().getName(), testBase.testName.getMethodName(), token, configCallback, kdc);
 +  }
 +
 +  public MiniAccumuloClusterImpl create(AccumuloClusterHarness testBase, AuthenticationToken token, TestingKdc kdc) throws Exception {
 +    return create(testBase.getClass().getName(), testBase.testName.getMethodName(), token, testBase, kdc);
 +  }
 +
 +  public MiniAccumuloClusterImpl create(AccumuloClusterHarness testBase, AuthenticationToken token, MiniClusterConfigurationCallback callback) throws Exception {
 +    return create(testBase.getClass().getName(), testBase.testName.getMethodName(), token, callback);
 +  }
 +
 +  public MiniAccumuloClusterImpl create(String testClassName, String testMethodName, AuthenticationToken token) throws Exception {
 +    return create(testClassName, testMethodName, token, MiniClusterConfigurationCallback.NO_CALLBACK);
 +  }
 +
 +  public MiniAccumuloClusterImpl create(String testClassName, String testMethodName, AuthenticationToken token, TestingKdc kdc) throws Exception {
 +    return create(testClassName, testMethodName, token, MiniClusterConfigurationCallback.NO_CALLBACK, kdc);
 +  }
 +
 +  public MiniAccumuloClusterImpl create(String testClassName, String testMethodName, AuthenticationToken token, MiniClusterConfigurationCallback configCallback)
 +      throws Exception {
 +    return create(testClassName, testMethodName, token, configCallback, null);
 +  }
 +
 +  public MiniAccumuloClusterImpl create(String testClassName, String testMethodName, AuthenticationToken token,
 +      MiniClusterConfigurationCallback configCallback, TestingKdc kdc) throws Exception {
-     Preconditions.checkNotNull(token);
-     Preconditions.checkArgument(token instanceof PasswordToken || token instanceof KerberosToken, "A PasswordToken or KerberosToken is required");
++    requireNonNull(token);
++    checkArgument(token instanceof PasswordToken || token instanceof KerberosToken, "A PasswordToken or KerberosToken is required");
 +
 +    String rootPasswd;
 +    if (token instanceof PasswordToken) {
 +      rootPasswd = new String(((PasswordToken) token).getPassword(), UTF_8);
 +    } else {
 +      rootPasswd = UUID.randomUUID().toString();
 +    }
 +
 +    File baseDir = AccumuloClusterHarness.createTestDir(testClassName + "_" + testMethodName);
 +    MiniAccumuloConfigImpl cfg = new MiniAccumuloConfigImpl(baseDir, rootPasswd);
 +
 +    // Enable native maps by default
 +    cfg.setNativeLibPaths(NativeMapIT.nativeMapLocation().getAbsolutePath());
 +    cfg.setProperty(Property.TSERV_NATIVEMAP_ENABLED, Boolean.TRUE.toString());
 +
 +    Configuration coreSite = new Configuration(false);
 +
 +    // Setup SSL and credential providers if the properties request such
 +    configureForEnvironment(cfg, getClass(), AccumuloClusterHarness.getSslDir(baseDir), coreSite, kdc);
 +
 +    // Invoke the callback for tests to configure MAC before it starts
 +    configCallback.configureMiniCluster(cfg, coreSite);
 +
 +    MiniAccumuloClusterImpl miniCluster = new MiniAccumuloClusterImpl(cfg);
 +
 +    // Write out any configuration items to a file so HDFS will pick them up automatically (from the classpath)
 +    if (coreSite.size() > 0) {
 +      File csFile = new File(miniCluster.getConfig().getConfDir(), "core-site.xml");
 +      if (csFile.exists())
 +        throw new RuntimeException(csFile + " already exist");
 +
 +      OutputStream out = new BufferedOutputStream(new FileOutputStream(new File(miniCluster.getConfig().getConfDir(), "core-site.xml")));
 +      coreSite.writeXml(out);
 +      out.close();
 +    }
 +
 +    return miniCluster;
 +  }
 +
 +  protected void configureForEnvironment(MiniAccumuloConfigImpl cfg, Class<?> testClass, File folder, Configuration coreSite, TestingKdc kdc) {
 +    if (TRUE.equals(System.getProperty(USE_SSL_FOR_IT_OPTION))) {
 +      configureForSsl(cfg, folder);
 +    }
 +    if (TRUE.equals(System.getProperty(USE_CRED_PROVIDER_FOR_IT_OPTION))) {
 +      cfg.setUseCredentialProvider(true);
 +    }
 +
 +    if (TRUE.equals(System.getProperty(USE_KERBEROS_FOR_IT_OPTION))) {
 +      if (TRUE.equals(System.getProperty(USE_SSL_FOR_IT_OPTION))) {
 +        throw new RuntimeException("Cannot use both SSL and Kerberos");
 +      }
 +
 +      try {
 +        configureForKerberos(cfg, folder, coreSite, kdc);
 +      } catch (Exception e) {
 +        throw new RuntimeException("Failed to initialize KDC", e);
 +      }
 +    }
 +  }
 +
 +  protected void configureForSsl(MiniAccumuloConfigImpl cfg, File folder) {
 +    Map<String,String> siteConfig = cfg.getSiteConfig();
 +    if (TRUE.equals(siteConfig.get(Property.INSTANCE_RPC_SSL_ENABLED.getKey()))) {
 +      // already enabled; don't mess with it
 +      return;
 +    }
 +
 +    File sslDir = new File(folder, "ssl");
 +    assertTrue(sslDir.mkdirs() || sslDir.isDirectory());
 +    File rootKeystoreFile = new File(sslDir, "root-" + cfg.getInstanceName() + ".jks");
 +    File localKeystoreFile = new File(sslDir, "local-" + cfg.getInstanceName() + ".jks");
 +    File publicTruststoreFile = new File(sslDir, "public-" + cfg.getInstanceName() + ".jks");
 +    final String rootKeystorePassword = "root_keystore_password", truststorePassword = "truststore_password";
 +    try {
 +      new CertUtils(Property.RPC_SSL_KEYSTORE_TYPE.getDefaultValue(), "o=Apache Accumulo,cn=MiniAccumuloCluster", "RSA", 2048, "sha1WithRSAEncryption")
 +          .createAll(rootKeystoreFile, localKeystoreFile, publicTruststoreFile, cfg.getInstanceName(), rootKeystorePassword, cfg.getRootPassword(),
 +              truststorePassword);
 +    } catch (Exception e) {
 +      throw new RuntimeException("error creating MAC keystore", e);
 +    }
 +
 +    siteConfig.put(Property.INSTANCE_RPC_SSL_ENABLED.getKey(), "true");
 +    siteConfig.put(Property.RPC_SSL_KEYSTORE_PATH.getKey(), localKeystoreFile.getAbsolutePath());
 +    siteConfig.put(Property.RPC_SSL_KEYSTORE_PASSWORD.getKey(), cfg.getRootPassword());
 +    siteConfig.put(Property.RPC_SSL_TRUSTSTORE_PATH.getKey(), publicTruststoreFile.getAbsolutePath());
 +    siteConfig.put(Property.RPC_SSL_TRUSTSTORE_PASSWORD.getKey(), truststorePassword);
 +    cfg.setSiteConfig(siteConfig);
 +  }
 +
 +  protected void configureForKerberos(MiniAccumuloConfigImpl cfg, File folder, Configuration coreSite, TestingKdc kdc) throws Exception {
 +    Map<String,String> siteConfig = cfg.getSiteConfig();
 +    if (TRUE.equals(siteConfig.get(Property.INSTANCE_RPC_SSL_ENABLED.getKey()))) {
 +      throw new RuntimeException("Cannot use both SSL and SASL/Kerberos");
 +    }
 +
 +    if (TRUE.equals(siteConfig.get(Property.INSTANCE_RPC_SASL_ENABLED.getKey()))) {
 +      // already enabled
 +      return;
 +    }
 +
 +    if (null == kdc) {
 +      throw new IllegalStateException("MiniClusterKdc was null");
 +    }
 +
 +    log.info("Enabling Kerberos/SASL for minicluster");
 +
 +    // Turn on SASL and set the keytab/principal information
 +    cfg.setProperty(Property.INSTANCE_RPC_SASL_ENABLED, "true");
 +    ClusterUser serverUser = kdc.getAccumuloServerUser();
 +    cfg.setProperty(Property.GENERAL_KERBEROS_KEYTAB, serverUser.getKeytab().getAbsolutePath());
 +    cfg.setProperty(Property.GENERAL_KERBEROS_PRINCIPAL, serverUser.getPrincipal());
 +    cfg.setProperty(Property.INSTANCE_SECURITY_AUTHENTICATOR, KerberosAuthenticator.class.getName());
 +    cfg.setProperty(Property.INSTANCE_SECURITY_AUTHORIZOR, KerberosAuthorizor.class.getName());
 +    cfg.setProperty(Property.INSTANCE_SECURITY_PERMISSION_HANDLER, KerberosPermissionHandler.class.getName());
 +    // Piggy-back on the "system user" credential, but use it as a normal KerberosToken, not the SystemToken.
 +    cfg.setProperty(Property.TRACE_USER, serverUser.getPrincipal());
 +    cfg.setProperty(Property.TRACE_TOKEN_TYPE, KerberosToken.CLASS_NAME);
 +
 +    // Pass down some KRB5 debug properties
 +    Map<String,String> systemProperties = cfg.getSystemProperties();
 +    systemProperties.put(JAVA_SECURITY_KRB5_CONF, System.getProperty(JAVA_SECURITY_KRB5_CONF, ""));
 +    systemProperties.put(SUN_SECURITY_KRB5_DEBUG, System.getProperty(SUN_SECURITY_KRB5_DEBUG, "false"));
 +    cfg.setSystemProperties(systemProperties);
 +
 +    // Make sure UserGroupInformation will do the correct login
 +    coreSite.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
 +
 +    cfg.setRootUserName(kdc.getRootUser().getPrincipal());
 +  }
 +}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dc087b12/test/src/main/java/org/apache/accumulo/harness/TestingKdc.java
----------------------------------------------------------------------
diff --cc test/src/main/java/org/apache/accumulo/harness/TestingKdc.java
index 653139a,0000000..8e976a8
mode 100644,000000..100644
--- a/test/src/main/java/org/apache/accumulo/harness/TestingKdc.java
+++ b/test/src/main/java/org/apache/accumulo/harness/TestingKdc.java
@@@ -1,219 -1,0 +1,219 @@@
 +/*
 + * Licensed to the Apache Software Foundation (ASF) under one or more
 + * contributor license agreements.  See the NOTICE file distributed with
 + * this work for additional information regarding copyright ownership.
 + * The ASF licenses this file to You under the Apache License, Version 2.0
 + * (the "License"); you may not use this file except in compliance with
 + * the License.  You may obtain a copy of the License at
 + *
 + *     http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +package org.apache.accumulo.harness;
 +
 +import static com.google.common.base.Preconditions.checkArgument;
- import static com.google.common.base.Preconditions.checkNotNull;
++import static java.util.Objects.requireNonNull;
 +import static org.junit.Assert.assertTrue;
 +
 +import java.io.File;
 +import java.net.InetAddress;
 +import java.util.ArrayList;
 +import java.util.List;
 +import java.util.Properties;
 +
 +import org.apache.accumulo.cluster.ClusterUser;
 +import org.apache.hadoop.minikdc.MiniKdc;
 +import org.junit.Assert;
 +import org.slf4j.Logger;
 +import org.slf4j.LoggerFactory;
 +
 +/**
 + * Creates a {@link MiniKdc} for tests to use to exercise secure Accumulo
 + */
 +public class TestingKdc {
 +  private static final Logger log = LoggerFactory.getLogger(TestingKdc.class);
 +
 +  public static final int NUM_USERS = 10;
 +  public static final long MAX_TICKET_LIFETIME_MILLIS = 86400000; // one day
 +
 +  protected MiniKdc kdc = null;
 +  protected ClusterUser accumuloServerUser = null, accumuloAdmin = null;
 +  protected List<ClusterUser> clientPrincipals = null;
 +
 +  public final String ORG_NAME = "EXAMPLE", ORG_DOMAIN = "COM";
 +
 +  private String hostname;
 +  private File keytabDir;
 +  private boolean started = false;
 +
 +  public TestingKdc() throws Exception {
 +    this(computeKdcDir(), computeKeytabDir(), MAX_TICKET_LIFETIME_MILLIS);
 +  }
 +
 +  public static File computeKdcDir() {
 +    File targetDir = new File(System.getProperty("user.dir"), "target");
 +    if (!targetDir.exists())
 +      Assert.assertTrue(targetDir.mkdirs());
 +    Assert.assertTrue("Could not find Maven target directory: " + targetDir, targetDir.exists() && targetDir.isDirectory());
 +
 +    // Create the directories: target/kerberos/minikdc
 +    File kdcDir = new File(new File(targetDir, "kerberos"), "minikdc");
 +
 +    assertTrue(kdcDir.mkdirs() || kdcDir.isDirectory());
 +
 +    return kdcDir;
 +  }
 +
 +  public static File computeKeytabDir() {
 +    File targetDir = new File(System.getProperty("user.dir"), "target");
 +    Assert.assertTrue("Could not find Maven target directory: " + targetDir, targetDir.exists() && targetDir.isDirectory());
 +
 +    // Create the directories: target/kerberos/keytabs
 +    File keytabDir = new File(new File(targetDir, "kerberos"), "keytabs");
 +
 +    assertTrue(keytabDir.mkdirs() || keytabDir.isDirectory());
 +
 +    return keytabDir;
 +  }
 +
 +  public TestingKdc(File kdcDir, File keytabDir) throws Exception {
 +    this(kdcDir, keytabDir, MAX_TICKET_LIFETIME_MILLIS);
 +  }
 +
 +  public TestingKdc(File kdcDir, File keytabDir, long maxTicketLifetime) throws Exception {
-     checkNotNull(kdcDir, "KDC directory was null");
-     checkNotNull(keytabDir, "Keytab directory was null");
++    requireNonNull(kdcDir, "KDC directory was null");
++    requireNonNull(keytabDir, "Keytab directory was null");
 +    checkArgument(maxTicketLifetime > 0, "Ticket lifetime must be positive");
 +
 +    this.keytabDir = keytabDir;
 +    this.hostname = InetAddress.getLocalHost().getCanonicalHostName();
 +
 +    log.debug("Starting MiniKdc in {} with keytabs in {}", kdcDir, keytabDir);
 +
 +    Properties kdcConf = MiniKdc.createConf();
 +    kdcConf.setProperty(MiniKdc.ORG_NAME, ORG_NAME);
 +    kdcConf.setProperty(MiniKdc.ORG_DOMAIN, ORG_DOMAIN);
 +    kdcConf.setProperty(MiniKdc.MAX_TICKET_LIFETIME, Long.toString(maxTicketLifetime));
 +    // kdcConf.setProperty(MiniKdc.DEBUG, "true");
 +    kdc = new MiniKdc(kdcConf, kdcDir);
 +  }
 +
 +  /**
 +   * Starts the KDC and creates the principals and their keytabs
 +   */
 +  public synchronized void start() throws Exception {
 +    checkArgument(!started, "KDC was already started");
 +    kdc.start();
 +    Thread.sleep(1000);
 +
 +    // Create the identity for accumulo servers
 +    File accumuloKeytab = new File(keytabDir, "accumulo.keytab");
 +    String accumuloPrincipal = String.format("accumulo/%s", hostname);
 +
 +    log.info("Creating Kerberos principal {} with keytab {}", accumuloPrincipal, accumuloKeytab);
 +    kdc.createPrincipal(accumuloKeytab, accumuloPrincipal);
 +
 +    accumuloServerUser = new ClusterUser(qualifyUser(accumuloPrincipal), accumuloKeytab);
 +
 +    // Create the identity for the "root" user
 +    String rootPrincipal = "root";
 +    File rootKeytab = new File(keytabDir, rootPrincipal + ".keytab");
 +
 +    log.info("Creating Kerberos principal {} with keytab {}", rootPrincipal, rootKeytab);
 +    kdc.createPrincipal(rootKeytab, rootPrincipal);
 +
 +    accumuloAdmin = new ClusterUser(qualifyUser(rootPrincipal), rootKeytab);
 +
 +    clientPrincipals = new ArrayList<>(NUM_USERS);
 +    // Create a number of unprivileged users for tests to use
 +    for (int i = 1; i <= NUM_USERS; i++) {
 +      String clientPrincipal = "client" + i;
 +      File clientKeytab = new File(keytabDir, clientPrincipal + ".keytab");
 +
 +      log.info("Creating Kerberos principal {} with keytab {}", clientPrincipal, clientKeytab);
 +      kdc.createPrincipal(clientKeytab, clientPrincipal);
 +
 +      clientPrincipals.add(new ClusterUser(qualifyUser(clientPrincipal), clientKeytab));
 +    }
 +
 +    started = true;
 +  }
 +
 +  public synchronized void stop() throws Exception {
 +    checkArgument(started, "KDC is not started");
 +    kdc.stop();
 +    started = false;
 +  }
 +
 +  /**
 +   * A directory where the automatically-created keytab files are written
 +   */
 +  public File getKeytabDir() {
 +    return keytabDir;
 +  }
 +
 +  /**
 +   * A {@link ClusterUser} for Accumulo server processes to use
 +   */
 +  public ClusterUser getAccumuloServerUser() {
 +    checkArgument(started, "The KDC is not started");
 +    return accumuloServerUser;
 +  }
 +
 +  /**
 +   * A {@link ClusterUser} which is the Accumulo "root" user
 +   */
 +  public ClusterUser getRootUser() {
 +    checkArgument(started, "The KDC is not started");
 +    return accumuloAdmin;
 +  }
 +
 +  /**
 +   * The {@link ClusterUser} corresponding to the given offset. Represents an unprivileged user.
 +   *
 +   * @param offset
 +   *          The offset to fetch credentials for, valid through {@link #NUM_USERS}
 +   */
 +  public ClusterUser getClientPrincipal(int offset) {
 +    checkArgument(started, "Client principal is not initialized, is the KDC started?");
 +    checkArgument(offset >= 0 && offset < NUM_USERS, "Offset is invalid, must be non-negative and less than " + NUM_USERS);
 +    return clientPrincipals.get(offset);
 +  }
 +
 +  /**
 +   * @see MiniKdc#createPrincipal(File, String...)
 +   */
 +  public void createPrincipal(File keytabFile, String... principals) throws Exception {
 +    checkArgument(started, "KDC is not started");
 +    kdc.createPrincipal(keytabFile, principals);
 +  }
 +
 +  /**
 +   * @return the name for the realm
 +   */
 +  public String getOrgName() {
 +    return ORG_NAME;
 +  }
 +
 +  /**
 +   * @return the domain for the realm
 +   */
 +  public String getOrgDomain() {
 +    return ORG_DOMAIN;
 +  }
 +
 +  /**
 +   * Qualify a username (only the primary from the kerberos principal) with the proper realm
 +   *
 +   * @param primary
 +   *          The primary or primary and instance
 +   */
 +  public String qualifyUser(String primary) {
 +    return String.format("%s@%s.%s", primary, getOrgName(), getOrgDomain());
 +  }
 +}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dc087b12/test/src/main/java/org/apache/accumulo/harness/conf/AccumuloClusterPropertyConfiguration.java
----------------------------------------------------------------------
diff --cc test/src/main/java/org/apache/accumulo/harness/conf/AccumuloClusterPropertyConfiguration.java
index 2300da3,0000000..cedb4d0
mode 100644,000000..100644
--- a/test/src/main/java/org/apache/accumulo/harness/conf/AccumuloClusterPropertyConfiguration.java
+++ b/test/src/main/java/org/apache/accumulo/harness/conf/AccumuloClusterPropertyConfiguration.java
@@@ -1,195 -1,0 +1,195 @@@
 +/*
 + * Licensed to the Apache Software Foundation (ASF) under one or more
 + * contributor license agreements.  See the NOTICE file distributed with
 + * this work for additional information regarding copyright ownership.
 + * The ASF licenses this file to You under the Apache License, Version 2.0
 + * (the "License"); you may not use this file except in compliance with
 + * the License.  You may obtain a copy of the License at
 + *
 + *     http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +package org.apache.accumulo.harness.conf;
 +
++import static java.util.Objects.requireNonNull;
++
 +import java.io.File;
 +import java.io.FileNotFoundException;
 +import java.io.FileReader;
 +import java.io.IOException;
 +import java.util.HashMap;
 +import java.util.Map;
 +import java.util.Map.Entry;
 +import java.util.Properties;
 +
 +import org.apache.accumulo.harness.AccumuloClusterHarness.ClusterType;
 +import org.slf4j.Logger;
 +import org.slf4j.LoggerFactory;
 +
- import com.google.common.base.Preconditions;
- 
 +/**
 + * Base class for extracting configuration values from Java Properties
 + */
 +public abstract class AccumuloClusterPropertyConfiguration implements AccumuloClusterConfiguration {
 +  private static final Logger log = LoggerFactory.getLogger(AccumuloClusterPropertyConfiguration.class);
 +
 +  public static final String ACCUMULO_IT_PROPERTIES_FILE = "accumulo.it.properties";
 +
 +  public static final String ACCUMULO_CLUSTER_TYPE_KEY = "accumulo.it.cluster.type";
 +
 +  public static final String ACCUMULO_MINI_PREFIX = "accumulo.it.cluster.mini.";
 +  public static final String ACCUMULO_STANDALONE_PREFIX = "accumulo.it.cluster.standalone.";
 +
 +  public static final String ACCUMULO_CLUSTER_CLIENT_CONF_KEY = "accumulo.it.cluster.clientconf";
 +
 +  protected ClusterType clusterType;
 +
 +  public static AccumuloClusterPropertyConfiguration get() {
 +    Properties systemProperties = System.getProperties();
 +
 +    String clusterTypeValue = null, clientConf = null;
 +    String propertyFile = systemProperties.getProperty(ACCUMULO_IT_PROPERTIES_FILE);
 +
 +    if (null != propertyFile) {
 +      // Check for properties provided in a file
 +      File f = new File(propertyFile);
 +      if (f.exists() && f.isFile() && f.canRead()) {
 +        Properties fileProperties = new Properties();
 +        FileReader reader = null;
 +        try {
 +          reader = new FileReader(f);
 +        } catch (FileNotFoundException e) {
 +          log.warn("Could not read properties from specified file: {}", propertyFile, e);
 +        }
 +
 +        if (null != reader) {
 +          try {
 +            fileProperties.load(reader);
 +          } catch (IOException e) {
 +            log.warn("Could not load properties from specified file: {}", propertyFile, e);
 +          } finally {
 +            try {
 +              reader.close();
 +            } catch (IOException e) {
 +              log.warn("Could not close reader", e);
 +            }
 +          }
 +
 +          clusterTypeValue = fileProperties.getProperty(ACCUMULO_CLUSTER_TYPE_KEY);
 +          clientConf = fileProperties.getProperty(ACCUMULO_CLUSTER_CLIENT_CONF_KEY);
 +        }
 +      } else {
 +        log.debug("Property file ({}) is not a readable file", propertyFile);
 +      }
 +    } else {
 +      log.debug("No properties file found in {}", ACCUMULO_IT_PROPERTIES_FILE);
 +    }
 +
 +    if (null == clusterTypeValue) {
 +      clusterTypeValue = systemProperties.getProperty(ACCUMULO_CLUSTER_TYPE_KEY);
 +    }
 +
 +    if (null == clientConf) {
 +      clientConf = systemProperties.getProperty(ACCUMULO_CLUSTER_CLIENT_CONF_KEY);
 +    }
 +
 +    ClusterType type;
 +    if (null == clusterTypeValue) {
 +      type = ClusterType.MINI;
 +    } else {
 +      type = ClusterType.valueOf(clusterTypeValue);
 +    }
 +
 +    log.info("Using {} cluster type from system properties", type);
 +
 +    switch (type) {
 +      case MINI:
 +        // we'll let no client conf pass through and expect that the caller will set it after MAC is started
 +        return new AccumuloMiniClusterConfiguration();
 +      case STANDALONE:
 +        if (null == clientConf) {
 +          throw new RuntimeException("Expected client configuration to be provided: " + ACCUMULO_CLUSTER_CLIENT_CONF_KEY);
 +        }
 +        File clientConfFile = new File(clientConf);
 +        if (!clientConfFile.exists() || !clientConfFile.isFile()) {
 +          throw new RuntimeException("Client configuration should be a normal file: " + clientConfFile);
 +        }
 +        return new StandaloneAccumuloClusterConfiguration(clientConfFile);
 +      default:
 +        throw new RuntimeException("Clusters other than MiniAccumuloCluster are not yet implemented");
 +    }
 +  }
 +
 +  public Map<String,String> getConfiguration(ClusterType type) {
-     Preconditions.checkNotNull(type);
++    requireNonNull(type);
 +
 +    String prefix;
 +    switch (type) {
 +      case MINI:
 +        prefix = ACCUMULO_MINI_PREFIX;
 +        break;
 +      case STANDALONE:
 +        prefix = ACCUMULO_STANDALONE_PREFIX;
 +        break;
 +      default:
 +        throw new IllegalArgumentException("Unknown ClusterType: " + type);
 +    }
 +
 +    Map<String,String> configuration = new HashMap<String,String>();
 +
 +    Properties systemProperties = System.getProperties();
 +
 +    String propertyFile = systemProperties.getProperty(ACCUMULO_IT_PROPERTIES_FILE);
 +
 +    // Check for properties provided in a file
 +    if (null != propertyFile) {
 +      File f = new File(propertyFile);
 +      if (f.exists() && f.isFile() && f.canRead()) {
 +        Properties fileProperties = new Properties();
 +        FileReader reader = null;
 +        try {
 +          reader = new FileReader(f);
 +        } catch (FileNotFoundException e) {
 +          log.warn("Could not read properties from specified file: {}", propertyFile, e);
 +        }
 +
 +        if (null != reader) {
 +          try {
 +            fileProperties.load(reader);
 +            loadFromProperties(prefix, fileProperties, configuration);
 +          } catch (IOException e) {
 +            log.warn("Could not load properties from specified file: {}", propertyFile, e);
 +          } finally {
 +            try {
 +              reader.close();
 +            } catch (IOException e) {
 +              log.warn("Could not close reader", e);
 +            }
 +          }
 +        }
 +      }
 +    }
 +
 +    // Load any properties specified directly in the system properties
 +    loadFromProperties(prefix, systemProperties, configuration);
 +
 +    return configuration;
 +  }
 +
 +  protected void loadFromProperties(String desiredPrefix, Properties properties, Map<String,String> configuration) {
 +    for (Entry<Object,Object> entry : properties.entrySet()) {
 +      if (!(entry.getKey() instanceof String)) {
 +        continue;
 +      }
 +
 +      String key = (String) entry.getKey();
 +      if (key.startsWith(desiredPrefix)) {
 +        configuration.put(key, (String) entry.getValue());
 +      }
 +    }
 +  }
 +}

http://git-wip-us.apache.org/repos/asf/accumulo/blob/dc087b12/test/src/main/java/org/apache/accumulo/harness/conf/AccumuloMiniClusterConfiguration.java
----------------------------------------------------------------------
diff --cc test/src/main/java/org/apache/accumulo/harness/conf/AccumuloMiniClusterConfiguration.java
index 4d233a5,0000000..0a43621
mode 100644,000000..100644
--- a/test/src/main/java/org/apache/accumulo/harness/conf/AccumuloMiniClusterConfiguration.java
+++ b/test/src/main/java/org/apache/accumulo/harness/conf/AccumuloMiniClusterConfiguration.java
@@@ -1,117 -1,0 +1,117 @@@
 +/*
 + * Licensed to the Apache Software Foundation (ASF) under one or more
 + * contributor license agreements.  See the NOTICE file distributed with
 + * this work for additional information regarding copyright ownership.
 + * The ASF licenses this file to You under the Apache License, Version 2.0
 + * (the "License"); you may not use this file except in compliance with
 + * the License.  You may obtain a copy of the License at
 + *
 + *     http://www.apache.org/licenses/LICENSE-2.0
 + *
 + * Unless required by applicable law or agreed to in writing, software
 + * distributed under the License is distributed on an "AS IS" BASIS,
 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 + * See the License for the specific language governing permissions and
 + * limitations under the License.
 + */
 +package org.apache.accumulo.harness.conf;
 +
++import static java.util.Objects.requireNonNull;
++
 +import java.io.IOException;
 +import java.util.Map;
 +
 +import org.apache.accumulo.cluster.ClusterUser;
 +import org.apache.accumulo.core.client.ClientConfiguration;
 +import org.apache.accumulo.core.client.security.tokens.AuthenticationToken;
 +import org.apache.accumulo.core.client.security.tokens.KerberosToken;
 +import org.apache.accumulo.core.client.security.tokens.PasswordToken;
 +import org.apache.accumulo.harness.AccumuloClusterHarness;
 +import org.apache.accumulo.harness.AccumuloClusterHarness.ClusterType;
 +import org.apache.accumulo.harness.MiniClusterHarness;
 +import org.apache.hadoop.conf.Configuration;
 +import org.apache.hadoop.fs.CommonConfigurationKeysPublic;
 +import org.apache.hadoop.security.UserGroupInformation;
 +import org.slf4j.Logger;
 +import org.slf4j.LoggerFactory;
 +
- import com.google.common.base.Preconditions;
- 
 +/**
 + * Extract configuration properties for a MiniAccumuloCluster from Java properties
 + */
 +public class AccumuloMiniClusterConfiguration extends AccumuloClusterPropertyConfiguration {
 +  private static final Logger log = LoggerFactory.getLogger(AccumuloMiniClusterConfiguration.class);
 +  private static final String TRUE = Boolean.toString(true);
 +
 +  public static final String ACCUMULO_MINI_PRINCIPAL_KEY = ACCUMULO_MINI_PREFIX + "principal";
 +  public static final String ACCUMULO_MINI_PRINCIPAL_DEFAULT = "root";
 +  public static final String ACCUMULO_MINI_PASSWORD_KEY = ACCUMULO_MINI_PREFIX + "password";
 +  public static final String ACCUMULO_MINI_PASSWORD_DEFAULT = "rootPassword1";
 +
 +  private final Map<String,String> conf;
 +  private final boolean saslEnabled;
 +  private ClientConfiguration clientConf;
 +
 +  public AccumuloMiniClusterConfiguration() {
 +    ClusterType type = getClusterType();
 +    if (ClusterType.MINI != type) {
 +      throw new IllegalStateException("Expected only to see mini cluster state");
 +    }
 +
 +    this.conf = getConfiguration(type);
 +    this.saslEnabled = TRUE.equals(System.getProperty(MiniClusterHarness.USE_KERBEROS_FOR_IT_OPTION));
 +    log.debug("SASL is {}enabled", (saslEnabled ? "" : "not "));
 +  }
 +
 +  @Override
 +  public String getAdminPrincipal() {
 +    if (saslEnabled) {
 +      return AccumuloClusterHarness.getKdc().getRootUser().getPrincipal();
 +    } else {
 +      String principal = conf.get(ACCUMULO_MINI_PRINCIPAL_KEY);
 +      if (null == principal) {
 +        principal = ACCUMULO_MINI_PRINCIPAL_DEFAULT;
 +      }
 +
 +      return principal;
 +    }
 +  }
 +
 +  @Override
 +  public AuthenticationToken getAdminToken() {
 +    if (saslEnabled) {
 +      // Turn on Kerberos authentication so UGI acts properly
 +      final Configuration conf = new Configuration(false);
 +      conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
 +      UserGroupInformation.setConfiguration(conf);
 +
 +      ClusterUser rootUser = AccumuloClusterHarness.getKdc().getRootUser();
 +      try {
 +        return new KerberosToken(rootUser.getPrincipal(), rootUser.getKeytab(), true);
 +      } catch (IOException e) {
 +        throw new RuntimeException(e);
 +      }
 +    } else {
 +      String password = conf.get(ACCUMULO_MINI_PASSWORD_KEY);
 +      if (null == password) {
 +        password = ACCUMULO_MINI_PASSWORD_DEFAULT;
 +      }
 +
 +      return new PasswordToken(password);
 +    }
 +  }
 +
 +  @Override
 +  public ClusterType getClusterType() {
 +    return ClusterType.MINI;
 +  }
 +
 +  @Override
 +  public ClientConfiguration getClientConf() {
 +    return clientConf;
 +  }
 +
 +  public void setClientConf(ClientConfiguration conf) {
-     Preconditions.checkNotNull(conf, "Client configuration was null");
++    requireNonNull(conf, "Client configuration was null");
 +    this.clientConf = conf;
 +  }
 +}


Mime
View raw message