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();
}
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());
}
}
}
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);
}
}
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();
}
}
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());
}
}
Aggregations