Search in sources :

Example 1 with CommandStatusReportsProto

use of org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.CommandStatusReportsProto in project ozone by apache.

the class ScmTestMock method sendHeartbeat.

/**
 * Used by data node to send a Heartbeat.
 *
 * @param heartbeat - node heartbeat.
 * @return - SCMHeartbeatResponseProto
 * @throws IOException
 */
@Override
public StorageContainerDatanodeProtocolProtos.SCMHeartbeatResponseProto sendHeartbeat(SCMHeartbeatRequestProto heartbeat) throws IOException {
    rpcCount.incrementAndGet();
    heartbeatCount.incrementAndGet();
    if (heartbeat.getCommandStatusReportsCount() != 0) {
        for (CommandStatusReportsProto statusReport : heartbeat.getCommandStatusReportsList()) {
            cmdStatusList.addAll(statusReport.getCmdStatusList());
            commandStatusReport.incrementAndGet();
        }
    }
    sleepIfNeeded();
    return SCMHeartbeatResponseProto.newBuilder().addAllCommands(scmCommandRequests).setDatanodeUUID(heartbeat.getDatanodeDetails().getUuid()).build();
}
Also used : CommandStatusReportsProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.CommandStatusReportsProto)

Example 2 with CommandStatusReportsProto

use of org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.CommandStatusReportsProto in project ozone by apache.

the class TestSCMDatanodeHeartbeatDispatcher method testContainerReportDispatcher.

@Test
public void testContainerReportDispatcher() throws IOException {
    AtomicInteger eventReceived = new AtomicInteger();
    ContainerReportsProto containerReport = ContainerReportsProto.getDefaultInstance();
    CommandStatusReportsProto commandStatusReport = CommandStatusReportsProto.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) {
            Assert.assertTrue(event.equals(CONTAINER_REPORT) || event.equals(CMD_STATUS_REPORT));
            if (payload instanceof ContainerReportFromDatanode) {
                Assert.assertEquals(containerReport, ((ContainerReportFromDatanode) payload).getReport());
            }
            if (payload instanceof CommandStatusReportFromDatanode) {
                Assert.assertEquals(commandStatusReport, ((CommandStatusReportFromDatanode) payload).getReport());
            }
            eventReceived.incrementAndGet();
        }
    });
    DatanodeDetails datanodeDetails = randomDatanodeDetails();
    SCMHeartbeatRequestProto heartbeat = SCMHeartbeatRequestProto.newBuilder().setDatanodeDetails(datanodeDetails.getProtoBufMessage()).setContainerReport(containerReport).addCommandStatusReports(commandStatusReport).build();
    dispatcher.dispatch(heartbeat);
    Assert.assertEquals(2, eventReceived.get());
}
Also used : EventPublisher(org.apache.hadoop.hdds.server.events.EventPublisher) CommandStatusReportFromDatanode(org.apache.hadoop.hdds.scm.server.SCMDatanodeHeartbeatDispatcher.CommandStatusReportFromDatanode) ContainerReportFromDatanode(org.apache.hadoop.hdds.scm.server.SCMDatanodeHeartbeatDispatcher.ContainerReportFromDatanode) SCMHeartbeatRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMHeartbeatRequestProto) NodeManager(org.apache.hadoop.hdds.scm.node.NodeManager) ContainerReportsProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerReportsProto) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MockDatanodeDetails.randomDatanodeDetails(org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanodeDetails) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) CommandStatusReportsProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.CommandStatusReportsProto) Test(org.junit.Test)

Example 3 with CommandStatusReportsProto

use of org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.CommandStatusReportsProto in project ozone by apache.

the class TestCommandStatusReportHandler method getStatusReport.

private CommandStatusReportFromDatanode getStatusReport(List<CommandStatus> reports) {
    CommandStatusReportsProto report = HddsTestUtils.createCommandStatusReport(reports);
    DatanodeDetails dn = MockDatanodeDetails.randomDatanodeDetails();
    return new SCMDatanodeHeartbeatDispatcher.CommandStatusReportFromDatanode(dn, report);
}
Also used : CommandStatusReportFromDatanode(org.apache.hadoop.hdds.scm.server.SCMDatanodeHeartbeatDispatcher.CommandStatusReportFromDatanode) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) MockDatanodeDetails(org.apache.hadoop.hdds.protocol.MockDatanodeDetails) CommandStatusReportsProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.CommandStatusReportsProto)

Example 4 with CommandStatusReportsProto

use of org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.CommandStatusReportsProto in project ozone by apache.

the class CommandStatusReportPublisher method getReport.

@Override
protected CommandStatusReportsProto getReport() {
    Map<Long, CommandStatus> map = this.getContext().getCommandStatusMap();
    Iterator<Long> iterator = map.keySet().iterator();
    CommandStatusReportsProto.Builder builder = CommandStatusReportsProto.newBuilder();
    iterator.forEachRemaining(key -> {
        CommandStatus cmdStatus = map.get(key);
        // CommandHandler will change its status when it works on this command.
        if (!cmdStatus.getStatus().equals(Status.PENDING)) {
            builder.addCmdStatus(cmdStatus.getProtoBufMessage());
            map.remove(key);
        }
    });
    return builder.getCmdStatusCount() > 0 ? builder.build() : null;
}
Also used : CommandStatusReportsProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.CommandStatusReportsProto) CommandStatus(org.apache.hadoop.ozone.protocol.commands.CommandStatus)

Example 5 with CommandStatusReportsProto

use of org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.CommandStatusReportsProto in project ozone by apache.

the class SCMDatanodeHeartbeatDispatcher method dispatch.

/**
 * Dispatches heartbeat to registered event handlers.
 *
 * @param heartbeat heartbeat to be dispatched.
 *
 * @return list of SCMCommand
 */
public List<SCMCommand> dispatch(SCMHeartbeatRequestProto heartbeat) {
    DatanodeDetails datanodeDetails = DatanodeDetails.getFromProtoBuf(heartbeat.getDatanodeDetails());
    List<SCMCommand> commands;
    // Heartbeat for unregistered nodes.
    if (!nodeManager.isNodeRegistered(datanodeDetails)) {
        LOG.info("SCM received heartbeat from an unregistered datanode {}. " + "Asking datanode to re-register.", datanodeDetails);
        UUID dnID = datanodeDetails.getUuid();
        nodeManager.addDatanodeCommand(dnID, new ReregisterCommand());
        commands = nodeManager.getCommandQueue(dnID);
    } else {
        LayoutVersionProto layoutVersion = null;
        if (!heartbeat.hasDataNodeLayoutVersion()) {
            // Backward compatibility to make sure old Datanodes can still talk to
            // SCM.
            layoutVersion = toLayoutVersionProto(INITIAL_VERSION.layoutVersion(), INITIAL_VERSION.layoutVersion());
        } else {
            layoutVersion = heartbeat.getDataNodeLayoutVersion();
        }
        LOG.debug("Processing DataNode Layout Report.");
        nodeManager.processLayoutVersionReport(datanodeDetails, layoutVersion);
        // should we dispatch heartbeat through eventPublisher?
        commands = nodeManager.processHeartbeat(datanodeDetails, layoutVersion);
        if (heartbeat.hasNodeReport()) {
            LOG.debug("Dispatching Node Report.");
            eventPublisher.fireEvent(NODE_REPORT, new NodeReportFromDatanode(datanodeDetails, heartbeat.getNodeReport()));
        }
        if (heartbeat.hasContainerReport()) {
            LOG.debug("Dispatching Container Report.");
            eventPublisher.fireEvent(CONTAINER_REPORT, new ContainerReportFromDatanode(datanodeDetails, heartbeat.getContainerReport()));
        }
        final List<IncrementalContainerReportProto> icrs = heartbeat.getIncrementalContainerReportList();
        if (icrs.size() > 0) {
            LOG.debug("Dispatching ICRs.");
            for (IncrementalContainerReportProto icr : icrs) {
                eventPublisher.fireEvent(INCREMENTAL_CONTAINER_REPORT, new IncrementalContainerReportFromDatanode(datanodeDetails, icr));
            }
        }
        if (heartbeat.hasContainerActions()) {
            LOG.debug("Dispatching Container Actions.");
            eventPublisher.fireEvent(CONTAINER_ACTIONS, new ContainerActionsFromDatanode(datanodeDetails, heartbeat.getContainerActions()));
        }
        if (heartbeat.hasPipelineReports()) {
            LOG.debug("Dispatching Pipeline Report.");
            eventPublisher.fireEvent(PIPELINE_REPORT, new PipelineReportFromDatanode(datanodeDetails, heartbeat.getPipelineReports()));
        }
        if (heartbeat.hasPipelineActions()) {
            LOG.debug("Dispatching Pipeline Actions.");
            eventPublisher.fireEvent(PIPELINE_ACTIONS, new PipelineActionsFromDatanode(datanodeDetails, heartbeat.getPipelineActions()));
        }
        if (heartbeat.getCommandStatusReportsCount() != 0) {
            LOG.debug("Dispatching Command Status Report.");
            for (CommandStatusReportsProto commandStatusReport : heartbeat.getCommandStatusReportsList()) {
                eventPublisher.fireEvent(CMD_STATUS_REPORT, new CommandStatusReportFromDatanode(datanodeDetails, commandStatusReport));
            }
        }
    }
    return commands;
}
Also used : UpgradeUtils.toLayoutVersionProto(org.apache.hadoop.ozone.container.upgrade.UpgradeUtils.toLayoutVersionProto) LayoutVersionProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.LayoutVersionProto) IncrementalContainerReportProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.IncrementalContainerReportProto) ReregisterCommand(org.apache.hadoop.ozone.protocol.commands.ReregisterCommand) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) CommandStatusReportsProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.CommandStatusReportsProto) UUID(java.util.UUID) SCMCommand(org.apache.hadoop.ozone.protocol.commands.SCMCommand)

Aggregations

CommandStatusReportsProto (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.CommandStatusReportsProto)5 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)3 CommandStatusReportFromDatanode (org.apache.hadoop.hdds.scm.server.SCMDatanodeHeartbeatDispatcher.CommandStatusReportFromDatanode)2 UUID (java.util.UUID)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MockDatanodeDetails (org.apache.hadoop.hdds.protocol.MockDatanodeDetails)1 MockDatanodeDetails.randomDatanodeDetails (org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanodeDetails)1 ContainerReportsProto (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.ContainerReportsProto)1 IncrementalContainerReportProto (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.IncrementalContainerReportProto)1 LayoutVersionProto (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.LayoutVersionProto)1 SCMHeartbeatRequestProto (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMHeartbeatRequestProto)1 NodeManager (org.apache.hadoop.hdds.scm.node.NodeManager)1 ContainerReportFromDatanode (org.apache.hadoop.hdds.scm.server.SCMDatanodeHeartbeatDispatcher.ContainerReportFromDatanode)1 EventPublisher (org.apache.hadoop.hdds.server.events.EventPublisher)1 UpgradeUtils.toLayoutVersionProto (org.apache.hadoop.ozone.container.upgrade.UpgradeUtils.toLayoutVersionProto)1 CommandStatus (org.apache.hadoop.ozone.protocol.commands.CommandStatus)1 ReregisterCommand (org.apache.hadoop.ozone.protocol.commands.ReregisterCommand)1 SCMCommand (org.apache.hadoop.ozone.protocol.commands.SCMCommand)1 Test (org.junit.Test)1