Search in sources :

Example 21 with NotFoundException

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

the class TimelineReaderWebServices method getApp.

/**
   * Return a single app for given cluster id and app id. If userid, flow name
   * and flowrun id which are optional query parameters are not specified, they
   * will be queried based on app id and cluster id from the flow context
   * information stored in underlying storage implementation.
   *
   * @param req Servlet request.
   * @param res Servlet response.
   * @param clusterId Cluster id to which the app to be queried belong to(
   *     Mandatory path param).
   * @param appId Application id to be queried(Mandatory path param).
   * @param flowName Flow name which should match for the app(Optional query
   *     param).
   * @param flowRunId Run id which should match for the app(Optional query
   *     param).
   * @param userId User id which should match for the app(Optional query param).
   * @param confsToRetrieve If specified, defines which configurations to
   *     retrieve and send back in response. These configs will be retrieved
   *     irrespective of whether configs are specified in fields to retrieve or
   *     not.
   * @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 of the app entity object to retrieve,
   *     see {@link Field}. All fields will be retrieved if fields=ALL. If not
   *     specified, 3 fields i.e. entity type(equivalent to YARN_APPLICATION),
   *     app id and app created time is returned(Optional query param).
   * @param metricsLimit If specified, defines the number of metrics to return.
   *     Considered only if fields contains METRICS/ALL or metricsToRetrieve is
   *     specified. Ignored otherwise. The maximum possible value for
   *     metricsLimit can be {@link Integer#MAX_VALUE}. If it is not specified
   *     or has a value less than 1, and metrics have to be retrieved, then
   *     metricsLimit will be considered as 1 i.e. latest single value of
   *     metric(s) will be returned. (Optional query param).
   *
   * @return If successful, a HTTP 200(OK) response having a JSON representing a
   *     <cite>TimelineEntity</cite> instance is returned.<br>
   *     On failures,<br>
   *     If any problem occurs in parsing request, HTTP 400(Bad Request) is
   *     returned.<br>
   *     If flow context information cannot be retrieved or app for the given
   *     app id cannot be found, HTTP 404(Not Found) is returned.<br>
   *     For all other errors while retrieving data, HTTP 500(Internal Server
   *     Error) is returned.
   */
@GET
@Path("/clusters/{clusterid}/apps/{appid}/")
@Produces(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8)
public TimelineEntity getApp(@Context HttpServletRequest req, @Context HttpServletResponse res, @PathParam("clusterid") String clusterId, @PathParam("appid") String appId, @QueryParam("flowname") String flowName, @QueryParam("flowrunid") String flowRunId, @QueryParam("userid") String userId, @QueryParam("confstoretrieve") String confsToRetrieve, @QueryParam("metricstoretrieve") String metricsToRetrieve, @QueryParam("fields") String fields, @QueryParam("metricslimit") String metricsLimit) {
    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();
    TimelineEntity entity = null;
    try {
        entity = timelineReaderManager.getEntity(TimelineReaderWebServicesUtils.createTimelineReaderContext(clusterId, userId, flowName, flowRunId, appId, TimelineEntityType.YARN_APPLICATION.toString(), null), TimelineReaderWebServicesUtils.createTimelineDataToRetrieve(confsToRetrieve, metricsToRetrieve, fields, metricsLimit));
    } catch (Exception e) {
        handleException(e, url, startTime, "flowrunid");
    }
    long endTime = Time.monotonicNow();
    if (entity == null) {
        LOG.info("Processed URL " + url + " but app not found" + " (Took " + (endTime - startTime) + " ms.)");
        throw new NotFoundException("App " + appId + " not found");
    }
    LOG.info("Processed URL " + url + " (Took " + (endTime - startTime) + " ms.)");
    return entity;
}
Also used : NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) 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)

Example 22 with NotFoundException

use of org.apache.hadoop.yarn.webapp.NotFoundException in project apex-core by apache.

the class StramWebServices method getOperatorClasses.

@GET
@Path(PATH_OPERATOR_CLASSES)
@Produces(MediaType.APPLICATION_JSON)
public JSONObject getOperatorClasses(@QueryParam("q") String searchTerm, @QueryParam("parent") String parent) {
    init();
    JSONObject result = new JSONObject();
    JSONArray classNames = new JSONArray();
    if (parent != null) {
        if (parent.equals("chart")) {
            parent = "com.datatorrent.lib.chart.ChartOperator";
        } else if (parent.equals("filter")) {
            parent = "com.datatorrent.common.util.SimpleFilterOperator";
        }
    }
    try {
        Set<String> operatorClasses = operatorDiscoverer.getOperatorClasses(parent, searchTerm);
        for (String clazz : operatorClasses) {
            JSONObject j = new JSONObject();
            j.put("name", clazz);
            classNames.put(j);
        }
        result.put("operatorClasses", classNames);
    } catch (ClassNotFoundException ex) {
        throw new NotFoundException();
    } catch (JSONException ex) {
        throw new RuntimeException(ex);
    }
    return result;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) JSONException(org.codehaus.jettison.json.JSONException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 23 with NotFoundException

use of org.apache.hadoop.yarn.webapp.NotFoundException in project apex-core by apache.

the class StramWebServices method getOperatorAggregation.

@GET
@Path(PATH_LOGICAL_PLAN_OPERATORS + "/{operatorName}/aggregation")
@Produces(MediaType.APPLICATION_JSON)
public JSONObject getOperatorAggregation(@PathParam("operatorName") String operatorName) throws Exception {
    init();
    OperatorMeta logicalOperator = dagManager.getLogicalPlan().getOperatorMeta(operatorName);
    if (logicalOperator == null) {
        throw new NotFoundException();
    }
    OperatorAggregationInfo operatorAggregationInfo = dagManager.getOperatorAggregationInfo(operatorName);
    return new JSONObject(objectMapper.writeValueAsString(operatorAggregationInfo));
}
Also used : OperatorMeta(com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta) JSONObject(org.codehaus.jettison.json.JSONObject) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 24 with NotFoundException

use of org.apache.hadoop.yarn.webapp.NotFoundException in project apex-core by apache.

the class StramWebServices method getOperatorProperties.

@GET
@Path(PATH_LOGICAL_PLAN_OPERATORS + "/{operatorName}/properties")
@Produces(MediaType.APPLICATION_JSON)
public JSONObject getOperatorProperties(@PathParam("operatorName") String operatorName, @QueryParam("propertyName") String propertyName) throws IOException, JSONException {
    init();
    OperatorMeta logicalOperator = dagManager.getLogicalPlan().getOperatorMeta(operatorName);
    BeanMap operatorProperties = null;
    if (logicalOperator == null) {
        ModuleMeta logicalModule = dagManager.getModuleMeta(operatorName);
        if (logicalModule == null) {
            throw new NotFoundException();
        }
        operatorProperties = LogicalPlanConfiguration.getObjectProperties(logicalModule.getOperator());
    } else {
        operatorProperties = LogicalPlanConfiguration.getObjectProperties(logicalOperator.getOperator());
    }
    Map<String, Object> m = getPropertiesAsMap(propertyName, operatorProperties);
    return new JSONObject(objectMapper.writeValueAsString(m));
}
Also used : ModuleMeta(com.datatorrent.stram.plan.logical.LogicalPlan.ModuleMeta) BeanMap(org.apache.commons.beanutils.BeanMap) OperatorMeta(com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta) JSONObject(org.codehaus.jettison.json.JSONObject) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) JSONObject(org.codehaus.jettison.json.JSONObject) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 25 with NotFoundException

use of org.apache.hadoop.yarn.webapp.NotFoundException in project apex-core by apache.

the class StramWebServices method getPortAttributes.

@GET
@Path(PATH_LOGICAL_PLAN_OPERATORS + "/{operatorName}/ports/{portName}/attributes")
@Produces(MediaType.APPLICATION_JSON)
public JSONObject getPortAttributes(@PathParam("operatorName") String operatorName, @PathParam("portName") String portName, @QueryParam("attributeName") String attributeName) {
    init();
    OperatorMeta logicalOperator = dagManager.getLogicalPlan().getOperatorMeta(operatorName);
    if (logicalOperator == null) {
        throw new NotFoundException();
    }
    HashMap<String, String> map = new HashMap<>();
    for (Map.Entry<Attribute<?>, Object> entry : dagManager.getPortAttributes(operatorName, portName).entrySet()) {
        if (attributeName == null || entry.getKey().getSimpleName().equals(attributeName)) {
            Map.Entry<Attribute<Object>, Object> entry1 = (Map.Entry<Attribute<Object>, Object>) (Map.Entry) entry;
            map.put(entry1.getKey().getSimpleName(), entry1.getKey().codec.toString(entry1.getValue()));
        }
    }
    return new JSONObject(map);
}
Also used : OperatorMeta(com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta) JSONObject(org.codehaus.jettison.json.JSONObject) HashMap(java.util.HashMap) Attribute(com.datatorrent.api.Attribute) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) JSONObject(org.codehaus.jettison.json.JSONObject) Map(java.util.Map) BeanMap(org.apache.commons.beanutils.BeanMap) HashMap(java.util.HashMap) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

NotFoundException (org.apache.hadoop.yarn.webapp.NotFoundException)49 Path (javax.ws.rs.Path)36 Produces (javax.ws.rs.Produces)35 GET (javax.ws.rs.GET)30 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)15 WebApplicationException (javax.ws.rs.WebApplicationException)14 BadRequestException (org.apache.hadoop.yarn.webapp.BadRequestException)14 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)11 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)11 JSONObject (org.codehaus.jettison.json.JSONObject)11 IOException (java.io.IOException)10 OperatorMeta (com.datatorrent.stram.plan.logical.LogicalPlan.OperatorMeta)8 ForbiddenException (org.apache.hadoop.yarn.webapp.ForbiddenException)7 Consumes (javax.ws.rs.Consumes)6 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)6 PUT (javax.ws.rs.PUT)5 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)5 JSONException (org.codehaus.jettison.json.JSONException)5 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)4 Application (org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application)4