Search in sources :

Example 1 with QueryInfo

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

the class ProfileResources method getProfilesJSON.

@SuppressWarnings("resource")
@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(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());
        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(work.getContext().getConfig(), profileEntry.getKey(), profile.getStart(), profile.getEnd(), 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 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)

Example 2 with QueryInfo

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

the class ProfileResources method getQueryProfile.

@SuppressWarnings("resource")
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 3 with QueryInfo

use of org.apache.drill.exec.proto.UserBitShared.QueryInfo 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 4 with QueryInfo

use of org.apache.drill.exec.proto.UserBitShared.QueryInfo 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)

Example 5 with QueryInfo

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

the class ProfileResources method cancelQuery.

@SuppressWarnings("resource")
@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
    if (work.getBee().cancelForeman(id, principal)) {
        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);
    }
}
Also used : QueryId(org.apache.drill.exec.proto.UserBitShared.QueryId) Ack(org.apache.drill.exec.proto.GeneralRPCProtos.Ack) QueryInfo(org.apache.drill.exec.proto.UserBitShared.QueryInfo) UserException(org.apache.drill.common.exceptions.UserException) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

DrillRuntimeException (org.apache.drill.common.exceptions.DrillRuntimeException)7 UserException (org.apache.drill.common.exceptions.UserException)7 QueryInfo (org.apache.drill.exec.proto.UserBitShared.QueryInfo)7 GET (javax.ws.rs.GET)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 QueryId (org.apache.drill.exec.proto.UserBitShared.QueryId)4 QueryProfile (org.apache.drill.exec.proto.UserBitShared.QueryProfile)4 Map (java.util.Map)3 QueryProfileStoreContext (org.apache.drill.exec.server.QueryProfileStoreContext)3 Ack (org.apache.drill.exec.proto.GeneralRPCProtos.Ack)2 Foreman (org.apache.drill.exec.work.foreman.Foreman)2