|
@@ -19,12 +19,14 @@
|
|
|
package org.apache.hadoop.yarn.server.resourcemanager.rmcontainer;
|
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
-import static org.mockito.Mockito.any;
|
|
|
-import static org.mockito.Mockito.anyLong;
|
|
|
+import static org.mockito.Matchers.any;
|
|
|
+import static org.mockito.Matchers.anyLong;
|
|
|
+import static org.mockito.Mockito.doReturn;
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
import static org.mockito.Mockito.never;
|
|
|
import static org.mockito.Mockito.reset;
|
|
|
import static org.mockito.Mockito.spy;
|
|
|
+import static org.mockito.Mockito.times;
|
|
|
import static org.mockito.Mockito.verify;
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
@@ -270,4 +272,77 @@ public class TestRMContainerImpl {
|
|
|
Assert.assertNull(scheduler.getRMContainer(containerId2)
|
|
|
.getResourceRequests());
|
|
|
}
|
|
|
+
|
|
|
+ @Test (timeout = 180000)
|
|
|
+ public void testStoreAllContainerMetrics() throws Exception {
|
|
|
+ Configuration conf = new Configuration();
|
|
|
+ conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1);
|
|
|
+ MockRM rm1 = new MockRM(conf);
|
|
|
+
|
|
|
+ SystemMetricsPublisher publisher = mock(SystemMetricsPublisher.class);
|
|
|
+ rm1.getRMContext().setSystemMetricsPublisher(publisher);
|
|
|
+
|
|
|
+ rm1.start();
|
|
|
+ MockNM nm1 = rm1.registerNode("unknownhost:1234", 8000);
|
|
|
+ RMApp app1 = rm1.submitApp(1024);
|
|
|
+ MockAM am1 = MockRM.launchAndRegisterAM(app1, rm1, nm1);
|
|
|
+ nm1.nodeHeartbeat(am1.getApplicationAttemptId(), 1, ContainerState.RUNNING);
|
|
|
+
|
|
|
+ // request a container.
|
|
|
+ am1.allocate("127.0.0.1", 1024, 1, new ArrayList<ContainerId>());
|
|
|
+ ContainerId containerId2 = ContainerId.newContainerId(
|
|
|
+ am1.getApplicationAttemptId(), 2);
|
|
|
+ rm1.waitForState(nm1, containerId2, RMContainerState.ALLOCATED);
|
|
|
+ am1.allocate(new ArrayList<ResourceRequest>(), new ArrayList<ContainerId>())
|
|
|
+ .getAllocatedContainers();
|
|
|
+ rm1.waitForState(nm1, containerId2, RMContainerState.ACQUIRED);
|
|
|
+ nm1.nodeHeartbeat(am1.getApplicationAttemptId(), 2, ContainerState.RUNNING);
|
|
|
+ nm1.nodeHeartbeat(am1.getApplicationAttemptId(), 2, ContainerState.COMPLETE);
|
|
|
+ nm1.nodeHeartbeat(am1.getApplicationAttemptId(), 1, ContainerState.COMPLETE);
|
|
|
+ rm1.waitForState(nm1, containerId2, RMContainerState.COMPLETED);
|
|
|
+ rm1.stop();
|
|
|
+
|
|
|
+ // RMContainer should be publishing system metrics for all containers.
|
|
|
+ // Since there is 1 AM container and 1 non-AM container, there should be 2
|
|
|
+ // container created events and 2 container finished events.
|
|
|
+ verify(publisher, times(2)).containerCreated(any(RMContainer.class), anyLong());
|
|
|
+ verify(publisher, times(2)).containerFinished(any(RMContainer.class), anyLong());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test (timeout = 180000)
|
|
|
+ public void testStoreOnlyAMContainerMetrics() throws Exception {
|
|
|
+ Configuration conf = new Configuration();
|
|
|
+ conf.setInt(YarnConfiguration.RM_AM_MAX_ATTEMPTS, 1);
|
|
|
+ conf.setBoolean(
|
|
|
+ YarnConfiguration.APPLICATION_HISTORY_SAVE_NON_AM_CONTAINER_META_INFO,
|
|
|
+ false);
|
|
|
+ MockRM rm1 = new MockRM(conf);
|
|
|
+
|
|
|
+ SystemMetricsPublisher publisher = mock(SystemMetricsPublisher.class);
|
|
|
+ rm1.getRMContext().setSystemMetricsPublisher(publisher);
|
|
|
+
|
|
|
+ rm1.start();
|
|
|
+ MockNM nm1 = rm1.registerNode("unknownhost:1234", 8000);
|
|
|
+ RMApp app1 = rm1.submitApp(1024);
|
|
|
+ MockAM am1 = MockRM.launchAndRegisterAM(app1, rm1, nm1);
|
|
|
+ nm1.nodeHeartbeat(am1.getApplicationAttemptId(), 1, ContainerState.RUNNING);
|
|
|
+
|
|
|
+ // request a container.
|
|
|
+ am1.allocate("127.0.0.1", 1024, 1, new ArrayList<ContainerId>());
|
|
|
+ ContainerId containerId2 = ContainerId.newContainerId(
|
|
|
+ am1.getApplicationAttemptId(), 2);
|
|
|
+ rm1.waitForState(nm1, containerId2, RMContainerState.ALLOCATED);
|
|
|
+ am1.allocate(new ArrayList<ResourceRequest>(), new ArrayList<ContainerId>())
|
|
|
+ .getAllocatedContainers();
|
|
|
+ rm1.waitForState(nm1, containerId2, RMContainerState.ACQUIRED);
|
|
|
+ nm1.nodeHeartbeat(am1.getApplicationAttemptId(), 2, ContainerState.RUNNING);
|
|
|
+ nm1.nodeHeartbeat(am1.getApplicationAttemptId(), 2, ContainerState.COMPLETE);
|
|
|
+ nm1.nodeHeartbeat(am1.getApplicationAttemptId(), 1, ContainerState.COMPLETE);
|
|
|
+ rm1.waitForState(nm1, containerId2, RMContainerState.COMPLETED);
|
|
|
+ rm1.stop();
|
|
|
+
|
|
|
+ // RMContainer should be publishing system metrics only for AM container.
|
|
|
+ verify(publisher, times(1)).containerCreated(any(RMContainer.class), anyLong());
|
|
|
+ verify(publisher, times(1)).containerFinished(any(RMContainer.class), anyLong());
|
|
|
+ }
|
|
|
}
|