use of org.apache.accumulo.proxy.thrift.ScanOptions in project accumulo by apache.
the class KerberosProxyIT method testProxyClient.
@Test
public void testProxyClient() throws Exception {
ClusterUser rootUser = kdc.getRootUser();
UserGroupInformation ugi = UserGroupInformation.loginUserFromKeytabAndReturnUGI(rootUser.getPrincipal(), rootUser.getKeytab().getAbsolutePath());
TSocket socket = new TSocket(hostname, proxyPort);
log.info("Connecting to proxy with server primary '{}' running on {}", proxyPrimary, hostname);
TSaslClientTransport transport = new TSaslClientTransport("GSSAPI", null, proxyPrimary, hostname, Collections.singletonMap("javax.security.sasl.qop", "auth"), null, socket);
final UGIAssumingTransport ugiTransport = new UGIAssumingTransport(transport, ugi);
// UGI transport will perform the doAs for us
ugiTransport.open();
AccumuloProxy.Client.Factory factory = new AccumuloProxy.Client.Factory();
Client client = factory.getClient(new TCompactProtocol(ugiTransport), new TCompactProtocol(ugiTransport));
// Will fail if the proxy can impersonate the client
ByteBuffer login = client.login(rootUser.getPrincipal(), Collections.<String, String>emptyMap());
// For all of the below actions, the proxy user doesn't have permission to do any of them, but the client user does.
// The fact that any of them actually run tells us that impersonation is working.
// Create a table
String table = "table";
if (!client.tableExists(login, table)) {
client.createTable(login, table, true, TimeType.MILLIS);
}
// Write two records to the table
String writer = client.createWriter(login, table, new WriterOptions());
Map<ByteBuffer, List<ColumnUpdate>> updates = new HashMap<>();
ColumnUpdate update = new ColumnUpdate(ByteBuffer.wrap("cf1".getBytes(UTF_8)), ByteBuffer.wrap("cq1".getBytes(UTF_8)));
update.setValue(ByteBuffer.wrap("value1".getBytes(UTF_8)));
updates.put(ByteBuffer.wrap("row1".getBytes(UTF_8)), Collections.singletonList(update));
update = new ColumnUpdate(ByteBuffer.wrap("cf2".getBytes(UTF_8)), ByteBuffer.wrap("cq2".getBytes(UTF_8)));
update.setValue(ByteBuffer.wrap("value2".getBytes(UTF_8)));
updates.put(ByteBuffer.wrap("row2".getBytes(UTF_8)), Collections.singletonList(update));
client.update(writer, updates);
// Flush and close the writer
client.flush(writer);
client.closeWriter(writer);
// Open a scanner to the table
String scanner = client.createScanner(login, table, new ScanOptions());
ScanResult results = client.nextK(scanner, 10);
assertEquals(2, results.getResults().size());
// Check the first key-value
KeyValue kv = results.getResults().get(0);
Key k = kv.key;
ByteBuffer v = kv.value;
assertEquals(ByteBuffer.wrap("row1".getBytes(UTF_8)), k.row);
assertEquals(ByteBuffer.wrap("cf1".getBytes(UTF_8)), k.colFamily);
assertEquals(ByteBuffer.wrap("cq1".getBytes(UTF_8)), k.colQualifier);
assertEquals(ByteBuffer.wrap(new byte[0]), k.colVisibility);
assertEquals(ByteBuffer.wrap("value1".getBytes(UTF_8)), v);
// And then the second
kv = results.getResults().get(1);
k = kv.key;
v = kv.value;
assertEquals(ByteBuffer.wrap("row2".getBytes(UTF_8)), k.row);
assertEquals(ByteBuffer.wrap("cf2".getBytes(UTF_8)), k.colFamily);
assertEquals(ByteBuffer.wrap("cq2".getBytes(UTF_8)), k.colQualifier);
assertEquals(ByteBuffer.wrap(new byte[0]), k.colVisibility);
assertEquals(ByteBuffer.wrap("value2".getBytes(UTF_8)), v);
// Close the scanner
client.closeScanner(scanner);
ugiTransport.close();
}
use of org.apache.accumulo.proxy.thrift.ScanOptions in project accumulo by apache.
the class SimpleProxyBase method tableNotFound.
@Test
public void tableNotFound() throws Exception {
final String doesNotExist = "doesNotExists";
try {
client.addConstraint(creds, doesNotExist, NumericValueConstraint.class.getName());
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.addSplits(creds, doesNotExist, Collections.<ByteBuffer>emptySet());
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
final IteratorSetting setting = new IteratorSetting(100, "slow", SlowIterator.class.getName(), Collections.singletonMap("sleepTime", "200"));
try {
client.attachIterator(creds, doesNotExist, setting, EnumSet.allOf(IteratorScope.class));
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.cancelCompaction(creds, doesNotExist);
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.checkIteratorConflicts(creds, doesNotExist, setting, EnumSet.allOf(IteratorScope.class));
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.clearLocatorCache(creds, doesNotExist);
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
final String TABLE_TEST = getUniqueNames(1)[0];
client.cloneTable(creds, doesNotExist, TABLE_TEST, false, null, null);
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.compactTable(creds, doesNotExist, null, null, null, true, false, null);
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.createBatchScanner(creds, doesNotExist, new BatchScanOptions());
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.createScanner(creds, doesNotExist, new ScanOptions());
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.createWriter(creds, doesNotExist, new WriterOptions());
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.deleteRows(creds, doesNotExist, null, null);
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.deleteTable(creds, doesNotExist);
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.exportTable(creds, doesNotExist, "/tmp");
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.flushTable(creds, doesNotExist, null, null, false);
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.getIteratorSetting(creds, doesNotExist, "foo", IteratorScope.SCAN);
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.getLocalityGroups(creds, doesNotExist);
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.getMaxRow(creds, doesNotExist, Collections.<ByteBuffer>emptySet(), null, false, null, false);
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.getTableProperties(creds, doesNotExist);
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.grantTablePermission(creds, "root", doesNotExist, TablePermission.WRITE);
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.hasTablePermission(creds, "root", doesNotExist, TablePermission.WRITE);
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
MiniAccumuloClusterImpl cluster = SharedMiniClusterBase.getCluster();
Path base = cluster.getTemporaryPath();
Path importDir = new Path(base, "importDir");
Path failuresDir = new Path(base, "failuresDir");
assertTrue(cluster.getFileSystem().mkdirs(importDir));
assertTrue(cluster.getFileSystem().mkdirs(failuresDir));
client.importDirectory(creds, doesNotExist, importDir.toString(), failuresDir.toString(), true);
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.listConstraints(creds, doesNotExist);
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.listSplits(creds, doesNotExist, 10000);
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.mergeTablets(creds, doesNotExist, null, null);
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.offlineTable(creds, doesNotExist, false);
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.onlineTable(creds, doesNotExist, false);
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.removeConstraint(creds, doesNotExist, 0);
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.removeIterator(creds, doesNotExist, "name", EnumSet.allOf(IteratorScope.class));
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.removeTableProperty(creds, doesNotExist, Property.TABLE_FILE_MAX.getKey());
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.renameTable(creds, doesNotExist, "someTableName");
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.revokeTablePermission(creds, "root", doesNotExist, TablePermission.ALTER_TABLE);
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.setTableProperty(creds, doesNotExist, Property.TABLE_FILE_MAX.getKey(), "0");
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.splitRangeByTablets(creds, doesNotExist, client.getRowRange(ByteBuffer.wrap("row".getBytes(UTF_8))), 10);
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.updateAndFlush(creds, doesNotExist, new HashMap<ByteBuffer, List<ColumnUpdate>>());
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.getDiskUsage(creds, Collections.singleton(doesNotExist));
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.testTableClassLoad(creds, doesNotExist, VersioningIterator.class.getName(), SortedKeyValueIterator.class.getName());
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
try {
client.createConditionalWriter(creds, doesNotExist, new ConditionalWriterOptions());
fail("exception not thrown");
} catch (TableNotFoundException ex) {
}
}
use of org.apache.accumulo.proxy.thrift.ScanOptions in project accumulo by apache.
the class SimpleProxyBase method assertScan.
private void assertScan(String[][] expected, String table) throws Exception {
String scid = client.createScanner(creds, table, new ScanOptions());
ScanResult keyValues = client.nextK(scid, expected.length + 1);
assertEquals("Saw " + keyValues.results, expected.length, keyValues.results.size());
assertFalse(keyValues.more);
for (int i = 0; i < keyValues.results.size(); i++) {
checkKey(expected[i][0], expected[i][1], expected[i][2], expected[i][3], keyValues.results.get(i));
}
client.closeScanner(scid);
}
use of org.apache.accumulo.proxy.thrift.ScanOptions in project accumulo by apache.
the class TestProxyReadWrite method testVisibility.
@Test
public void testVisibility() throws Exception {
Set<ByteBuffer> auths = new HashSet<>();
auths.add(ByteBuffer.wrap("even".getBytes()));
tpc.proxy().changeUserAuthorizations(userpass, "root", auths);
int maxInserts = 10000;
Map<ByteBuffer, List<ColumnUpdate>> mutations = new HashMap<>();
String format = "%1$05d";
String writer = tpc.proxy().createWriter(userpass, testtable, null);
for (int i = 0; i < maxInserts; i++) {
if (i % 2 == 0)
addMutation(mutations, String.format(format, i), "cf" + i, "cq" + i, "even", Util.randString(10));
else
addMutation(mutations, String.format(format, i), "cf" + i, "cq" + i, "odd", Util.randString(10));
if (i % 1000 == 0 || i == maxInserts - 1) {
tpc.proxy().update(writer, mutations);
mutations.clear();
}
}
tpc.proxy().flush(writer);
tpc.proxy().closeWriter(writer);
ScanOptions opts = new ScanOptions();
opts.authorizations = auths;
String cookie = tpc.proxy().createScanner(userpass, testtable, opts);
int i = 0;
boolean hasNext = true;
int k = 1000;
int numRead = 0;
while (hasNext) {
ScanResult kvList = tpc.proxy().nextK(cookie, k);
for (KeyValue kv : kvList.getResults()) {
assertEquals(Integer.parseInt(new String(kv.getKey().getRow())), i);
i += 2;
numRead++;
}
hasNext = kvList.isMore();
}
assertEquals(maxInserts / 2, numRead);
}
use of org.apache.accumulo.proxy.thrift.ScanOptions in project accumulo by apache.
the class TestProxyReadWrite method asynchReadWrite.
@Test
public void asynchReadWrite() throws Exception {
int maxInserts = 10000;
Map<ByteBuffer, List<ColumnUpdate>> mutations = new HashMap<>();
String format = "%1$05d";
String writer = tpc.proxy().createWriter(userpass, testtable, null);
for (int i = 0; i < maxInserts; i++) {
addMutation(mutations, String.format(format, i), "cf" + i, "cq" + i, Util.randString(10));
if (i % 1000 == 0 || i == maxInserts - 1) {
tpc.proxy().update(writer, mutations);
mutations.clear();
}
}
tpc.proxy().flush(writer);
tpc.proxy().closeWriter(writer);
String regex = ".*[02468]";
org.apache.accumulo.core.client.IteratorSetting is = new org.apache.accumulo.core.client.IteratorSetting(50, regex, RegExFilter.class);
RegExFilter.setRegexs(is, regex, null, null, null, false);
IteratorSetting pis = Util.iteratorSetting2ProxyIteratorSetting(is);
ScanOptions opts = new ScanOptions();
opts.iterators = Collections.singletonList(pis);
String cookie = tpc.proxy().createScanner(userpass, testtable, opts);
int i = 0;
boolean hasNext = true;
int k = 1000;
int numRead = 0;
while (hasNext) {
ScanResult kvList = tpc.proxy().nextK(cookie, k);
for (KeyValue kv : kvList.getResults()) {
assertEquals(i, Integer.parseInt(new String(kv.getKey().getRow())));
numRead++;
i += 2;
}
hasNext = kvList.isMore();
}
assertEquals(maxInserts / 2, numRead);
}
Aggregations