Example usage for org.apache.hadoop.yarn.api.protocolrecords StartContainersResponse getFailedRequests

List of usage examples for org.apache.hadoop.yarn.api.protocolrecords StartContainersResponse getFailedRequests

Introduction

In this page you can find the example usage for org.apache.hadoop.yarn.api.protocolrecords StartContainersResponse getFailedRequests.

Prototype

@Public
@Stable
public abstract Map<ContainerId, SerializedException> getFailedRequests();

Source Link

Document

Get the containerId-to-exception map in which the exception indicates error from per container for failed requests

Usage

From source file:org.springframework.yarn.am.container.DefaultContainerLauncher.java

License:Apache License

@Override
public void launchContainer(Container container, List<String> commands) {
    if (log.isDebugEnabled()) {
        log.debug("Launching container: " + container);
    }// ww w . j ava 2  s  .c  o m

    ContainerLaunchContext ctx = Records.newRecord(ContainerLaunchContext.class);
    String stagingId = container.getId().getApplicationAttemptId().getApplicationId().toString();
    getResourceLocalizer().setStagingId(stagingId);
    ctx.setLocalResources(getResourceLocalizer().getResources());
    ctx.setCommands(commands);

    // Yarn doesn't tell container what is its container id
    // so we do it here
    Map<String, String> env = getEnvironment();
    env.put(YarnSystemConstants.SYARN_CONTAINER_ID, ConverterUtils.toString(container.getId()));
    ctx.setEnvironment(env);
    ctx = getInterceptors().preLaunch(container, ctx);

    StartContainerRequest startContainerRequest = Records.newRecord(StartContainerRequest.class);
    startContainerRequest.setContainerLaunchContext(ctx);
    startContainerRequest.setContainerToken(container.getContainerToken());

    StartContainersRequest startContainersRequest = Records.newRecord(StartContainersRequest.class);
    ArrayList<StartContainerRequest> startContainerRequestList = new ArrayList<StartContainerRequest>();
    startContainerRequestList.add(startContainerRequest);
    startContainersRequest.setStartContainerRequests(startContainerRequestList);

    StartContainersResponse startContainersResponse = getCmTemplate(container)
            .startContainers(startContainersRequest);
    Map<ContainerId, SerializedException> failedRequests = startContainersResponse.getFailedRequests();
    List<ContainerId> successfullyStartedContainers = startContainersResponse
            .getSuccessfullyStartedContainers();
    // TODO: handle failed/success

    // notify interested parties of new launched container
    if (getYarnEventPublisher() != null) {
        getYarnEventPublisher().publishContainerLaunched(this, container);
    }
}