Search in sources :

Example 71 with ApplicationReport

use of org.apache.hadoop.yarn.api.records.ApplicationReport 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)

Example 72 with ApplicationReport

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

the class InlineAM method run.

public boolean run() throws Exception {
    LOG.info("Starting Client");
    // Connect to ResourceManager
    rmClient.start();
    try {
        // Get a new application id
        YarnClientApplication newApp = rmClient.createApplication();
        ApplicationId appId = newApp.getNewApplicationResponse().getApplicationId();
        // Create launch context for app master
        LOG.info("Setting up application submission context for ASM");
        ApplicationSubmissionContext appContext = Records.newRecord(ApplicationSubmissionContext.class);
        // set the application id
        appContext.setApplicationId(appId);
        // set the application name
        appContext.setApplicationName(appName);
        // Set the priority for the application master
        Priority pri = Records.newRecord(Priority.class);
        pri.setPriority(amPriority);
        appContext.setPriority(pri);
        // Set the queue to which this application is to be submitted in the RM
        appContext.setQueue(amQueue);
        // Set up the container launch context for the application master
        ContainerLaunchContext amContainer = Records.newRecord(ContainerLaunchContext.class);
        appContext.setAMContainerSpec(amContainer);
        // unmanaged AM
        appContext.setUnmanagedAM(true);
        LOG.info("Setting unmanaged AM");
        // Submit the application to the applications manager
        LOG.info("Submitting application to ASM");
        rmClient.submitApplication(appContext);
        // Monitor the application to wait for launch state
        ApplicationReport appReport = monitorApplication(appId, EnumSet.of(YarnApplicationState.ACCEPTED));
        ApplicationAttemptId attemptId = appReport.getCurrentApplicationAttemptId();
        LOG.info("Launching application with id: " + attemptId);
        // launch AM
        runAM(attemptId);
        // Monitor the application for end state
        appReport = monitorApplication(appId, EnumSet.of(YarnApplicationState.KILLED, YarnApplicationState.FAILED, YarnApplicationState.FINISHED));
        YarnApplicationState appState = appReport.getYarnApplicationState();
        FinalApplicationStatus appStatus = appReport.getFinalApplicationStatus();
        LOG.info("App ended with state: " + appReport.getYarnApplicationState() + " and status: " + appStatus);
        boolean success;
        if (YarnApplicationState.FINISHED == appState && FinalApplicationStatus.SUCCEEDED == appStatus) {
            LOG.info("Application has completed successfully.");
            success = true;
        } else {
            LOG.info("Application did finished unsuccessfully." + " YarnState=" + appState.toString() + ", FinalStatus=" + appStatus.toString());
            success = false;
        }
        return success;
    } finally {
        rmClient.stop();
    }
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) YarnClientApplication(org.apache.hadoop.yarn.client.api.YarnClientApplication) FinalApplicationStatus(org.apache.hadoop.yarn.api.records.FinalApplicationStatus) Priority(org.apache.hadoop.yarn.api.records.Priority) ApplicationSubmissionContext(org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext) YarnApplicationState(org.apache.hadoop.yarn.api.records.YarnApplicationState) ContainerLaunchContext(org.apache.hadoop.yarn.api.records.ContainerLaunchContext) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId)

Example 73 with ApplicationReport

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

the class YarnAppLauncherImpl method shutdownApp.

protected void shutdownApp(YarnAppHandleImpl app, ShutdownMode shutdownMode) throws LauncherException {
    if (shutdownMode == ShutdownMode.KILL) {
        YarnClient yarnClient = YarnClient.createYarnClient();
        try {
            ApplicationId applicationId = app.appId;
            ApplicationReport appReport = yarnClient.getApplicationReport(applicationId);
            if (appReport == null) {
                throw new LauncherException("Application " + app.getApplicationId() + " not found");
            }
            yarnClient.killApplication(applicationId);
        } catch (YarnException | IOException e) {
            throw Throwables.propagate(e);
        } finally {
            IOUtils.closeQuietly(yarnClient);
        }
    } else {
        throw new UnsupportedOperationException("Orderly shutdown not supported, try kill instead");
    }
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) IOException(java.io.IOException) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) YarnClient(org.apache.hadoop.yarn.client.api.YarnClient) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Example 74 with ApplicationReport

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

the class TestYarnJobValidationTool method testValidateRunningAttemptId.

@Test
public void testValidateRunningAttemptId() throws Exception {
    ApplicationReport appReport = mock(ApplicationReport.class);
    when(client.getApplicationReport(appId)).thenReturn(appReport);
    when(appReport.getCurrentApplicationAttemptId()).thenReturn(attemptId);
    ApplicationAttemptReport attemptReport = mock(ApplicationAttemptReport.class);
    when(attemptReport.getYarnApplicationAttemptState()).thenReturn(YarnApplicationAttemptState.RUNNING);
    when(attemptReport.getApplicationAttemptId()).thenReturn(attemptId);
    when(client.getApplicationAttemptReport(attemptId)).thenReturn(attemptReport);
    assertTrue(tool.validateRunningAttemptId(appId).equals(attemptId));
    when(attemptReport.getYarnApplicationAttemptState()).thenReturn(YarnApplicationAttemptState.FAILED);
    exception.expect(SamzaException.class);
    tool.validateRunningAttemptId(appId);
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) ApplicationAttemptReport(org.apache.hadoop.yarn.api.records.ApplicationAttemptReport) Test(org.junit.Test)

Example 75 with ApplicationReport

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

the class TestYarnJobValidationTool method testValidateAppId.

@Test
public void testValidateAppId() throws Exception {
    ApplicationReport appReport = mock(ApplicationReport.class);
    when(appReport.getName()).thenReturn(jobName + "_" + jobId);
    when(appReport.getApplicationId()).thenReturn(appId);
    when(client.getApplications()).thenReturn(Collections.singletonList(appReport));
    assertTrue(tool.validateAppId().equals(appId));
    when(appReport.getName()).thenReturn("dummy");
    exception.expect(SamzaException.class);
    tool.validateAppId();
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) Test(org.junit.Test)

Aggregations

ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)143 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)65 Test (org.junit.Test)52 IOException (java.io.IOException)41 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)32 YarnApplicationState (org.apache.hadoop.yarn.api.records.YarnApplicationState)29 YarnClient (org.apache.hadoop.yarn.client.api.YarnClient)21 ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)19 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)18 ApplicationSubmissionContext (org.apache.hadoop.yarn.api.records.ApplicationSubmissionContext)16 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)16 Configuration (org.apache.hadoop.conf.Configuration)14 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)14 ArrayList (java.util.ArrayList)13 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)13 GetApplicationReportRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportRequest)11 GetApplicationsRequest (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationsRequest)11 GetApplicationReportResponse (org.apache.hadoop.yarn.api.protocolrecords.GetApplicationReportResponse)10 ApplicationResourceUsageReport (org.apache.hadoop.yarn.api.records.ApplicationResourceUsageReport)10 ContainerLaunchContext (org.apache.hadoop.yarn.api.records.ContainerLaunchContext)10