@Override public RMAppMetrics getRMAppMetrics() { return new RMAppMetrics(Resource.newInstance(0, 0), 0, 0, 0, 0); }
@Override public RMAppMetrics getRMAppMetrics() { return new RMAppMetrics(Resource.newInstance(0, 0), 0, 0, new HashMap<>(), new HashMap<>()); }
@Override public RMAppMetrics getRMAppMetrics() { return new RMAppMetrics(Resource.newInstance(0, 0), 0, 0, new HashMap<>(), new HashMap<>()); } @Override
@Override public RMAppMetrics getRMAppMetrics() { return new RMAppMetrics(Resource.newInstance(0, 0), 0, 0, 0, 0); } @Override
return new RMAppMetrics(resourcePreempted, numNonAMContainerPreempted, numAMContainerPreempted, resourceSecondsMap, preemptedSecondsMap);
private static RMApp createRMApp(ApplicationId appId) { RMApp app = mock(RMApp.class); when(app.getApplicationId()).thenReturn(appId); when(app.getName()).thenReturn("test app"); when(app.getApplicationType()).thenReturn("test app type"); when(app.getUser()).thenReturn("test user"); when(app.getQueue()).thenReturn("test queue"); when(app.getSubmitTime()).thenReturn(Integer.MAX_VALUE + 1L); when(app.getStartTime()).thenReturn(Integer.MAX_VALUE + 2L); when(app.getFinishTime()).thenReturn(Integer.MAX_VALUE + 3L); when(app.getDiagnostics()).thenReturn( new StringBuilder("test diagnostics info")); RMAppAttempt appAttempt = mock(RMAppAttempt.class); when(appAttempt.getAppAttemptId()).thenReturn( ApplicationAttemptId.newInstance(appId, 1)); when(app.getCurrentAppAttempt()).thenReturn(appAttempt); when(app.getFinalApplicationStatus()).thenReturn( FinalApplicationStatus.UNDEFINED); when(app.getRMAppMetrics()).thenReturn( new RMAppMetrics(null, 0, 0, Integer.MAX_VALUE, Long.MAX_VALUE)); return app; }
.put(ResourceInformation.VCORES.getName(), Long.MAX_VALUE); when(app.getRMAppMetrics()).thenReturn( new RMAppMetrics(Resource.newInstance(0, 0), 0, 0, resourceSecondsMap, new HashMap<>())); when(app.getApplicationTags()).thenReturn(Collections.<String>emptySet());
preemptedMap.put(ResourceInformation.VCORES.getName(), Long.MAX_VALUE); when(rmApp.getRMAppMetrics()).thenReturn( new RMAppMetrics(Resource.newInstance(0, 0), 0, 0, resourceMap, preemptedMap)); when(rmApp.getApplicationTags()).thenReturn(
new RMAppMetrics(Resource.newInstance(0, 0), 0, 0, new HashMap<>(), new HashMap<>()); when(app.getRMAppMetrics()).thenReturn(appMetrics);
preemptedMap.put(ResourceInformation.VCORES.getName(), Long.MAX_VALUE); when(app.getRMAppMetrics()) .thenReturn(new RMAppMetrics(null, 0, 0, resourceMap, preemptedMap)); Set<String> appTags = new HashSet<String>(); appTags.add("test");
@Test (timeout = 30000) public void testEscapeApplicationSummary() { RMApp app = mock(RMAppImpl.class); when(app.getApplicationId()).thenReturn( ApplicationId.newInstance(100L, 1)); when(app.getName()).thenReturn("Multiline\n\n\r\rAppName"); when(app.getUser()).thenReturn("Multiline\n\n\r\rUserName"); when(app.getQueue()).thenReturn("Multiline\n\n\r\rQueueName"); when(app.getState()).thenReturn(RMAppState.RUNNING); when(app.getApplicationType()).thenReturn("MAPREDUCE"); RMAppMetrics metrics = new RMAppMetrics(Resource.newInstance(1234, 56), 10, 1, 16384, 64); when(app.getRMAppMetrics()).thenReturn(metrics); RMAppManager.ApplicationSummary.SummaryBuilder summary = new RMAppManager.ApplicationSummary().createAppSummary(app); String msg = summary.toString(); LOG.info("summary: " + msg); Assert.assertFalse(msg.contains("\n")); Assert.assertFalse(msg.contains("\r")); String escaped = "\\n\\n\\r\\r"; Assert.assertTrue(msg.contains("Multiline" + escaped +"AppName")); Assert.assertTrue(msg.contains("Multiline" + escaped +"UserName")); Assert.assertTrue(msg.contains("Multiline" + escaped +"QueueName")); Assert.assertTrue(msg.contains("memorySeconds=16384")); Assert.assertTrue(msg.contains("vcoreSeconds=64")); Assert.assertTrue(msg.contains("preemptedAMContainers=1")); Assert.assertTrue(msg.contains("preemptedNonAMContainers=10")); Assert.assertTrue(msg.contains("preemptedResources=<memory:1234\\, vCores:56>")); Assert.assertTrue(msg.contains("applicationType=MAPREDUCE")); }
when(app.createApplicationState()).thenReturn(YarnApplicationState.FAILED); RMAppMetrics appMetrics = new RMAppMetrics(Resource.newInstance(0, 0), 0, 0, 0, 0); when(app.getRMAppMetrics()).thenReturn(appMetrics);
resourceSecondsMap.put(ResourceInformation.VCORES.getName(), 64L); RMAppMetrics metrics = new RMAppMetrics(Resource.newInstance(1234, 56), 10, 1, resourceSecondsMap, new HashMap<>()); when(app.getRMAppMetrics()).thenReturn(metrics);
@Override public RMAppMetrics getRMAppMetrics() { Resource resourcePreempted = Resource.newInstance(0, 0); int numAMContainerPreempted = 0; int numNonAMContainerPreempted = 0; long memorySeconds = 0; long vcoreSeconds = 0; for (RMAppAttempt attempt : attempts.values()) { if (null != attempt) { RMAppAttemptMetrics attemptMetrics = attempt.getRMAppAttemptMetrics(); Resources.addTo(resourcePreempted, attemptMetrics.getResourcePreempted()); numAMContainerPreempted += attemptMetrics.getIsPreempted() ? 1 : 0; numNonAMContainerPreempted += attemptMetrics.getNumNonAMContainersPreempted(); // getAggregateAppResourceUsage() will calculate resource usage stats // for both running and finished containers. AggregateAppResourceUsage resUsage = attempt.getRMAppAttemptMetrics().getAggregateAppResourceUsage(); memorySeconds += resUsage.getMemorySeconds(); vcoreSeconds += resUsage.getVcoreSeconds(); } } return new RMAppMetrics(resourcePreempted, numNonAMContainerPreempted, numAMContainerPreempted, memorySeconds, vcoreSeconds); }
@Override public RMAppMetrics getRMAppMetrics() { Resource resourcePreempted = Resource.newInstance(0, 0); int numAMContainerPreempted = 0; int numNonAMContainerPreempted = 0; long memorySeconds = 0; long vcoreSeconds = 0; for (RMAppAttempt attempt : attempts.values()) { if (null != attempt) { RMAppAttemptMetrics attemptMetrics = attempt.getRMAppAttemptMetrics(); Resources.addTo(resourcePreempted, attemptMetrics.getResourcePreempted()); numAMContainerPreempted += attemptMetrics.getIsPreempted() ? 1 : 0; numNonAMContainerPreempted += attemptMetrics.getNumNonAMContainersPreempted(); // getAggregateAppResourceUsage() will calculate resource usage stats // for both running and finished containers. AggregateAppResourceUsage resUsage = attempt.getRMAppAttemptMetrics().getAggregateAppResourceUsage(); memorySeconds += resUsage.getMemorySeconds(); vcoreSeconds += resUsage.getVcoreSeconds(); } } return new RMAppMetrics(resourcePreempted, numNonAMContainerPreempted, numAMContainerPreempted, memorySeconds, vcoreSeconds); }