use of org.apache.accumulo.tracer.TraceDump.Printer in project accumulo by apache.
the class TracerRecoversAfterOfflineTableIT method test.
@Test
public void test() throws Exception {
Process tracer = null;
Connector conn = getConnector();
if (!conn.tableOperations().exists("trace")) {
MiniAccumuloClusterImpl mac = cluster;
tracer = mac.exec(TraceServer.class);
while (!conn.tableOperations().exists("trace")) {
sleepUninterruptibly(1, TimeUnit.SECONDS);
}
sleepUninterruptibly(5, TimeUnit.SECONDS);
}
log.info("Taking table offline");
conn.tableOperations().offline("trace", true);
String tableName = getUniqueNames(1)[0];
conn.tableOperations().create(tableName);
log.info("Start a distributed trace span");
DistributedTrace.enable("localhost", "testTrace", getClientConfig());
Span root = Trace.on("traceTest");
BatchWriter bw = conn.createBatchWriter(tableName, null);
Mutation m = new Mutation("m");
m.put("a", "b", "c");
bw.addMutation(m);
bw.close();
root.stop();
log.info("Bringing trace table back online");
conn.tableOperations().online("trace", true);
log.info("Trace table is online, should be able to find trace");
try (Scanner scanner = conn.createScanner("trace", Authorizations.EMPTY)) {
scanner.setRange(new Range(new Text(Long.toHexString(root.traceId()))));
while (true) {
final StringBuilder finalBuffer = new StringBuilder();
int traceCount = TraceDump.printTrace(scanner, new Printer() {
@Override
public void print(final String line) {
try {
finalBuffer.append(line).append("\n");
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
});
String traceOutput = finalBuffer.toString();
log.info("Trace output:{}", traceOutput);
if (traceCount > 0) {
int lastPos = 0;
for (String part : "traceTest,close,binMutations".split(",")) {
log.info("Looking in trace output for '{}'", part);
int pos = traceOutput.indexOf(part);
assertTrue("Did not find '" + part + "' in output", pos > 0);
assertTrue("'" + part + "' occurred earlier than the previous element unexpectedly", pos > lastPos);
lastPos = pos;
}
break;
} else {
log.info("Ignoring trace output as traceCount not greater than zero: {}", traceCount);
Thread.sleep(1000);
}
}
if (tracer != null) {
tracer.destroy();
}
}
}
use of org.apache.accumulo.tracer.TraceDump.Printer in project accumulo by apache.
the class ConditionalWriterIT method testTrace.
@Test
public void testTrace() throws Exception {
// Need to add a getClientConfig() to AccumuloCluster
Assume.assumeTrue(getClusterType() == ClusterType.MINI);
Process tracer = null;
Connector conn = getConnector();
AccumuloCluster cluster = getCluster();
MiniAccumuloClusterImpl mac = (MiniAccumuloClusterImpl) cluster;
if (!conn.tableOperations().exists("trace")) {
tracer = mac.exec(TraceServer.class);
while (!conn.tableOperations().exists("trace")) {
sleepUninterruptibly(1, TimeUnit.SECONDS);
}
}
String tableName = getUniqueNames(1)[0];
conn.tableOperations().create(tableName);
DistributedTrace.enable("localhost", "testTrace", mac.getClientConfig());
sleepUninterruptibly(1, TimeUnit.SECONDS);
Span root = Trace.on("traceTest");
try (ConditionalWriter cw = conn.createConditionalWriter(tableName, new ConditionalWriterConfig())) {
// mutation conditional on column tx:seq not exiting
ConditionalMutation cm0 = new ConditionalMutation("99006", new Condition("tx", "seq"));
cm0.put("name", "last", "doe");
cm0.put("name", "first", "john");
cm0.put("tx", "seq", "1");
Assert.assertEquals(Status.ACCEPTED, cw.write(cm0).getStatus());
root.stop();
}
try (Scanner scanner = conn.createScanner("trace", Authorizations.EMPTY)) {
scanner.setRange(new Range(new Text(Long.toHexString(root.traceId()))));
loop: while (true) {
final StringBuilder finalBuffer = new StringBuilder();
int traceCount = TraceDump.printTrace(scanner, new Printer() {
@Override
public void print(final String line) {
try {
finalBuffer.append(line).append("\n");
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
});
String traceOutput = finalBuffer.toString();
log.info("Trace output:" + traceOutput);
if (traceCount > 0) {
int lastPos = 0;
for (String part : "traceTest, startScan,startConditionalUpdate,conditionalUpdate,Check conditions,apply conditional mutations".split(",")) {
log.info("Looking in trace output for '" + part + "'");
int pos = traceOutput.indexOf(part);
if (-1 == pos) {
log.info("Trace output doesn't contain '" + part + "'");
Thread.sleep(1000);
break loop;
}
assertTrue("Did not find '" + part + "' in output", pos > 0);
assertTrue("'" + part + "' occurred earlier than the previous element unexpectedly", pos > lastPos);
lastPos = pos;
}
break;
} else {
log.info("Ignoring trace output as traceCount not greater than zero: " + traceCount);
Thread.sleep(1000);
}
}
if (tracer != null) {
tracer.destroy();
}
}
}
use of org.apache.accumulo.tracer.TraceDump.Printer in project accumulo-examples by apache.
the class TraceDumpExample method dump.
public void dump(Opts opts) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
if (opts.traceId.isEmpty()) {
throw new IllegalArgumentException("--traceid option is required");
}
final Connector conn = opts.getConnector();
final String principal = opts.getPrincipal();
final String table = opts.getTableName();
if (!conn.securityOperations().hasTablePermission(principal, table, TablePermission.READ)) {
conn.securityOperations().grantTablePermission(principal, table, TablePermission.READ);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
while (!conn.securityOperations().hasTablePermission(principal, table, TablePermission.READ)) {
log.info("{} didn't propagate read permission on {}", principal, table);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
}
}
}
Scanner scanner = conn.createScanner(table, opts.auths);
scanner.setRange(new Range(new Text(opts.traceId)));
TraceDump.printTrace(scanner, new Printer() {
@Override
public void print(String line) {
System.out.println(line);
}
});
}
Aggregations