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;
}
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;
}
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);
}
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);
}
Aggregations