Search in sources :

Example 11 with YarnApplicationState

use of org.apache.hadoop.yarn.api.records.YarnApplicationState in project hadoop by apache.

the class TestSubmitApplicationWithRMHA method verifySubmitApp.

private void verifySubmitApp(MockRM rm, RMApp app, ApplicationId expectedAppId) throws Exception {
    int maxWaittingTimes = 20;
    int count = 0;
    while (true) {
        YarnApplicationState state = rm.getApplicationReport(app.getApplicationId()).getYarnApplicationState();
        if (!state.equals(YarnApplicationState.NEW) && !state.equals(YarnApplicationState.NEW_SAVING)) {
            break;
        }
        if (count > maxWaittingTimes) {
            break;
        }
        Thread.sleep(200);
        count++;
    }
    // Verify submittion is successful
    YarnApplicationState state = rm.getApplicationReport(app.getApplicationId()).getYarnApplicationState();
    Assert.assertTrue(state == YarnApplicationState.ACCEPTED || state == YarnApplicationState.SUBMITTED);
    Assert.assertEquals(expectedAppId, app.getApplicationId());
}
Also used : YarnApplicationState(org.apache.hadoop.yarn.api.records.YarnApplicationState)

Example 12 with YarnApplicationState

use of org.apache.hadoop.yarn.api.records.YarnApplicationState in project hadoop by apache.

the class EntityGroupFSTimelineStore method getAppState.

/**
   * Ask the RM for the state of the application.
   * This method has to be synchronized to control traffic to RM
   * @param appId application ID
   * @param yarnClient
   * @return the state or {@link AppState#UNKNOWN} if it could not
   * be determined
   * @throws IOException
   */
private static synchronized AppState getAppState(ApplicationId appId, YarnClient yarnClient) throws IOException {
    AppState appState = AppState.ACTIVE;
    try {
        ApplicationReport report = yarnClient.getApplicationReport(appId);
        YarnApplicationState yarnState = report.getYarnApplicationState();
        if (APP_FINAL_STATES.contains(yarnState)) {
            appState = AppState.COMPLETED;
        }
    } catch (ApplicationNotFoundException e) {
        appState = AppState.UNKNOWN;
    } catch (YarnException e) {
        throw new IOException(e);
    }
    return appState;
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) YarnApplicationState(org.apache.hadoop.yarn.api.records.YarnApplicationState) IOException(java.io.IOException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Example 13 with YarnApplicationState

use of org.apache.hadoop.yarn.api.records.YarnApplicationState in project weave by continuuity.

the class YarnWeaveController method doStartUp.

@Override
protected void doStartUp() {
    super.doStartUp();
    // Submit and poll the status of the yarn application
    try {
        processController = startUp.call();
        YarnApplicationReport report = processController.getReport();
        LOG.debug("Application {} submit", report.getApplicationId());
        YarnApplicationState state = report.getYarnApplicationState();
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        stopWatch.split();
        long maxTime = TimeUnit.MILLISECONDS.convert(Constants.APPLICATION_MAX_START_SECONDS, TimeUnit.SECONDS);
        LOG.info("Checking yarn application status");
        while (!hasRun(state) && stopWatch.getSplitTime() < maxTime) {
            report = processController.getReport();
            state = report.getYarnApplicationState();
            LOG.debug("Yarn application status: {}", state);
            TimeUnit.SECONDS.sleep(1);
            stopWatch.split();
        }
        LOG.info("Yarn application is in state {}", state);
        if (state != YarnApplicationState.RUNNING) {
            LOG.info("Yarn application is not in running state. Shutting down controller.", Constants.APPLICATION_MAX_START_SECONDS);
            forceShutDown();
        } else {
            try {
                URL resourceUrl = URI.create(String.format("http://%s:%d", report.getHost(), report.getRpcPort())).resolve(TrackerService.PATH).toURL();
                resourcesClient = new ResourceReportClient(resourceUrl);
            } catch (IOException e) {
                resourcesClient = null;
            }
        }
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : YarnApplicationReport(com.continuuity.weave.internal.yarn.YarnApplicationReport) YarnApplicationState(org.apache.hadoop.yarn.api.records.YarnApplicationState) IOException(java.io.IOException) URL(java.net.URL) IOException(java.io.IOException) StopWatch(org.apache.commons.lang.time.StopWatch)

Example 14 with YarnApplicationState

use of org.apache.hadoop.yarn.api.records.YarnApplicationState in project alluxio by Alluxio.

the class Client method monitorApplication.

/**
   * Monitor the submitted application until app is running, finished, killed or failed.
   *
   * @throws YarnException if errors occur when obtaining application report from ResourceManager
   * @throws IOException if errors occur when obtaining application report from ResourceManager
   */
private void monitorApplication() throws YarnException, IOException {
    while (true) {
        // Check app status every 5 seconds
        CommonUtils.sleepMs(5 * Constants.SECOND_MS);
        // Get application report for the appId we are interested in
        ApplicationReport report = mYarnClient.getApplicationReport(mAppId);
        YarnApplicationState state = report.getYarnApplicationState();
        FinalApplicationStatus dsStatus = report.getFinalApplicationStatus();
        switch(state) {
            case RUNNING:
                System.out.println("Application is running. Tracking url is " + report.getTrackingUrl());
                return;
            case FINISHED:
                if (FinalApplicationStatus.SUCCEEDED == dsStatus) {
                    System.out.println("Application has completed successfully");
                } else {
                    System.out.println("Application finished unsuccessfully. YarnState=" + state.toString() + ", DSFinalStatus=" + dsStatus.toString());
                }
                return;
            // intended to fall through
            case KILLED:
            case FAILED:
                System.out.println("Application did not finish. YarnState=" + state.toString() + ", DSFinalStatus=" + dsStatus.toString());
                return;
            default:
                System.out.println("Application is in state " + state + ". Waiting.");
        }
    }
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) FinalApplicationStatus(org.apache.hadoop.yarn.api.records.FinalApplicationStatus) YarnApplicationState(org.apache.hadoop.yarn.api.records.YarnApplicationState)

Example 15 with YarnApplicationState

use of org.apache.hadoop.yarn.api.records.YarnApplicationState in project apex-core by apache.

the class InlineAM method monitorApplication.

/**
   * Monitor the submitted application for completion. Kill application if time
   * expires.
   *
   * @param appId
   *          Application Id of application to be monitored
   * @return true if application completed successfully
   * @throws YarnRemoteException
   */
private ApplicationReport monitorApplication(ApplicationId appId, Set<YarnApplicationState> finalState) throws YarnException, IOException {
    while (true) {
        // Check app status every 1 second.
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            LOG.debug("Thread sleep in monitoring loop interrupted");
        }
        // Get application report for the appId we are interested in
        ApplicationReport report = rmClient.getApplicationReport(appId);
        LOG.info("Got application report from ASM for" + ", appId=" + appId.getId() + ", appAttemptId=" + report.getCurrentApplicationAttemptId() + ", clientToken=" + report.getClientToAMToken() + ", appDiagnostics=" + report.getDiagnostics() + ", appMasterHost=" + report.getHost() + ", appQueue=" + report.getQueue() + ", appMasterRpcPort=" + report.getRpcPort() + ", appStartTime=" + report.getStartTime() + ", yarnAppState=" + report.getYarnApplicationState().toString() + ", distributedFinalState=" + report.getFinalApplicationStatus().toString() + ", appTrackingUrl=" + report.getTrackingUrl() + ", appUser=" + report.getUser());
        YarnApplicationState state = report.getYarnApplicationState();
        if (finalState.contains(state)) {
            return report;
        }
    }
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) YarnApplicationState(org.apache.hadoop.yarn.api.records.YarnApplicationState)

Aggregations

YarnApplicationState (org.apache.hadoop.yarn.api.records.YarnApplicationState)41 ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)27 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)14 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)11 IOException (java.io.IOException)10 FinalApplicationStatus (org.apache.hadoop.yarn.api.records.FinalApplicationStatus)8 HashSet (java.util.HashSet)7 ApplicationSubmissionContext (org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext)7 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)6 ArrayList (java.util.ArrayList)5 ContainerLaunchContext (org.apache.hadoop.yarn.api.records.ContainerLaunchContext)5 YarnClient (org.apache.hadoop.yarn.client.api.YarnClient)5 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)5 Test (org.junit.Test)5 Path (org.apache.hadoop.fs.Path)4 Resource (org.apache.hadoop.yarn.api.records.Resource)4 YarnClientApplication (org.apache.hadoop.yarn.client.api.YarnClientApplication)4 File (java.io.File)3 HashMap (java.util.HashMap)3 FileSystem (org.apache.hadoop.fs.FileSystem)3