Search in sources :

Example 6 with Job

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();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) Job(com.airbnb.airpal.api.Job)

Example 7 with Job

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();
}
Also used : Table(com.airbnb.airpal.presto.Table) PartitionedTable(com.airbnb.airpal.presto.PartitionedTable) Column(com.facebook.presto.client.Column) ImmutableList(com.google.common.collect.ImmutableList) Job(com.airbnb.airpal.api.Job) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Job (com.airbnb.airpal.api.Job)7 Table (com.airbnb.airpal.presto.Table)4 ImmutableList (com.google.common.collect.ImmutableList)4 PartitionedTable (com.airbnb.airpal.presto.PartitionedTable)3 Column (com.facebook.presto.client.Column)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)2 PartitionedTableToTable (com.airbnb.airpal.presto.PartitionedTable.PartitionedTableToTable)1 JobTableOutputJoinRow (com.airbnb.airpal.sql.beans.JobTableOutputJoinRow)1 QueryError (com.facebook.presto.client.QueryError)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Produces (javax.ws.rs.Produces)1 Handle (org.skife.jdbi.v2.Handle)1