Search in sources :

Example 21 with ContainerManager

use of org.apache.hadoop.hdds.scm.container.ContainerManager in project ozone by apache.

the class TestSCMMXBean method testSCMContainerStateCount.

@Test
public void testSCMContainerStateCount() throws Exception {
    ObjectName bean = new ObjectName("Hadoop:service=StorageContainerManager," + "name=StorageContainerManagerInfo," + "component=ServerRuntime");
    TabularData data = (TabularData) mbs.getAttribute(bean, "ContainerStateCount");
    Map<String, Integer> containerStateCount = scm.getContainerStateCount();
    verifyEquals(data, containerStateCount);
    // Do some changes like allocate containers and change the container states
    ContainerManager scmContainerManager = scm.getContainerManager();
    List<ContainerInfo> containerInfoList = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        containerInfoList.add(scmContainerManager.allocateContainer(StandaloneReplicationConfig.getInstance(ReplicationFactor.ONE), UUID.randomUUID().toString()));
    }
    long containerID;
    for (int i = 0; i < 10; i++) {
        if (i % 2 == 0) {
            containerID = containerInfoList.get(i).getContainerID();
            scmContainerManager.updateContainerState(ContainerID.valueOf(containerID), HddsProtos.LifeCycleEvent.FINALIZE);
            assertEquals(scmContainerManager.getContainer(ContainerID.valueOf(containerID)).getState(), HddsProtos.LifeCycleState.CLOSING);
        } else {
            containerID = containerInfoList.get(i).getContainerID();
            scmContainerManager.updateContainerState(ContainerID.valueOf(containerID), HddsProtos.LifeCycleEvent.FINALIZE);
            scmContainerManager.updateContainerState(ContainerID.valueOf(containerID), HddsProtos.LifeCycleEvent.CLOSE);
            assertEquals(scmContainerManager.getContainer(ContainerID.valueOf(containerID)).getState(), HddsProtos.LifeCycleState.CLOSED);
        }
    }
    data = (TabularData) mbs.getAttribute(bean, "ContainerStateCount");
    containerStateCount = scm.getContainerStateCount();
    containerStateCount.forEach((k, v) -> {
        if (k.equals(HddsProtos.LifeCycleState.CLOSING.toString())) {
            assertEquals((int) v, 5);
        } else if (k.equals(HddsProtos.LifeCycleState.CLOSED.toString())) {
            assertEquals((int) v, 5);
        } else {
            // Remaining all container state count should be zero.
            assertEquals((int) v, 0);
        }
    });
    verifyEquals(data, containerStateCount);
}
Also used : ContainerManager(org.apache.hadoop.hdds.scm.container.ContainerManager) StorageContainerManager(org.apache.hadoop.hdds.scm.server.StorageContainerManager) ContainerInfo(org.apache.hadoop.hdds.scm.container.ContainerInfo) ArrayList(java.util.ArrayList) ObjectName(javax.management.ObjectName) TabularData(javax.management.openmbean.TabularData) Test(org.junit.Test)

Aggregations

ContainerManager (org.apache.hadoop.hdds.scm.container.ContainerManager)21 StorageContainerManager (org.apache.hadoop.hdds.scm.server.StorageContainerManager)14 Test (org.junit.Test)13 ContainerInfo (org.apache.hadoop.hdds.scm.container.ContainerInfo)12 ContainerID (org.apache.hadoop.hdds.scm.container.ContainerID)7 Pipeline (org.apache.hadoop.hdds.scm.pipeline.Pipeline)6 PipelineManager (org.apache.hadoop.hdds.scm.pipeline.PipelineManager)6 ReconStorageContainerManagerFacade (org.apache.hadoop.ozone.recon.scm.ReconStorageContainerManagerFacade)6 GenericTestUtils (org.apache.ozone.test.GenericTestUtils)6 IOException (java.io.IOException)5 ContainerReplica (org.apache.hadoop.hdds.scm.container.ContainerReplica)5 Before (org.junit.Before)5 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)4 File (java.io.File)3 OzoneStorageContainerManager (org.apache.hadoop.hdds.scm.server.OzoneStorageContainerManager)3 ReconNodeManager (org.apache.hadoop.ozone.recon.scm.ReconNodeManager)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Optional (java.util.Optional)2 RatisReplicationConfig (org.apache.hadoop.hdds.client.RatisReplicationConfig)2