Search in sources :

Example 1 with StreamingContainerAgent

use of com.datatorrent.stram.StreamingContainerAgent in project apex-core by apache.

the class StramWebServices method getContainer.

@GET
@Path(PATH_PHYSICAL_PLAN_CONTAINERS + "/{containerId}")
@Produces(MediaType.APPLICATION_JSON)
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));
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) StreamingContainerAgent(com.datatorrent.stram.StreamingContainerAgent) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with StreamingContainerAgent

use of com.datatorrent.stram.StreamingContainerAgent in project apex-core by apache.

the class StramWebServices method listContainers.

@GET
@Path(PATH_PHYSICAL_PLAN_CONTAINERS)
@Produces(MediaType.APPLICATION_JSON)
public JSONObject listContainers(@QueryParam("states") String states) throws Exception {
    init();
    Set<String> stateSet = null;
    if (states != null) {
        stateSet = new HashSet<>();
        stateSet.addAll(Arrays.asList(StringUtils.split(states, ',')));
    }
    ContainersInfo ci = new ContainersInfo();
    for (ContainerInfo containerInfo : dagManager.getCompletedContainerInfo()) {
        if (stateSet == null || stateSet.contains(containerInfo.state)) {
            ci.add(containerInfo);
        }
    }
    Collection<StreamingContainerAgent> containerAgents = dagManager.getContainerAgents();
    // add itself (app master container)
    ContainerInfo appMasterContainerInfo = dagManager.getAppMasterContainerInfo();
    if (stateSet == null || stateSet.contains(appMasterContainerInfo.state)) {
        ci.add(appMasterContainerInfo);
    }
    for (StreamingContainerAgent sca : containerAgents) {
        ContainerInfo containerInfo = sca.getContainerInfo();
        if (stateSet == null || stateSet.contains(containerInfo.state)) {
            ci.add(containerInfo);
        }
    }
    // To get around the nasty JAXB problem for lists
    return new JSONObject(objectMapper.writeValueAsString(ci));
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) StreamingContainerAgent(com.datatorrent.stram.StreamingContainerAgent) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with StreamingContainerAgent

use of com.datatorrent.stram.StreamingContainerAgent in project apex-core by apache.

the class StramWebServices method getContainerStackTrace.

@GET
@Path(PATH_PHYSICAL_PLAN_CONTAINERS + "/{containerId}/" + PATH_STACKTRACE)
@Produces(MediaType.APPLICATION_JSON)
public JSONObject getContainerStackTrace(@PathParam("containerId") String containerId) throws Exception {
    init();
    if (containerId.equals(System.getenv(ApplicationConstants.Environment.CONTAINER_ID.toString()))) {
        return StramUtils.getStackTrace();
    }
    StreamingContainerAgent sca = dagManager.getContainerAgent(containerId);
    if (sca == null) {
        throw new NotFoundException("Container not found.");
    }
    if (!sca.getContainerInfo().state.equals("ACTIVE")) {
        throw new NotFoundException("Container is not active.");
    }
    for (int i = 0; i < STACK_TRACE_ATTEMPTS; ++i) {
        String result = sca.getStackTrace();
        if (result != null) {
            return new JSONObject(result);
        }
        Thread.sleep(STACK_TRACE_WAIT_TIME);
    }
    throw new TimeoutException("Not able to get the stack trace");
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) StreamingContainerAgent(com.datatorrent.stram.StreamingContainerAgent) TimeoutException(java.util.concurrent.TimeoutException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

StreamingContainerAgent (com.datatorrent.stram.StreamingContainerAgent)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 JSONObject (org.codehaus.jettison.json.JSONObject)3 NotFoundException (org.apache.hadoop.yarn.webapp.NotFoundException)2 TimeoutException (java.util.concurrent.TimeoutException)1