Search in sources :

Example 21 with ClientConfiguration

use of org.apache.accumulo.core.client.ClientConfiguration in project accumulo by apache.

the class RestartIT method shutdownDuringCompactingSplitting.

@Test
public void shutdownDuringCompactingSplitting() throws Exception {
    Connector c = getConnector();
    String tableName = getUniqueNames(1)[0];
    VOPTS.setTableName(tableName);
    ClientConfiguration clientConfig = cluster.getClientConfig();
    if (clientConfig.hasSasl()) {
        OPTS.updateKerberosCredentials(clientConfig);
        VOPTS.updateKerberosCredentials(clientConfig);
    } else {
        OPTS.setPrincipal(getAdminPrincipal());
        VOPTS.setPrincipal(getAdminPrincipal());
    }
    c.tableOperations().create(tableName);
    c.tableOperations().setProperty(tableName, Property.TABLE_SPLIT_THRESHOLD.getKey(), "10K");
    String splitThreshold = null;
    for (Entry<String, String> entry : c.tableOperations().getProperties(tableName)) {
        if (entry.getKey().equals(Property.TABLE_SPLIT_THRESHOLD.getKey())) {
            splitThreshold = entry.getValue();
            break;
        }
    }
    Assert.assertNotNull(splitThreshold);
    try {
        c.tableOperations().setProperty(MetadataTable.NAME, Property.TABLE_SPLIT_THRESHOLD.getKey(), "20K");
        TestIngest.Opts opts = new TestIngest.Opts();
        opts.setTableName(tableName);
        if (clientConfig.hasSasl()) {
            opts.updateKerberosCredentials(clientConfig);
        } else {
            opts.setPrincipal(getAdminPrincipal());
        }
        TestIngest.ingest(c, opts, BWOPTS);
        c.tableOperations().flush(tableName, null, null, false);
        VerifyIngest.verifyIngest(c, VOPTS, SOPTS);
        getCluster().stop();
    } finally {
        if (getClusterType() == ClusterType.STANDALONE) {
            getCluster().start();
            c.tableOperations().setProperty(MetadataTable.NAME, Property.TABLE_SPLIT_THRESHOLD.getKey(), splitThreshold);
        }
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) TestIngest(org.apache.accumulo.test.TestIngest) ScannerOpts(org.apache.accumulo.core.cli.ScannerOpts) BatchWriterOpts(org.apache.accumulo.core.cli.BatchWriterOpts) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) Test(org.junit.Test)

Example 22 with ClientConfiguration

use of org.apache.accumulo.core.client.ClientConfiguration in project accumulo by apache.

the class RestartIT method restartMasterRecovery.

@Test
public void restartMasterRecovery() throws Exception {
    Connector c = getConnector();
    String tableName = getUniqueNames(1)[0];
    c.tableOperations().create(tableName);
    OPTS.setTableName(tableName);
    VOPTS.setTableName(tableName);
    ClientConfiguration clientConfig = cluster.getClientConfig();
    if (clientConfig.hasSasl()) {
        OPTS.updateKerberosCredentials(clientConfig);
        VOPTS.updateKerberosCredentials(clientConfig);
    } else {
        OPTS.setPrincipal(getAdminPrincipal());
        VOPTS.setPrincipal(getAdminPrincipal());
    }
    TestIngest.ingest(c, OPTS, BWOPTS);
    ClusterControl control = getCluster().getClusterControl();
    // TODO implement a kill all too?
    // cluster.stop() would also stop ZooKeeper
    control.stopAllServers(ServerType.MASTER);
    control.stopAllServers(ServerType.TRACER);
    control.stopAllServers(ServerType.TABLET_SERVER);
    control.stopAllServers(ServerType.GARBAGE_COLLECTOR);
    control.stopAllServers(ServerType.MONITOR);
    ZooReader zreader = new ZooReader(c.getInstance().getZooKeepers(), c.getInstance().getZooKeepersSessionTimeOut());
    ZooCache zcache = new ZooCache(zreader, null);
    byte[] masterLockData;
    do {
        masterLockData = ZooLock.getLockData(zcache, ZooUtil.getRoot(c.getInstance()) + Constants.ZMASTER_LOCK, null);
        if (null != masterLockData) {
            log.info("Master lock is still held");
            Thread.sleep(1000);
        }
    } while (null != masterLockData);
    cluster.start();
    sleepUninterruptibly(5, TimeUnit.MILLISECONDS);
    control.stopAllServers(ServerType.MASTER);
    masterLockData = new byte[0];
    do {
        masterLockData = ZooLock.getLockData(zcache, ZooUtil.getRoot(c.getInstance()) + Constants.ZMASTER_LOCK, null);
        if (null != masterLockData) {
            log.info("Master lock is still held");
            Thread.sleep(1000);
        }
    } while (null != masterLockData);
    cluster.start();
    VerifyIngest.verifyIngest(c, VOPTS, SOPTS);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) ZooReader(org.apache.accumulo.fate.zookeeper.ZooReader) ZooCache(org.apache.accumulo.fate.zookeeper.ZooCache) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) ClusterControl(org.apache.accumulo.cluster.ClusterControl) Test(org.junit.Test)

Example 23 with ClientConfiguration

use of org.apache.accumulo.core.client.ClientConfiguration in project accumulo by apache.

the class Shell method setInstance.

/**
 * Sets the instance used by the shell based on the given options.
 *
 * @param options
 *          shell options
 */
protected void setInstance(ShellOptionsJC options) {
    // should only be one set of instance options set
    instance = null;
    if (options.isFake()) {
        instance = DeprecationUtil.makeMockInstance("fake");
    } else {
        String instanceName, hosts;
        if (options.isHdfsZooInstance()) {
            instanceName = hosts = null;
        } else if (options.getZooKeeperInstance().size() > 0) {
            List<String> zkOpts = options.getZooKeeperInstance();
            instanceName = zkOpts.get(0);
            hosts = zkOpts.get(1);
        } else {
            instanceName = options.getZooKeeperInstanceName();
            hosts = options.getZooKeeperHosts();
        }
        final ClientConfiguration clientConf;
        try {
            clientConf = options.getClientConfiguration();
        } catch (ConfigurationException | FileNotFoundException e) {
            throw new IllegalArgumentException("Unable to load client config from " + options.getClientConfigFile(), e);
        }
        instance = getZooInstance(instanceName, hosts, clientConf);
    }
}
Also used : ConfigurationException(org.apache.commons.configuration.ConfigurationException) FileNotFoundException(java.io.FileNotFoundException) List(java.util.List) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration)

Example 24 with ClientConfiguration

use of org.apache.accumulo.core.client.ClientConfiguration in project accumulo by apache.

the class ShellOptionsJC method getClientConfiguration.

public ClientConfiguration getClientConfiguration() throws ConfigurationException, FileNotFoundException {
    ClientConfiguration clientConfig = clientConfigFile == null ? ClientConfiguration.loadDefault() : ClientConfiguration.fromFile(new File(getClientConfigFile()));
    if (useSsl()) {
        clientConfig.setProperty(ClientProperty.INSTANCE_RPC_SSL_ENABLED, "true");
    }
    if (useSasl()) {
        clientConfig.setProperty(ClientProperty.INSTANCE_RPC_SASL_ENABLED, "true");
    }
    if (!getZooKeeperInstance().isEmpty()) {
        List<String> zkOpts = getZooKeeperInstance();
        String instanceName = zkOpts.get(0);
        String hosts = zkOpts.get(1);
        clientConfig.setProperty(ClientProperty.INSTANCE_ZK_HOST, hosts);
        clientConfig.setProperty(ClientProperty.INSTANCE_NAME, instanceName);
    }
    // If the user provided the hosts, set the ZK for tracing too
    if (null != zooKeeperHosts && !zooKeeperHosts.isEmpty()) {
        clientConfig.setProperty(ClientProperty.INSTANCE_ZK_HOST, zooKeeperHosts);
    }
    if (null != zooKeeperInstanceName && !zooKeeperInstanceName.isEmpty()) {
        clientConfig.setProperty(ClientProperty.INSTANCE_NAME, zooKeeperInstanceName);
    }
    // Automatically try to add in the proper ZK from accumulo-site for backwards compat.
    if (!clientConfig.containsKey(ClientProperty.INSTANCE_ZK_HOST.getKey())) {
        AccumuloConfiguration siteConf = SiteConfiguration.getInstance();
        clientConfig.withZkHosts(siteConf.get(Property.INSTANCE_ZK_HOST));
    }
    return clientConfig;
}
Also used : File(java.io.File) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration)

Example 25 with ClientConfiguration

use of org.apache.accumulo.core.client.ClientConfiguration in project accumulo by apache.

the class ShellOptionsJC method getUsername.

public String getUsername() throws Exception {
    if (null == username) {
        final ClientConfiguration clientConf = getClientConfiguration();
        if (Boolean.parseBoolean(clientConf.get(ClientProperty.INSTANCE_RPC_SASL_ENABLED))) {
            if (!UserGroupInformation.isSecurityEnabled()) {
                throw new RuntimeException("Kerberos security is not enabled");
            }
            UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
            username = ugi.getUserName();
        } else {
            username = System.getProperty("user.name", "root");
        }
    }
    return username;
}
Also used : ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Aggregations

ClientConfiguration (org.apache.accumulo.core.client.ClientConfiguration)78 Test (org.junit.Test)40 Connector (org.apache.accumulo.core.client.Connector)28 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)27 IOException (java.io.IOException)16 TestIngest (org.apache.accumulo.test.TestIngest)15 BatchWriterOpts (org.apache.accumulo.core.cli.BatchWriterOpts)13 ScannerOpts (org.apache.accumulo.core.cli.ScannerOpts)12 KerberosToken (org.apache.accumulo.core.client.security.tokens.KerberosToken)12 AccumuloConfiguration (org.apache.accumulo.core.conf.AccumuloConfiguration)11 VerifyIngest (org.apache.accumulo.test.VerifyIngest)11 ClusterUser (org.apache.accumulo.cluster.ClusterUser)9 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)9 ZooKeeperInstance (org.apache.accumulo.core.client.ZooKeeperInstance)8 Map (java.util.Map)7 AccumuloException (org.apache.accumulo.core.client.AccumuloException)6 Instance (org.apache.accumulo.core.client.Instance)6 AuthenticationToken (org.apache.accumulo.core.client.security.tokens.AuthenticationToken)6 Authorizations (org.apache.accumulo.core.security.Authorizations)6 Path (org.apache.hadoop.fs.Path)6