YARN-5083. YARN CLI for AM logs does not give any error message if entered invalid am value. Contributed by Jian He.

This commit is contained in:
Junping Du 2016-06-16 08:55:56 -07:00
parent cc6c265171
commit e14ee0d3b5
2 changed files with 29 additions and 1 deletions

View File

@ -274,7 +274,7 @@ private void printHelpMessage(Options options) {
formatter.printHelp("general options are:", options);
}
private List<JSONObject> getAMContainerInfoForRMWebService(
protected List<JSONObject> getAMContainerInfoForRMWebService(
Configuration conf, String appId) throws ClientHandlerException,
UniformInterfaceException, JSONException {
Client webServiceClient = Client.create();
@ -538,6 +538,11 @@ private int printAMContainerLogs(Configuration conf,
if (amContainerId <= requests.size()) {
outputAMContainerLogs(requests.get(amContainerId - 1), conf,
logCliHelper);
} else {
System.err.println(String.format("ERROR: Specified AM containerId"
+ " (%s) exceeds the number of AM containers (%s).",
amContainerId, requests.size()));
return -1;
}
}
}

View File

@ -71,6 +71,7 @@
import org.apache.hadoop.yarn.logaggregation.ContainerLogsRequest;
import org.apache.hadoop.yarn.logaggregation.LogAggregationUtils;
import org.apache.hadoop.yarn.logaggregation.LogCLIHelpers;
import org.codehaus.jettison.json.JSONObject;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@ -131,6 +132,28 @@ public void testInvalidApplicationId() throws Exception {
assertTrue(sysErrStream.toString().startsWith("Invalid ApplicationId specified"));
}
@Test(timeout = 5000L)
public void testInvalidAMContainerId() throws Exception {
Configuration conf = new YarnConfiguration();
conf.setBoolean(YarnConfiguration.APPLICATION_HISTORY_ENABLED, true);
YarnClient mockYarnClient =
createMockYarnClient(YarnApplicationState.FINISHED,
UserGroupInformation.getCurrentUser().getShortUserName());
LogsCLI cli = spy(new LogsCLIForTest(mockYarnClient));
List<JSONObject> list = Arrays.asList(new JSONObject());
doReturn(list).when(cli)
.getAMContainerInfoForRMWebService(any(Configuration.class),
any(String.class));
cli.setConf(conf);
int exitCode = cli.run(
new String[] {"-applicationId", "application_1465862913885_0027",
"-am", "1000" });
assertTrue(exitCode == -1);
assertTrue(sysErrStream.toString()
.contains("exceeds the number of AM containers"));
}
@Test(timeout = 5000l)
public void testUnknownApplicationId() throws Exception {
Configuration conf = new YarnConfiguration();