use of org.apache.accumulo.proxy.thrift.ColumnUpdate in project accumulo by apache.
the class ProxyServer method addUpdatesToMutation.
private void addUpdatesToMutation(HashMap<Text, ColumnVisibility> vizMap, Mutation m, List<ColumnUpdate> cu) {
for (ColumnUpdate update : cu) {
ColumnVisibility viz = EMPTY_VIS;
if (update.isSetColVisibility()) {
viz = getCahcedCV(vizMap, update.getColVisibility());
}
byte[] value = new byte[0];
if (update.isSetValue())
value = update.getValue();
if (update.isSetTimestamp()) {
if (update.isSetDeleteCell() && update.isDeleteCell()) {
m.putDelete(update.getColFamily(), update.getColQualifier(), viz, update.getTimestamp());
} else {
m.put(update.getColFamily(), update.getColQualifier(), viz, update.getTimestamp(), value);
}
} else {
if (update.isSetDeleteCell() && update.isDeleteCell()) {
m.putDelete(new Text(update.getColFamily()), new Text(update.getColQualifier()), viz);
} else {
m.put(new Text(update.getColFamily()), new Text(update.getColQualifier()), viz, new Value(value));
}
}
}
}
use of org.apache.accumulo.proxy.thrift.ColumnUpdate 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.ColumnUpdate in project accumulo by apache.
the class TestProxyTableOperations method addMutation.
private static void addMutation(Map<ByteBuffer, List<ColumnUpdate>> mutations, String row, String cf, String cq, String value) {
ColumnUpdate update = new ColumnUpdate(ByteBuffer.wrap(cf.getBytes()), ByteBuffer.wrap(cq.getBytes()));
update.setValue(value.getBytes());
mutations.put(ByteBuffer.wrap(row.getBytes()), Collections.singletonList(update));
}
use of org.apache.accumulo.proxy.thrift.ColumnUpdate in project accumulo by apache.
the class ProxyDurabilityIT method testDurability.
@Test
public void testDurability() throws Exception {
Connector c = getConnector();
Properties props = new Properties();
// Avoid issues with locally installed client configuration files with custom properties
File emptyFile = Files.createTempFile(null, null).toFile();
emptyFile.deleteOnExit();
props.put("instance", c.getInstance().getInstanceName());
props.put("zookeepers", c.getInstance().getZooKeepers());
props.put("tokenClass", PasswordToken.class.getName());
props.put("clientConfigurationFile", emptyFile.toString());
TJSONProtocol.Factory protocol = new TJSONProtocol.Factory();
int proxyPort = PortUtils.getRandomFreePort();
final TServer proxyServer = Proxy.createProxyServer(HostAndPort.fromParts("localhost", proxyPort), protocol, props).server;
while (!proxyServer.isServing()) sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
Client client = new TestProxyClient("localhost", proxyPort, protocol).proxy();
Map<String, String> properties = new TreeMap<>();
properties.put("password", ROOT_PASSWORD);
ByteBuffer login = client.login("root", properties);
String tableName = getUniqueNames(1)[0];
client.createTable(login, tableName, true, TimeType.MILLIS);
assertTrue(c.tableOperations().exists(tableName));
WriterOptions options = new WriterOptions();
options.setDurability(Durability.NONE);
String writer = client.createWriter(login, tableName, options);
Map<ByteBuffer, List<ColumnUpdate>> cells = new TreeMap<>();
ColumnUpdate column = new ColumnUpdate(bytes("cf"), bytes("cq"));
column.setValue("value".getBytes());
cells.put(bytes("row"), Collections.singletonList(column));
client.update(writer, cells);
client.closeWriter(writer);
assertEquals(1, count(tableName));
restartTServer();
assertEquals(0, count(tableName));
ConditionalWriterOptions cfg = new ConditionalWriterOptions();
cfg.setDurability(Durability.SYNC);
String cwriter = client.createConditionalWriter(login, tableName, cfg);
ConditionalUpdates updates = new ConditionalUpdates();
updates.addToConditions(new Condition(new Column(bytes("cf"), bytes("cq"), bytes(""))));
updates.addToUpdates(column);
Map<ByteBuffer, ConditionalStatus> status = client.updateRowsConditionally(cwriter, Collections.singletonMap(bytes("row"), updates));
assertEquals(ConditionalStatus.ACCEPTED, status.get(bytes("row")));
assertEquals(1, count(tableName));
restartTServer();
assertEquals(1, count(tableName));
proxyServer.stop();
}
use of org.apache.accumulo.proxy.thrift.ColumnUpdate in project accumulo by apache.
the class SimpleProxyBase method mutation.
private Map<ByteBuffer, List<ColumnUpdate>> mutation(String row, String cf, String cq, String value) {
ColumnUpdate upd = new ColumnUpdate(s2bb(cf), s2bb(cq));
upd.setValue(value.getBytes(UTF_8));
return Collections.singletonMap(s2bb(row), Collections.singletonList(upd));
}
Aggregations