Search in sources :

Example 26 with MockNodeManager

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

the class TestContainerBalancer method setup.

/**
 * Sets up configuration values and creates a mock cluster.
 */
@Before
public void setup() throws SCMException, NodeNotFoundException {
    conf = new OzoneConfiguration();
    scm = Mockito.mock(StorageContainerManager.class);
    containerManager = Mockito.mock(ContainerManager.class);
    replicationManager = Mockito.mock(ReplicationManager.class);
    balancerConfiguration = conf.getObject(ContainerBalancerConfiguration.class);
    balancerConfiguration.setThreshold(10);
    balancerConfiguration.setIterations(1);
    balancerConfiguration.setMaxDatanodesPercentageToInvolvePerIteration(100);
    balancerConfiguration.setMaxSizeToMovePerIteration(50 * OzoneConsts.GB);
    balancerConfiguration.setMaxSizeEnteringTarget(50 * OzoneConsts.GB);
    conf.setFromObject(balancerConfiguration);
    GenericTestUtils.setLogLevel(ContainerBalancer.LOG, Level.DEBUG);
    averageUtilization = createCluster();
    mockNodeManager = new MockNodeManager(datanodeToContainersMap);
    placementPolicy = ContainerPlacementPolicyFactory.getPolicy(conf, mockNodeManager, mockNodeManager.getClusterNetworkTopologyMap(), true, SCMContainerPlacementMetrics.create());
    Mockito.when(replicationManager.isContainerReplicatingOrDeleting(Mockito.any(ContainerID.class))).thenReturn(false);
    Mockito.when(replicationManager.move(Mockito.any(ContainerID.class), Mockito.any(DatanodeDetails.class), Mockito.any(DatanodeDetails.class))).thenReturn(CompletableFuture.completedFuture(ReplicationManager.MoveResult.COMPLETED));
    when(containerManager.getContainerReplicas(Mockito.any(ContainerID.class))).thenAnswer(invocationOnMock -> {
        ContainerID cid = (ContainerID) invocationOnMock.getArguments()[0];
        return cidToReplicasMap.get(cid);
    });
    when(containerManager.getContainer(Mockito.any(ContainerID.class))).thenAnswer(invocationOnMock -> {
        ContainerID cid = (ContainerID) invocationOnMock.getArguments()[0];
        return cidToInfoMap.get(cid);
    });
    when(containerManager.getContainers()).thenReturn(new ArrayList<>(cidToInfoMap.values()));
    when(scm.getScmNodeManager()).thenReturn(mockNodeManager);
    when(scm.getContainerPlacementPolicy()).thenReturn(placementPolicy);
    when(scm.getContainerManager()).thenReturn(containerManager);
    when(scm.getReplicationManager()).thenReturn(replicationManager);
    when(scm.getScmContext()).thenReturn(SCMContext.emptyContext());
    when(scm.getClusterMap()).thenReturn(null);
    when(scm.getEventQueue()).thenReturn(mock(EventPublisher.class));
    when(scm.getConfiguration()).thenReturn(conf);
    containerBalancer = new ContainerBalancer(scm);
}
Also used : StorageContainerManager(org.apache.hadoop.hdds.scm.server.StorageContainerManager) ContainerManager(org.apache.hadoop.hdds.scm.container.ContainerManager) StorageContainerManager(org.apache.hadoop.hdds.scm.server.StorageContainerManager) ReplicationManager(org.apache.hadoop.hdds.scm.container.ReplicationManager) EventPublisher(org.apache.hadoop.hdds.server.events.EventPublisher) ContainerID(org.apache.hadoop.hdds.scm.container.ContainerID) MockDatanodeDetails(org.apache.hadoop.hdds.protocol.MockDatanodeDetails) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) MockNodeManager(org.apache.hadoop.hdds.scm.container.MockNodeManager) Before(org.junit.Before)

Aggregations

MockNodeManager (org.apache.hadoop.hdds.scm.container.MockNodeManager)26 Test (org.junit.Test)14 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)13 ArrayList (java.util.ArrayList)9 MockRatisPipelineProvider (org.apache.hadoop.hdds.scm.pipeline.MockRatisPipelineProvider)8 PipelineProvider (org.apache.hadoop.hdds.scm.pipeline.PipelineProvider)8 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)7 Before (org.junit.Before)7 MockDatanodeDetails (org.apache.hadoop.hdds.protocol.MockDatanodeDetails)6 SCMServiceManager (org.apache.hadoop.hdds.scm.ha.SCMServiceManager)6 SCMDBDefinition (org.apache.hadoop.hdds.scm.metadata.SCMDBDefinition)6 PipelineManagerImpl (org.apache.hadoop.hdds.scm.pipeline.PipelineManagerImpl)6 ContainerInfo (org.apache.hadoop.hdds.scm.container.ContainerInfo)5 TestContainerManagerImpl (org.apache.hadoop.hdds.scm.container.TestContainerManagerImpl)5 SCMMetadataStoreImpl (org.apache.hadoop.hdds.scm.metadata.SCMMetadataStoreImpl)5 Pipeline (org.apache.hadoop.hdds.scm.pipeline.Pipeline)5 EventQueue (org.apache.hadoop.hdds.server.events.EventQueue)5 File (java.io.File)4 SCMException (org.apache.hadoop.hdds.scm.exceptions.SCMException)4 MockSCMHAManager (org.apache.hadoop.hdds.scm.ha.MockSCMHAManager)4