YARN-2356. yarn status command for non-existent application/application
attempt/container is too verbose. Contributed by Sunil G.
(cherry picked from commit fae3e8614f
)
This commit is contained in:
parent
a3fa1f0761
commit
4c6760bc6b
|
@ -193,6 +193,9 @@ Release 2.7.0 - UNRELEASED
|
||||||
|
|
||||||
YARN-2912 Jersey Tests failing with port in use. (varun saxena via stevel)
|
YARN-2912 Jersey Tests failing with port in use. (varun saxena via stevel)
|
||||||
|
|
||||||
|
YARN-2356. yarn status command for non-existent application/application
|
||||||
|
attempt/container is too verbose. (Sunil G via devaraj)
|
||||||
|
|
||||||
Release 2.6.0 - 2014-11-18
|
Release 2.6.0 - 2014-11-18
|
||||||
|
|
||||||
INCOMPATIBLE CHANGES
|
INCOMPATIBLE CHANGES
|
||||||
|
|
|
@ -41,7 +41,9 @@ import org.apache.hadoop.yarn.api.records.ApplicationReport;
|
||||||
import org.apache.hadoop.yarn.api.records.ApplicationResourceUsageReport;
|
import org.apache.hadoop.yarn.api.records.ApplicationResourceUsageReport;
|
||||||
import org.apache.hadoop.yarn.api.records.ContainerReport;
|
import org.apache.hadoop.yarn.api.records.ContainerReport;
|
||||||
import org.apache.hadoop.yarn.api.records.YarnApplicationState;
|
import org.apache.hadoop.yarn.api.records.YarnApplicationState;
|
||||||
|
import org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException;
|
||||||
import org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException;
|
import org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException;
|
||||||
|
import org.apache.hadoop.yarn.exceptions.ContainerNotFoundException;
|
||||||
import org.apache.hadoop.yarn.exceptions.YarnException;
|
import org.apache.hadoop.yarn.exceptions.YarnException;
|
||||||
import org.apache.hadoop.yarn.util.ConverterUtils;
|
import org.apache.hadoop.yarn.util.ConverterUtils;
|
||||||
import org.apache.hadoop.yarn.util.Times;
|
import org.apache.hadoop.yarn.util.Times;
|
||||||
|
@ -152,12 +154,14 @@ public class ApplicationCLI extends YarnCLI {
|
||||||
return exitCode;
|
return exitCode;
|
||||||
}
|
}
|
||||||
if (args[0].equalsIgnoreCase(APPLICATION)) {
|
if (args[0].equalsIgnoreCase(APPLICATION)) {
|
||||||
printApplicationReport(cliParser.getOptionValue(STATUS_CMD));
|
exitCode = printApplicationReport(cliParser.getOptionValue(STATUS_CMD));
|
||||||
} else if (args[0].equalsIgnoreCase(APPLICATION_ATTEMPT)) {
|
} else if (args[0].equalsIgnoreCase(APPLICATION_ATTEMPT)) {
|
||||||
printApplicationAttemptReport(cliParser.getOptionValue(STATUS_CMD));
|
exitCode = printApplicationAttemptReport(cliParser
|
||||||
|
.getOptionValue(STATUS_CMD));
|
||||||
} else if (args[0].equalsIgnoreCase(CONTAINER)) {
|
} else if (args[0].equalsIgnoreCase(CONTAINER)) {
|
||||||
printContainerReport(cliParser.getOptionValue(STATUS_CMD));
|
exitCode = printContainerReport(cliParser.getOptionValue(STATUS_CMD));
|
||||||
}
|
}
|
||||||
|
return exitCode;
|
||||||
} else if (cliParser.hasOption(LIST_CMD)) {
|
} else if (cliParser.hasOption(LIST_CMD)) {
|
||||||
if (args[0].equalsIgnoreCase(APPLICATION)) {
|
if (args[0].equalsIgnoreCase(APPLICATION)) {
|
||||||
allAppStates = false;
|
allAppStates = false;
|
||||||
|
@ -252,13 +256,24 @@ public class ApplicationCLI extends YarnCLI {
|
||||||
* Prints the application attempt report for an application attempt id.
|
* Prints the application attempt report for an application attempt id.
|
||||||
*
|
*
|
||||||
* @param applicationAttemptId
|
* @param applicationAttemptId
|
||||||
|
* @return exitCode
|
||||||
* @throws YarnException
|
* @throws YarnException
|
||||||
*/
|
*/
|
||||||
private void printApplicationAttemptReport(String applicationAttemptId)
|
private int printApplicationAttemptReport(String applicationAttemptId)
|
||||||
throws YarnException, IOException {
|
throws YarnException, IOException {
|
||||||
ApplicationAttemptReport appAttemptReport = client
|
ApplicationAttemptReport appAttemptReport = null;
|
||||||
.getApplicationAttemptReport(ConverterUtils
|
try {
|
||||||
|
appAttemptReport = client.getApplicationAttemptReport(ConverterUtils
|
||||||
.toApplicationAttemptId(applicationAttemptId));
|
.toApplicationAttemptId(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.
|
// Use PrintWriter.println, which uses correct platform line ending.
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
PrintWriter appAttemptReportStr = new PrintWriter(baos);
|
PrintWriter appAttemptReportStr = new PrintWriter(baos);
|
||||||
|
@ -282,22 +297,42 @@ public class ApplicationCLI extends YarnCLI {
|
||||||
appAttemptReportStr.print(appAttemptReport.getDiagnostics());
|
appAttemptReportStr.print(appAttemptReport.getDiagnostics());
|
||||||
} else {
|
} else {
|
||||||
appAttemptReportStr.print("Application Attempt with id '"
|
appAttemptReportStr.print("Application Attempt with id '"
|
||||||
+ applicationAttemptId + "' doesn't exist in History Server.");
|
+ applicationAttemptId + "' doesn't exist in Timeline Server.");
|
||||||
|
appAttemptReportStr.close();
|
||||||
|
sysout.println(baos.toString("UTF-8"));
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
appAttemptReportStr.close();
|
appAttemptReportStr.close();
|
||||||
sysout.println(baos.toString("UTF-8"));
|
sysout.println(baos.toString("UTF-8"));
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints the container report for an container id.
|
* Prints the container report for an container id.
|
||||||
*
|
*
|
||||||
* @param containerId
|
* @param containerId
|
||||||
|
* @return exitCode
|
||||||
* @throws YarnException
|
* @throws YarnException
|
||||||
*/
|
*/
|
||||||
private void printContainerReport(String containerId) throws YarnException,
|
private int printContainerReport(String containerId) throws YarnException,
|
||||||
IOException {
|
IOException {
|
||||||
ContainerReport containerReport = client.getContainerReport((ConverterUtils
|
ContainerReport containerReport = null;
|
||||||
|
try {
|
||||||
|
containerReport = client.getContainerReport((ConverterUtils
|
||||||
.toContainerId(containerId)));
|
.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.
|
// Use PrintWriter.println, which uses correct platform line ending.
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
PrintWriter containerReportStr = new PrintWriter(baos);
|
PrintWriter containerReportStr = new PrintWriter(baos);
|
||||||
|
@ -319,10 +354,14 @@ public class ApplicationCLI extends YarnCLI {
|
||||||
containerReportStr.print(containerReport.getDiagnosticsInfo());
|
containerReportStr.print(containerReport.getDiagnosticsInfo());
|
||||||
} else {
|
} else {
|
||||||
containerReportStr.print("Container with id '" + containerId
|
containerReportStr.print("Container with id '" + containerId
|
||||||
+ "' doesn't exist in Hostory Server.");
|
+ "' doesn't exist in Timeline Server.");
|
||||||
|
containerReportStr.close();
|
||||||
|
sysout.println(baos.toString("UTF-8"));
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
containerReportStr.close();
|
containerReportStr.close();
|
||||||
sysout.println(baos.toString("UTF-8"));
|
sysout.println(baos.toString("UTF-8"));
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -423,12 +462,20 @@ public class ApplicationCLI extends YarnCLI {
|
||||||
* Prints the application report for an application id.
|
* Prints the application report for an application id.
|
||||||
*
|
*
|
||||||
* @param applicationId
|
* @param applicationId
|
||||||
|
* @return exitCode
|
||||||
* @throws YarnException
|
* @throws YarnException
|
||||||
*/
|
*/
|
||||||
private void printApplicationReport(String applicationId)
|
private int printApplicationReport(String applicationId)
|
||||||
throws YarnException, IOException {
|
throws YarnException, IOException {
|
||||||
ApplicationReport appReport = client.getApplicationReport(ConverterUtils
|
ApplicationReport appReport = null;
|
||||||
|
try {
|
||||||
|
appReport = client.getApplicationReport(ConverterUtils
|
||||||
.toApplicationId(applicationId));
|
.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.
|
// Use PrintWriter.println, which uses correct platform line ending.
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
PrintWriter appReportStr = new PrintWriter(baos);
|
PrintWriter appReportStr = new PrintWriter(baos);
|
||||||
|
@ -478,9 +525,13 @@ public class ApplicationCLI extends YarnCLI {
|
||||||
} else {
|
} else {
|
||||||
appReportStr.print("Application with id '" + applicationId
|
appReportStr.print("Application with id '" + applicationId
|
||||||
+ "' doesn't exist in RM.");
|
+ "' doesn't exist in RM.");
|
||||||
|
appReportStr.close();
|
||||||
|
sysout.println(baos.toString("UTF-8"));
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
appReportStr.close();
|
appReportStr.close();
|
||||||
sysout.println(baos.toString("UTF-8"));
|
sysout.println(baos.toString("UTF-8"));
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getAllValidApplicationStates() {
|
private String getAllValidApplicationStates() {
|
||||||
|
|
|
@ -62,7 +62,9 @@ import org.apache.hadoop.yarn.api.records.Resource;
|
||||||
import org.apache.hadoop.yarn.api.records.YarnApplicationAttemptState;
|
import org.apache.hadoop.yarn.api.records.YarnApplicationAttemptState;
|
||||||
import org.apache.hadoop.yarn.api.records.YarnApplicationState;
|
import org.apache.hadoop.yarn.api.records.YarnApplicationState;
|
||||||
import org.apache.hadoop.yarn.client.api.YarnClient;
|
import org.apache.hadoop.yarn.client.api.YarnClient;
|
||||||
|
import org.apache.hadoop.yarn.exceptions.ApplicationAttemptNotFoundException;
|
||||||
import org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException;
|
import org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException;
|
||||||
|
import org.apache.hadoop.yarn.exceptions.ContainerNotFoundException;
|
||||||
import org.apache.hadoop.yarn.util.Records;
|
import org.apache.hadoop.yarn.util.Records;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -319,14 +321,12 @@ public class TestYarnCLI {
|
||||||
when(client.getApplicationReport(any(ApplicationId.class))).thenThrow(
|
when(client.getApplicationReport(any(ApplicationId.class))).thenThrow(
|
||||||
new ApplicationNotFoundException("History file for application"
|
new ApplicationNotFoundException("History file for application"
|
||||||
+ applicationId + " is not found"));
|
+ applicationId + " is not found"));
|
||||||
try {
|
int exitCode = cli.run(new String[] { "application", "-status",
|
||||||
cli.run(new String[] { "application", "-status", applicationId.toString() });
|
applicationId.toString() });
|
||||||
Assert.fail();
|
verify(sysOut).println(
|
||||||
} catch (Exception ex) {
|
"Application with id '" + applicationId
|
||||||
Assert.assertTrue(ex instanceof ApplicationNotFoundException);
|
+ "' doesn't exist in RM or Timeline Server.");
|
||||||
Assert.assertEquals("History file for application"
|
Assert.assertNotSame("should return non-zero exit code.", 0, exitCode);
|
||||||
+ applicationId + " is not found", ex.getMessage());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1318,6 +1318,80 @@ public class TestYarnCLI {
|
||||||
Assert.assertEquals(queueInfoStr, sysOutStream.toString());
|
Assert.assertEquals(queueInfoStr, sysOutStream.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
|
||||||
private void verifyUsageInfo(YarnCLI cli) throws Exception {
|
private void verifyUsageInfo(YarnCLI cli) throws Exception {
|
||||||
cli.setSysErrPrintStream(sysErr);
|
cli.setSysErrPrintStream(sysErr);
|
||||||
|
|
Loading…
Reference in New Issue