Search in sources :

Example 31 with BadRequestException

use of org.apache.hadoop.yarn.webapp.BadRequestException in project hadoop by apache.

the class TimelineWebServices method getEntity.

/**
   * Return a single entity of the given entity type and Id.
   */
@GET
@Path("/{entityType}/{entityId}")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8 })
public TimelineEntity getEntity(@Context HttpServletRequest req, @Context HttpServletResponse res, @PathParam("entityType") String entityType, @PathParam("entityId") String entityId, @QueryParam("fields") String fields) {
    init(res);
    TimelineEntity entity = null;
    try {
        entity = timelineDataManager.getEntity(parseStr(entityType), parseStr(entityId), parseFieldsStr(fields, ","), getUser(req));
    } catch (IllegalArgumentException e) {
        throw new BadRequestException(e);
    } catch (Exception e) {
        LOG.error("Error getting entity", e);
        throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
    }
    if (entity == null) {
        throw new NotFoundException("Timeline entity " + new EntityIdentifier(parseStr(entityId), parseStr(entityType)) + " is not found");
    }
    return entity;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) EntityIdentifier(org.apache.hadoop.yarn.server.timeline.EntityIdentifier) TimelineEntity(org.apache.hadoop.yarn.api.records.timeline.TimelineEntity) ForbiddenException(org.apache.hadoop.yarn.webapp.ForbiddenException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) IOException(java.io.IOException) WebApplicationException(javax.ws.rs.WebApplicationException) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 32 with BadRequestException

use of org.apache.hadoop.yarn.webapp.BadRequestException in project hadoop by apache.

the class TimelineWebServices method getDomain.

/**
   * Return a single domain of the given domain Id.
   */
@GET
@Path("/domain/{domainId}")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8 })
public TimelineDomain getDomain(@Context HttpServletRequest req, @Context HttpServletResponse res, @PathParam("domainId") String domainId) {
    init(res);
    domainId = parseStr(domainId);
    if (domainId == null || domainId.length() == 0) {
        throw new BadRequestException("Domain ID is not specified.");
    }
    TimelineDomain domain = null;
    try {
        domain = timelineDataManager.getDomain(parseStr(domainId), getUser(req));
    } catch (Exception e) {
        LOG.error("Error getting domain", e);
        throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
    }
    if (domain == null) {
        throw new NotFoundException("Timeline domain [" + domainId + "] is not found");
    }
    return domain;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) TimelineDomain(org.apache.hadoop.yarn.api.records.timeline.TimelineDomain) ForbiddenException(org.apache.hadoop.yarn.webapp.ForbiddenException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) IOException(java.io.IOException) WebApplicationException(javax.ws.rs.WebApplicationException) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 33 with BadRequestException

use of org.apache.hadoop.yarn.webapp.BadRequestException in project hadoop by apache.

the class TimelineWebServices method getDomains.

/**
   * Return a list of domains of the given owner.
   */
@GET
@Path("/domain")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8 })
public TimelineDomains getDomains(@Context HttpServletRequest req, @Context HttpServletResponse res, @QueryParam("owner") String owner) {
    init(res);
    owner = parseStr(owner);
    UserGroupInformation callerUGI = getUser(req);
    if (owner == null || owner.length() == 0) {
        if (callerUGI == null) {
            throw new BadRequestException("Domain owner is not specified.");
        } else {
            // By default it's going to list the caller's domains
            owner = callerUGI.getShortUserName();
        }
    }
    try {
        return timelineDataManager.getDomains(owner, callerUGI);
    } catch (Exception e) {
        LOG.error("Error getting domains", e);
        throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) ForbiddenException(org.apache.hadoop.yarn.webapp.ForbiddenException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) IOException(java.io.IOException) WebApplicationException(javax.ws.rs.WebApplicationException) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 34 with BadRequestException

use of org.apache.hadoop.yarn.webapp.BadRequestException in project hadoop by apache.

the class WebServices method getApps.

public AppsInfo getApps(HttpServletRequest req, HttpServletResponse res, String stateQuery, Set<String> statesQuery, String finalStatusQuery, String userQuery, String queueQuery, String count, String startedBegin, String startedEnd, String finishBegin, String finishEnd, Set<String> applicationTypes) {
    UserGroupInformation callerUGI = getUser(req);
    boolean checkEnd = false;
    boolean checkAppTypes = false;
    boolean checkAppStates = false;
    long countNum = Long.MAX_VALUE;
    // set values suitable in case both of begin/end not specified
    long sBegin = 0;
    long sEnd = Long.MAX_VALUE;
    long fBegin = 0;
    long fEnd = Long.MAX_VALUE;
    if (count != null && !count.isEmpty()) {
        countNum = Long.parseLong(count);
        if (countNum <= 0) {
            throw new BadRequestException("limit value must be greater then 0");
        }
    }
    if (startedBegin != null && !startedBegin.isEmpty()) {
        sBegin = Long.parseLong(startedBegin);
        if (sBegin < 0) {
            throw new BadRequestException("startedTimeBegin must be greater than 0");
        }
    }
    if (startedEnd != null && !startedEnd.isEmpty()) {
        sEnd = Long.parseLong(startedEnd);
        if (sEnd < 0) {
            throw new BadRequestException("startedTimeEnd must be greater than 0");
        }
    }
    if (sBegin > sEnd) {
        throw new BadRequestException("startedTimeEnd must be greater than startTimeBegin");
    }
    if (finishBegin != null && !finishBegin.isEmpty()) {
        checkEnd = true;
        fBegin = Long.parseLong(finishBegin);
        if (fBegin < 0) {
            throw new BadRequestException("finishTimeBegin must be greater than 0");
        }
    }
    if (finishEnd != null && !finishEnd.isEmpty()) {
        checkEnd = true;
        fEnd = Long.parseLong(finishEnd);
        if (fEnd < 0) {
            throw new BadRequestException("finishTimeEnd must be greater than 0");
        }
    }
    if (fBegin > fEnd) {
        throw new BadRequestException("finishTimeEnd must be greater than finishTimeBegin");
    }
    Set<String> appTypes = parseQueries(applicationTypes, false);
    if (!appTypes.isEmpty()) {
        checkAppTypes = true;
    }
    // stateQuery is deprecated.
    if (stateQuery != null && !stateQuery.isEmpty()) {
        statesQuery.add(stateQuery);
    }
    Set<String> appStates = parseQueries(statesQuery, true);
    if (!appStates.isEmpty()) {
        checkAppStates = true;
    }
    AppsInfo allApps = new AppsInfo();
    Collection<ApplicationReport> appReports = null;
    final GetApplicationsRequest request = GetApplicationsRequest.newInstance();
    request.setLimit(countNum);
    request.setStartRange(new LongRange(sBegin, sEnd));
    try {
        if (callerUGI == null) {
            // TODO: the request should take the params like what RMWebServices does
            // in YARN-1819.
            appReports = appBaseProt.getApplications(request).getApplicationList();
        } else {
            appReports = callerUGI.doAs(new PrivilegedExceptionAction<Collection<ApplicationReport>>() {

                @Override
                public Collection<ApplicationReport> run() throws Exception {
                    return appBaseProt.getApplications(request).getApplicationList();
                }
            });
        }
    } catch (Exception e) {
        rewrapAndThrowException(e);
    }
    if (appReports == null) {
        return allApps;
    }
    for (ApplicationReport appReport : appReports) {
        if (checkAppStates && !appStates.contains(StringUtils.toLowerCase(appReport.getYarnApplicationState().toString()))) {
            continue;
        }
        if (finalStatusQuery != null && !finalStatusQuery.isEmpty()) {
            FinalApplicationStatus.valueOf(finalStatusQuery);
            if (!appReport.getFinalApplicationStatus().toString().equalsIgnoreCase(finalStatusQuery)) {
                continue;
            }
        }
        if (userQuery != null && !userQuery.isEmpty()) {
            if (!appReport.getUser().equals(userQuery)) {
                continue;
            }
        }
        if (queueQuery != null && !queueQuery.isEmpty()) {
            if (!appReport.getQueue().equals(queueQuery)) {
                continue;
            }
        }
        if (checkAppTypes && !appTypes.contains(StringUtils.toLowerCase(appReport.getApplicationType().trim()))) {
            continue;
        }
        if (checkEnd && (appReport.getFinishTime() < fBegin || appReport.getFinishTime() > fEnd)) {
            continue;
        }
        AppInfo app = new AppInfo(appReport);
        allApps.add(app);
    }
    return allApps;
}
Also used : PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) GetApplicationsRequest(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest) ForbiddenException(org.apache.hadoop.yarn.webapp.ForbiddenException) AuthorizationException(org.apache.hadoop.security.authorize.AuthorizationException) ContainerNotFoundException(org.apache.hadoop.yarn.exceptions.ContainerNotFoundException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) WebApplicationException(javax.ws.rs.WebApplicationException) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) AppInfo(org.apache.hadoop.yarn.server.webapp.dao.AppInfo) ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) LongRange(org.apache.commons.lang.math.LongRange) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) AppsInfo(org.apache.hadoop.yarn.server.webapp.dao.AppsInfo) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation)

Example 35 with BadRequestException

use of org.apache.hadoop.yarn.webapp.BadRequestException in project hadoop by apache.

the class NMWebServices method getNodeApps.

@GET
@Path("/apps")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
public AppsInfo getNodeApps(@QueryParam("state") String stateQuery, @QueryParam("user") String userQuery) {
    init();
    AppsInfo allApps = new AppsInfo();
    for (Entry<ApplicationId, Application> entry : this.nmContext.getApplications().entrySet()) {
        AppInfo appInfo = new AppInfo(entry.getValue());
        if (stateQuery != null && !stateQuery.isEmpty()) {
            ApplicationState.valueOf(stateQuery);
            if (!appInfo.getState().equalsIgnoreCase(stateQuery)) {
                continue;
            }
        }
        if (userQuery != null) {
            if (userQuery.isEmpty()) {
                String msg = "Error: You must specify a non-empty string for the user";
                throw new BadRequestException(msg);
            }
            if (!appInfo.getUser().equals(userQuery)) {
                continue;
            }
        }
        allApps.add(appInfo);
    }
    return allApps;
}
Also used : BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) AppsInfo(org.apache.hadoop.yarn.server.nodemanager.webapp.dao.AppsInfo) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Application(org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application) AppInfo(org.apache.hadoop.yarn.server.nodemanager.webapp.dao.AppInfo) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

BadRequestException (org.apache.hadoop.yarn.webapp.BadRequestException)38 Produces (javax.ws.rs.Produces)27 Path (javax.ws.rs.Path)26 IOException (java.io.IOException)18 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)18 GET (javax.ws.rs.GET)16 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)16 NotFoundException (org.apache.hadoop.yarn.webapp.NotFoundException)16 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)13 WebApplicationException (javax.ws.rs.WebApplicationException)12 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)9 ForbiddenException (org.apache.hadoop.yarn.webapp.ForbiddenException)9 POST (javax.ws.rs.POST)8 Consumes (javax.ws.rs.Consumes)7 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)6 ParseException (java.text.ParseException)6 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)6 YarnRuntimeException (org.apache.hadoop.yarn.exceptions.YarnRuntimeException)6 ArrayList (java.util.ArrayList)4 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)3