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;
}
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());
}
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;
}
Aggregations