use of org.apache.drill.exec.proto.UserBitShared.QueryInfo in project drill by apache.
the class ProfileResources method getRunningProfilesJSON.
@GET
@Path("/profiles/running.json")
@Produces(MediaType.APPLICATION_JSON)
public Response getRunningProfilesJSON(@Context UriInfo uriInfo) {
try {
final QueryProfileStoreContext profileStoreContext = work.getContext().getProfileStoreContext();
final TransientStore<QueryInfo> running = profileStoreContext.getRunningProfileStore();
final List<String> errors = Lists.newArrayList();
final List<ProfileInfo> runningQueries = Lists.newArrayList();
final Iterator<Map.Entry<String, QueryInfo>> runningEntries = running.entries();
while (runningEntries.hasNext()) {
try {
final Map.Entry<String, QueryInfo> runningEntry = runningEntries.next();
final QueryInfo profile = runningEntry.getValue();
if (principal.canManageProfileOf(profile.getUser())) {
runningQueries.add(new ProfileInfo(work.getContext().getConfig(), runningEntry.getKey(), profile.getStart(), System.currentTimeMillis(), profile.getForeman().getAddress(), profile.getQuery(), ProfileUtil.getQueryStateDisplayName(profile.getState()), profile.getUser(), profile.getTotalCost(), profile.getQueueName()));
}
} catch (Exception e) {
errors.add(e.getMessage());
logger.error("Error getting running query info.", e);
}
}
Collections.sort(runningQueries, Collections.reverseOrder());
QProfilesRunning rProf = new QProfilesRunning(runningQueries, errors);
return errors.size() == 0 ? Response.ok().entity(rProf).build() : Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(rProf).build();
} catch (Exception e) {
throw UserException.resourceError(e).message("Failed to get running profiles from ephemeral store.").build(logger);
}
}
use of org.apache.drill.exec.proto.UserBitShared.QueryInfo in project drill by apache.
the class ProfileResources method cancelQuery.
@GET
@Path("/profiles/cancel/{queryid}")
@Produces(MediaType.TEXT_PLAIN)
public String cancelQuery(@PathParam("queryid") String queryId) {
QueryId id = QueryIdHelper.getQueryIdFromString(queryId);
// Prevent XSS
String encodedQueryID = forHtml(queryId);
// first check local running
if (work.getBee().cancelForeman(id, principal)) {
return String.format("Cancelled query %s on locally running node.", encodedQueryID);
}
// then check remote running
try {
final TransientStore<QueryInfo> running = work.getContext().getProfileStoreContext().getRunningProfileStore();
final QueryInfo info = running.get(queryId);
checkOrThrowQueryCancelAuthorization(info.getUser(), queryId);
Ack a = work.getContext().getController().getTunnel(info.getForeman()).requestCancelQuery(id).checkedGet(2, TimeUnit.SECONDS);
if (a.getOk()) {
return String.format("Query %s canceled on node %s.", encodedQueryID, info.getForeman().getAddress());
} else {
return String.format("Attempted to cancel query %s on %s but the query is no longer active on that node.", encodedQueryID, info.getForeman().getAddress());
}
} catch (Exception e) {
logger.debug("Failure to find query as running profile.", e);
return String.format("Failure attempting to cancel query %s. Unable to find information about where query is actively running.", encodedQueryID);
}
}
Aggregations