Example usage for org.apache.hadoop.yarn.api.records FinalApplicationStatus FAILED

List of usage examples for org.apache.hadoop.yarn.api.records FinalApplicationStatus FAILED

Introduction

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

Prototype

FinalApplicationStatus FAILED

To view the source code for org.apache.hadoop.yarn.api.records FinalApplicationStatus FAILED.

Click Source Link

Document

Application which failed.

Usage

From source file:ApplicationMaster.java

License:Apache License

@VisibleForTesting
protected boolean finish() {
    // wait for completion.
    while (!done && (numCompletedContainers.get() != numTotalContainers)) {
        try {/*from   w  ww.ja va 2  s .  c o  m*/
            Thread.sleep(200);
        } catch (InterruptedException ex) {
        }
    }

    // Join all launched threads
    // needed for when we time out
    // and we need to release containers
    for (Thread launchThread : launchThreads) {
        try {
            launchThread.join(10000);
        } catch (InterruptedException e) {
            LOG.info("Exception thrown in thread join: " + e.getMessage());
            e.printStackTrace();
        }
    }

    // When the application completes, it should stop all running containers
    LOG.info("Application completed. Stopping running containers");
    nmClientAsync.stop();

    // When the application completes, it should send a finish application
    // signal to the RM
    LOG.info("Application completed. Signalling finish to RM");

    FinalApplicationStatus appStatus;
    String appMessage = null;
    boolean success = true;
    if (numFailedContainers.get() == 0 && numCompletedContainers.get() == numTotalContainers) {
        appStatus = FinalApplicationStatus.SUCCEEDED;
    } else {
        appStatus = FinalApplicationStatus.FAILED;
        appMessage = "Diagnostics." + ", total=" + numTotalContainers + ", completed="
                + numCompletedContainers.get() + ", allocated=" + numAllocatedContainers.get() + ", failed="
                + numFailedContainers.get();
        success = false;
    }
    try {
        amRMClient.unregisterApplicationMaster(appStatus, appMessage, null);
    } catch (YarnException ex) {
        LOG.error("Failed to unregister application", ex);
    } catch (IOException e) {
        LOG.error("Failed to unregister application", e);
    }

    amRMClient.stop();

    return success;
}

From source file:cn.edu.buaa.act.petuumOnYarn.ApplicationMaster.java

License:Apache License

@VisibleForTesting
protected boolean finish() {
    // wait for completion.
    while (!done && (numCompletedContainers.get() != numTotalContainers)) {
        try {//from   w  w w . ja v  a  2 s .c o m
            Thread.sleep(200);
        } catch (InterruptedException ex) {
        }
    }

    // Join all launched threads
    // needed for when we time out
    // and we need to release containers
    for (Thread launchThread : launchThreads) {
        try {
            launchThread.join(10000);
        } catch (InterruptedException e) {
            LOG.info("Exception thrown in thread join: " + e.getMessage());
            e.printStackTrace();
        }
    }

    // When the application completes, it should stop all running containers
    LOG.info("Application completed. Stopping running containers");
    nmClientAsync.stop();

    // When the application completes, it should send a finish application
    // signal to the RM
    LOG.info("Application completed. Signalling finish to RM");

    FinalApplicationStatus appStatus;
    String appMessage = null;
    boolean success = true;
    if (numFailedContainers.get() == 0 && numCompletedContainers.get() == numTotalContainers) {
        appStatus = FinalApplicationStatus.SUCCEEDED;
    } else {
        appStatus = FinalApplicationStatus.FAILED;
        appMessage = "Diagnostics." + ", total=" + numTotalContainers + ", completed="
                + numCompletedContainers.get() + ", allocated=" + numAllocatedContainers.get() + ", failed="
                + numFailedContainers.get();
        LOG.info(appMessage);
        success = false;
    }
    try {
        amRMClient.unregisterApplicationMaster(appStatus, appMessage, null);
    } catch (YarnException ex) {
        LOG.error("Failed to unregister application", ex);
    } catch (IOException e) {
        LOG.error("Failed to unregister application", e);
    }

    amRMClient.stop();

    return success;
}

From source file:co.cask.cdap.internal.app.runtime.distributed.AbstractTwillProgramController.java

License:Apache License

/**
 * Starts listening to TwillController state changes. For internal use only.
 * The listener cannot be binded in constructor to avoid reference leak.
 *
 * @return this instance./*from w w  w . ja  v a 2 s  .c o m*/
 */
public ProgramController startListen() {
    twillController.onRunning(new Runnable() {
        @Override
        public void run() {
            LOG.info("Twill program running: {}, twill runId: {}", getProgramRunId(),
                    twillController.getRunId());
            started();
        }
    }, Threads.SAME_THREAD_EXECUTOR);

    twillController.onTerminated(new Runnable() {
        @Override
        public void run() {
            LOG.info("Twill program terminated: {}, twill runId: {}", getProgramRunId(),
                    twillController.getRunId());
            if (stopRequested) {
                // Service was killed
                stop();
            } else {
                try {
                    // This never blocks since the twill controller is already terminated. It will throw exception if
                    // the twill program failed.
                    twillController.awaitTerminated();
                    // Service completed by itself. Simply signal the state change of this controller.
                    // TODO (CDAP-6806): this should not be done with reflection but through a proper Twill API
                    // Figure out whether the final Yarn status is in error, if so, set state accordingly
                    if (twillController instanceof YarnTwillController) {
                        FinalApplicationStatus finalStatus = ((YarnTwillController) twillController)
                                .getTerminationStatus();
                        if (FinalApplicationStatus.FAILED.equals(finalStatus)) {
                            complete(State.ERROR);
                            return;
                        } else if (FinalApplicationStatus.KILLED.equals(finalStatus)) {
                            complete(State.KILLED);
                            return;
                        }
                    }
                    // normal termination
                    complete();
                } catch (Exception e) {
                    error(e);
                }
            }
        }
    }, Threads.SAME_THREAD_EXECUTOR);
    return this;
}

From source file:com.bigjob.ApplicationMaster.java

License:Apache License

private void finish() {
    // Join all launched threads
    // needed for when we time out
    // and we need to release containers
    for (Thread launchThread : launchThreads) {
        try {//from  w  w  w .j a  v a  2s . c o  m
            launchThread.join(10000);
        } catch (InterruptedException e) {
            LOG.info("Exception thrown in thread join: " + e.getMessage());
            e.printStackTrace();
        }
    }

    // When the application completes, it should stop all running containers
    LOG.info("Application completed. Stopping running containers");
    nmClientAsync.stop();

    // When the application completes, it should send a finish application
    // signal to the RM
    LOG.info("Application completed. Signalling finish to RM");

    FinalApplicationStatus appStatus;
    String appMessage = null;
    success = true;
    if (numFailedContainers.get() == 0 && numCompletedContainers.get() == numTotalContainers) {
        appStatus = FinalApplicationStatus.SUCCEEDED;
    } else {
        appStatus = FinalApplicationStatus.FAILED;
        appMessage = "Diagnostics." + ", total=" + numTotalContainers + ", completed="
                + numCompletedContainers.get() + ", allocated=" + numAllocatedContainers.get() + ", failed="
                + numFailedContainers.get();
        success = false;
    }
    try {
        amRMClient.unregisterApplicationMaster(appStatus, appMessage, null);
    } catch (YarnException ex) {
        LOG.error("Failed to unregister application", ex);
    } catch (IOException e) {
        LOG.error("Failed to unregister application", e);
    }

    amRMClient.stop();
}

From source file:com.cfets.door.yarn.jboss.JBossApplicationMaster.java

License:Apache License

private void finish() {
    for (Thread launchThread : launchThreads) {
        try {// w  w  w .java2 s  .  c o m
            launchThread.join(10000);
        } catch (InterruptedException e) {
            LOG.info("Exception thrown in thread join: " + e.getMessage());
            e.printStackTrace();
        }
    }

    LOG.info("Application completed. Stopping running containers");
    nmClientAsync.stop();

    LOG.info("Application completed. Signalling finish to RM");

    FinalApplicationStatus appStatus;
    String appMessage = null;
    success = true;
    if (numFailedContainers.get() == 0 && numCompletedContainers.get() == numTotalContainers) {
        appStatus = FinalApplicationStatus.SUCCEEDED;
    } else {
        appStatus = FinalApplicationStatus.FAILED;
        appMessage = "Diagnostics." + ", total=" + numTotalContainers + ", completed="
                + numCompletedContainers.get() + ", allocated=" + numAllocatedContainers.get() + ", failed="
                + numFailedContainers.get();
        success = false;
    }
    try {
        resourceManager.unregisterApplicationMaster(appStatus, appMessage, null);
    } catch (YarnException ex) {
        LOG.log(Level.SEVERE, "Failed to unregister application", ex);
    } catch (IOException e) {
        LOG.log(Level.SEVERE, "Failed to unregister application", e);
    }

    done = true;
    resourceManager.stop();
}

From source file:com.cloudera.kitten.appmaster.service.ApplicationMasterServiceImpl.java

License:Open Source License

@Override
protected void shutDown() {
    // Stop the containers in the case that we're finishing because of a timeout.
    LOG.info("Stopping trackers");
    for (ContainerTracker tracker : containerTrackers) {
        tracker.stopServices();/*from w w w.  ja  v a  2 s .  co  m*/
    }

    FinishApplicationMasterRequest finishReq = Records.newRecord(FinishApplicationMasterRequest.class);
    finishReq.setAppAttemptId(getApplicationAttemptId());
    if (state() == State.FAILED || totalFailures.incrementAndGet() > parameters.getAllowedFailures()) {
        //TODO: diagnostics
        finishReq.setFinishApplicationStatus(FinalApplicationStatus.FAILED);
    } else {
        finishReq.setFinishApplicationStatus(FinalApplicationStatus.SUCCEEDED);
    }
    LOG.info("Sending finish request with status = " + finishReq.getFinalApplicationStatus());
    try {
        resourceManager.finishApplicationMaster(finishReq);
    } catch (YarnRemoteException e) {
        LOG.error("Error finishing application master", e);
    }
}

From source file:com.cloudera.kitten.appmaster.service.ApplicationMasterServiceImpl1.java

License:Open Source License

@Override
protected void shutDown() {
    // Stop the containers in the case that we're finishing because of a timeout.
    LOG.info("Stopping trackers");
    this.hasRunningContainers = false;

    for (ContainerTracker tracker : trackers) {
        if (tracker.hasRunningContainers()) {
            tracker.kill();/*from  w  ww .  j a  v  a  2s  . c  om*/
        }
    }
    FinalApplicationStatus status;
    String message = null;
    if (state() == State.FAILED || totalFailures.get() > parameters.getAllowedFailures()) {
        //TODO: diagnostics
        status = FinalApplicationStatus.FAILED;
        if (throwable != null) {
            message = throwable.getLocalizedMessage();
        }
    } else {
        status = FinalApplicationStatus.SUCCEEDED;
    }
    LOG.info("Sending finish request with status = " + status);
    try {
        resourceManager.unregisterApplicationMaster(status, message, null);
    } catch (Exception e) {
        LOG.error("Error finishing application master", e);
    }
}

From source file:com.cloudera.kitten.appmaster.service.WorkflowService.java

License:Open Source License

@Override
protected void shutDown() {
    // Stop the containers in the case that we're finishing because of a timeout.
    LOG.info("Stopping trackers");
    this.hasRunningContainers = false;

    for (ContainerTracker tracker : trackers.values()) {
        if (tracker.hasRunningContainers()) {
            tracker.kill();/*  ww w .jav a 2 s . c om*/
        }
    }
    FinalApplicationStatus status;
    String message = null;
    if (state() == State.FAILED || totalFailures.get() > parameters.getAllowedFailures()) {
        //TODO: diagnostics
        status = FinalApplicationStatus.FAILED;
        if (throwable != null) {
            message = throwable.getLocalizedMessage();
        }
    } else {
        status = FinalApplicationStatus.SUCCEEDED;
    }
    LOG.info("Sending finish request with status = " + status);
    try {
        resourceManager.unregisterApplicationMaster(status, message, null);
    } catch (Exception e) {
        LOG.error("Error finishing application master", e);
    }
}

From source file:com.cloudera.llama.am.yarn.YarnRMConnector.java

License:Apache License

private ApplicationReport _monitorAppState(YarnClient rmClient, ApplicationId appId,
        Set<YarnApplicationState> states, boolean calledFromStopped) throws LlamaException {
    String action = calledFromStopped ? "stopping" : "starting";
    try {/*from w ww .j  ava  2 s  .  c om*/
        long timeout = getConf().getLong(APP_MONITOR_TIMEOUT_KEY, APP_MONITOR_TIMEOUT_DEFAULT);

        long polling = getConf().getLong(APP_MONITOR_POLLING_KEY, APP_MONITOR_POLLING_DEFAULT);

        long start = System.currentTimeMillis();
        ApplicationReport report = rmClient.getApplicationReport(appId);
        while (!states.contains(report.getYarnApplicationState())) {
            if (System.currentTimeMillis() - start > timeout) {
                throw new LlamaException(ErrorCode.AM_TIMED_OUT_STARTING_STOPPING, appId, timeout,
                        report.getYarnApplicationState(), states, action);
            }
            Thread.sleep(polling);
            report = rmClient.getApplicationReport(appId);
        }
        return report;
    } catch (Exception ex) {
        if (!calledFromStopped) {
            _stop(FinalApplicationStatus.FAILED, "Could not start, error: " + ex, true);
        }
        throw new LlamaException(ex, ErrorCode.AM_FAILED_WHILE_STARTING_STOPPING, appId, action);
    }
}

From source file:com.cloudera.llama.am.yarn.YarnRMConnector.java

License:Apache License

@Override
public void onShutdownRequest() {
    llamaCallback.stoppedByRM();/*ww w .j  ava2s  .  co  m*/

    LOG.warn("Yarn requested AM to shutdown");

    // no need to use a ugi.doAs() as this is called from within Yarn client
    _stop(FinalApplicationStatus.FAILED, "Shutdown by Yarn", true);
}