Example usage for org.apache.hadoop.yarn.api.records ContainerId getId

List of usage examples for org.apache.hadoop.yarn.api.records ContainerId getId

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.api.records ContainerId getId.

Prototype

@Public
@Deprecated
@Unstable
public abstract int getId();

Source Link

Document

Get the lower 32 bits of identifier of the ContainerId, which doesn't include epoch.

Usage

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

License:Apache License

/**
 * Ask RM to allocate given no. of containers to this Application Master
 *
 * @param containerRequests  Containers to ask for from RM
 * @param removedContainerRequests Container requests to be removed
 * @param releasedContainers/*from  ww w.  j av a2 s. c o m*/
 * @return Response from RM to AM with allocated containers
 * @throws YarnException
 */
private AllocateResponse sendContainerAskToRM(List<ContainerRequest> containerRequests,
        List<ContainerRequest> removedContainerRequests, List<ContainerId> releasedContainers)
        throws YarnException, IOException {
    if (removedContainerRequests.size() > 0) {
        LOG.info(" Removing container request: " + removedContainerRequests);
        for (ContainerRequest cr : removedContainerRequests) {
            LOG.info("Removed container: {}", cr.toString());
            amRmClient.removeContainerRequest(cr);
        }
    }
    if (containerRequests.size() > 0) {
        LOG.info("Asking RM for containers: " + containerRequests);
        for (ContainerRequest cr : containerRequests) {
            LOG.info("Requested container: {}", cr.toString());
            amRmClient.addContainerRequest(cr);
        }
    }

    for (ContainerId containerId : releasedContainers) {
        LOG.info("Released container, id={}", containerId.getId());
        amRmClient.releaseAssignedContainer(containerId);
    }

    for (String containerIdStr : dnmgr.containerStopRequests.values()) {
        AllocatedContainer allocatedContainer = this.allocatedContainers.get(containerIdStr);
        if (allocatedContainer != null && !allocatedContainer.stopRequested) {
            nmClient.stopContainerAsync(allocatedContainer.container.getId(),
                    allocatedContainer.container.getNodeId());
            LOG.info("Requested stop container {}", containerIdStr);
            allocatedContainer.stopRequested = true;
        }
        dnmgr.containerStopRequests.remove(containerIdStr);
    }

    return amRmClient.allocate(0);
}

From source file:org.apache.tajo.worker.TaskRunnerId.java

License:Apache License

public static YarnProtos.ContainerIdProto getContainerIdProto(ContainerId containerId) {
    if (containerId instanceof TaskRunnerId) {
        return ((TaskRunnerId) containerId).getProto();
    } else {/* w  w  w.  j a  v a 2s.co m*/
        YarnProtos.ApplicationIdProto appIdProto = YarnProtos.ApplicationIdProto.newBuilder()
                .setClusterTimestamp(
                        containerId.getApplicationAttemptId().getApplicationId().getClusterTimestamp())
                .setId(containerId.getApplicationAttemptId().getApplicationId().getId()).build();

        YarnProtos.ApplicationAttemptIdProto attemptIdProto = YarnProtos.ApplicationAttemptIdProto.newBuilder()
                .setAttemptId(containerId.getApplicationAttemptId().getAttemptId()).setApplicationId(appIdProto)
                .build();

        return YarnProtos.ContainerIdProto.newBuilder().setAppAttemptId(attemptIdProto).setAppId(appIdProto)
                .setId(containerId.getId()).build();
    }
}

From source file:org.deeplearning4j.iterativereduce.runtime.yarn.ResourceManagerHandler.java

License:Apache License

/**
 * Changed the return type to AllocateResponse which use to hold a reference to 
 * AMResponse. //  w  ww .  ja va  2 s .co m
 * 
 * AMResponse seems to have disappeared in CDH 4.6
 * 
 * @param requestedContainers
 * @param releasedContainers
 * @return
 * @throws YarnRemoteException
 */

public AllocateResponse allocateRequest(List<ResourceRequest> requestedContainers,
        List<ContainerId> releasedContainers) throws YarnRemoteException {

    if (amResourceManager == null)
        throw new IllegalStateException(
                "Cannot send allocation request before connecting to the resource manager!");

    LOG.info("Sending allocation request" + ", requestedSize=" + requestedContainers.size() + ", releasedSize="
            + releasedContainers.size());

    for (ResourceRequest req : requestedContainers)
        LOG.info("Requesting container, host=" + req.getHostName() + ", amount=" + req.getNumContainers()
                + ", memory=" + req.getCapability().getMemory() + ", priority="
                + req.getPriority().getPriority());

    for (ContainerId rel : releasedContainers)
        LOG.info("Releasing container: " + rel.getId());

    AllocateRequest request = Records.newRecord(AllocateRequest.class);
    request.setResponseId(rmRequestId.incrementAndGet());
    request.setApplicationAttemptId(appAttemptId);
    request.addAllAsks(requestedContainers);
    request.addAllReleases(releasedContainers);

    AllocateResponse response = amResourceManager.allocate(request);

    //response.getAllocatedContainers()

    LOG.debug("Got an allocation response, " + ", responseId=" + response.getResponseId() + ", numClusterNodes="
            + response.getNumClusterNodes() + ", headroom=" + response.getAvailableResources().getMemory()
            + ", allocatedSize=" + response.getAllocatedContainers().size() + ", updatedNodes="
            + response.getUpdatedNodes().size() + ", reboot=" + response.getReboot() + ", completedSize="
            + response.getCompletedContainersStatuses().size());

    return response;
}

From source file:org.springframework.yarn.examples.FailingContextContainer.java

License:Apache License

@Override
protected void runInternal() {
    log.info("Hello from FailingContextContainer");

    log.info("container parameters:");
    for (Entry<Object, Object> entry : getParameters().entrySet()) {
        log.info("key=" + entry.getKey() + ", value=" + entry.getValue());
    }/*w  w  w . ja  v a2 s .  co m*/

    log.info("container environment:");
    for (Entry<String, String> entry : getEnvironment().entrySet()) {
        log.info("key=" + entry.getKey() + ", value=" + entry.getValue());
    }

    ContainerId cid = ConverterUtils.toContainerId(getEnvironment(YarnSystemConstants.SYARN_CONTAINER_ID));
    int containerId = cid.getId();

    // We just use the container id found from token variable
    // to fail every other container.
    if ((containerId % 2) == 0) {
        log.info("Exiting with error");
        System.exit(1);
    } else {
        log.info("Exiting with ok");
        System.exit(0);
    }
}