Search in sources :

Example 1 with YarnContainer

use of org.apache.samza.job.yarn.YarnContainer in project samza by apache.

the class YarnContainerHeartbeatServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    ContainerId yarnContainerId;
    PrintWriter printWriter = resp.getWriter();
    String containerIdParam = req.getParameter(YARN_CONTAINER_ID);
    ContainerHeartbeatResponse response;
    resp.setContentType(APPLICATION_JSON);
    boolean alive = false;
    try {
        yarnContainerId = ContainerId.fromString(containerIdParam);
        for (YarnContainer yarnContainer : yarnAppState.runningYarnContainers.values()) {
            if (yarnContainer.id().compareTo(yarnContainerId) == 0) {
                alive = true;
                break;
            }
        }
        if (!alive) {
            heartbeatsExpiredCount.inc();
        }
        response = new ContainerHeartbeatResponse(alive);
        printWriter.write(mapper.writeValueAsString(response));
    } catch (IllegalArgumentException e) {
        LOG.error("Container ID {} passed is invalid", containerIdParam);
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
    }
}
Also used : ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) ContainerHeartbeatResponse(org.apache.samza.container.ContainerHeartbeatResponse) YarnContainer(org.apache.samza.job.yarn.YarnContainer) PrintWriter(java.io.PrintWriter)

Aggregations

PrintWriter (java.io.PrintWriter)1 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)1 ContainerHeartbeatResponse (org.apache.samza.container.ContainerHeartbeatResponse)1 YarnContainer (org.apache.samza.job.yarn.YarnContainer)1