use of org.apache.drill.exec.work.foreman.Foreman in project drill by apache.
the class ProfileResources method getQueryProfile.
private QueryProfile getQueryProfile(String queryId) {
QueryId id = QueryIdHelper.getQueryIdFromString(queryId);
// first check local running
Foreman f = work.getBee().getForemanForQueryId(id);
if (f != null) {
QueryProfile queryProfile = f.getQueryManager().getQueryProfile();
checkOrThrowProfileViewAuthorization(queryProfile);
return queryProfile;
}
// then check remote running
try {
final TransientStore<QueryInfo> running = work.getContext().getProfileStoreContext().getRunningProfileStore();
final QueryInfo info = running.get(queryId);
if (info != null) {
QueryProfile queryProfile = work.getContext().getController().getTunnel(info.getForeman()).requestQueryProfile(id).checkedGet(2, TimeUnit.SECONDS);
checkOrThrowProfileViewAuthorization(queryProfile);
return queryProfile;
}
} catch (Exception e) {
logger.trace("Failed to find query as running profile.", e);
}
// then check blob store
try {
final PersistentStore<QueryProfile> profiles = work.getContext().getProfileStoreContext().getCompletedProfileStore();
final QueryProfile queryProfile = profiles.get(queryId);
if (queryProfile != null) {
checkOrThrowProfileViewAuthorization(queryProfile);
return queryProfile;
}
} catch (final Exception e) {
throw new DrillRuntimeException("error while retrieving profile", e);
}
throw UserException.validationError().message("No profile with given query id '%s' exists. Please verify the query id.", queryId).build(logger);
}
use of org.apache.drill.exec.work.foreman.Foreman in project drill by apache.
the class ControlMessageHandler method handle.
@Override
public void handle(ControlConnection connection, int rpcType, ByteBuf pBody, ByteBuf dBody, ResponseSender sender) throws RpcException {
if (RpcConstants.EXTRA_DEBUGGING) {
logger.debug("Received bit com message of type {}", rpcType);
}
switch(rpcType) {
case RpcType.REQ_CANCEL_FRAGMENT_VALUE:
{
final FragmentHandle handle = get(pBody, FragmentHandle.PARSER);
cancelFragment(handle);
sender.send(ControlRpcConfig.OK);
break;
}
case RpcType.REQ_CUSTOM_VALUE:
{
final CustomMessage customMessage = get(pBody, CustomMessage.PARSER);
sender.send(handlerRegistry.handle(customMessage, (DrillBuf) dBody));
break;
}
case RpcType.REQ_RECEIVER_FINISHED_VALUE:
{
final FinishedReceiver finishedReceiver = get(pBody, FinishedReceiver.PARSER);
receivingFragmentFinished(finishedReceiver);
sender.send(ControlRpcConfig.OK);
break;
}
case RpcType.REQ_FRAGMENT_STATUS_VALUE:
bee.getContext().getWorkBus().statusUpdate(get(pBody, FragmentStatus.PARSER));
// TODO: Support a type of message that has no response.
sender.send(ControlRpcConfig.OK);
break;
case RpcType.REQ_QUERY_CANCEL_VALUE:
{
final QueryId queryId = get(pBody, QueryId.PARSER);
final Foreman foreman = bee.getForemanForQueryId(queryId);
if (foreman != null) {
foreman.cancel();
sender.send(ControlRpcConfig.OK);
} else {
sender.send(ControlRpcConfig.FAIL);
}
break;
}
case RpcType.REQ_INITIALIZE_FRAGMENTS_VALUE:
{
final InitializeFragments fragments = get(pBody, InitializeFragments.PARSER);
for (int i = 0; i < fragments.getFragmentCount(); i++) {
startNewRemoteFragment(fragments.getFragment(i));
}
sender.send(ControlRpcConfig.OK);
break;
}
case RpcType.REQ_QUERY_STATUS_VALUE:
{
final QueryId queryId = get(pBody, QueryId.PARSER);
final Foreman foreman = bee.getForemanForQueryId(queryId);
if (foreman == null) {
throw new RpcException("Query not running on node.");
}
final QueryProfile profile = foreman.getQueryManager().getQueryProfile();
sender.send(new Response(RpcType.RESP_QUERY_STATUS, profile));
break;
}
case RpcType.REQ_UNPAUSE_FRAGMENT_VALUE:
{
final FragmentHandle handle = get(pBody, FragmentHandle.PARSER);
resumeFragment(handle);
sender.send(ControlRpcConfig.OK);
break;
}
default:
throw new RpcException("Not yet supported.");
}
}
use of org.apache.drill.exec.work.foreman.Foreman in project drill by apache.
the class UserWorker method submitWork.
public QueryId submitWork(UserClientConnection connection, RunQuery query) {
final QueryId id = queryIdGenerator();
incrementer.increment(connection.getSession());
Foreman foreman = new Foreman(bee, bee.getContext(), connection, id, query);
bee.addNewForeman(foreman);
return id;
}
use of org.apache.drill.exec.work.foreman.Foreman 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);
// first check local running
Foreman f = work.getBee().getForemanForQueryId(id);
if (f != null) {
checkOrThrowQueryCancelAuthorization(f.getQueryContext().getQueryUserName(), queryId);
f.cancel();
return String.format("Cancelled query %s on locally running node.", queryId);
}
// 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.", queryId, info.getForeman().getAddress());
} else {
return String.format("Attempted to cancel query %s on %s but the query is no longer active on that node.", queryId, 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.", queryId);
}
}
Aggregations