Search in sources :

Example 26 with AccumuloClient

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

the class AccumuloClientIT method testAccumuloClientBuilder.

@Test
public void testAccumuloClientBuilder() throws Exception {
    AccumuloClient c = Accumulo.newClient().from(getClientProps()).build();
    String instanceName = getClientInfo().getInstanceName();
    String zookeepers = getClientInfo().getZooKeepers();
    ClusterUser testuser1 = getUser(0);
    final String user1 = testuser1.getPrincipal();
    final String password1 = testuser1.getPassword();
    c.securityOperations().createLocalUser(user1, new PasswordToken(password1));
    AccumuloClient client = Accumulo.newClient().to(instanceName, zookeepers).as(user1, password1).zkTimeout(1234).build();
    Properties props = client.properties();
    assertFalse(props.containsKey(ClientProperty.AUTH_TOKEN.getKey()));
    ClientInfo info = ClientInfo.from(client.properties());
    assertEquals(instanceName, info.getInstanceName());
    assertEquals(zookeepers, info.getZooKeepers());
    assertEquals(user1, client.whoami());
    assertEquals(1234, info.getZooKeepersSessionTimeOut());
    props = Accumulo.newClientProperties().to(instanceName, zookeepers).as(user1, password1).build();
    assertTrue(props.containsKey(ClientProperty.AUTH_TOKEN.getKey()));
    assertEquals(password1, props.get(ClientProperty.AUTH_TOKEN.getKey()));
    assertEquals("password", props.get(ClientProperty.AUTH_TYPE.getKey()));
    assertEquals(instanceName, props.getProperty(ClientProperty.INSTANCE_NAME.getKey()));
    info = ClientInfo.from(props);
    assertEquals(instanceName, info.getInstanceName());
    assertEquals(zookeepers, info.getZooKeepers());
    assertEquals(user1, info.getPrincipal());
    assertTrue(info.getAuthenticationToken() instanceof PasswordToken);
    props = new Properties();
    props.put(ClientProperty.INSTANCE_NAME.getKey(), instanceName);
    props.put(ClientProperty.INSTANCE_ZOOKEEPERS.getKey(), zookeepers);
    props.put(ClientProperty.AUTH_PRINCIPAL.getKey(), user1);
    props.put(ClientProperty.INSTANCE_ZOOKEEPERS_TIMEOUT.getKey(), "22s");
    ClientProperty.setPassword(props, password1);
    client.close();
    client = Accumulo.newClient().from(props).build();
    info = ClientInfo.from(client.properties());
    assertEquals(instanceName, info.getInstanceName());
    assertEquals(zookeepers, info.getZooKeepers());
    assertEquals(user1, client.whoami());
    assertEquals(22000, info.getZooKeepersSessionTimeOut());
    ClusterUser testuser2 = getUser(1);
    final String user2 = testuser2.getPrincipal();
    final String password2 = testuser2.getPassword();
    c.securityOperations().createLocalUser(user2, new PasswordToken(password2));
    AccumuloClient client2 = Accumulo.newClient().from(client.properties()).as(user2, new PasswordToken(password2)).build();
    info = ClientInfo.from(client2.properties());
    assertEquals(instanceName, info.getInstanceName());
    assertEquals(zookeepers, info.getZooKeepers());
    assertEquals(user2, client2.whoami());
    assertEquals(user2, info.getPrincipal());
    c.close();
    client.close();
    client2.close();
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) ClusterUser(org.apache.accumulo.cluster.ClusterUser) ClientInfo(org.apache.accumulo.core.clientImpl.ClientInfo) Properties(java.util.Properties) Test(org.junit.Test)

Example 27 with AccumuloClient

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

the class AccumuloClientIT method deleteUsers.

@After
public void deleteUsers() throws Exception {
    try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
        Set<String> users = client.securityOperations().listLocalUsers();
        ClusterUser user1 = getUser(0);
        ClusterUser user2 = getUser(1);
        if (users.contains(user1.getPrincipal())) {
            client.securityOperations().dropLocalUser(user1.getPrincipal());
        }
        if (users.contains(user2.getPrincipal())) {
            client.securityOperations().dropLocalUser(user2.getPrincipal());
        }
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) ClusterUser(org.apache.accumulo.cluster.ClusterUser) After(org.junit.After)

Example 28 with AccumuloClient

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

the class AddSplitIT method addSplitTest.

@Test
public void addSplitTest() throws Exception {
    String tableName = getUniqueNames(1)[0];
    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
        c.tableOperations().create(tableName);
        insertData(c, tableName, 1L);
        TreeSet<Text> splits = new TreeSet<>();
        splits.add(new Text(String.format("%09d", 333)));
        splits.add(new Text(String.format("%09d", 666)));
        c.tableOperations().addSplits(tableName, splits);
        sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
        Collection<Text> actualSplits = c.tableOperations().listSplits(tableName);
        if (!splits.equals(new TreeSet<>(actualSplits))) {
            throw new Exception(splits + " != " + actualSplits);
        }
        verifyData(c, tableName, 1L);
        insertData(c, tableName, 2L);
        // did not clear splits on purpose, it should ignore existing split points
        // and still create the three additional split points
        splits.add(new Text(String.format("%09d", 200)));
        splits.add(new Text(String.format("%09d", 500)));
        splits.add(new Text(String.format("%09d", 800)));
        c.tableOperations().addSplits(tableName, splits);
        sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
        actualSplits = c.tableOperations().listSplits(tableName);
        if (!splits.equals(new TreeSet<>(actualSplits))) {
            throw new Exception(splits + " != " + actualSplits);
        }
        verifyData(c, tableName, 2L);
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) TreeSet(java.util.TreeSet) Text(org.apache.hadoop.io.Text) Test(org.junit.Test)

Example 29 with AccumuloClient

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

the class BackupManagerIT method test.

@Test
public void test() throws Exception {
    // wait for manager
    UtilWaitThread.sleep(1000);
    // create a backup
    Process backup = exec(Manager.class);
    try (AccumuloClient client = Accumulo.newClient().from(getClientProperties()).build()) {
        String secret = getCluster().getSiteConfiguration().get(Property.INSTANCE_SECRET);
        ZooReaderWriter writer = new ZooReaderWriter(cluster.getZooKeepers(), 30_000, secret);
        String root = "/accumulo/" + client.instanceOperations().getInstanceId();
        List<String> children;
        // wait for 2 lock entries
        do {
            UtilWaitThread.sleep(100);
            var path = ServiceLock.path(root + Constants.ZMANAGER_LOCK);
            children = ServiceLock.validateAndSort(path, writer.getChildren(path.toString()));
        } while (children.size() != 2);
        // wait for the backup manager to learn to be the backup
        UtilWaitThread.sleep(1000);
        // generate a false zookeeper event
        String lockPath = root + Constants.ZMANAGER_LOCK + "/" + children.get(0);
        byte[] data = writer.getData(lockPath);
        writer.getZooKeeper().setData(lockPath, data, -1);
        // let it propagate
        UtilWaitThread.sleep(500);
        // kill the manager by removing its lock
        writer.recursiveDelete(lockPath, NodeMissingPolicy.FAIL);
        // ensure the backup becomes the manager
        client.tableOperations().create(getUniqueNames(1)[0]);
    } finally {
        backup.destroy();
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) ZooReaderWriter(org.apache.accumulo.fate.zookeeper.ZooReaderWriter) Test(org.junit.Test)

Example 30 with AccumuloClient

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

the class TestIngest method main.

public static void main(String[] args) throws Exception {
    Opts opts = new Opts();
    opts.parseArgs(TestIngest.class.getSimpleName(), args);
    try (AccumuloClient client = Accumulo.newClient().from(opts.getClientProps()).build()) {
        ingest(client, opts.getIngestPrams());
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) ClientOpts(org.apache.accumulo.core.cli.ClientOpts)

Aggregations

AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)500 Test (org.junit.Test)411 BatchWriter (org.apache.accumulo.core.client.BatchWriter)149 Text (org.apache.hadoop.io.Text)143 Mutation (org.apache.accumulo.core.data.Mutation)138 Scanner (org.apache.accumulo.core.client.Scanner)122 Value (org.apache.accumulo.core.data.Value)118 Key (org.apache.accumulo.core.data.Key)108 NewTableConfiguration (org.apache.accumulo.core.client.admin.NewTableConfiguration)91 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)64 HashMap (java.util.HashMap)61 Range (org.apache.accumulo.core.data.Range)51 TreeSet (java.util.TreeSet)50 ArrayList (java.util.ArrayList)47 Entry (java.util.Map.Entry)41 Path (org.apache.hadoop.fs.Path)39 CompactionConfig (org.apache.accumulo.core.client.admin.CompactionConfig)34 Authorizations (org.apache.accumulo.core.security.Authorizations)34 BatchScanner (org.apache.accumulo.core.client.BatchScanner)32 HashSet (java.util.HashSet)31