use of org.apache.accumulo.core.data.Mutation in project accumulo by apache.
the class KerberosIT method createTableWithDataAndCompact.
/**
* Creates a table, adds a record to it, and then compacts the table. A simple way to make sure that the system user exists (since the master does an RPC to
* the tserver which will create the system user if it doesn't already exist).
*/
private void createTableWithDataAndCompact(Connector conn) throws TableNotFoundException, AccumuloSecurityException, AccumuloException, TableExistsException {
final String table = testName.getMethodName() + "_table";
conn.tableOperations().create(table);
BatchWriter bw = conn.createBatchWriter(table, new BatchWriterConfig());
Mutation m = new Mutation("a");
m.put("b", "c", "d");
bw.addMutation(m);
bw.close();
conn.tableOperations().compact(table, new CompactionConfig().setFlush(true).setWait(true));
}
use of org.apache.accumulo.core.data.Mutation in project accumulo by apache.
the class KerberosIT method testDelegationToken.
@Test
public void testDelegationToken() throws Exception {
final String tableName = getUniqueNames(1)[0];
// Login as the "root" user
UserGroupInformation root = UserGroupInformation.loginUserFromKeytabAndReturnUGI(rootUser.getPrincipal(), rootUser.getKeytab().getAbsolutePath());
log.info("Logged in as {}", rootUser.getPrincipal());
final int numRows = 100, numColumns = 10;
// As the "root" user, open up the connection and get a delegation token
final AuthenticationToken delegationToken = root.doAs(new PrivilegedExceptionAction<AuthenticationToken>() {
@Override
public AuthenticationToken run() throws Exception {
Connector conn = mac.getConnector(rootUser.getPrincipal(), new KerberosToken());
log.info("Created connector as {}", rootUser.getPrincipal());
assertEquals(rootUser.getPrincipal(), conn.whoami());
conn.tableOperations().create(tableName);
BatchWriter bw = conn.createBatchWriter(tableName, new BatchWriterConfig());
for (int r = 0; r < numRows; r++) {
Mutation m = new Mutation(Integer.toString(r));
for (int c = 0; c < numColumns; c++) {
String col = Integer.toString(c);
m.put(col, col, col);
}
bw.addMutation(m);
}
bw.close();
return conn.securityOperations().getDelegationToken(new DelegationTokenConfig());
}
});
// The above login with keytab doesn't have a way to logout, so make a fake user that won't have krb credentials
UserGroupInformation userWithoutPrivs = UserGroupInformation.createUserForTesting("fake_user", new String[0]);
int recordsSeen = userWithoutPrivs.doAs(new PrivilegedExceptionAction<Integer>() {
@Override
public Integer run() throws Exception {
Connector conn = mac.getConnector(rootUser.getPrincipal(), delegationToken);
try (BatchScanner bs = conn.createBatchScanner(tableName, Authorizations.EMPTY, 2)) {
bs.setRanges(Collections.singleton(new Range()));
int recordsSeen = Iterables.size(bs);
return recordsSeen;
}
}
});
assertEquals(numRows * numColumns, recordsSeen);
}
use of org.apache.accumulo.core.data.Mutation in project accumulo by apache.
the class KerberosRenewalIT method createReadWriteDrop.
/**
* Creates a table, adds a record to it, and then compacts the table. A simple way to make sure that the system user exists (since the master does an RPC to
* the tserver which will create the system user if it doesn't already exist).
*/
private void createReadWriteDrop(Connector conn) throws TableNotFoundException, AccumuloSecurityException, AccumuloException, TableExistsException {
final String table = testName.getMethodName() + "_table";
conn.tableOperations().create(table);
BatchWriter bw = conn.createBatchWriter(table, new BatchWriterConfig());
Mutation m = new Mutation("a");
m.put("b", "c", "d");
bw.addMutation(m);
bw.close();
conn.tableOperations().compact(table, new CompactionConfig().setFlush(true).setWait(true));
try (Scanner s = conn.createScanner(table, Authorizations.EMPTY)) {
Entry<Key, Value> entry = Iterables.getOnlyElement(s);
assertEquals("Did not find the expected key", 0, new Key("a", "b", "c").compareTo(entry.getKey(), PartialKey.ROW_COLFAM_COLQUAL));
assertEquals("d", entry.getValue().toString());
conn.tableOperations().delete(table);
}
}
use of org.apache.accumulo.core.data.Mutation in project accumulo by apache.
the class LargeRowIT method basicTest.
private void basicTest(Connector c, String table, int expectedSplits) throws Exception {
BatchWriter bw = c.createBatchWriter(table, new BatchWriterConfig());
Random r = new Random();
byte[] rowData = new byte[ROW_SIZE];
r.setSeed(SEED);
for (int i = 0; i < NUM_ROWS; i++) {
r.nextBytes(rowData);
TestIngest.toPrintableChars(rowData);
Mutation mut = new Mutation(new Text(rowData));
mut.put(new Text(""), new Text(""), new Value(Integer.toString(i).getBytes(UTF_8)));
bw.addMutation(mut);
}
bw.close();
FunctionalTestUtils.checkSplits(c, table, expectedSplits, expectedSplits);
verify(c, table);
FunctionalTestUtils.checkSplits(c, table, expectedSplits, expectedSplits);
c.tableOperations().flush(table, null, null, false);
// verify while table flush is running
verify(c, table);
// give split time to complete
c.tableOperations().flush(table, null, null, true);
FunctionalTestUtils.checkSplits(c, table, expectedSplits, expectedSplits);
verify(c, table);
FunctionalTestUtils.checkSplits(c, table, expectedSplits, expectedSplits);
}
use of org.apache.accumulo.core.data.Mutation in project accumulo by apache.
the class MapReduceIT method runTest.
static void runTest(Connector c, MiniAccumuloClusterImpl cluster) throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException, MutationsRejectedException, IOException, InterruptedException, NoSuchAlgorithmException {
c.tableOperations().create(tablename);
BatchWriter bw = c.createBatchWriter(tablename, new BatchWriterConfig());
for (int i = 0; i < 10; i++) {
Mutation m = new Mutation("" + i);
m.put(input_cf, input_cq, "row" + i);
bw.addMutation(m);
}
bw.close();
Process hash = cluster.exec(RowHash.class, Collections.singletonList(hadoopTmpDirArg), "-i", c.getInstance().getInstanceName(), "-z", c.getInstance().getZooKeepers(), "-u", "root", "-p", ROOT_PASSWORD, "-t", tablename, "--column", input_cfcq);
assertEquals(0, hash.waitFor());
try (Scanner s = c.createScanner(tablename, Authorizations.EMPTY)) {
s.fetchColumn(new Text(input_cf), new Text(output_cq));
int i = 0;
for (Entry<Key, Value> entry : s) {
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] check = Base64.getEncoder().encode(md.digest(("row" + i).getBytes()));
assertEquals(entry.getValue().toString(), new String(check));
i++;
}
}
}
Aggregations