Search in sources :

Example 1 with QueryProfile

use of org.apache.drill.exec.proto.UserBitShared.QueryProfile 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);
}
Also used : QueryProfile(org.apache.drill.exec.proto.UserBitShared.QueryProfile) QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId) Foreman(org.apache.drill.exec.work.foreman.Foreman) QueryInfo(org.apache.drill.exec.proto.UserBitShared.QueryInfo) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) UserException(org.apache.drill.common.exceptions.UserException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException)

Example 2 with QueryProfile

use of org.apache.drill.exec.proto.UserBitShared.QueryProfile in project drill by apache.

the class QueryManager method getQueryProfile.

private QueryProfile getQueryProfile(UserException ex) {
    final String queryText = foreman.getQueryText();
    final QueryProfile.Builder profileBuilder = QueryProfile.newBuilder().setUser(foreman.getQueryContext().getQueryUserName()).setType(runQuery.getType()).setId(queryId).setState(foreman.getState()).setForeman(foreman.getQueryContext().getCurrentEndpoint()).setStart(startTime).setEnd(endTime).setPlanEnd(planningEndTime).setQueueWaitEnd(queueWaitEndTime).setTotalFragments(fragmentDataSet.size()).setFinishedFragments(finishedFragments.get()).setOptionsJson(getQueryOptionsAsJson());
    if (ex != null) {
        profileBuilder.setError(ex.getMessage(false));
        profileBuilder.setVerboseError(ex.getVerboseMessage(false));
        profileBuilder.setErrorId(ex.getErrorId());
        if (ex.getErrorLocation() != null) {
            profileBuilder.setErrorNode(ex.getErrorLocation());
        }
    }
    if (planText != null) {
        profileBuilder.setPlan(planText);
    }
    if (queryText != null) {
        profileBuilder.setQuery(queryText);
    }
    fragmentDataMap.forEach(new OuterIter(profileBuilder));
    return profileBuilder.build();
}
Also used : QueryProfile(org.apache.drill.exec.proto.UserBitShared.QueryProfile) Builder(org.apache.drill.exec.proto.UserBitShared.QueryProfile.Builder)

Example 3 with QueryProfile

use of org.apache.drill.exec.proto.UserBitShared.QueryProfile 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.");
    }
}
Also used : Response(org.apache.drill.exec.rpc.Response) QueryProfile(org.apache.drill.exec.proto.UserBitShared.QueryProfile) InitializeFragments(org.apache.drill.exec.proto.BitControl.InitializeFragments) QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId) UserRpcException(org.apache.drill.exec.rpc.UserRpcException) RpcException(org.apache.drill.exec.rpc.RpcException) CustomMessage(org.apache.drill.exec.proto.BitControl.CustomMessage) FragmentHandle(org.apache.drill.exec.proto.ExecProtos.FragmentHandle) Foreman(org.apache.drill.exec.work.foreman.Foreman) FinishedReceiver(org.apache.drill.exec.proto.BitControl.FinishedReceiver)

Example 4 with QueryProfile

use of org.apache.drill.exec.proto.UserBitShared.QueryProfile in project drill by apache.

the class ProfileResources method getProfilesJSON.

@GET
@Path("/profiles.json")
@Produces(MediaType.APPLICATION_JSON)
public QProfiles getProfilesJSON(@Context UriInfo uriInfo) {
    try {
        final QueryProfileStoreContext profileStoreContext = work.getContext().getProfileStoreContext();
        final PersistentStore<QueryProfile> completed = profileStoreContext.getCompletedProfileStore();
        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(runningEntry.getKey(), profile.getStart(), System.currentTimeMillis(), profile.getForeman().getAddress(), profile.getQuery(), profile.getState().name(), profile.getUser()));
                }
            } catch (Exception e) {
                errors.add(e.getMessage());
                logger.error("Error getting running query info.", e);
            }
        }
        Collections.sort(runningQueries, Collections.reverseOrder());
        final List<ProfileInfo> finishedQueries = Lists.newArrayList();
        //Defining #Profiles to load
        int maxProfilesToLoad = work.getContext().getConfig().getInt(ExecConstants.HTTP_MAX_PROFILES);
        String maxProfilesParams = uriInfo.getQueryParameters().getFirst(MAX_QPROFILES_PARAM);
        if (maxProfilesParams != null && !maxProfilesParams.isEmpty()) {
            maxProfilesToLoad = Integer.valueOf(maxProfilesParams);
        }
        final Iterator<Map.Entry<String, QueryProfile>> range = completed.getRange(0, maxProfilesToLoad);
        while (range.hasNext()) {
            try {
                final Map.Entry<String, QueryProfile> profileEntry = range.next();
                final QueryProfile profile = profileEntry.getValue();
                if (principal.canManageProfileOf(profile.getUser())) {
                    finishedQueries.add(new ProfileInfo(profileEntry.getKey(), profile.getStart(), profile.getEnd(), profile.getForeman().getAddress(), profile.getQuery(), profile.getState().name(), profile.getUser()));
                }
            } catch (Exception e) {
                errors.add(e.getMessage());
                logger.error("Error getting finished query profile.", e);
            }
        }
        Collections.sort(finishedQueries, Collections.reverseOrder());
        return new QProfiles(runningQueries, finishedQueries, errors);
    } catch (Exception e) {
        throw UserException.resourceError(e).message("Failed to get profiles from persistent or ephemeral store.").build(logger);
    }
}
Also used : QueryProfile(org.apache.drill.exec.proto.UserBitShared.QueryProfile) QueryInfo(org.apache.drill.exec.proto.UserBitShared.QueryInfo) UserException(org.apache.drill.common.exceptions.UserException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) QueryProfileStoreContext(org.apache.drill.exec.server.QueryProfileStoreContext) Map(java.util.Map) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

QueryProfile (org.apache.drill.exec.proto.UserBitShared.QueryProfile)4 DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)2 UserException (org.apache.drill.common.exceptions.UserException)2 QueryId (org.apache.drill.exec.proto.UserBitShared.QueryId)2 QueryInfo (org.apache.drill.exec.proto.UserBitShared.QueryInfo)2 Foreman (org.apache.drill.exec.work.foreman.Foreman)2 Map (java.util.Map)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 CustomMessage (org.apache.drill.exec.proto.BitControl.CustomMessage)1 FinishedReceiver (org.apache.drill.exec.proto.BitControl.FinishedReceiver)1 InitializeFragments (org.apache.drill.exec.proto.BitControl.InitializeFragments)1 FragmentHandle (org.apache.drill.exec.proto.ExecProtos.FragmentHandle)1 Builder (org.apache.drill.exec.proto.UserBitShared.QueryProfile.Builder)1 Response (org.apache.drill.exec.rpc.Response)1 RpcException (org.apache.drill.exec.rpc.RpcException)1 UserRpcException (org.apache.drill.exec.rpc.UserRpcException)1 QueryProfileStoreContext (org.apache.drill.exec.server.QueryProfileStoreContext)1