Search in sources :

Example 1 with ApplicationAttemptNotFoundException

use of org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException in project hadoop by apache.

the class ApplicationCLI method printApplicationAttemptReport.

/**
   * Prints the application attempt report for an application attempt id.
   * 
   * @param applicationAttemptId
   * @return exitCode
   * @throws YarnException
   */
private int printApplicationAttemptReport(String applicationAttemptId) throws YarnException, IOException {
    ApplicationAttemptReport appAttemptReport = null;
    try {
        appAttemptReport = client.getApplicationAttemptReport(ApplicationAttemptId.fromString(applicationAttemptId));
    } catch (ApplicationNotFoundException e) {
        sysout.println("Application for AppAttempt with id '" + applicationAttemptId + "' doesn't exist in RM or Timeline Server.");
        return -1;
    } catch (ApplicationAttemptNotFoundException e) {
        sysout.println("Application Attempt with id '" + applicationAttemptId + "' doesn't exist in RM or Timeline Server.");
        return -1;
    }
    // Use PrintWriter.println, which uses correct platform line ending.
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter appAttemptReportStr = new PrintWriter(new OutputStreamWriter(baos, Charset.forName("UTF-8")));
    if (appAttemptReport != null) {
        appAttemptReportStr.println("Application Attempt Report : ");
        appAttemptReportStr.print("\tApplicationAttempt-Id : ");
        appAttemptReportStr.println(appAttemptReport.getApplicationAttemptId());
        appAttemptReportStr.print("\tState : ");
        appAttemptReportStr.println(appAttemptReport.getYarnApplicationAttemptState());
        appAttemptReportStr.print("\tAMContainer : ");
        appAttemptReportStr.println(appAttemptReport.getAMContainerId() == null ? "N/A" : appAttemptReport.getAMContainerId().toString());
        appAttemptReportStr.print("\tTracking-URL : ");
        appAttemptReportStr.println(appAttemptReport.getTrackingUrl());
        appAttemptReportStr.print("\tRPC Port : ");
        appAttemptReportStr.println(appAttemptReport.getRpcPort());
        appAttemptReportStr.print("\tAM Host : ");
        appAttemptReportStr.println(appAttemptReport.getHost());
        appAttemptReportStr.print("\tDiagnostics : ");
        appAttemptReportStr.print(appAttemptReport.getDiagnostics());
    } else {
        appAttemptReportStr.print("Application Attempt with id '" + applicationAttemptId + "' doesn't exist in Timeline Server.");
        appAttemptReportStr.close();
        sysout.println(baos.toString("UTF-8"));
        return -1;
    }
    appAttemptReportStr.close();
    sysout.println(baos.toString("UTF-8"));
    return 0;
}
Also used : ApplicationAttemptReport(org.apache.hadoop.yarn.api.records.ApplicationAttemptReport) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException) PrintWriter(java.io.PrintWriter)

Example 2 with ApplicationAttemptNotFoundException

use of org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException in project hadoop by apache.

the class TestAMRMClientAsync method testAMRMClientAsyncShutDownWithWaitFor.

@Test(timeout = 10000)
public void testAMRMClientAsyncShutDownWithWaitFor() throws Exception {
    Configuration conf = new Configuration();
    final TestCallbackHandler callbackHandler = new TestCallbackHandler();
    @SuppressWarnings("unchecked") AMRMClient<ContainerRequest> client = mock(AMRMClientImpl.class);
    when(client.allocate(anyFloat())).thenThrow(new ApplicationAttemptNotFoundException("app not found, shut down"));
    AMRMClientAsync<ContainerRequest> asyncClient = AMRMClientAsync.createAMRMClientAsync(client, 10, callbackHandler);
    asyncClient.init(conf);
    asyncClient.start();
    Supplier<Boolean> checker = new Supplier<Boolean>() {

        @Override
        public Boolean get() {
            return callbackHandler.reboot;
        }
    };
    asyncClient.registerApplicationMaster("localhost", 1234, null);
    asyncClient.waitFor(checker);
    asyncClient.stop();
    // stopping should have joined all threads and completed all callbacks
    Assert.assertTrue(callbackHandler.callbackCount == 0);
    verify(client, times(1)).allocate(anyFloat());
    asyncClient.stop();
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) ContainerRequest(org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest) Supplier(com.google.common.base.Supplier) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException) Test(org.junit.Test)

Example 3 with ApplicationAttemptNotFoundException

use of org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException in project hadoop by apache.

the class TestAMRMClientAsync method testAMRMClientAsyncShutDown.

@Test(timeout = 10000)
public void testAMRMClientAsyncShutDown() throws Exception {
    Configuration conf = new Configuration();
    TestCallbackHandler callbackHandler = new TestCallbackHandler();
    @SuppressWarnings("unchecked") AMRMClient<ContainerRequest> client = mock(AMRMClientImpl.class);
    createAllocateResponse(new ArrayList<ContainerStatus>(), new ArrayList<Container>(), null);
    when(client.allocate(anyFloat())).thenThrow(new ApplicationAttemptNotFoundException("app not found, shut down"));
    AMRMClientAsync<ContainerRequest> asyncClient = AMRMClientAsync.createAMRMClientAsync(client, 10, callbackHandler);
    asyncClient.init(conf);
    asyncClient.start();
    asyncClient.registerApplicationMaster("localhost", 1234, null);
    Thread.sleep(50);
    verify(client, times(1)).allocate(anyFloat());
    asyncClient.stop();
}
Also used : ContainerStatus(org.apache.hadoop.yarn.api.records.ContainerStatus) UpdatedContainer(org.apache.hadoop.yarn.api.records.UpdatedContainer) Container(org.apache.hadoop.yarn.api.records.Container) Configuration(org.apache.hadoop.conf.Configuration) ContainerRequest(org.apache.hadoop.yarn.client.api.AMRMClient.ContainerRequest) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException) Test(org.junit.Test)

Example 4 with ApplicationAttemptNotFoundException

use of org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException in project hadoop by apache.

the class ClientRMService method getApplicationAttemptReport.

@Override
public GetApplicationAttemptReportResponse getApplicationAttemptReport(GetApplicationAttemptReportRequest request) throws YarnException, IOException {
    ApplicationAttemptId appAttemptId = request.getApplicationAttemptId();
    UserGroupInformation callerUGI;
    try {
        callerUGI = UserGroupInformation.getCurrentUser();
    } catch (IOException ie) {
        LOG.info("Error getting UGI ", ie);
        throw RPCUtil.getRemoteException(ie);
    }
    RMApp application = this.rmContext.getRMApps().get(appAttemptId.getApplicationId());
    if (application == null) {
        // ApplicationNotFoundException and let client to handle.
        throw new ApplicationNotFoundException("Application with id '" + request.getApplicationAttemptId().getApplicationId() + "' doesn't exist in RM. Please check that the job " + "submission was successful.");
    }
    boolean allowAccess = checkAccess(callerUGI, application.getUser(), ApplicationAccessType.VIEW_APP, application);
    GetApplicationAttemptReportResponse response = null;
    if (allowAccess) {
        RMAppAttempt appAttempt = application.getAppAttempts().get(appAttemptId);
        if (appAttempt == null) {
            throw new ApplicationAttemptNotFoundException("ApplicationAttempt with id '" + appAttemptId + "' doesn't exist in RM.");
        }
        ApplicationAttemptReport attemptReport = appAttempt.createApplicationAttemptReport();
        response = GetApplicationAttemptReportResponse.newInstance(attemptReport);
    } else {
        throw new YarnException("User " + callerUGI.getShortUserName() + " does not have privilege to see this attempt " + appAttemptId);
    }
    return response;
}
Also used : RMApp(org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp) RMAppAttempt(org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt) ApplicationAttemptReport(org.apache.hadoop.yarn.api.records.ApplicationAttemptReport) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) GetApplicationAttemptReportResponse(org.apache.hadoop.yarn.api.protocolrecords.GetApplicationAttemptReportResponse) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) IOException(java.io.IOException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException)

Example 5 with ApplicationAttemptNotFoundException

use of org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException in project hadoop by apache.

the class TestYarnCLI method testGetApplicationAttemptReportException.

@Test
public void testGetApplicationAttemptReportException() throws Exception {
    ApplicationCLI cli = createAndGetAppCLI();
    ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
    ApplicationAttemptId attemptId1 = ApplicationAttemptId.newInstance(applicationId, 1);
    when(client.getApplicationAttemptReport(attemptId1)).thenThrow(new ApplicationNotFoundException("History file for application" + applicationId + " is not found"));
    int exitCode = cli.run(new String[] { "applicationattempt", "-status", attemptId1.toString() });
    verify(sysOut).println("Application for AppAttempt with id '" + attemptId1 + "' doesn't exist in RM or Timeline Server.");
    Assert.assertNotSame("should return non-zero exit code.", 0, exitCode);
    ApplicationAttemptId attemptId2 = ApplicationAttemptId.newInstance(applicationId, 2);
    when(client.getApplicationAttemptReport(attemptId2)).thenThrow(new ApplicationAttemptNotFoundException("History file for application attempt" + attemptId2 + " is not found"));
    exitCode = cli.run(new String[] { "applicationattempt", "-status", attemptId2.toString() });
    verify(sysOut).println("Application Attempt with id '" + attemptId2 + "' doesn't exist in RM or Timeline Server.");
    Assert.assertNotSame("should return non-zero exit code.", 0, exitCode);
}
Also used : ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) ApplicationAttemptId(org.apache.hadoop.yarn.api.records.ApplicationAttemptId) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException) Test(org.junit.Test)

Aggregations

ApplicationAttemptNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException)18 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)9 ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)9 IOException (java.io.IOException)8 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)7 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)7 RMAppAttempt (org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt)7 Test (org.junit.Test)7 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)5 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)4 AllocateResponse (org.apache.hadoop.yarn.api.protocolrecords.AllocateResponse)4 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)4 ApplicationMasterNotRegisteredException (org.apache.hadoop.yarn.exceptions.ApplicationMasterNotRegisteredException)4 ContainerNotFoundException (org.apache.hadoop.yarn.exceptions.ContainerNotFoundException)4 ArrayList (java.util.ArrayList)3 ApplicationAttemptReport (org.apache.hadoop.yarn.api.records.ApplicationAttemptReport)3 Container (org.apache.hadoop.yarn.api.records.Container)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)2 PrintWriter (java.io.PrintWriter)2