use of org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException in project ozone by apache.
the class TestReplicationManager method setup.
@Before
public void setup() throws IOException, InterruptedException, NodeNotFoundException, InvalidStateTransitionException {
OzoneConfiguration conf = new OzoneConfiguration();
conf.setTimeDuration(HddsConfigKeys.HDDS_SCM_WAIT_TIME_AFTER_SAFE_MODE_EXIT, 0, TimeUnit.SECONDS);
scmLogs = GenericTestUtils.LogCapturer.captureLogs(ReplicationManager.LOG);
containerManager = Mockito.mock(ContainerManager.class);
nodeManager = new SimpleMockNodeManager();
eventQueue = new EventQueue();
scmhaManager = MockSCMHAManager.getInstance(true);
testDir = GenericTestUtils.getTestDir(TestContainerManagerImpl.class.getSimpleName() + UUID.randomUUID());
conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, testDir.getAbsolutePath());
dbStore = DBStoreBuilder.createDBStore(conf, new SCMDBDefinition());
pipelineManager = Mockito.mock(PipelineManager.class);
when(pipelineManager.containsPipeline(Mockito.any(PipelineID.class))).thenReturn(true);
containerStateManager = ContainerStateManagerImpl.newBuilder().setConfiguration(conf).setPipelineManager(pipelineManager).setRatisServer(scmhaManager.getRatisServer()).setContainerStore(SCMDBDefinition.CONTAINERS.getTable(dbStore)).setSCMDBTransactionBuffer(scmhaManager.getDBTransactionBuffer()).build();
serviceManager = new SCMServiceManager();
datanodeCommandHandler = new DatanodeCommandHandler();
eventQueue.addHandler(SCMEvents.DATANODE_COMMAND, datanodeCommandHandler);
Mockito.when(containerManager.getContainers()).thenAnswer(invocation -> {
Set<ContainerID> ids = containerStateManager.getContainerIDs();
List<ContainerInfo> containers = new ArrayList<>();
for (ContainerID id : ids) {
containers.add(containerStateManager.getContainer(id));
}
return containers;
});
Mockito.when(containerManager.getContainer(Mockito.any(ContainerID.class))).thenAnswer(invocation -> containerStateManager.getContainer(((ContainerID) invocation.getArguments()[0])));
Mockito.when(containerManager.getContainerReplicas(Mockito.any(ContainerID.class))).thenAnswer(invocation -> containerStateManager.getContainerReplicas(((ContainerID) invocation.getArguments()[0])));
containerPlacementPolicy = Mockito.mock(PlacementPolicy.class);
Mockito.when(containerPlacementPolicy.chooseDatanodes(Mockito.any(), Mockito.any(), Mockito.anyInt(), Mockito.anyLong(), Mockito.anyLong())).thenAnswer(invocation -> {
int count = (int) invocation.getArguments()[2];
return IntStream.range(0, count).mapToObj(i -> randomDatanodeDetails()).collect(Collectors.toList());
});
Mockito.when(containerPlacementPolicy.validateContainerPlacement(Mockito.any(), Mockito.anyInt())).thenAnswer(invocation -> new ContainerPlacementStatusDefault(2, 2, 3));
clock = new TestClock(Instant.now(), ZoneId.of("UTC"));
createReplicationManager(new ReplicationManagerConfiguration());
}
use of org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException in project ozone by apache.
the class TestContainerStateManagerIntegration method testContainerStateManagerRestart.
@Test
public void testContainerStateManagerRestart() throws IOException, TimeoutException, InterruptedException, AuthenticationException, InvalidStateTransitionException {
for (int i = 0; i < 10; i++) {
ContainerWithPipeline container = scm.getClientProtocolServer().allocateContainer(SCMTestUtils.getReplicationType(conf), SCMTestUtils.getReplicationFactor(conf), OzoneConsts.OZONE);
if (i >= 5) {
scm.getContainerManager().updateContainerState(container.getContainerInfo().containerID(), HddsProtos.LifeCycleEvent.FINALIZE);
}
}
// Restart SCM will not trigger container report to satisfy the safe mode
// exit rule.
cluster.restartStorageContainerManager(false);
List<ContainerInfo> result = cluster.getStorageContainerManager().getContainerManager().getContainers(null, 100);
long matchCount = result.stream().filter(info -> info.getOwner().equals(OzoneConsts.OZONE)).filter(info -> info.getReplicationType() == SCMTestUtils.getReplicationType(conf)).filter(info -> ReplicationConfig.getLegacyFactor(info.getReplicationConfig()) == SCMTestUtils.getReplicationFactor(conf)).filter(info -> info.getState() == HddsProtos.LifeCycleState.OPEN).count();
Assert.assertEquals(5, matchCount);
matchCount = result.stream().filter(info -> info.getOwner().equals(OzoneConsts.OZONE)).filter(info -> info.getReplicationType() == SCMTestUtils.getReplicationType(conf)).filter(info -> ReplicationConfig.getLegacyFactor(info.getReplicationConfig()) == SCMTestUtils.getReplicationFactor(conf)).filter(info -> info.getState() == HddsProtos.LifeCycleState.CLOSING).count();
Assert.assertEquals(5, matchCount);
}
use of org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException in project ozone by apache.
the class IncrementalContainerReportHandler method onMessage.
@Override
public void onMessage(final IncrementalContainerReportFromDatanode report, final EventPublisher publisher) {
final DatanodeDetails dnFromReport = report.getDatanodeDetails();
if (LOG.isDebugEnabled()) {
LOG.debug("Processing incremental container report from data node {}", dnFromReport.getUuid());
}
DatanodeDetails dd = nodeManager.getNodeByUuid(dnFromReport.getUuidString());
if (dd == null) {
LOG.warn("Received container report from unknown datanode {}", dnFromReport);
return;
}
boolean success = true;
// ContainerManager.
synchronized (dd) {
for (ContainerReplicaProto replicaProto : report.getReport().getReportList()) {
ContainerID id = ContainerID.valueOf(replicaProto.getContainerID());
ContainerInfo container = null;
try {
try {
container = getContainerManager().getContainer(id);
// Ensure we reuse the same ContainerID instance in containerInfo
id = container.containerID();
} finally {
if (!replicaProto.getState().equals(ContainerReplicaProto.State.DELETED)) {
nodeManager.addContainer(dd, id);
}
}
processContainerReplica(dd, container, replicaProto, publisher);
} catch (ContainerNotFoundException e) {
success = false;
LOG.warn("Container {} not found!", replicaProto.getContainerID());
} catch (NodeNotFoundException ex) {
success = false;
LOG.error("Received ICR from unknown datanode {}", report.getDatanodeDetails(), ex);
} catch (ContainerReplicaNotFoundException e) {
success = false;
LOG.warn("Container {} replica not found!", replicaProto.getContainerID());
} catch (IOException | InvalidStateTransitionException e) {
success = false;
LOG.error("Exception while processing ICR for container {}", replicaProto.getContainerID(), e);
}
}
}
getContainerManager().notifyContainerReportProcessing(false, success);
}
use of org.apache.hadoop.ozone.common.statemachine.InvalidStateTransitionException in project ozone by apache.
the class NodeStateManager method updateNodeState.
/**
* Updates the node state if the condition satisfies.
*
* @param node DatanodeInfo
* @param condition condition to check
* @param status current status of node
* @param lifeCycleEvent NodeLifeCycleEvent to be applied if condition
* matches
*
* @throws NodeNotFoundException if the node is not present
*/
private void updateNodeState(DatanodeInfo node, Predicate<Long> condition, NodeStatus status, NodeLifeCycleEvent lifeCycleEvent) throws NodeNotFoundException {
try {
if (condition.test(node.getLastHeartbeatTime())) {
NodeState newHealthState = nodeHealthSM.getNextState(status.getHealth(), lifeCycleEvent);
NodeStatus newStatus = nodeStateMap.updateNodeHealthState(node.getUuid(), newHealthState);
fireHealthStateEvent(newStatus.getHealth(), node);
}
} catch (InvalidStateTransitionException e) {
LOG.warn("Invalid state transition of node {}." + " Current state: {}, life cycle event: {}", node, status.getHealth(), lifeCycleEvent);
}
}
Aggregations