|
@@ -196,7 +196,7 @@ public class TestLogsCLI {
|
|
|
"Unable to get ApplicationState"));
|
|
|
}
|
|
|
|
|
|
- @Test(timeout = 5000l)
|
|
|
+ @Test (timeout = 10000)
|
|
|
public void testHelpMessage() throws Exception {
|
|
|
Configuration conf = new YarnConfiguration();
|
|
|
YarnClient mockYarnClient = createMockYarnClient(
|
|
@@ -207,79 +207,102 @@ public class TestLogsCLI {
|
|
|
|
|
|
int exitCode = dumper.run(new String[]{});
|
|
|
assertTrue(exitCode == -1);
|
|
|
+
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
PrintWriter pw = new PrintWriter(baos);
|
|
|
pw.println("Retrieve logs for YARN applications.");
|
|
|
pw.println("usage: yarn logs -applicationId <application ID> [OPTIONS]");
|
|
|
pw.println();
|
|
|
pw.println("general options are:");
|
|
|
- pw.println(" -am <AM Containers> Prints the AM Container logs for");
|
|
|
- pw.println(" this application. Specify");
|
|
|
- pw.println(" comma-separated value to get logs");
|
|
|
- pw.println(" for related AM Container. For");
|
|
|
- pw.println(" example, If we specify -am 1,2,");
|
|
|
- pw.println(" we will get the logs for the");
|
|
|
- pw.println(" first AM Container as well as the");
|
|
|
- pw.println(" second AM Container. To get logs");
|
|
|
- pw.println(" for all AM Containers, use -am");
|
|
|
- pw.println(" ALL. To get logs for the latest");
|
|
|
- pw.println(" AM Container, use -am -1. By");
|
|
|
- pw.println(" default, it will print all");
|
|
|
- pw.println(" available logs. Work with");
|
|
|
- pw.println(" -log_files to get only specific");
|
|
|
- pw.println(" logs.");
|
|
|
- pw.println(" -appOwner <Application Owner> AppOwner (assumed to be current");
|
|
|
- pw.println(" user if not specified)");
|
|
|
- pw.println(" -containerId <Container ID> ContainerId. By default, it will");
|
|
|
- pw.println(" print all available logs. Work");
|
|
|
- pw.println(" with -log_files to get only");
|
|
|
- pw.println(" specific logs. If specified, the");
|
|
|
- pw.println(" applicationId can be omitted");
|
|
|
- pw.println(" -help Displays help for all commands.");
|
|
|
- pw.println(" -list_nodes Show the list of nodes that");
|
|
|
- pw.println(" successfully aggregated logs.");
|
|
|
- pw.println(" This option can only be used with");
|
|
|
- pw.println(" finished applications.");
|
|
|
- pw.println(" -log_files <Log File Name> Specify comma-separated value to");
|
|
|
- pw.println(" get exact matched log files. Use");
|
|
|
- pw.println(" \"ALL\" or \"*\" to fetch all the log");
|
|
|
- pw.println(" files for the container.");
|
|
|
- pw.println(" -log_files_pattern <Log File Pattern> Specify comma-separated value to");
|
|
|
- pw.println(" get matched log files by using");
|
|
|
- pw.println(" java regex. Use \".*\" to fetch all");
|
|
|
- pw.println(" the log files for the container.");
|
|
|
- pw.println(" -nodeAddress <Node Address> NodeAddress in the format");
|
|
|
- pw.println(" nodename:port");
|
|
|
- pw.println(" -out <Local Directory> Local directory for storing");
|
|
|
- pw.println(" individual container logs. The");
|
|
|
- pw.println(" container logs will be stored");
|
|
|
- pw.println(" based on the node the container");
|
|
|
- pw.println(" ran on.");
|
|
|
- pw.println(" -show_application_log_info Show the containerIds which");
|
|
|
- pw.println(" belong to the specific");
|
|
|
- pw.println(" Application. You can combine this");
|
|
|
- pw.println(" with --nodeAddress to get");
|
|
|
- pw.println(" containerIds for all the");
|
|
|
- pw.println(" containers on the specific");
|
|
|
- pw.println(" NodeManager.");
|
|
|
- pw.println(" -show_container_log_info Show the container log metadata,");
|
|
|
- pw.println(" including log-file names, the");
|
|
|
- pw.println(" size of the log files. You can");
|
|
|
- pw.println(" combine this with --containerId");
|
|
|
- pw.println(" to get log metadata for the");
|
|
|
- pw.println(" specific container, or with");
|
|
|
- pw.println(" --nodeAddress to get log metadata");
|
|
|
- pw.println(" for all the containers on the");
|
|
|
- pw.println(" specific NodeManager.");
|
|
|
- pw.println(" -size <size> Prints the log file's first 'n'");
|
|
|
- pw.println(" bytes or the last 'n' bytes. Use");
|
|
|
- pw.println(" negative values as bytes to read");
|
|
|
- pw.println(" from the end and positive values");
|
|
|
- pw.println(" as bytes to read from the");
|
|
|
- pw.println(" beginning.");
|
|
|
+ pw.println(" -am <AM Containers> Prints the AM Container logs");
|
|
|
+ pw.println(" for this application.");
|
|
|
+ pw.println(" Specify comma-separated");
|
|
|
+ pw.println(" value to get logs for");
|
|
|
+ pw.println(" related AM Container. For");
|
|
|
+ pw.println(" example, If we specify -am");
|
|
|
+ pw.println(" 1,2, we will get the logs");
|
|
|
+ pw.println(" for the first AM Container");
|
|
|
+ pw.println(" as well as the second AM");
|
|
|
+ pw.println(" Container. To get logs for");
|
|
|
+ pw.println(" all AM Containers, use -am");
|
|
|
+ pw.println(" ALL. To get logs for the");
|
|
|
+ pw.println(" latest AM Container, use -am");
|
|
|
+ pw.println(" -1. By default, it will");
|
|
|
+ pw.println(" print all available logs.");
|
|
|
+ pw.println(" Work with -log_files to get");
|
|
|
+ pw.println(" only specific logs.");
|
|
|
+ pw.println(" -appOwner <Application Owner> AppOwner (assumed to be");
|
|
|
+ pw.println(" current user if not");
|
|
|
+ pw.println(" specified)");
|
|
|
+ pw.println(" -client_max_retries <Max Retries> Set max retry number for a");
|
|
|
+ pw.println(" retry client to get the");
|
|
|
+ pw.println(" container logs for the");
|
|
|
+ pw.println(" running applications. Use a");
|
|
|
+ pw.println(" negative value to make retry");
|
|
|
+ pw.println(" forever. The default value");
|
|
|
+ pw.println(" is 30.");
|
|
|
+ pw.println(" -client_retry_interval_ms <Retry Interval> Work with");
|
|
|
+ pw.println(" --client_max_retries to");
|
|
|
+ pw.println(" create a retry client. The");
|
|
|
+ pw.println(" default value is 1000.");
|
|
|
+ pw.println(" -containerId <Container ID> ContainerId. By default, it");
|
|
|
+ pw.println(" will print all available");
|
|
|
+ pw.println(" logs. Work with -log_files");
|
|
|
+ pw.println(" to get only specific logs.");
|
|
|
+ pw.println(" If specified, the");
|
|
|
+ pw.println(" applicationId can be omitted");
|
|
|
+ pw.println(" -help Displays help for all");
|
|
|
+ pw.println(" commands.");
|
|
|
+ pw.println(" -list_nodes Show the list of nodes that");
|
|
|
+ pw.println(" successfully aggregated");
|
|
|
+ pw.println(" logs. This option can only");
|
|
|
+ pw.println(" be used with finished");
|
|
|
+ pw.println(" applications.");
|
|
|
+ pw.println(" -log_files <Log File Name> Specify comma-separated");
|
|
|
+ pw.println(" value to get exact matched");
|
|
|
+ pw.println(" log files. Use \"ALL\" or \"*\"");
|
|
|
+ pw.println(" to fetch all the log files");
|
|
|
+ pw.println(" for the container.");
|
|
|
+ pw.println(" -log_files_pattern <Log File Pattern> Specify comma-separated");
|
|
|
+ pw.println(" value to get matched log");
|
|
|
+ pw.println(" files by using java regex.");
|
|
|
+ pw.println(" Use \".*\" to fetch all the");
|
|
|
+ pw.println(" log files for the container.");
|
|
|
+ pw.println(" -nodeAddress <Node Address> NodeAddress in the format");
|
|
|
+ pw.println(" nodename:port");
|
|
|
+ pw.println(" -out <Local Directory> Local directory for storing");
|
|
|
+ pw.println(" individual container logs.");
|
|
|
+ pw.println(" The container logs will be");
|
|
|
+ pw.println(" stored based on the node the");
|
|
|
+ pw.println(" container ran on.");
|
|
|
+ pw.println(" -show_application_log_info Show the containerIds which");
|
|
|
+ pw.println(" belong to the specific");
|
|
|
+ pw.println(" Application. You can combine");
|
|
|
+ pw.println(" this with --nodeAddress to");
|
|
|
+ pw.println(" get containerIds for all the");
|
|
|
+ pw.println(" containers on the specific");
|
|
|
+ pw.println(" NodeManager.");
|
|
|
+ pw.println(" -show_container_log_info Show the container log");
|
|
|
+ pw.println(" metadata, including log-file");
|
|
|
+ pw.println(" names, the size of the log");
|
|
|
+ pw.println(" files. You can combine this");
|
|
|
+ pw.println(" with --containerId to get");
|
|
|
+ pw.println(" log metadata for the");
|
|
|
+ pw.println(" specific container, or with");
|
|
|
+ pw.println(" --nodeAddress to get log");
|
|
|
+ pw.println(" metadata for all the");
|
|
|
+ pw.println(" containers on the specific");
|
|
|
+ pw.println(" NodeManager.");
|
|
|
+ pw.println(" -size <size> Prints the log file's first");
|
|
|
+ pw.println(" 'n' bytes or the last 'n'");
|
|
|
+ pw.println(" bytes. Use negative values");
|
|
|
+ pw.println(" as bytes to read from the");
|
|
|
+ pw.println(" end and positive values as");
|
|
|
+ pw.println(" bytes to read from the");
|
|
|
+ pw.println(" beginning.");
|
|
|
pw.close();
|
|
|
String appReportStr = baos.toString("UTF-8");
|
|
|
- Assert.assertEquals(appReportStr, sysOutStream.toString());
|
|
|
+ Assert.assertTrue(sysOutStream.toString().contains(appReportStr));
|
|
|
}
|
|
|
|
|
|
@Test (timeout = 15000)
|
|
@@ -609,6 +632,56 @@ public class TestLogsCLI {
|
|
|
fs.delete(new Path(rootLogDir), true);
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testCheckRetryCount() throws Exception {
|
|
|
+ UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
|
|
|
+
|
|
|
+ NodeId nodeId = NodeId.newInstance("localhost", 1234);
|
|
|
+ ApplicationId appId = ApplicationId.newInstance(0, 1);
|
|
|
+ ApplicationAttemptId appAttemptId = ApplicationAttemptId
|
|
|
+ .newInstance(appId, 1);
|
|
|
+
|
|
|
+ // Create a mock ApplicationAttempt Report
|
|
|
+ ApplicationAttemptReport mockAttemptReport = mock(
|
|
|
+ ApplicationAttemptReport.class);
|
|
|
+ doReturn(appAttemptId).when(mockAttemptReport).getApplicationAttemptId();
|
|
|
+ List<ApplicationAttemptReport> attemptReports = Arrays.asList(
|
|
|
+ mockAttemptReport);
|
|
|
+
|
|
|
+ // Create one mock containerReport
|
|
|
+ ContainerId containerId1 = ContainerId.newContainerId(appAttemptId, 1);
|
|
|
+ ContainerReport mockContainerReport1 = mock(ContainerReport.class);
|
|
|
+ doReturn(containerId1).when(mockContainerReport1).getContainerId();
|
|
|
+ doReturn(nodeId).when(mockContainerReport1).getAssignedNode();
|
|
|
+ doReturn("http://localhost:2345").when(mockContainerReport1)
|
|
|
+ .getNodeHttpAddress();
|
|
|
+ doReturn(ContainerState.RUNNING).when(mockContainerReport1)
|
|
|
+ .getContainerState();
|
|
|
+ List<ContainerReport> containerReports = Arrays.asList(
|
|
|
+ mockContainerReport1);
|
|
|
+ // Mock the YarnClient, and it would report the previous created
|
|
|
+ // mockAttemptReport and previous two created mockContainerReports
|
|
|
+ YarnClient mockYarnClient = createMockYarnClient(
|
|
|
+ YarnApplicationState.RUNNING, ugi.getShortUserName(), true,
|
|
|
+ attemptReports, containerReports);
|
|
|
+ doReturn(mockContainerReport1).when(mockYarnClient).getContainerReport(
|
|
|
+ any(ContainerId.class));
|
|
|
+ LogsCLI cli = new LogsCLIForTest(mockYarnClient);
|
|
|
+ cli.setConf(new YarnConfiguration());
|
|
|
+ try {
|
|
|
+ cli.run(new String[] {"-containerId",
|
|
|
+ containerId1.toString(), "-client_max_retries", "5"});
|
|
|
+ Assert.fail("Exception expected! "
|
|
|
+ + "NodeManager should be off to run this test. ");
|
|
|
+ } catch (RuntimeException ce) {
|
|
|
+ Assert.assertTrue(
|
|
|
+ "Handler exception for reason other than retry: " + ce.getMessage(),
|
|
|
+ ce.getMessage().contains("Connection retries limit exceeded"));
|
|
|
+ Assert.assertTrue("Retry filter didn't perform any retries! ", cli
|
|
|
+ .connectionRetry.getRetired());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Test (timeout = 5000)
|
|
|
public void testGetRunningContainerLogs() throws Exception {
|
|
|
UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
|