use of org.apache.accumulo.core.client.admin.NewTableConfiguration in project accumulo by apache.
the class MiniAccumuloClusterTest method test.
@Test(timeout = 30000)
public void test() throws Exception {
Connector conn = accumulo.getConnector("root", "superSecret");
conn.tableOperations().create("table1", new NewTableConfiguration());
conn.securityOperations().createLocalUser("user1", new PasswordToken("pass1"));
conn.securityOperations().changeUserAuthorizations("user1", new Authorizations("A", "B"));
conn.securityOperations().grantTablePermission("user1", "table1", TablePermission.WRITE);
conn.securityOperations().grantTablePermission("user1", "table1", TablePermission.READ);
IteratorSetting is = new IteratorSetting(10, SummingCombiner.class);
SummingCombiner.setEncodingType(is, LongCombiner.Type.STRING);
SummingCombiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("META", "COUNT")));
conn.tableOperations().attachIterator("table1", is);
Connector uconn = accumulo.getConnector("user1", "pass1");
BatchWriter bw = uconn.createBatchWriter("table1", new BatchWriterConfig());
UUID uuid = UUID.randomUUID();
Mutation m = new Mutation(uuid.toString());
m.put("META", "SIZE", new ColumnVisibility("A|B"), "8");
m.put("META", "CRC", new ColumnVisibility("A|B"), "456");
m.put("META", "COUNT", new ColumnVisibility("A|B"), "1");
m.put("DATA", "IMG", new ColumnVisibility("A&B"), "ABCDEFGH");
bw.addMutation(m);
bw.flush();
m = new Mutation(uuid.toString());
m.put("META", "COUNT", new ColumnVisibility("A|B"), "1");
m.put("META", "CRC", new ColumnVisibility("A|B"), "123");
bw.addMutation(m);
bw.close();
int count = 0;
Scanner scanner = uconn.createScanner("table1", new Authorizations("A"));
for (Entry<Key, Value> entry : scanner) {
if (entry.getKey().getColumnQualifierData().toString().equals("COUNT")) {
Assert.assertEquals("2", entry.getValue().toString());
} else if (entry.getKey().getColumnQualifierData().toString().equals("SIZE")) {
Assert.assertEquals("8", entry.getValue().toString());
} else if (entry.getKey().getColumnQualifierData().toString().equals("CRC")) {
Assert.assertEquals("123", entry.getValue().toString());
} else {
Assert.assertTrue(false);
}
count++;
}
Assert.assertEquals(3, count);
count = 0;
scanner = uconn.createScanner("table1", new Authorizations("A", "B"));
for (Entry<Key, Value> entry : scanner) {
if (entry.getKey().getColumnQualifierData().toString().equals("IMG")) {
Assert.assertEquals("ABCDEFGH", entry.getValue().toString());
}
count++;
}
Assert.assertEquals(4, count);
conn.tableOperations().delete("table1");
}
use of org.apache.accumulo.core.client.admin.NewTableConfiguration in project accumulo by apache.
the class ProxyServer method createTable.
@Override
public void createTable(ByteBuffer login, String tableName, boolean versioningIter, org.apache.accumulo.proxy.thrift.TimeType type) throws org.apache.accumulo.proxy.thrift.AccumuloException, org.apache.accumulo.proxy.thrift.AccumuloSecurityException, org.apache.accumulo.proxy.thrift.TableExistsException, TException {
try {
if (type == null)
type = org.apache.accumulo.proxy.thrift.TimeType.MILLIS;
NewTableConfiguration tConfig = new NewTableConfiguration().setTimeType(TimeType.valueOf(type.toString()));
if (!versioningIter)
tConfig = tConfig.withoutDefaultIterators();
getConnector(login).tableOperations().create(tableName, tConfig);
} catch (TableExistsException e) {
throw new org.apache.accumulo.proxy.thrift.TableExistsException(e.toString());
} catch (Exception e) {
handleException(e);
}
}
use of org.apache.accumulo.core.client.admin.NewTableConfiguration in project accumulo by apache.
the class NewTableConfigurationIT method testMultipleIteratorValid.
/**
* Verify that multiple calls to attachIterator keep adding to iterators, i.e., do not overwrite existing iterators.
*/
@Test
public void testMultipleIteratorValid() throws AccumuloException, TableNotFoundException, AccumuloSecurityException, TableExistsException {
Connector conn = getConnector();
String tableName = getUniqueNames(2)[0];
NewTableConfiguration ntc = new NewTableConfiguration();
IteratorSetting setting = new IteratorSetting(10, "firstIterator", "first.class");
ntc.attachIterator(setting, EnumSet.of(IteratorScope.scan));
setting = new IteratorSetting(11, "secondIterator", "second.class");
ntc.attachIterator(setting, EnumSet.of(IteratorScope.scan));
conn.tableOperations().create(tableName, ntc);
verifyIterators(conn, tableName, new String[] { "table.iterator.scan.firstIterator=10,first.class", "table.iterator.scan.secondIterator=11,second.class" }, true);
conn.tableOperations().removeIterator(tableName, "firstIterator", EnumSet.of(IteratorScope.scan));
verifyIterators(conn, tableName, new String[] { "table.iterator.scan.secondIterator=11,second.class" }, true);
conn.tableOperations().removeIterator(tableName, "secondIterator", EnumSet.of(IteratorScope.scan));
verifyIterators(conn, tableName, new String[] {}, true);
}
use of org.apache.accumulo.core.client.admin.NewTableConfiguration in project accumulo by apache.
the class NewTableConfigurationIT method testSimpleLocalityGroupCreation.
/**
* Test simplest case of setting locality groups at table creation.
*/
@Test
public void testSimpleLocalityGroupCreation() throws AccumuloSecurityException, AccumuloException, TableExistsException, TableNotFoundException {
Connector conn = getConnector();
String tableName = getUniqueNames(2)[0];
NewTableConfiguration ntc = new NewTableConfiguration();
// set locality groups map
Map<String, Set<Text>> lgroups = new HashMap<>();
lgroups.put("lg1", ImmutableSet.of(new Text("dog"), new Text("cat")));
lgroups.put("lg2", ImmutableSet.of(new Text("lion"), new Text("tiger")));
// set groups via NewTableConfiguration
ntc.setLocalityGroups(lgroups);
conn.tableOperations().create(tableName, ntc);
// verify
Map<String, Set<Text>> createdLocalityGroups = conn.tableOperations().getLocalityGroups(tableName);
assertEquals(2, createdLocalityGroups.size());
assertEquals(createdLocalityGroups.get("lg1"), ImmutableSet.of(new Text("dog"), new Text("cat")));
assertEquals(createdLocalityGroups.get("lg2"), ImmutableSet.of(new Text("lion"), new Text("tiger")));
}
use of org.apache.accumulo.core.client.admin.NewTableConfiguration in project accumulo by apache.
the class NewTableConfigurationIT method testIteratorConflictFound1.
/**
* Verify iterator conflicts are discovered
*/
@Test(expected = IllegalArgumentException.class)
public void testIteratorConflictFound1() throws AccumuloException, TableNotFoundException, AccumuloSecurityException, TableExistsException {
Connector conn = getConnector();
String tableName = getUniqueNames(2)[0];
NewTableConfiguration ntc = new NewTableConfiguration();
IteratorSetting setting = new IteratorSetting(10, "someName", "foo.bar");
ntc.attachIterator(setting, EnumSet.of(IteratorScope.scan));
setting = new IteratorSetting(12, "someName", "foo2.bar");
ntc.attachIterator(setting, EnumSet.of(IteratorScope.scan));
conn.tableOperations().create(tableName, ntc);
}
Aggregations