Example usage for org.apache.hadoop.yarn.webapp NotFoundException NotFoundException

List of usage examples for org.apache.hadoop.yarn.webapp NotFoundException NotFoundException

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.webapp NotFoundException NotFoundException.

Prototype

public NotFoundException() 

Source Link

Usage

From source file:com.datatorrent.stram.AlertsManager.java

License:Apache License

public JSONObject deleteAlert(String name) throws JSONException {
    JSONObject response = new JSONObject();
    List<LogicalPlanRequest> requests = new ArrayList<LogicalPlanRequest>();

    try {/*from   w  w w  .j a  va  2 s.  c o m*/
        synchronized (alerts) {
            if (!alerts.containsKey(name)) {
                throw new NotFoundException();
            }
            AlertInfo alertInfo = alerts.get(name);
            {
                StreamMeta stream = dagManager.getLogicalPlan().getStream(alertInfo.filterStreamName);
                if (stream == null) {
                    LOG.warn("Stream to the filter operator does not exist! Ignoring...");
                } else {
                    List<InputPortMeta> sinks = stream.getSinks();
                    if (sinks.size() == 1 && sinks.get(0).getOperatorWrapper().getName()
                            .equals(alertInfo.filterOperatorName)) {
                        // The only sink is the filter operator, so it's safe to remove
                        RemoveStreamRequest request = new RemoveStreamRequest();
                        request.setStreamName(alertInfo.filterStreamName);
                        requests.add(request);
                    }
                }
            }
            {
                RemoveStreamRequest request = new RemoveStreamRequest();
                request.setStreamName(alertInfo.escalationStreamName);
                requests.add(request);
            }
            for (String streamName : alertInfo.actionStreamNames) {
                RemoveStreamRequest request = new RemoveStreamRequest();
                request.setStreamName(streamName);
                requests.add(request);
            }
            {
                RemoveOperatorRequest request = new RemoveOperatorRequest();
                request.setOperatorName(alertInfo.filterOperatorName);
                requests.add(request);
                request = new RemoveOperatorRequest();
                request.setOperatorName(alertInfo.escalationOperatorName);
                requests.add(request);
            }
            for (String operatorName : alertInfo.actionOperatorNames) {
                RemoveOperatorRequest request = new RemoveOperatorRequest();
                request.setOperatorName(operatorName);
                requests.add(request);
            }
            Future<?> fr = dagManager.logicalPlanModification(requests);
            fr.get(3000, TimeUnit.MILLISECONDS);
            alerts.remove(name);
            LOG.info("Alert {} removed. There are now {} alerts.", name, alerts.size());
        }
    } catch (Exception ex) {
        LOG.error("Error deleting alert", ex);
        try {
            if (ex instanceof ExecutionException) {
                response.put("error", ex.getCause().toString());
            } else {
                response.put("error", ex.toString());
            }
        } catch (Exception e) {
            // ignore
        }
    }

    return response;
}

From source file:com.datatorrent.stram.webapp.StramWebServices.java

License:Apache License

@GET
@Path(PATH_PHYSICAL_PLAN_OPERATORS + "/{operatorId:\\d+}")
@Produces(MediaType.APPLICATION_JSON)/*from   www .  j  av a  2 s. c o m*/
public JSONObject getOperatorInfo(@PathParam("operatorId") int operatorId) throws Exception {
    init();
    OperatorInfo oi = dagManager.getOperatorInfo(operatorId);
    if (oi == null) {
        throw new NotFoundException();
    }
    return new JSONObject(objectMapper.writeValueAsString(oi));
}

From source file:com.datatorrent.stram.webapp.StramWebServices.java

License:Apache License

@GET
@Path(PATH_PHYSICAL_PLAN_OPERATORS + "/{operatorId:\\d+}/ports")
@Produces(MediaType.APPLICATION_JSON)// ww  w.  j  av  a2  s .  c  om
public JSONObject getPortsInfo(@PathParam("operatorId") int operatorId) throws Exception {
    init();
    Map<String, Object> map = new HashMap<String, Object>();
    OperatorInfo oi = dagManager.getOperatorInfo(operatorId);
    if (oi == null) {
        throw new NotFoundException();
    }
    map.put("ports", oi.ports);
    return new JSONObject(objectMapper.writeValueAsString(map));
}

From source file:com.datatorrent.stram.webapp.StramWebServices.java

License:Apache License

@GET
@Path(PATH_PHYSICAL_PLAN_OPERATORS + "/{operatorId:\\d+}/ports/{portName}")
@Produces(MediaType.APPLICATION_JSON)//w w w  .  j  a  v  a 2  s .com
public JSONObject getPortsInfo(@PathParam("operatorId") int operatorId, @PathParam("portName") String portName)
        throws Exception {
    init();
    OperatorInfo oi = dagManager.getOperatorInfo(operatorId);
    if (oi == null) {
        throw new NotFoundException();
    }
    for (PortInfo pi : oi.ports) {
        if (pi.name.equals(portName)) {
            return new JSONObject(objectMapper.writeValueAsString(pi));
        }
    }
    throw new NotFoundException();
}

From source file:com.datatorrent.stram.webapp.StramWebServices.java

License:Apache License

@GET
@Path(PATH_OPERATOR_CLASSES)//from   www. j  av a2  s .  c om
@Produces(MediaType.APPLICATION_JSON)
public JSONObject getOperatorClasses(@QueryParam("q") String searchTerm, @QueryParam("parent") String parent) {
    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<Class<? extends Operator>> operatorClasses = operatorDiscoverer.getOperatorClasses(parent,
                searchTerm);

        for (Class<?> clazz : operatorClasses) {
            JSONObject j = new JSONObject();
            j.put("name", clazz.getName());
            classNames.put(j);
        }

        result.put("operatorClasses", classNames);
    } catch (ClassNotFoundException ex) {
        throw new NotFoundException();
    } catch (JSONException ex) {
    }
    return result;
}

From source file:com.datatorrent.stram.webapp.StramWebServices.java

License:Apache License

@GET
@Path(PATH_OPERATOR_CLASSES + "/{className}")
@Produces(MediaType.APPLICATION_JSON)/*  w w w  .  j  a v a2  s.co m*/
@SuppressWarnings("unchecked")
public JSONObject describeOperator(@PathParam("className") String className) {
    if (className == null) {
        throw new UnsupportedOperationException();
    }
    try {
        Class<?> clazz = Class.forName(className);
        if (Operator.class.isAssignableFrom(clazz)) {
            return operatorDiscoverer.describeOperator((Class<? extends Operator>) clazz);
        } else {
            throw new NotFoundException();
        }
    } catch (Exception ex) {
        throw new NotFoundException();
    }
}

From source file:com.datatorrent.stram.webapp.StramWebServices.java

License:Apache License

@GET
@Path(PATH_PHYSICAL_PLAN_CONTAINERS + "/{containerId}")
@Produces(MediaType.APPLICATION_JSON)/* w w w . j  ava  2  s .c  o  m*/
public JSONObject getContainer(@PathParam("containerId") String containerId) throws Exception {
    init();
    ContainerInfo ci = null;
    if (containerId.equals(System.getenv(ApplicationConstants.Environment.CONTAINER_ID.toString()))) {
        ci = dagManager.getAppMasterContainerInfo();
    } else {
        for (ContainerInfo containerInfo : dagManager.getCompletedContainerInfo()) {
            if (containerInfo.id.equals(containerId)) {
                ci = containerInfo;
            }
        }
        if (ci == null) {
            StreamingContainerAgent sca = dagManager.getContainerAgent(containerId);
            if (sca == null) {
                throw new NotFoundException();
            }
            ci = sca.getContainerInfo();
        }
    }
    return new JSONObject(objectMapper.writeValueAsString(ci));
}

From source file:com.datatorrent.stram.webapp.StramWebServices.java

License:Apache License

@GET
@Path(PATH_LOGICAL_PLAN_OPERATORS + "/{operatorName}")
@Produces(MediaType.APPLICATION_JSON)/*from  w w  w  .jav a2  s . c  o m*/
public JSONObject getLogicalOperator(@PathParam("operatorName") String operatorName) throws Exception {
    OperatorMeta logicalOperator = dagManager.getLogicalPlan().getOperatorMeta(operatorName);
    if (logicalOperator == null) {
        throw new NotFoundException();
    }

    LogicalOperatorInfo logicalOperatorInfo = dagManager.getLogicalOperatorInfo(operatorName);
    return new JSONObject(objectMapper.writeValueAsString(logicalOperatorInfo));
}

From source file:com.datatorrent.stram.webapp.StramWebServices.java

License:Apache License

@GET
@Path(PATH_LOGICAL_PLAN_OPERATORS + "/{operatorName}/aggregation")
@Produces(MediaType.APPLICATION_JSON)/*from w w  w.ja  va2 s. co m*/
public JSONObject getOperatorAggregation(@PathParam("operatorName") String operatorName) throws Exception {
    OperatorMeta logicalOperator = dagManager.getLogicalPlan().getOperatorMeta(operatorName);
    if (logicalOperator == null) {
        throw new NotFoundException();
    }

    OperatorAggregationInfo operatorAggregationInfo = dagManager.getOperatorAggregationInfo(operatorName);
    return new JSONObject(objectMapper.writeValueAsString(operatorAggregationInfo));
}

From source file:com.datatorrent.stram.webapp.StramWebServices.java

License:Apache License

@POST // not supported by WebAppProxyServlet, can only be called directly
@Path(PATH_LOGICAL_PLAN_OPERATORS + "/{operatorName}/properties")
@Consumes(MediaType.APPLICATION_JSON)/*w w w  .j  av a  2  s  . c  om*/
@Produces(MediaType.APPLICATION_JSON)
public JSONObject setOperatorProperties(JSONObject request, @PathParam("operatorName") String operatorName) {
    init();
    OperatorMeta logicalOperator = dagManager.getLogicalPlan().getOperatorMeta(operatorName);
    if (logicalOperator == null) {
        throw new NotFoundException();
    }
    JSONObject response = new JSONObject();
    try {
        @SuppressWarnings("unchecked")
        Iterator<String> keys = request.keys();
        while (keys.hasNext()) {
            String key = keys.next();
            String val = request.getString(key);
            LOG.debug("Setting property for {}: {}={}", operatorName, key, val);
            dagManager.setOperatorProperty(operatorName, key, val);
        }
    } catch (JSONException ex) {
        LOG.warn("Got JSON Exception: ", ex);
    } catch (Exception ex) {
        LOG.error("Caught exception: ", ex);
        throw new RuntimeException(ex);
    }
    return response;
}