use of org.apache.hadoop.ozone.protocol.commands.SCMCommand in project ozone by apache.
the class PipelineReportHandler method processPipelineReport.
protected void processPipelineReport(PipelineReport report, DatanodeDetails dn, EventPublisher publisher) throws IOException {
PipelineID pipelineID = PipelineID.getFromProtobuf(report.getPipelineID());
Pipeline pipeline;
try {
pipeline = pipelineManager.getPipeline(pipelineID);
} catch (PipelineNotFoundException e) {
if (scmContext.isLeader()) {
LOGGER.info("Reported pipeline {} is not found", pipelineID);
SCMCommand<?> command = new ClosePipelineCommand(pipelineID);
command.setTerm(scmContext.getTermOfLeader());
publisher.fireEvent(SCMEvents.DATANODE_COMMAND, new CommandForDatanode<>(dn.getUuid(), command));
}
return;
}
setReportedDatanode(pipeline, dn);
setPipelineLeaderId(report, pipeline, dn);
if (pipeline.getPipelineState() == Pipeline.PipelineState.ALLOCATED) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Pipeline {} {} reported by {}", pipeline.getReplicationConfig(), pipeline.getId(), dn);
}
if (pipeline.isHealthy()) {
pipelineManager.openPipeline(pipelineID);
}
}
if (pipeline.isHealthy()) {
if (pipelineAvailabilityCheck && scmSafeModeManager.getInSafeMode()) {
publisher.fireEvent(SCMEvents.OPEN_PIPELINE, pipeline);
}
}
}
use of org.apache.hadoop.ozone.protocol.commands.SCMCommand in project ozone by apache.
the class SCMDatanodeProtocolServer method sendHeartbeat.
@Override
public SCMHeartbeatResponseProto sendHeartbeat(SCMHeartbeatRequestProto heartbeat) throws IOException {
List<SCMCommandProto> cmdResponses = new ArrayList<>();
for (SCMCommand cmd : heartbeatDispatcher.dispatch(heartbeat)) {
cmdResponses.add(getCommandResponse(cmd));
}
boolean auditSuccess = true;
Map<String, String> auditMap = Maps.newHashMap();
auditMap.put("datanodeUUID", heartbeat.getDatanodeDetails().getUuid());
auditMap.put("command", flatten(cmdResponses.toString()));
try {
return SCMHeartbeatResponseProto.newBuilder().setDatanodeUUID(heartbeat.getDatanodeDetails().getUuid()).addAllCommands(cmdResponses).build();
} catch (Exception ex) {
auditSuccess = false;
AUDIT.logWriteFailure(buildAuditMessageForFailure(SCMAction.SEND_HEARTBEAT, auditMap, ex));
throw ex;
} finally {
if (auditSuccess) {
AUDIT.logWriteSuccess(buildAuditMessageForSuccess(SCMAction.SEND_HEARTBEAT, auditMap));
}
}
}
use of org.apache.hadoop.ozone.protocol.commands.SCMCommand in project ozone by apache.
the class PipelineActionHandler method processPipelineAction.
/**
* Process the given PipelineAction.
*
* @param datanode the datanode which has sent the PipelineAction
* @param pipelineAction the PipelineAction
* @param publisher EventPublisher to fire new events if required
*/
private void processPipelineAction(final DatanodeDetails datanode, final PipelineAction pipelineAction, final EventPublisher publisher) {
final ClosePipelineInfo info = pipelineAction.getClosePipeline();
final PipelineAction.Action action = pipelineAction.getAction();
final PipelineID pid = PipelineID.getFromProtobuf(info.getPipelineID());
try {
LOG.info("Received pipeline action {} for {} from datanode {}. " + "Reason : {}", action, pid, datanode.getUuidString(), info.getDetailedReason());
if (action == PipelineAction.Action.CLOSE) {
pipelineManager.closePipeline(pipelineManager.getPipeline(pid), false);
} else {
LOG.error("unknown pipeline action:{}", action);
}
} catch (PipelineNotFoundException e) {
LOG.warn("Pipeline action {} received for unknown pipeline {}, " + "firing close pipeline event.", action, pid);
SCMCommand<?> command = new ClosePipelineCommand(pid);
try {
command.setTerm(scmContext.getTermOfLeader());
} catch (NotLeaderException nle) {
LOG.warn("Skip sending ClosePipelineCommand for pipeline {}," + " since not leader SCM.", pid);
return;
}
publisher.fireEvent(SCMEvents.DATANODE_COMMAND, new CommandForDatanode<>(datanode.getUuid(), command));
} catch (IOException ioe) {
LOG.error("Could not execute pipeline action={} pipeline={}", action, pid, ioe);
}
}
use of org.apache.hadoop.ozone.protocol.commands.SCMCommand in project ozone by apache.
the class TestSCMNodeManager method testHandlingSCMCommandEvent.
@Test
public void testHandlingSCMCommandEvent() throws IOException, AuthenticationException {
OzoneConfiguration conf = getConf();
conf.getTimeDuration(ScmConfigKeys.OZONE_SCM_HEARTBEAT_PROCESS_INTERVAL, 100, TimeUnit.MILLISECONDS);
DatanodeDetails datanodeDetails = randomDatanodeDetails();
UUID dnId = datanodeDetails.getUuid();
String storagePath = testDir.getAbsolutePath() + "/" + dnId;
StorageReportProto report = HddsTestUtils.createStorageReport(dnId, storagePath, 100, 10, 90, null);
EventQueue eq = new EventQueue();
try (SCMNodeManager nodemanager = createNodeManager(conf)) {
eq.addHandler(DATANODE_COMMAND, nodemanager);
nodemanager.register(datanodeDetails, HddsTestUtils.createNodeReport(Arrays.asList(report), Collections.emptyList()), HddsTestUtils.getRandomPipelineReports());
eq.fireEvent(DATANODE_COMMAND, new CommandForDatanode<>(datanodeDetails.getUuid(), new CloseContainerCommand(1L, PipelineID.randomId())));
LayoutVersionManager versionManager = nodemanager.getLayoutVersionManager();
LayoutVersionProto layoutInfo = toLayoutVersionProto(versionManager.getMetadataLayoutVersion(), versionManager.getSoftwareLayoutVersion());
eq.processAll(1000L);
List<SCMCommand> command = nodemanager.processHeartbeat(datanodeDetails, layoutInfo);
// With dh registered, SCM will send create pipeline command to dn
Assert.assertTrue(command.size() >= 1);
Assert.assertTrue(command.get(0).getClass().equals(CloseContainerCommand.class) || command.get(1).getClass().equals(CloseContainerCommand.class));
} catch (IOException e) {
e.printStackTrace();
throw e;
}
}
use of org.apache.hadoop.ozone.protocol.commands.SCMCommand in project ozone by apache.
the class ReconNodeManager method processHeartbeat.
/**
* Send heartbeat to indicate the datanode is alive and doing well.
*
* @param datanodeDetails - DatanodeDetailsProto.
* @param layoutInfo - Layout Version Proto
* @return SCMheartbeat response.
*/
@Override
public List<SCMCommand> processHeartbeat(DatanodeDetails datanodeDetails, LayoutVersionProto layoutInfo) {
List<SCMCommand> cmds = new ArrayList<>();
long currentTime = Time.now();
if (needUpdate(datanodeDetails, currentTime)) {
cmds.add(new ReregisterCommand());
LOG.info("Sending ReregisterCommand() for " + datanodeDetails.getHostName());
datanodeHeartbeatMap.put(datanodeDetails.getUuid(), Time.now());
return cmds;
}
// Update heartbeat map with current time
datanodeHeartbeatMap.put(datanodeDetails.getUuid(), Time.now());
cmds.addAll(super.processHeartbeat(datanodeDetails, layoutInfo));
return cmds.stream().filter(c -> ALLOWED_COMMANDS.contains(c.getType())).collect(toList());
}
Aggregations