Search in sources :

Example 36 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)

Example 37 with BadRequestException

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

the class NMWebServices method getNodeContainer.

@GET
@Path("/containers/{containerid}")
@Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 })
public ContainerInfo getNodeContainer(@javax.ws.rs.core.Context HttpServletRequest hsr, @PathParam("containerid") String id) {
    ContainerId containerId = null;
    init();
    try {
        containerId = ContainerId.fromString(id);
    } catch (Exception e) {
        throw new BadRequestException("invalid container id, " + id);
    }
    Container container = nmContext.getContainers().get(containerId);
    if (container == null) {
        throw new NotFoundException("container with id, " + id + ", not found");
    }
    return new ContainerInfo(this.nmContext, container, uriInfo.getBaseUri().toString(), webapp.name(), hsr.getRemoteUser());
}
Also used : Container(org.apache.hadoop.yarn.server.nodemanager.containermanager.container.Container) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ContainerInfo(org.apache.hadoop.yarn.server.nodemanager.webapp.dao.ContainerInfo) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) WebApplicationException(javax.ws.rs.WebApplicationException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) IOException(java.io.IOException) BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 38 with BadRequestException

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

the class TimelineReaderWebServices method getFlowRuns.

/**
   * Return a list of flow runs for given UID which is a delimited string
   * containing clusterid, userid and flow name.
   *
   * @param req Servlet request.
   * @param res Servlet response.
   * @param uId a delimited string containing clusterid, userid, and flow name
   *     which are extracted from UID and then used to query backend(Mandatory
   *     path param).
   * @param limit If specified, defines the number of flow runs to return. The
   *     maximum possible value for limit can be {@link Long#MAX_VALUE}. If it
   *     is not specified or has a value less than 0, then limit will be
   *     considered as 100. (Optional query param).
   * @param createdTimeStart If specified, matched flow runs should not be
   *     created before this timestamp(Optional query param).
   * @param createdTimeEnd If specified, matched flow runs should not be created
   *     after this timestamp(Optional query param).
   * @param metricsToRetrieve If specified, defines which metrics to retrieve
   *     and send back in response. These metrics will be retrieved
   *     irrespective of whether metrics are specified in fields to retrieve or
   *     not.
   * @param fields Specifies which fields to retrieve, see {@link Field}. All
   *     fields will be retrieved if fields=ALL. Amongst all the fields, only
   *     METRICS makes sense for flow runs hence only ALL or METRICS are
   *     supported as fields for fetching flow runs. Other fields will lead to
   *     HTTP 400 (Bad Request) response. (Optional query param).
   *
   * @return If successful, a HTTP 200(OK) response having a JSON representing a
   *     set of <cite>FlowRunEntity</cite> instances for the given flow are
   *     returned.<br>
   *     On failures,<br>
   *     If any problem occurs in parsing request or UID is incorrect,
   *     HTTP 400(Bad Request) is returned.<br>
   *     For all other errors while retrieving data, HTTP 500(Internal Server
   *     Error) is returned.
   */
@GET
@Path("/flow-uid/{uid}/runs/")
@Produces(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8)
public Set<TimelineEntity> getFlowRuns(@Context HttpServletRequest req, @Context HttpServletResponse res, @PathParam("uid") String uId, @QueryParam("limit") String limit, @QueryParam("createdtimestart") String createdTimeStart, @QueryParam("createdtimeend") String createdTimeEnd, @QueryParam("metricstoretrieve") String metricsToRetrieve, @QueryParam("fields") String fields) {
    String url = req.getRequestURI() + (req.getQueryString() == null ? "" : QUERY_STRING_SEP + req.getQueryString());
    UserGroupInformation callerUGI = TimelineReaderWebServicesUtils.getUser(req);
    LOG.info("Received URL " + url + " from user " + TimelineReaderWebServicesUtils.getUserName(callerUGI));
    long startTime = Time.monotonicNow();
    init(res);
    TimelineReaderManager timelineReaderManager = getTimelineReaderManager();
    Set<TimelineEntity> entities = null;
    try {
        TimelineReaderContext context = TimelineUIDConverter.FLOW_UID.decodeUID(uId);
        if (context == null) {
            throw new BadRequestException("Incorrect UID " + uId);
        }
        context.setEntityType(TimelineEntityType.YARN_FLOW_RUN.toString());
        entities = timelineReaderManager.getEntities(context, TimelineReaderWebServicesUtils.createTimelineEntityFilters(limit, createdTimeStart, createdTimeEnd, null, null, null, null, null, null), TimelineReaderWebServicesUtils.createTimelineDataToRetrieve(null, metricsToRetrieve, fields, null));
    } catch (Exception e) {
        handleException(e, url, startTime, "createdTime start/end or limit");
    }
    long endTime = Time.monotonicNow();
    if (entities == null) {
        entities = Collections.emptySet();
    }
    LOG.info("Processed URL " + url + " (Took " + (endTime - startTime) + " ms.)");
    return entities;
}
Also used : BadRequestException(org.apache.hadoop.yarn.webapp.BadRequestException) TimelineEntity(org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) ParseException(java.text.ParseException) 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)

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