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

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

Introduction

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

Prototype

@Private
    @Deprecated
    @Unstable
    public static ContainerId newInstance(ApplicationAttemptId appAttemptId, int containerId) 

Source Link

Usage

From source file:org.apache.tez.runtime.task.TaskExecutionTestHelpers.java

License:Apache License

@SuppressWarnings("deprecation")
public static ContainerId createContainerId(ApplicationId appId) {
    ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1);
    ContainerId containerId = ContainerId.newInstance(appAttemptId, 1);
    return containerId;
}

From source file:org.apache.tez.runtime.task.TestContainerExecution.java

License:Apache License

@Test(timeout = 5000)
public void testGetTaskShouldDie() throws InterruptedException, ExecutionException {
    ListeningExecutorService executor = null;
    try {/* w  w  w .jav a2 s  . c  om*/
        ExecutorService rawExecutor = Executors.newFixedThreadPool(1);
        executor = MoreExecutors.listeningDecorator(rawExecutor);
        ApplicationId appId = ApplicationId.newInstance(10000, 1);
        ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1);
        @SuppressWarnings("deprecation")
        ContainerId containerId = ContainerId.newInstance(appAttemptId, 1);

        TaskExecutionTestHelpers.TezTaskUmbilicalForTest umbilical = new TaskExecutionTestHelpers.TezTaskUmbilicalForTest();
        ContainerContext containerContext = new ContainerContext(containerId.toString());

        ContainerReporter containerReporter = new ContainerReporter(umbilical, containerContext, 100);
        ListenableFuture<ContainerTask> getTaskFuture = executor.submit(containerReporter);

        getTaskFuture.get();
        assertEquals(1, umbilical.getTaskInvocations);

    } finally {
        executor.shutdownNow();
    }
}

From source file:org.apache.tez.runtime.task.TestTaskExecution.java

License:Apache License

@Test(timeout = 5000)
public void testGetTaskShouldDie() throws InterruptedException, ExecutionException {
    ListeningExecutorService executor = null;
    try {/*from www .  j a  v  a 2 s  .co m*/
        ExecutorService rawExecutor = Executors.newFixedThreadPool(1);
        executor = MoreExecutors.listeningDecorator(rawExecutor);
        ApplicationId appId = ApplicationId.newInstance(10000, 1);
        ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1);
        ContainerId containerId = ContainerId.newInstance(appAttemptId, 1);

        TezTaskUmbilicalForTest umbilical = new TezTaskUmbilicalForTest();
        ContainerContext containerContext = new ContainerContext(containerId.toString());

        ContainerReporter containerReporter = new ContainerReporter(umbilical, containerContext, 100);
        ListenableFuture<ContainerTask> getTaskFuture = executor.submit(containerReporter);

        getTaskFuture.get();
        assertEquals(1, umbilical.getTaskInvocations);

    } finally {
        executor.shutdownNow();
    }
}

From source file:org.apache.tez.runtime.task.TestTaskExecution.java

License:Apache License

private ContainerId createContainerId(ApplicationId appId) {
    ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1);
    ContainerId containerId = ContainerId.newInstance(appAttemptId, 1);
    return containerId;
}

From source file:org.apache.tez.test.TestRecovery.java

License:Apache License

@Test(timeout = 1800000)
public void testRecovery_OrderedWordCount() throws Exception {
    ApplicationId appId = ApplicationId.newInstance(System.currentTimeMillis(), 1);
    TezDAGID dagId = TezDAGID.getInstance(appId, 1);
    TezVertexID vertexId0 = TezVertexID.getInstance(dagId, 0);
    TezVertexID vertexId1 = TezVertexID.getInstance(dagId, 1);
    TezVertexID vertexId2 = TezVertexID.getInstance(dagId, 2);
    ContainerId containerId = ContainerId.newInstance(ApplicationAttemptId.newInstance(appId, 1), 1);
    NodeId nodeId = NodeId.newInstance("localhost", 10);

    List<TezEvent> initGeneratedEvents = Lists.newArrayList(
            new TezEvent(InputDataInformationEvent.createWithObjectPayload(0, new Object()), null));

    List<SimpleShutdownCondition> shutdownConditions = Lists.newArrayList(
            new SimpleShutdownCondition(TIMING.POST,
                    new DAGInitializedEvent(dagId, 0L, "username", "dagName", null)),
            new SimpleShutdownCondition(TIMING.POST, new DAGStartedEvent(dagId, 0L, "username", "dagName")),
            new SimpleShutdownCondition(TIMING.POST,
                    new DAGFinishedEvent(dagId, 0L, 0L, DAGState.SUCCEEDED, "", new TezCounters(), "username",
                            "dagName", new HashMap<String, Integer>(),
                            ApplicationAttemptId.newInstance(appId, 1), null)),
            new SimpleShutdownCondition(TIMING.POST,
                    new VertexInitializedEvent(vertexId0, "Tokenizer", 0L, 0L, 0, "", null, initGeneratedEvents,
                            null)),//from  www  . ja  va  2  s  .co  m
            new SimpleShutdownCondition(TIMING.POST,
                    new VertexInitializedEvent(vertexId1, "Summation", 0L, 0L, 0, "", null, null, null)),
            new SimpleShutdownCondition(TIMING.POST,
                    new VertexInitializedEvent(vertexId2, "Sorter", 0L, 0L, 0, "", null, null, null)),

            new SimpleShutdownCondition(TIMING.POST,
                    new VertexConfigurationDoneEvent(vertexId0, 0L, 2, null, null, null, true)),

            new SimpleShutdownCondition(TIMING.POST,
                    new VertexConfigurationDoneEvent(vertexId1, 0L, 2, null, null, null, true)),

            new SimpleShutdownCondition(TIMING.POST,
                    new VertexConfigurationDoneEvent(vertexId2, 0L, 2, null, null, null, true)),
            new SimpleShutdownCondition(TIMING.POST, new VertexStartedEvent(vertexId0, 0L, 0L)),
            new SimpleShutdownCondition(TIMING.POST, new VertexStartedEvent(vertexId1, 0L, 0L)),
            new SimpleShutdownCondition(TIMING.POST, new VertexStartedEvent(vertexId2, 0L, 0L)),

            new SimpleShutdownCondition(TIMING.POST,
                    new VertexFinishedEvent(vertexId0, "vertexName", 1, 0L, 0L, 0L, 0L, 0L,
                            VertexState.SUCCEEDED, "", new TezCounters(), new VertexStats(),
                            new HashMap<String, Integer>(), null)),
            new SimpleShutdownCondition(TIMING.POST,
                    new VertexFinishedEvent(vertexId1, "vertexName", 1, 0L, 0L, 0L, 0L, 0L,
                            VertexState.SUCCEEDED, "", new TezCounters(), new VertexStats(),
                            new HashMap<String, Integer>(), null)),
            new SimpleShutdownCondition(TIMING.POST,
                    new VertexFinishedEvent(vertexId2, "vertexName", 1, 0L, 0L, 0L, 0L, 0L,
                            VertexState.SUCCEEDED, "", new TezCounters(), new VertexStats(),
                            new HashMap<String, Integer>(), null)),

            new SimpleShutdownCondition(TIMING.POST,
                    new TaskStartedEvent(TezTaskID.getInstance(vertexId0, 0), "vertexName", 0L, 0L)),
            new SimpleShutdownCondition(TIMING.POST,
                    new TaskStartedEvent(TezTaskID.getInstance(vertexId1, 0), "vertexName", 0L, 0L)),
            new SimpleShutdownCondition(TIMING.POST,
                    new TaskStartedEvent(TezTaskID.getInstance(vertexId2, 0), "vertexName", 0L, 0L)),

            new SimpleShutdownCondition(TIMING.POST,
                    new TaskFinishedEvent(TezTaskID.getInstance(vertexId0, 0), "vertexName", 0L, 0L, null,
                            TaskState.SUCCEEDED, "", new TezCounters(), 0)),
            new SimpleShutdownCondition(TIMING.POST,
                    new TaskFinishedEvent(TezTaskID.getInstance(vertexId1, 0), "vertexName", 0L, 0L, null,
                            TaskState.SUCCEEDED, "", new TezCounters(), 0)),
            new SimpleShutdownCondition(TIMING.POST,
                    new TaskFinishedEvent(TezTaskID.getInstance(vertexId2, 0), "vertexName", 0L, 0L, null,
                            TaskState.SUCCEEDED, "", new TezCounters(), 0)),

            new SimpleShutdownCondition(TIMING.POST,
                    new TaskAttemptStartedEvent(
                            TezTaskAttemptID.getInstance(TezTaskID.getInstance(vertexId0, 0), 0), "vertexName",
                            0L, containerId, nodeId, "", "", "")),
            new SimpleShutdownCondition(TIMING.POST,
                    new TaskAttemptStartedEvent(
                            TezTaskAttemptID.getInstance(TezTaskID.getInstance(vertexId1, 0), 0), "vertexName",
                            0L, containerId, nodeId, "", "", "")),
            new SimpleShutdownCondition(TIMING.POST,
                    new TaskAttemptStartedEvent(
                            TezTaskAttemptID.getInstance(TezTaskID.getInstance(vertexId2, 0), 0), "vertexName",
                            0L, containerId, nodeId, "", "", ""))

    );

    Random rand = new Random();
    for (int i = 0; i < shutdownConditions.size(); i++) {
        // randomly choose half of the test scenario to avoid
        // timeout.
        if (rand.nextDouble() < 0.5) {
            // generate split in client side when HistoryEvent type is VERTEX_STARTED (TEZ-2976)
            testOrderedWordCount(shutdownConditions.get(i), true, shutdownConditions.get(i).getHistoryEvent()
                    .getEventType() == HistoryEventType.VERTEX_STARTED);
        }
    }
}

From source file:org.apache.tez.test.TestRecovery.java

License:Apache License

@Test(timeout = 1800000)
public void testRecovery_HashJoin() throws Exception {
    ApplicationId appId = ApplicationId.newInstance(System.currentTimeMillis(), 1);
    TezDAGID dagId = TezDAGID.getInstance(appId, 1);
    TezVertexID vertexId0 = TezVertexID.getInstance(dagId, 0);
    TezVertexID vertexId1 = TezVertexID.getInstance(dagId, 1);
    TezVertexID vertexId2 = TezVertexID.getInstance(dagId, 2);
    ContainerId containerId = ContainerId.newInstance(ApplicationAttemptId.newInstance(appId, 1), 1);
    NodeId nodeId = NodeId.newInstance("localhost", 10);
    List<TezEvent> initGeneratedEvents = Lists.newArrayList(
            new TezEvent(InputDataInformationEvent.createWithObjectPayload(0, new Object()), null));

    List<SimpleShutdownCondition> shutdownConditions = Lists.newArrayList(

            new SimpleShutdownCondition(TIMING.POST,
                    new DAGInitializedEvent(dagId, 0L, "username", "dagName", null)),
            new SimpleShutdownCondition(TIMING.POST, new DAGStartedEvent(dagId, 0L, "username", "dagName")),
            new SimpleShutdownCondition(TIMING.POST,
                    new DAGFinishedEvent(dagId, 0L, 0L, DAGState.SUCCEEDED, "", new TezCounters(), "username",
                            "dagName", new HashMap<String, Integer>(),
                            ApplicationAttemptId.newInstance(appId, 1), null)),
            new SimpleShutdownCondition(TIMING.POST,
                    new VertexInitializedEvent(vertexId0, "hashSide", 0L, 0L, 0, "", null, initGeneratedEvents,
                            null)),//from w ww  .j  a  v a  2s  .  c o  m
            new SimpleShutdownCondition(TIMING.POST,
                    new VertexInitializedEvent(vertexId1, "streamingSide", 0L, 0L, 0, "", null, null, null)),
            new SimpleShutdownCondition(TIMING.POST,
                    new VertexInitializedEvent(vertexId2, "joiner", 0L, 0L, 0, "", null, null, null)),

            new SimpleShutdownCondition(TIMING.POST, new VertexStartedEvent(vertexId0, 0L, 0L)),
            new SimpleShutdownCondition(TIMING.POST, new VertexStartedEvent(vertexId1, 0L, 0L)),
            new SimpleShutdownCondition(TIMING.POST, new VertexStartedEvent(vertexId2, 0L, 0L)),

            new SimpleShutdownCondition(TIMING.POST,
                    new VertexConfigurationDoneEvent(vertexId0, 0L, 2, null, null, null, true)),

            new SimpleShutdownCondition(TIMING.POST,
                    new VertexConfigurationDoneEvent(vertexId1, 0L, 2, null, null, null, true)),

            new SimpleShutdownCondition(TIMING.POST,
                    new VertexConfigurationDoneEvent(vertexId2, 0L, 2, null, null, null, true)),

            new SimpleShutdownCondition(TIMING.POST,
                    new VertexFinishedEvent(vertexId0, "vertexName", 1, 0L, 0L, 0L, 0L, 0L,
                            VertexState.SUCCEEDED, "", new TezCounters(), new VertexStats(),
                            new HashMap<String, Integer>(), null)),
            new SimpleShutdownCondition(TIMING.POST,
                    new VertexFinishedEvent(vertexId1, "vertexName", 1, 0L, 0L, 0L, 0L, 0L,
                            VertexState.SUCCEEDED, "", new TezCounters(), new VertexStats(),
                            new HashMap<String, Integer>(), null)),
            new SimpleShutdownCondition(TIMING.POST,
                    new VertexFinishedEvent(vertexId2, "vertexName", 1, 0L, 0L, 0L, 0L, 0L,
                            VertexState.SUCCEEDED, "", new TezCounters(), new VertexStats(),
                            new HashMap<String, Integer>(), null)),

            new SimpleShutdownCondition(TIMING.POST,
                    new TaskStartedEvent(TezTaskID.getInstance(vertexId0, 0), "vertexName", 0L, 0L)),
            new SimpleShutdownCondition(TIMING.POST,
                    new TaskStartedEvent(TezTaskID.getInstance(vertexId1, 0), "vertexName", 0L, 0L)),
            new SimpleShutdownCondition(TIMING.POST,
                    new TaskStartedEvent(TezTaskID.getInstance(vertexId2, 0), "vertexName", 0L, 0L)),

            new SimpleShutdownCondition(TIMING.POST,
                    new TaskFinishedEvent(TezTaskID.getInstance(vertexId0, 0), "vertexName", 0L, 0L, null,
                            TaskState.SUCCEEDED, "", new TezCounters(), 0)),
            new SimpleShutdownCondition(TIMING.POST,
                    new TaskFinishedEvent(TezTaskID.getInstance(vertexId1, 0), "vertexName", 0L, 0L, null,
                            TaskState.SUCCEEDED, "", new TezCounters(), 0)),
            new SimpleShutdownCondition(TIMING.POST,
                    new TaskFinishedEvent(TezTaskID.getInstance(vertexId2, 0), "vertexName", 0L, 0L, null,
                            TaskState.SUCCEEDED, "", new TezCounters(), 0)),

            new SimpleShutdownCondition(TIMING.POST,
                    new TaskAttemptStartedEvent(
                            TezTaskAttemptID.getInstance(TezTaskID.getInstance(vertexId0, 0), 0), "vertexName",
                            0L, containerId, nodeId, "", "", "")),
            new SimpleShutdownCondition(TIMING.POST,
                    new TaskAttemptStartedEvent(
                            TezTaskAttemptID.getInstance(TezTaskID.getInstance(vertexId1, 0), 0), "vertexName",
                            0L, containerId, nodeId, "", "", "")),
            new SimpleShutdownCondition(TIMING.POST,
                    new TaskAttemptStartedEvent(
                            TezTaskAttemptID.getInstance(TezTaskID.getInstance(vertexId2, 0), 0), "vertexName",
                            0L, containerId, nodeId, "", "", ""))

    );

    Random rand = new Random();
    for (int i = 0; i < shutdownConditions.size(); i++) {
        // randomly choose half of the test scenario to avoid
        // timeout.
        if (rand.nextDouble() < 0.5) {
            // generate split in client side when HistoryEvent type is VERTEX_STARTED (TEZ-2976)
            testHashJoinExample(shutdownConditions.get(i), true, shutdownConditions.get(i).getHistoryEvent()
                    .getEventType() == HistoryEventType.VERTEX_STARTED);
        }
    }
}

From source file:org.apache.tez.test.TestRecovery.java

License:Apache License

@Test(timeout = 1800000)
public void testTwoRoundsRecoverying() throws Exception {
    ApplicationId appId = ApplicationId.newInstance(System.currentTimeMillis(), 1);
    TezDAGID dagId = TezDAGID.getInstance(appId, 1);
    TezVertexID vertexId0 = TezVertexID.getInstance(dagId, 0);
    TezVertexID vertexId1 = TezVertexID.getInstance(dagId, 1);
    TezVertexID vertexId2 = TezVertexID.getInstance(dagId, 2);
    ContainerId containerId = ContainerId.newInstance(ApplicationAttemptId.newInstance(appId, 1), 1);
    NodeId nodeId = NodeId.newInstance("localhost", 10);
    List<TezEvent> initGeneratedEvents = Lists.newArrayList(
            new TezEvent(InputDataInformationEvent.createWithObjectPayload(0, new Object()), null));

    List<SimpleShutdownCondition> shutdownConditions = Lists.newArrayList(

            new SimpleShutdownCondition(TIMING.POST,
                    new DAGInitializedEvent(dagId, 0L, "username", "dagName", null)),
            new SimpleShutdownCondition(TIMING.POST, new DAGStartedEvent(dagId, 0L, "username", "dagName")),
            new SimpleShutdownCondition(TIMING.POST,
                    new VertexInitializedEvent(vertexId0, "Tokenizer", 0L, 0L, 0, "", null, initGeneratedEvents,
                            null)),/*from  ww w.  j  a  v a2s .  c om*/
            new SimpleShutdownCondition(TIMING.POST, new VertexStartedEvent(vertexId0, 0L, 0L)),
            new SimpleShutdownCondition(TIMING.POST,
                    new VertexConfigurationDoneEvent(vertexId0, 0L, 2, null, null, null, true)),
            new SimpleShutdownCondition(TIMING.POST,
                    new TaskStartedEvent(TezTaskID.getInstance(vertexId0, 0), "vertexName", 0L, 0L)),
            new SimpleShutdownCondition(TIMING.POST,
                    new TaskAttemptStartedEvent(
                            TezTaskAttemptID.getInstance(TezTaskID.getInstance(vertexId0, 0), 0), "vertexName",
                            0L, containerId, nodeId, "", "", "")),
            new SimpleShutdownCondition(TIMING.POST,
                    new TaskFinishedEvent(TezTaskID.getInstance(vertexId0, 0), "vertexName", 0L, 0L, null,
                            TaskState.SUCCEEDED, "", new TezCounters(), 0)),
            new SimpleShutdownCondition(TIMING.POST,
                    new VertexFinishedEvent(vertexId0, "vertexName", 1, 0L, 0L, 0L, 0L, 0L,
                            VertexState.SUCCEEDED, "", new TezCounters(), new VertexStats(),
                            new HashMap<String, Integer>(), null)),
            new SimpleShutdownCondition(TIMING.POST,
                    new VertexFinishedEvent(vertexId1, "vertexName", 1, 0L, 0L, 0L, 0L, 0L,
                            VertexState.SUCCEEDED, "", new TezCounters(), new VertexStats(),
                            new HashMap<String, Integer>(), null)),
            new SimpleShutdownCondition(TIMING.POST,
                    new VertexFinishedEvent(vertexId2, "vertexName", 1, 0L, 0L, 0L, 0L, 0L,
                            VertexState.SUCCEEDED, "", new TezCounters(), new VertexStats(),
                            new HashMap<String, Integer>(), null)),
            new SimpleShutdownCondition(TIMING.POST,
                    new DAGFinishedEvent(dagId, 0L, 0L, DAGState.SUCCEEDED, "", new TezCounters(), "username",
                            "dagName", new HashMap<String, Integer>(),
                            ApplicationAttemptId.newInstance(appId, 1), null))

    );

    Random rand = new Random();
    for (int i = 0; i < shutdownConditions.size() - 1; i++) {
        // randomly choose half of the test scenario to avoid
        // timeout.
        if (rand.nextDouble() < 0.5) {
            int nextSimpleConditionIndex = i + 1 + rand.nextInt(shutdownConditions.size() - i - 1);
            if (nextSimpleConditionIndex == shutdownConditions.size() - 1) {
                testOrderedWordCountMultipleRoundRecoverying(
                        new RecoveryServiceWithEventHandlingHook.MultipleRoundShutdownCondition(
                                Lists.newArrayList(shutdownConditions.get(i),
                                        shutdownConditions.get(nextSimpleConditionIndex))),
                        true, shutdownConditions.get(i).getHistoryEvent()
                                .getEventType() == HistoryEventType.VERTEX_STARTED);
            }
        }
    }
}

From source file:origin.hadoop.yarn.unmanagedamlauncher.UnmanagedAMLauncher.java

License:Apache License

public void launchAM(ApplicationAttemptId attemptId) throws IOException, YarnException {
    Credentials credentials = new Credentials();
    Token<AMRMTokenIdentifier> token = rmClient.getAMRMToken(attemptId.getApplicationId());
    // Service will be empty but that's okay, we are just passing down only
    // AMRMToken down to the real AM which eventually sets the correct
    // service-address.
    credentials.addToken(token.getService(), token);
    File tokenFile = File.createTempFile("unmanagedAMRMToken", "", new File(System.getProperty("user.dir")));
    try {/*from   ww w .ja  v  a  2  s  .  c  om*/
        FileUtil.chmod(tokenFile.getAbsolutePath(), "600");
    } catch (InterruptedException ex) {
        throw new RuntimeException(ex);
    }
    tokenFile.deleteOnExit();
    DataOutputStream os = new DataOutputStream(new FileOutputStream(tokenFile, true));
    credentials.writeTokenStorageToStream(os);
    os.close();

    Map<String, String> env = System.getenv();
    ArrayList<String> envAMList = new ArrayList<String>();
    boolean setClasspath = false;
    for (Map.Entry<String, String> entry : env.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        if (key.equals("CLASSPATH")) {
            setClasspath = true;
            if (classpath != null) {
                value = value + File.pathSeparator + classpath;
            }
        }
        envAMList.add(key + "=" + value);
    }

    if (!setClasspath && classpath != null) {
        envAMList.add("CLASSPATH=" + classpath);
    }
    ContainerId containerId = ContainerId.newInstance(attemptId, 0);

    String hostname = InetAddress.getLocalHost().getHostName();
    envAMList.add(Environment.CONTAINER_ID.name() + "=" + containerId);
    envAMList.add(Environment.NM_HOST.name() + "=" + hostname);
    envAMList.add(Environment.NM_HTTP_PORT.name() + "=0");
    envAMList.add(Environment.NM_PORT.name() + "=0");
    envAMList.add(Environment.LOCAL_DIRS.name() + "= /tmp");
    envAMList.add(ApplicationConstants.APP_SUBMIT_TIME_ENV + "=" + System.currentTimeMillis());

    envAMList.add(ApplicationConstants.CONTAINER_TOKEN_FILE_ENV_NAME + "=" + tokenFile.getAbsolutePath());

    String[] envAM = new String[envAMList.size()];
    Process amProc = Runtime.getRuntime().exec(amCmd, envAMList.toArray(envAM));

    final BufferedReader errReader = new BufferedReader(new InputStreamReader(amProc.getErrorStream()));
    final BufferedReader inReader = new BufferedReader(new InputStreamReader(amProc.getInputStream()));

    // read error and input streams as this would free up the buffers
    // free the error stream buffer
    Thread errThread = new Thread() {
        @Override
        public void run() {
            try {
                String line = errReader.readLine();
                while ((line != null) && !isInterrupted()) {
                    System.err.println(line);
                    line = errReader.readLine();
                }
            } catch (IOException ioe) {
                LOG.warn("Error reading the error stream", ioe);
            }
        }
    };
    Thread outThread = new Thread() {
        @Override
        public void run() {
            try {
                String line = inReader.readLine();
                while ((line != null) && !isInterrupted()) {
                    System.out.println(line);
                    line = inReader.readLine();
                }
            } catch (IOException ioe) {
                LOG.warn("Error reading the out stream", ioe);
            }
        }
    };
    try {
        errThread.start();
        outThread.start();
    } catch (IllegalStateException ise) {
    }

    // wait for the process to finish and check the exit code
    try {
        int exitCode = amProc.waitFor();
        LOG.info("AM process exited with value: " + exitCode);
    } catch (InterruptedException e) {
        e.printStackTrace();
    } finally {
        amCompleted = true;
    }

    try {
        // make sure that the error thread exits
        // on Windows these threads sometimes get stuck and hang the execution
        // timeout and join later after destroying the process.
        errThread.join();
        outThread.join();
        errReader.close();
        inReader.close();
    } catch (InterruptedException ie) {
        LOG.info("ShellExecutor: Interrupted while reading the error/out stream", ie);
    } catch (IOException ioe) {
        LOG.warn("Error while closing the error/out stream", ioe);
    }
    amProc.destroy();
}

From source file:oz.hadoop.yarn.api.core.ApplicationContainerLauncherEmulatorImpl.java

License:Apache License

/**
 * /* ww w .j a va2s. c o  m*/
 * @param applicationSpecification
 * @param containerSpecification
 */
public ApplicationContainerLauncherEmulatorImpl(PrimitiveImmutableTypeMap applicationSpecification,
        PrimitiveImmutableTypeMap containerSpecification) {
    super(applicationSpecification, containerSpecification);
    this.executor = Executors.newCachedThreadPool();
    this.rmCallbackHandler = this.callbackSupport.buildResourceManagerCallbackHandler(this);
    this.nmCallbackHandler = this.callbackSupport.buildNodeManagerCallbackHandler(this);
    this.applicationId = ApplicationId.newInstance(System.currentTimeMillis(), 1);
    this.applicationAttemptId = ApplicationAttemptId.newInstance(this.applicationId, 1);
    this.applicationContainers = new HashMap<Container, ApplicationContainer>();

    // do preallocation early. Important for testing (see ApplicationContainerTests.validateSelfShutdownWithContainerStartupException)
    int containerStartId = 2;
    for (int i = 0; i < this.containerCount; i++) {
        ContainerRequest containerRequest = this.createConatinerRequest();
        // TODO implement a better mock so it can show ContainerRequest values
        Container container = new ContainerPBImpl();
        ContainerId containerId = ContainerId.newInstance(this.applicationAttemptId, containerStartId++);
        container.setId(containerId);
        ApplicationContainer applicationContainer = new ApplicationContainer(
                ApplicationContainerLauncherEmulatorImpl.this.applicationSpecification);
        this.applicationContainers.put(container, applicationContainer);
    }
}