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();
}
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());
}
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);
}
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;
}
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;
}
Aggregations