Search in sources :

Example 6 with ClusterControl

use of org.apache.accumulo.cluster.ClusterControl in project accumulo by apache.

the class RecoveryCompactionsAreFlushesIT method test.

@Test
public void test() throws Exception {
    // create a table
    String tableName = getUniqueNames(1)[0];
    Connector c = getConnector();
    c.tableOperations().create(tableName);
    c.tableOperations().setProperty(tableName, Property.TABLE_MAJC_RATIO.getKey(), "100");
    c.tableOperations().setProperty(tableName, Property.TABLE_FILE_MAX.getKey(), "3");
    // create 3 flush files
    BatchWriter bw = c.createBatchWriter(tableName, new BatchWriterConfig());
    Mutation m = new Mutation("a");
    m.put("b", "c", new Value("v".getBytes()));
    for (int i = 0; i < 3; i++) {
        bw.addMutation(m);
        bw.flush();
        c.tableOperations().flush(tableName, null, null, true);
    }
    // create an unsaved mutation
    bw.addMutation(m);
    bw.close();
    ClusterControl control = cluster.getClusterControl();
    // kill the tablet servers
    control.stopAllServers(ServerType.TABLET_SERVER);
    // recover
    control.startAllServers(ServerType.TABLET_SERVER);
    // ensure the table is readable
    Iterators.size(c.createScanner(tableName, Authorizations.EMPTY).iterator());
    // ensure that the recovery was not a merging minor compaction
    try (Scanner s = c.createScanner(MetadataTable.NAME, Authorizations.EMPTY)) {
        s.fetchColumnFamily(MetadataSchema.TabletsSection.DataFileColumnFamily.NAME);
        for (Entry<Key, Value> entry : s) {
            String filename = entry.getKey().getColumnQualifier().toString();
            String[] parts = filename.split("/");
            Assert.assertFalse(parts[parts.length - 1].startsWith("M"));
        }
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) Scanner(org.apache.accumulo.core.client.Scanner) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key) ClusterControl(org.apache.accumulo.cluster.ClusterControl) Test(org.junit.Test)

Example 7 with ClusterControl

use of org.apache.accumulo.cluster.ClusterControl in project accumulo by apache.

the class ReadWriteIT method multiTableTest.

@Test
public void multiTableTest() throws Exception {
    // Write to multiple tables
    final String instance = cluster.getInstanceName();
    final String keepers = cluster.getZooKeepers();
    final ClusterControl control = cluster.getClusterControl();
    final String prefix = getClass().getSimpleName() + "_" + testName.getMethodName();
    ExecutorService svc = Executors.newFixedThreadPool(2);
    Future<Integer> p1 = svc.submit(new Callable<Integer>() {

        @Override
        public Integer call() {
            try {
                ClientConfiguration clientConf = cluster.getClientConfig();
                // Need to pass along the keytab because of that.
                if (clientConf.hasSasl()) {
                    String principal = getAdminPrincipal();
                    AuthenticationToken token = getAdminToken();
                    assertTrue("Expected KerberosToken, but was " + token.getClass(), token instanceof KerberosToken);
                    KerberosToken kt = (KerberosToken) token;
                    assertNotNull("Expected keytab in token", kt.getKeytab());
                    return control.exec(TestMultiTableIngest.class, args("--count", Integer.toString(ROWS), "-i", instance, "-z", keepers, "--tablePrefix", prefix, "--keytab", kt.getKeytab().getAbsolutePath(), "-u", principal));
                }
                return control.exec(TestMultiTableIngest.class, args("--count", Integer.toString(ROWS), "-u", getAdminPrincipal(), "-i", instance, "-z", keepers, "-p", new String(((PasswordToken) getAdminToken()).getPassword(), UTF_8), "--tablePrefix", prefix));
            } catch (IOException e) {
                log.error("Error running MultiTableIngest", e);
                return -1;
            }
        }
    });
    Future<Integer> p2 = svc.submit(new Callable<Integer>() {

        @Override
        public Integer call() {
            try {
                ClientConfiguration clientConf = cluster.getClientConfig();
                // Need to pass along the keytab because of that.
                if (clientConf.hasSasl()) {
                    String principal = getAdminPrincipal();
                    AuthenticationToken token = getAdminToken();
                    assertTrue("Expected KerberosToken, but was " + token.getClass(), token instanceof KerberosToken);
                    KerberosToken kt = (KerberosToken) token;
                    assertNotNull("Expected keytab in token", kt.getKeytab());
                    return control.exec(TestMultiTableIngest.class, args("--count", Integer.toString(ROWS), "--readonly", "-i", instance, "-z", keepers, "--tablePrefix", prefix, "--keytab", kt.getKeytab().getAbsolutePath(), "-u", principal));
                }
                return control.exec(TestMultiTableIngest.class, args("--count", Integer.toString(ROWS), "--readonly", "-u", getAdminPrincipal(), "-i", instance, "-z", keepers, "-p", new String(((PasswordToken) getAdminToken()).getPassword(), UTF_8), "--tablePrefix", prefix));
            } catch (IOException e) {
                log.error("Error running MultiTableIngest", e);
                return -1;
            }
        }
    });
    svc.shutdown();
    while (!svc.isTerminated()) {
        svc.awaitTermination(15, TimeUnit.SECONDS);
    }
    assertEquals(0, p1.get().intValue());
    assertEquals(0, p2.get().intValue());
}
Also used : AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) KerberosToken(org.apache.accumulo.core.client.security.tokens.KerberosToken) IOException(java.io.IOException) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) TestMultiTableIngest(org.apache.accumulo.test.TestMultiTableIngest) ExecutorService(java.util.concurrent.ExecutorService) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) ClusterControl(org.apache.accumulo.cluster.ClusterControl) Test(org.junit.Test)

Example 8 with ClusterControl

use of org.apache.accumulo.cluster.ClusterControl in project accumulo by apache.

the class RestartIT method killedTabletServer2.

@Test
public void killedTabletServer2() throws Exception {
    final Connector c = getConnector();
    final String[] names = getUniqueNames(2);
    final String tableName = names[0];
    final ClusterControl control = getCluster().getClusterControl();
    c.tableOperations().create(tableName);
    // Original test started and then stopped a GC. Not sure why it did this. The GC was
    // already running by default, and it would have nothing to do after only creating a table
    control.stopAllServers(ServerType.TABLET_SERVER);
    cluster.start();
    c.tableOperations().create(names[1]);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) ClusterControl(org.apache.accumulo.cluster.ClusterControl) Test(org.junit.Test)

Example 9 with ClusterControl

use of org.apache.accumulo.cluster.ClusterControl in project accumulo by apache.

the class RestartIT method restartMaster.

@Test
public void restartMaster() throws Exception {
    Connector c = getConnector();
    final String tableName = getUniqueNames(1)[0];
    OPTS.setTableName(tableName);
    VOPTS.setTableName(tableName);
    c.tableOperations().create(tableName);
    final AuthenticationToken token = getAdminToken();
    final ClusterControl control = getCluster().getClusterControl();
    final String[] args;
    if (token instanceof PasswordToken) {
        byte[] password = ((PasswordToken) token).getPassword();
        args = new String[] { "-u", getAdminPrincipal(), "-p", new String(password, UTF_8), "-i", cluster.getInstanceName(), "-z", cluster.getZooKeepers(), "--rows", "" + OPTS.rows, "--table", tableName };
        OPTS.setPrincipal(getAdminPrincipal());
        VOPTS.setPrincipal(getAdminPrincipal());
    } else if (token instanceof KerberosToken) {
        ClusterUser rootUser = getAdminUser();
        args = new String[] { "-u", getAdminPrincipal(), "--keytab", rootUser.getKeytab().getAbsolutePath(), "-i", cluster.getInstanceName(), "-z", cluster.getZooKeepers(), "--rows", "" + OPTS.rows, "--table", tableName };
        ClientConfiguration clientConfig = cluster.getClientConfig();
        OPTS.updateKerberosCredentials(clientConfig);
        VOPTS.updateKerberosCredentials(clientConfig);
    } else {
        throw new RuntimeException("Unknown token");
    }
    Future<Integer> ret = svc.submit(new Callable<Integer>() {

        @Override
        public Integer call() {
            try {
                return control.exec(TestIngest.class, args);
            } catch (IOException e) {
                log.error("Error running TestIngest", e);
                return -1;
            }
        }
    });
    control.stopAllServers(ServerType.MASTER);
    control.startAllServers(ServerType.MASTER);
    assertEquals(0, ret.get().intValue());
    VerifyIngest.verifyIngest(c, VOPTS, SOPTS);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) KerberosToken(org.apache.accumulo.core.client.security.tokens.KerberosToken) IOException(java.io.IOException) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) TestIngest(org.apache.accumulo.test.TestIngest) ClusterUser(org.apache.accumulo.cluster.ClusterUser) ClientConfiguration(org.apache.accumulo.core.client.ClientConfiguration) ClusterControl(org.apache.accumulo.cluster.ClusterControl) Test(org.junit.Test)

Example 10 with ClusterControl

use of org.apache.accumulo.cluster.ClusterControl in project accumulo by apache.

the class RestartStressIT method test.

@Test
public void test() throws Exception {
    final Connector c = getConnector();
    final String tableName = getUniqueNames(1)[0];
    final AuthenticationToken token = getAdminToken();
    c.tableOperations().create(tableName);
    c.tableOperations().setProperty(tableName, Property.TABLE_SPLIT_THRESHOLD.getKey(), "500K");
    final ClusterControl control = getCluster().getClusterControl();
    final String[] args;
    if (token instanceof PasswordToken) {
        byte[] password = ((PasswordToken) token).getPassword();
        args = new String[] { "-u", getAdminPrincipal(), "-p", new String(password, UTF_8), "-i", cluster.getInstanceName(), "-z", cluster.getZooKeepers(), "--rows", "" + VOPTS.rows, "--table", tableName };
    } else if (token instanceof KerberosToken) {
        ClusterUser rootUser = getAdminUser();
        args = new String[] { "-u", getAdminPrincipal(), "--keytab", rootUser.getKeytab().getAbsolutePath(), "-i", cluster.getInstanceName(), "-z", cluster.getZooKeepers(), "--rows", "" + VOPTS.rows, "--table", tableName };
    } else {
        throw new RuntimeException("Unrecognized token");
    }
    Future<Integer> retCode = svc.submit(new Callable<Integer>() {

        @Override
        public Integer call() {
            try {
                return control.exec(TestIngest.class, args);
            } catch (Exception e) {
                log.error("Error running TestIngest", e);
                return -1;
            }
        }
    });
    for (int i = 0; i < 2; i++) {
        sleepUninterruptibly(10, TimeUnit.SECONDS);
        control.stopAllServers(ServerType.TABLET_SERVER);
        control.startAllServers(ServerType.TABLET_SERVER);
    }
    assertEquals(0, retCode.get().intValue());
    VOPTS.setTableName(tableName);
    if (token instanceof PasswordToken) {
        VOPTS.setPrincipal(getAdminPrincipal());
    } else if (token instanceof KerberosToken) {
        VOPTS.updateKerberosCredentials(cluster.getClientConfig());
    } else {
        throw new RuntimeException("Unrecognized token");
    }
    VerifyIngest.verifyIngest(c, VOPTS, SOPTS);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) AuthenticationToken(org.apache.accumulo.core.client.security.tokens.AuthenticationToken) KerberosToken(org.apache.accumulo.core.client.security.tokens.KerberosToken) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) TestIngest(org.apache.accumulo.test.TestIngest) ClusterUser(org.apache.accumulo.cluster.ClusterUser) ClusterControl(org.apache.accumulo.cluster.ClusterControl) Test(org.junit.Test)

Aggregations

ClusterControl (org.apache.accumulo.cluster.ClusterControl)10 Test (org.junit.Test)10 Connector (org.apache.accumulo.core.client.Connector)8 ClientConfiguration (org.apache.accumulo.core.client.ClientConfiguration)6 AuthenticationToken (org.apache.accumulo.core.client.security.tokens.AuthenticationToken)4 KerberosToken (org.apache.accumulo.core.client.security.tokens.KerberosToken)4 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)4 TestIngest (org.apache.accumulo.test.TestIngest)4 IOException (java.io.IOException)3 ClusterUser (org.apache.accumulo.cluster.ClusterUser)3 ZooCache (org.apache.accumulo.fate.zookeeper.ZooCache)3 ZooReader (org.apache.accumulo.fate.zookeeper.ZooReader)3 File (java.io.File)1 URL (java.net.URL)1 SecureRandom (java.security.SecureRandom)1 ExecutorService (java.util.concurrent.ExecutorService)1 SSLContext (javax.net.ssl.SSLContext)1 TrustManager (javax.net.ssl.TrustManager)1 X509TrustManager (javax.net.ssl.X509TrustManager)1 StandaloneAccumuloCluster (org.apache.accumulo.cluster.standalone.StandaloneAccumuloCluster)1