Search in sources :

Example 46 with ApplicationNotFoundException

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

the class ApplicationCLI method printContainerReport.

/**
 * Prints the container report for an container id.
 *
 * @param containerId
 * @return exitCode
 * @throws YarnException
 */
private int printContainerReport(String containerId) throws YarnException, IOException {
    ContainerReport containerReport = null;
    try {
        containerReport = client.getContainerReport((ConverterUtils.toContainerId(containerId)));
    } catch (ApplicationNotFoundException e) {
        sysout.println("Application for Container with id '" + containerId + "' doesn't exist in RM or Timeline Server.");
        return -1;
    } catch (ApplicationAttemptNotFoundException e) {
        sysout.println("Application Attempt for Container with id '" + containerId + "' doesn't exist in RM or Timeline Server.");
        return -1;
    } catch (ContainerNotFoundException e) {
        sysout.println("Container with id '" + containerId + "' doesn't exist in RM or Timeline Server.");
        return -1;
    }
    // Use PrintWriter.println, which uses correct platform line ending.
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter containerReportStr = new PrintWriter(new OutputStreamWriter(baos, Charset.forName("UTF-8")));
    if (containerReport != null) {
        containerReportStr.println("Container Report : ");
        containerReportStr.print("\tContainer-Id : ");
        containerReportStr.println(containerReport.getContainerId());
        containerReportStr.print("\tStart-Time : ");
        containerReportStr.println(containerReport.getCreationTime());
        containerReportStr.print("\tFinish-Time : ");
        containerReportStr.println(containerReport.getFinishTime());
        containerReportStr.print("\tState : ");
        containerReportStr.println(containerReport.getContainerState());
        containerReportStr.print("\tLOG-URL : ");
        containerReportStr.println(containerReport.getLogUrl());
        containerReportStr.print("\tHost : ");
        containerReportStr.println(containerReport.getAssignedNode());
        containerReportStr.print("\tNodeHttpAddress : ");
        containerReportStr.println(containerReport.getNodeHttpAddress() == null ? "N/A" : containerReport.getNodeHttpAddress());
        containerReportStr.print("\tDiagnostics : ");
        containerReportStr.print(containerReport.getDiagnosticsInfo());
    } else {
        containerReportStr.print("Container with id '" + containerId + "' doesn't exist in Timeline Server.");
        containerReportStr.close();
        sysout.println(baos.toString("UTF-8"));
        return -1;
    }
    containerReportStr.close();
    sysout.println(baos.toString("UTF-8"));
    return 0;
}
Also used : ContainerReport(org.apache.hadoop.yarn.api.records.ContainerReport) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ContainerNotFoundException(org.apache.hadoop.yarn.exceptions.ContainerNotFoundException) ApplicationAttemptNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException) PrintWriter(java.io.PrintWriter)

Example 47 with ApplicationNotFoundException

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

the class ApplicationCLI method printApplicationReport.

/**
 * Prints the application report for an application id.
 *
 * @param applicationId
 * @return exitCode
 * @throws YarnException
 */
private int printApplicationReport(String applicationId) throws YarnException, IOException {
    ApplicationReport appReport = null;
    try {
        appReport = client.getApplicationReport(ConverterUtils.toApplicationId(applicationId));
    } catch (ApplicationNotFoundException e) {
        sysout.println("Application with id '" + applicationId + "' doesn't exist in RM or Timeline Server.");
        return -1;
    }
    // Use PrintWriter.println, which uses correct platform line ending.
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter appReportStr = new PrintWriter(new OutputStreamWriter(baos, Charset.forName("UTF-8")));
    if (appReport != null) {
        appReportStr.println("Application Report : ");
        appReportStr.print("\tApplication-Id : ");
        appReportStr.println(appReport.getApplicationId());
        appReportStr.print("\tApplication-Name : ");
        appReportStr.println(appReport.getName());
        appReportStr.print("\tApplication-Type : ");
        appReportStr.println(appReport.getApplicationType());
        appReportStr.print("\tUser : ");
        appReportStr.println(appReport.getUser());
        appReportStr.print("\tQueue : ");
        appReportStr.println(appReport.getQueue());
        appReportStr.print("\tApplication Priority : ");
        appReportStr.println(appReport.getPriority());
        appReportStr.print("\tStart-Time : ");
        appReportStr.println(appReport.getStartTime());
        appReportStr.print("\tFinish-Time : ");
        appReportStr.println(appReport.getFinishTime());
        appReportStr.print("\tProgress : ");
        DecimalFormat formatter = new DecimalFormat("###.##%");
        String progress = formatter.format(appReport.getProgress());
        appReportStr.println(progress);
        appReportStr.print("\tState : ");
        appReportStr.println(appReport.getYarnApplicationState());
        appReportStr.print("\tFinal-State : ");
        appReportStr.println(appReport.getFinalApplicationStatus());
        appReportStr.print("\tTracking-URL : ");
        appReportStr.println(appReport.getOriginalTrackingUrl());
        appReportStr.print("\tRPC Port : ");
        appReportStr.println(appReport.getRpcPort());
        appReportStr.print("\tAM Host : ");
        appReportStr.println(appReport.getHost());
        appReportStr.print("\tAggregate Resource Allocation : ");
        ApplicationResourceUsageReport usageReport = appReport.getApplicationResourceUsageReport();
        if (usageReport != null) {
            // completed app report in the timeline server doesn't have usage report
            appReportStr.print(usageReport.getMemorySeconds() + " MB-seconds, ");
            appReportStr.println(usageReport.getVcoreSeconds() + " vcore-seconds");
        } else {
            appReportStr.println("N/A");
        }
        appReportStr.print("\tLog Aggregation Status : ");
        appReportStr.println(appReport.getLogAggregationStatus() == null ? "N/A" : appReport.getLogAggregationStatus());
        appReportStr.print("\tDiagnostics : ");
        appReportStr.println(appReport.getDiagnostics());
        appReportStr.print("\tUnmanaged Application : ");
        appReportStr.print(appReport.isUnmanagedApp());
    } else {
        appReportStr.print("Application with id '" + applicationId + "' doesn't exist in RM.");
        appReportStr.close();
        sysout.println(baos.toString("UTF-8"));
        return -1;
    }
    appReportStr.close();
    sysout.println(baos.toString("UTF-8"));
    return 0;
}
Also used : ApplicationReport(org.apache.hadoop.yarn.api.records.ApplicationReport) ApplicationNotFoundException(org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException) DecimalFormat(java.text.DecimalFormat) ApplicationResourceUsageReport(org.apache.hadoop.yarn.api.records.ApplicationResourceUsageReport) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PrintWriter(java.io.PrintWriter)

Example 48 with ApplicationNotFoundException

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

the class TestYarnCLI method testGetContainerReportException.

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

Example 49 with ApplicationNotFoundException

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

the class TestYarnCLI method testGetApplicationReportException.

@Test
public void testGetApplicationReportException() throws Exception {
    ApplicationCLI cli = createAndGetAppCLI();
    ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
    when(client.getApplicationReport(any(ApplicationId.class))).thenThrow(new ApplicationNotFoundException("History file for application" + applicationId + " is not found"));
    int exitCode = cli.run(new String[] { "application", "-status", applicationId.toString() });
    verify(sysOut).println("Application with id '" + applicationId + "' 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) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) Test(org.junit.Test)

Aggregations

ApplicationNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException)49 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)27 ApplicationReport (org.apache.hadoop.yarn.api.records.ApplicationReport)20 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)20 Test (org.junit.Test)20 IOException (java.io.IOException)19 RMApp (org.apache.hadoop.yarn.server.resourcemanager.rmapp.RMApp)13 ApplicationAttemptNotFoundException (org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException)12 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)11 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)9 ContainerNotFoundException (org.apache.hadoop.yarn.exceptions.ContainerNotFoundException)7 TezException (org.apache.tez.dag.api.TezException)6 RecordFactory (org.apache.hadoop.yarn.factories.RecordFactory)5 RMAppAttempt (org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.RMAppAttempt)5 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)4 YarnApplicationState (org.apache.hadoop.yarn.api.records.YarnApplicationState)4 YarnClient (org.apache.hadoop.yarn.client.api.YarnClient)4 ServiceException (com.google.protobuf.ServiceException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3