use of com.airbnb.airpal.api.Job in project airpal by airbnb.
the class LocalJobHistoryStore method getRecentlyRun.
@Override
public List<Job> getRecentlyRun(long maxResults) {
final ImmutableList.Builder<Job> builder = ImmutableList.builder();
long added = 0;
for (Job job : historyCache) {
if (added + 1 > maxResults)
break;
builder.add(job);
added += 1;
}
return builder.build();
}
use of com.airbnb.airpal.api.Job in project airpal by airbnb.
the class QueryResource method getHistory.
@GET
@Path("history")
@Produces(MediaType.APPLICATION_JSON)
public Response getHistory(@Auth AirpalUser user, @QueryParam("table") List<Table> tables) {
Iterable<Job> recentlyRun;
if (tables.size() < 1) {
recentlyRun = jobHistoryStore.getRecentlyRun(200);
} else {
Table[] tablesArray = tables.toArray(new Table[tables.size()]);
Table[] restTables = Arrays.copyOfRange(tablesArray, 1, tablesArray.length);
recentlyRun = jobHistoryStore.getRecentlyRun(200, tablesArray[0], restTables);
}
ImmutableList.Builder<Job> filtered = ImmutableList.builder();
for (Job job : recentlyRun) {
if (job.getTablesUsed().isEmpty() && (job.getState() == JobState.FAILED)) {
filtered.add(job);
continue;
}
for (Table table : job.getTablesUsed()) {
if (AuthorizationUtil.isAuthorizedRead(user, table)) {
filtered.add(new Job(job.getUser(), job.getQuery(), job.getUuid(), job.getOutput(), job.getQueryStats(), job.getState(), Collections.<Column>emptyList(), Collections.<Table>emptySet(), job.getQueryStartedDateTime(), job.getError(), job.getQueryFinishedDateTime()));
}
}
}
List<Job> sortedResult = Ordering.natural().nullsLast().onResultOf(JOB_ORDERING).reverse().immutableSortedCopy(filtered.build());
return Response.ok(sortedResult).build();
}
Aggregations