Search in sources :

Example 1 with EndpointStateMachine

use of org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine in project ozone by apache.

the class TestEndPoint method testHeartbeat.

@Test
public void testHeartbeat() throws Exception {
    DatanodeDetails dataNode = randomDatanodeDetails();
    try (EndpointStateMachine rpcEndPoint = createEndpoint(SCMTestUtils.getConf(), serverAddress, 1000)) {
        SCMHeartbeatRequestProto request = SCMHeartbeatRequestProto.newBuilder().setDatanodeDetails(dataNode.getProtoBufMessage()).setNodeReport(HddsTestUtils.createNodeReport(Arrays.asList(getStorageReports(dataNode.getUuid())), Arrays.asList(getMetadataStorageReports(dataNode.getUuid())))).build();
        SCMHeartbeatResponseProto responseProto = rpcEndPoint.getEndPoint().sendHeartbeat(request);
        Assert.assertNotNull(responseProto);
        Assert.assertEquals(0, responseProto.getCommandsCount());
    }
}
Also used : EndpointStateMachine(org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine) SCMHeartbeatRequestProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMHeartbeatRequestProto) MockDatanodeDetails.randomDatanodeDetails(org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanodeDetails) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) SCMHeartbeatResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMHeartbeatResponseProto) Test(org.junit.Test)

Example 2 with EndpointStateMachine

use of org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine in project ozone by apache.

the class TestEndPoint method testRegister.

@Test
public void testRegister() throws Exception {
    DatanodeDetails nodeToRegister = randomDatanodeDetails();
    try (EndpointStateMachine rpcEndPoint = createEndpoint(SCMTestUtils.getConf(), serverAddress, 1000)) {
        SCMRegisteredResponseProto responseProto = rpcEndPoint.getEndPoint().register(nodeToRegister.getExtendedProtoBufMessage(), HddsTestUtils.createNodeReport(Arrays.asList(getStorageReports(nodeToRegister.getUuid())), Arrays.asList(getMetadataStorageReports(nodeToRegister.getUuid()))), HddsTestUtils.getRandomContainerReports(10), HddsTestUtils.getRandomPipelineReports(), defaultLayoutVersionProto());
        Assert.assertNotNull(responseProto);
        Assert.assertEquals(nodeToRegister.getUuidString(), responseProto.getDatanodeUUID());
        Assert.assertNotNull(responseProto.getClusterID());
        Assert.assertEquals(10, scmServerImpl.getContainerCountsForDatanode(nodeToRegister));
        Assert.assertEquals(1, scmServerImpl.getNodeReportsCount(nodeToRegister));
    }
}
Also used : EndpointStateMachine(org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine) MockDatanodeDetails.randomDatanodeDetails(org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanodeDetails) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) SCMRegisteredResponseProto(org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMRegisteredResponseProto) Test(org.junit.Test)

Example 3 with EndpointStateMachine

use of org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine in project ozone by apache.

the class TestEndPoint method testGetVersionAssertRpcTimeOut.

@Test
public /**
 * This test makes a getVersionRPC call, but the DummyStorageServer is
 * going to respond little slowly. We will assert that we are still in the
 * GETVERSION state after the timeout.
 */
void testGetVersionAssertRpcTimeOut() throws Exception {
    final long rpcTimeout = 1000;
    final long tolerance = 100;
    OzoneConfiguration conf = SCMTestUtils.getConf();
    try (EndpointStateMachine rpcEndPoint = createEndpoint(conf, serverAddress, (int) rpcTimeout)) {
        rpcEndPoint.setState(EndpointStateMachine.EndPointStates.GETVERSION);
        DatanodeDetails datanodeDetails = randomDatanodeDetails();
        OzoneContainer ozoneContainer = new OzoneContainer(datanodeDetails, conf, getContext(datanodeDetails), null);
        VersionEndpointTask versionTask = new VersionEndpointTask(rpcEndPoint, conf, ozoneContainer);
        scmServerImpl.setRpcResponseDelay(1500);
        long start = Time.monotonicNow();
        EndpointStateMachine.EndPointStates newState = versionTask.call();
        long end = Time.monotonicNow();
        scmServerImpl.setRpcResponseDelay(0);
        Assert.assertThat(end - start, lessThanOrEqualTo(rpcTimeout + tolerance));
        Assert.assertEquals(EndpointStateMachine.EndPointStates.GETVERSION, newState);
    }
}
Also used : EndpointStateMachine(org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine) VersionEndpointTask(org.apache.hadoop.ozone.container.common.states.endpoint.VersionEndpointTask) MockDatanodeDetails.randomDatanodeDetails(org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanodeDetails) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) OzoneContainer(org.apache.hadoop.ozone.container.ozoneimpl.OzoneContainer) Test(org.junit.Test)

Example 4 with EndpointStateMachine

use of org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine in project ozone by apache.

the class TestMiniOzoneCluster method testDNstartAfterSCM.

/**
 * Test that a DN can register with SCM even if it was started before the SCM.
 * @throws Exception
 */
@Test(timeout = 100000)
public void testDNstartAfterSCM() throws Exception {
    // Start a cluster with 3 DN
    cluster = MiniOzoneCluster.newBuilder(conf).setNumDatanodes(3).build();
    cluster.waitForClusterToBeReady();
    // Stop the SCM
    StorageContainerManager scm = cluster.getStorageContainerManager();
    scm.stop();
    // Restart DN
    cluster.restartHddsDatanode(0, false);
    // DN should be in GETVERSION state till the SCM is restarted.
    // Check DN endpoint state for 20 seconds
    DatanodeStateMachine dnStateMachine = cluster.getHddsDatanodes().get(0).getDatanodeStateMachine();
    for (int i = 0; i < 20; i++) {
        for (EndpointStateMachine endpoint : dnStateMachine.getConnectionManager().getValues()) {
            Assert.assertEquals(EndpointStateMachine.EndPointStates.GETVERSION, endpoint.getState());
        }
        Thread.sleep(1000);
    }
    // DN should successfully register with the SCM after SCM is restarted.
    // Restart the SCM
    cluster.restartStorageContainerManager(true);
    // Wait for DN to register
    cluster.waitForClusterToBeReady();
    // DN should be in HEARTBEAT state after registering with the SCM
    for (EndpointStateMachine endpoint : dnStateMachine.getConnectionManager().getValues()) {
        Assert.assertEquals(EndpointStateMachine.EndPointStates.HEARTBEAT, endpoint.getState());
    }
}
Also used : EndpointStateMachine(org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine) StorageContainerManager(org.apache.hadoop.hdds.scm.server.StorageContainerManager) DatanodeStateMachine(org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine) Test(org.junit.Test)

Example 5 with EndpointStateMachine

use of org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine in project ozone by apache.

the class TestRunningDatanodeState method testAwait.

@Test
public void testAwait() throws InterruptedException {
    SCMConnectionManager connectionManager = Mockito.mock(SCMConnectionManager.class);
    List<EndpointStateMachine> stateMachines = new ArrayList<>();
    when(connectionManager.getValues()).thenReturn(stateMachines);
    RunningDatanodeState state = new RunningDatanodeState(null, connectionManager, null);
    int threadPoolSize = 2;
    ExecutorService executorService = Executors.newFixedThreadPool(threadPoolSize);
    ExecutorCompletionService ecs = new ExecutorCompletionService<>(executorService);
    state.setExecutorCompletionService(ecs);
    for (int i = 0; i < threadPoolSize; i++) {
        stateMachines.add(new EndpointStateMachine(null, null, null));
    }
    CompletableFuture<EndpointStateMachine.EndPointStates> futureOne = new CompletableFuture<>();
    for (int i = 0; i < threadPoolSize; i++) {
        ecs.submit(() -> futureOne.get());
    }
    long startTime = Time.monotonicNow();
    state.await(500, TimeUnit.MILLISECONDS);
    long endTime = Time.monotonicNow();
    Assert.assertTrue((endTime - startTime) >= 500);
    futureOne.complete(SHUTDOWN);
    CompletableFuture<EndpointStateMachine.EndPointStates> futureTwo = new CompletableFuture<>();
    for (int i = 0; i < threadPoolSize; i++) {
        ecs.submit(() -> futureTwo.get());
    }
    futureTwo.complete(SHUTDOWN);
    startTime = Time.monotonicNow();
    state.await(500, TimeUnit.MILLISECONDS);
    endTime = Time.monotonicNow();
    Assert.assertTrue((endTime - startTime) < 500);
    executorService.shutdown();
}
Also used : EndpointStateMachine(org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) ExecutorService(java.util.concurrent.ExecutorService) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) SCMConnectionManager(org.apache.hadoop.ozone.container.common.statemachine.SCMConnectionManager) Test(org.junit.Test)

Aggregations

EndpointStateMachine (org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine)18 Test (org.junit.Test)11 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)10 MockDatanodeDetails.randomDatanodeDetails (org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanodeDetails)8 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)6 VersionEndpointTask (org.apache.hadoop.ozone.container.common.states.endpoint.VersionEndpointTask)6 OzoneContainer (org.apache.hadoop.ozone.container.ozoneimpl.OzoneContainer)5 DatanodeStateMachine (org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine)3 StateContext (org.apache.hadoop.ozone.container.common.statemachine.StateContext)3 SCMHeartbeatRequestProto (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMHeartbeatRequestProto)2 SCMHeartbeatResponseProto (org.apache.hadoop.hdds.protocol.proto.StorageContainerDatanodeProtocolProtos.SCMHeartbeatResponseProto)2 HDDSLayoutVersionManager (org.apache.hadoop.hdds.upgrade.HDDSLayoutVersionManager)2 EndPointStates (org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine.EndPointStates)2 ReplicationConfig (org.apache.hadoop.ozone.container.replication.ReplicationServer.ReplicationConfig)2 File (java.io.File)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 EnumMap (java.util.EnumMap)1 UUID (java.util.UUID)1 Callable (java.util.concurrent.Callable)1