Search in sources :

Example 21 with NodeManager

use of org.apache.hadoop.hdds.scm.node.NodeManager in project ozone by apache.

the class TestReconPipelineManager method testInitialize.

@Test
public void testInitialize() throws IOException {
    // Get 3 OPEN pipelines from SCM.
    List<Pipeline> pipelinesFromScm = getPipelines(3);
    // Recon has 2 pipelines in ALLOCATED state. (1 is valid and 1 is obsolete)
    // Valid pipeline in Allocated state.
    Pipeline validPipeline = Pipeline.newBuilder().setReplicationConfig(StandaloneReplicationConfig.getInstance(ReplicationFactor.ONE)).setId(pipelinesFromScm.get(0).getId()).setNodes(pipelinesFromScm.get(0).getNodes()).setState(Pipeline.PipelineState.ALLOCATED).build();
    // Invalid pipeline.
    Pipeline invalidPipeline = Pipeline.newBuilder().setReplicationConfig(StandaloneReplicationConfig.getInstance(ReplicationFactor.ONE)).setId(PipelineID.randomId()).setNodes(Collections.singletonList(randomDatanodeDetails())).setState(Pipeline.PipelineState.CLOSED).build();
    NetworkTopology clusterMap = new NetworkTopologyImpl(conf);
    EventQueue eventQueue = new EventQueue();
    this.versionManager = Mockito.mock(HDDSLayoutVersionManager.class);
    Mockito.when(versionManager.getMetadataLayoutVersion()).thenReturn(maxLayoutVersion());
    Mockito.when(versionManager.getSoftwareLayoutVersion()).thenReturn(maxLayoutVersion());
    NodeManager nodeManager = new SCMNodeManager(conf, scmStorageConfig, eventQueue, clusterMap, SCMContext.emptyContext(), versionManager);
    try (ReconPipelineManager reconPipelineManager = ReconPipelineManager.newReconPipelineManager(conf, nodeManager, ReconSCMDBDefinition.PIPELINES.getTable(store), eventQueue, scmhaManager, scmContext)) {
        scmContext = new SCMContext.Builder().setIsInSafeMode(true).setLeader(true).setIsPreCheckComplete(true).setSCM(mock(StorageContainerManager.class)).build();
        reconPipelineManager.setScmContext(scmContext);
        reconPipelineManager.addPipeline(validPipeline);
        reconPipelineManager.addPipeline(invalidPipeline);
        reconPipelineManager.initializePipelines(pipelinesFromScm);
        List<Pipeline> newReconPipelines = reconPipelineManager.getPipelines();
        // Test if the number of pipelines in SCM is as expected.
        assertEquals(3, newReconPipelines.size());
        // Test if new pipelines from SCM are picked up.
        for (Pipeline pipeline : pipelinesFromScm) {
            assertTrue(reconPipelineManager.containsPipeline(pipeline.getId()));
        }
        // Test if existing pipeline state is updated.
        assertEquals(Pipeline.PipelineState.OPEN, reconPipelineManager.getPipeline(validPipeline.getId()).getPipelineState());
        // Test if obsolete pipelines in Recon are removed.
        assertFalse(reconPipelineManager.containsPipeline(invalidPipeline.getId()));
    }
}
Also used : NetworkTopologyImpl(org.apache.hadoop.hdds.scm.net.NetworkTopologyImpl) NodeManager(org.apache.hadoop.hdds.scm.node.NodeManager) SCMNodeManager(org.apache.hadoop.hdds.scm.node.SCMNodeManager) SCMNodeManager(org.apache.hadoop.hdds.scm.node.SCMNodeManager) StorageContainerManager(org.apache.hadoop.hdds.scm.server.StorageContainerManager) NetworkTopology(org.apache.hadoop.hdds.scm.net.NetworkTopology) DBStoreBuilder(org.apache.hadoop.hdds.utils.db.DBStoreBuilder) HDDSLayoutVersionManager(org.apache.hadoop.hdds.upgrade.HDDSLayoutVersionManager) EventQueue(org.apache.hadoop.hdds.server.events.EventQueue) OMMetadataManagerTestUtils.getRandomPipeline(org.apache.hadoop.ozone.recon.OMMetadataManagerTestUtils.getRandomPipeline) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) Test(org.junit.Test)

Example 22 with NodeManager

use of org.apache.hadoop.hdds.scm.node.NodeManager in project ozone by apache.

the class TestReconPipelineManager method testAddPipeline.

@Test
public void testAddPipeline() throws IOException {
    Pipeline pipeline = getRandomPipeline();
    NetworkTopology clusterMap = new NetworkTopologyImpl(conf);
    EventQueue eventQueue = new EventQueue();
    this.versionManager = Mockito.mock(HDDSLayoutVersionManager.class);
    Mockito.when(versionManager.getMetadataLayoutVersion()).thenReturn(maxLayoutVersion());
    Mockito.when(versionManager.getSoftwareLayoutVersion()).thenReturn(maxLayoutVersion());
    NodeManager nodeManager = new SCMNodeManager(conf, scmStorageConfig, eventQueue, clusterMap, SCMContext.emptyContext(), versionManager);
    ReconPipelineManager reconPipelineManager = ReconPipelineManager.newReconPipelineManager(conf, nodeManager, ReconSCMDBDefinition.PIPELINES.getTable(store), eventQueue, scmhaManager, scmContext);
    assertFalse(reconPipelineManager.containsPipeline(pipeline.getId()));
    reconPipelineManager.addPipeline(pipeline);
    assertTrue(reconPipelineManager.containsPipeline(pipeline.getId()));
}
Also used : NetworkTopologyImpl(org.apache.hadoop.hdds.scm.net.NetworkTopologyImpl) NodeManager(org.apache.hadoop.hdds.scm.node.NodeManager) SCMNodeManager(org.apache.hadoop.hdds.scm.node.SCMNodeManager) SCMNodeManager(org.apache.hadoop.hdds.scm.node.SCMNodeManager) NetworkTopology(org.apache.hadoop.hdds.scm.net.NetworkTopology) HDDSLayoutVersionManager(org.apache.hadoop.hdds.upgrade.HDDSLayoutVersionManager) EventQueue(org.apache.hadoop.hdds.server.events.EventQueue) OMMetadataManagerTestUtils.getRandomPipeline(org.apache.hadoop.ozone.recon.OMMetadataManagerTestUtils.getRandomPipeline) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) Test(org.junit.Test)

Example 23 with NodeManager

use of org.apache.hadoop.hdds.scm.node.NodeManager in project ozone by apache.

the class TestReconPipelineManager method testStubbedReconPipelineFactory.

@Test
public void testStubbedReconPipelineFactory() throws IOException {
    NodeManager nodeManagerMock = mock(NodeManager.class);
    ReconPipelineManager reconPipelineManager = ReconPipelineManager.newReconPipelineManager(conf, nodeManagerMock, ReconSCMDBDefinition.PIPELINES.getTable(store), new EventQueue(), scmhaManager, scmContext);
    PipelineFactory pipelineFactory = reconPipelineManager.getPipelineFactory();
    assertTrue(pipelineFactory instanceof ReconPipelineFactory);
    ReconPipelineFactory reconPipelineFactory = (ReconPipelineFactory) pipelineFactory;
    assertTrue(reconPipelineFactory.getProviders().isEmpty());
    for (ReplicationType type : reconPipelineFactory.getProviders().keySet()) {
        PipelineProvider pipelineProvider = reconPipelineFactory.getProviders().get(type);
        assertTrue(pipelineProvider instanceof ReconPipelineProvider);
    }
}
Also used : NodeManager(org.apache.hadoop.hdds.scm.node.NodeManager) SCMNodeManager(org.apache.hadoop.hdds.scm.node.SCMNodeManager) ReplicationType(org.apache.hadoop.hdds.protocol.proto.HddsProtos.ReplicationType) PipelineFactory(org.apache.hadoop.hdds.scm.pipeline.PipelineFactory) ReconPipelineProvider(org.apache.hadoop.ozone.recon.scm.ReconPipelineFactory.ReconPipelineProvider) ReconPipelineProvider(org.apache.hadoop.ozone.recon.scm.ReconPipelineFactory.ReconPipelineProvider) PipelineProvider(org.apache.hadoop.hdds.scm.pipeline.PipelineProvider) EventQueue(org.apache.hadoop.hdds.server.events.EventQueue) Test(org.junit.Test)

Example 24 with NodeManager

use of org.apache.hadoop.hdds.scm.node.NodeManager in project ozone by apache.

the class ContainerPlacementPolicyFactory method getPolicyInternal.

private static PlacementPolicy getPolicyInternal(Class<? extends PlacementPolicy> placementClass, ConfigurationSource conf, final NodeManager nodeManager, NetworkTopology clusterMap, final boolean fallback, SCMContainerPlacementMetrics metrics) throws SCMException {
    Constructor<? extends PlacementPolicy> constructor;
    try {
        constructor = placementClass.getDeclaredConstructor(NodeManager.class, ConfigurationSource.class, NetworkTopology.class, boolean.class, SCMContainerPlacementMetrics.class);
        LOG.info("Create container placement policy of type {}", placementClass.getCanonicalName());
    } catch (NoSuchMethodException e) {
        String msg = "Failed to find constructor(NodeManager, Configuration, " + "NetworkTopology, boolean) for class " + placementClass.getCanonicalName();
        LOG.error(msg);
        throw new SCMException(msg, SCMException.ResultCodes.FAILED_TO_INIT_CONTAINER_PLACEMENT_POLICY);
    }
    try {
        return constructor.newInstance(nodeManager, conf, clusterMap, fallback, metrics);
    } catch (Exception e) {
        throw new RuntimeException("Failed to instantiate class " + placementClass.getCanonicalName() + " for " + e.getMessage());
    }
}
Also used : NodeManager(org.apache.hadoop.hdds.scm.node.NodeManager) ConfigurationSource(org.apache.hadoop.hdds.conf.ConfigurationSource) NetworkTopology(org.apache.hadoop.hdds.scm.net.NetworkTopology) SCMException(org.apache.hadoop.hdds.scm.exceptions.SCMException) SCMException(org.apache.hadoop.hdds.scm.exceptions.SCMException)

Example 25 with NodeManager

use of org.apache.hadoop.hdds.scm.node.NodeManager in project ozone by apache.

the class TestSCMDatanodeHeartbeatDispatcher method testNodeReportDispatcher.

@Test
public void testNodeReportDispatcher() throws IOException {
    AtomicInteger eventReceived = new AtomicInteger();
    NodeReportProto nodeReport = NodeReportProto.getDefaultInstance();
    NodeManager mockNodeManager = Mockito.mock(NodeManager.class);
    Mockito.when(mockNodeManager.isNodeRegistered(Mockito.any())).thenReturn(true);
    SCMDatanodeHeartbeatDispatcher dispatcher = new SCMDatanodeHeartbeatDispatcher(mockNodeManager, new EventPublisher() {

        @Override
        public <PAYLOAD, EVENT extends Event<PAYLOAD>> void fireEvent(EVENT event, PAYLOAD payload) {
            Assertions.assertEquals(event, NODE_REPORT);
            eventReceived.incrementAndGet();
            Assertions.assertEquals(nodeReport, ((NodeReportFromDatanode) payload).getReport());
        }
    });
    DatanodeDetails datanodeDetails = randomDatanodeDetails();
    SCMHeartbeatRequestProto heartbeat = SCMHeartbeatRequestProto.newBuilder().setDatanodeDetails(datanodeDetails.getProtoBufMessage()).setNodeReport(nodeReport).build();
    dispatcher.dispatch(heartbeat);
    Assertions.assertEquals(1, eventReceived.get());
}
Also used : SCMHeartbeatRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMHeartbeatRequestProto) NodeManager(org.apache.hadoop.hdds.scm.node.NodeManager) EventPublisher(org.apache.hadoop.hdds.server.events.EventPublisher) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MockDatanodeDetails.randomDatanodeDetails(org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanodeDetails) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) NodeReportFromDatanode(org.apache.hadoop.hdds.scm.server.SCMDatanodeHeartbeatDispatcher.NodeReportFromDatanode) NodeReportProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.NodeReportProto) Test(org.junit.jupiter.api.Test)

Aggregations

NodeManager (org.apache.hadoop.hdds.scm.node.NodeManager)33 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)18 Test (org.junit.Test)13 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)12 Test (org.junit.jupiter.api.Test)9 ArrayList (java.util.ArrayList)8 NetworkTopologyImpl (org.apache.hadoop.hdds.scm.net.NetworkTopologyImpl)8 MockDatanodeDetails (org.apache.hadoop.hdds.protocol.MockDatanodeDetails)7 MockDatanodeDetails.randomDatanodeDetails (org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanodeDetails)7 MetadataStorageReportProto (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.MetadataStorageReportProto)7 StorageReportProto (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.StorageReportProto)7 DatanodeInfo (org.apache.hadoop.hdds.scm.node.DatanodeInfo)7 SCMException (org.apache.hadoop.hdds.scm.exceptions.SCMException)6 NetworkTopology (org.apache.hadoop.hdds.scm.net.NetworkTopology)6 EventPublisher (org.apache.hadoop.hdds.server.events.EventPublisher)6 ContainerID (org.apache.hadoop.hdds.scm.container.ContainerID)5 SCMNodeManager (org.apache.hadoop.hdds.scm.node.SCMNodeManager)5 Pipeline (org.apache.hadoop.hdds.scm.pipeline.Pipeline)5 EventQueue (org.apache.hadoop.hdds.server.events.EventQueue)5 IOException (java.io.IOException)4