use of com.treasuredata.client.model.TDJobSummary in project td-client-java by treasure-data.
the class TestTDClient method waitJobCompletion.
private TDJobSummary waitJobCompletion(String jobId) throws InterruptedException {
int retryCount = 0;
ExponentialBackOff backoff = new ExponentialBackOff();
long deadline = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(10);
TDJobSummary tdJob = null;
do {
if (System.currentTimeMillis() > deadline) {
throw new IllegalStateException(String.format("waiting job %s has timed out", jobId));
}
int nextWait = backoff.nextWaitTimeMillis();
logger.debug(String.format("Run job status check in %.2f sec.", nextWait / 1000.0));
Thread.sleep(nextWait);
tdJob = client.jobStatus(jobId);
logger.debug("job status: " + tdJob);
retryCount++;
} while (retryCount < 10 && !tdJob.getStatus().isFinished());
return tdJob;
}
use of com.treasuredata.client.model.TDJobSummary in project td-client-java by treasure-data.
the class TestTDClient method startSavedQuery.
@Test
public void startSavedQuery() throws Exception {
Date scheduledTime = new Date(1457046000 * 1000L);
try {
String jobId = client.startSavedQuery("no method to save a schedule yet", scheduledTime);
TDJobSummary tdJob = waitJobCompletion(jobId);
fail();
} catch (TDClientHttpNotFoundException e) {
// OK
}
}
use of com.treasuredata.client.model.TDJobSummary in project td-client-java by treasure-data.
the class TestTDClient method killJob.
@Test
public void killJob() throws Exception {
String jobId = client.submit(TDJobRequest.newPrestoQuery("sample_datasets", "-- td-client-java job kill test\n select time from nasdaq"));
client.killJob(jobId);
waitJobCompletion(jobId);
TDJobSummary summary = client.jobStatus(jobId);
assertEquals(TDJob.Status.KILLED, summary.getStatus());
}
use of com.treasuredata.client.model.TDJobSummary in project td-client-java by treasure-data.
the class Example method main.
public static void main(String[] args) {
TDClient client = TDClient.newClient();
try {
// Retrieve database and table names
List<TDDatabase> databases = client.listDatabases();
TDDatabase db = databases.get(0);
System.out.println("database: " + db.getName());
for (TDTable table : client.listTables(db.getName())) {
System.out.println(" table: " + table);
}
// Submit a new Presto query
String jobId = client.submit(TDJobRequest.newPrestoQuery("sample_datasets", "select count(1) cnt from www_access"));
// Wait until the query finishes
ExponentialBackOff backOff = new ExponentialBackOff();
TDJobSummary job = client.jobStatus(jobId);
while (!job.getStatus().isFinished()) {
Thread.sleep(backOff.nextWaitTimeMillis());
job = client.jobStatus(jobId);
}
// Read the detailed job information
TDJob jobInfo = client.jobInfo(jobId);
System.out.println("log:\n" + jobInfo.getCmdOut());
System.out.println("error log:\n" + jobInfo.getStdErr());
// Read the job results in msgpack.gz format
client.jobResult(jobId, TDResultFormat.MESSAGE_PACK_GZ, new Function<InputStream, Integer>() {
@Override
public Integer apply(InputStream input) {
int count = 0;
try {
MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(new GZIPInputStream(input));
while (unpacker.hasNext()) {
// Each row of the query result is array type value (e.g., [1, "name", ...])
ArrayValue array = unpacker.unpackValue().asArrayValue();
System.out.println(array);
count++;
}
unpacker.close();
} catch (Exception e) {
throw Throwables.propagate(e);
}
return count;
}
});
} catch (Exception e) {
e.printStackTrace();
} finally {
client.close();
}
}
use of com.treasuredata.client.model.TDJobSummary in project td-client-java by treasure-data.
the class TestTDClient method submitJobWithPoolName.
@Test
public void submitJobWithPoolName() throws Exception {
client.deleteTableIfExists(SAMPLE_DB, "sample_output");
String poolName = "hadoop2";
String jobId = client.submit(TDJobRequest.newHiveQuery("sample_datasets", "-- td-client-java test\nselect count(*) from nasdaq", null, poolName));
TDJobSummary tdJob = waitJobCompletion(jobId);
client.existsTable(SAMPLE_DB, "sample_output");
}
Aggregations