Search in sources :

Example 16 with EndpointStateMachine

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

the class TestDatanodeStateMachine method testDatanodeStateContext.

/**
 * This test explores the state machine by invoking each call in sequence just
 * like as if the state machine would call it. Because this is a test we are
 * able to verify each of the assumptions.
 * <p>
 * Here is what happens at High level.
 * <p>
 * 1. We start the datanodeStateMachine in the INIT State.
 * <p>
 * 2. We invoke the INIT state task.
 * <p>
 * 3. That creates a set of RPC endpoints that are ready to connect to SCMs.
 * <p>
 * 4. We assert that we have moved to the running state for the
 * DatanodeStateMachine.
 * <p>
 * 5. We get the task for the Running State - Executing that running state,
 * makes the first network call in of the state machine. The Endpoint is in
 * the GETVERSION State and we invoke the task.
 * <p>
 * 6. We assert that this call was a success by checking that each of the
 * endponts now have version response that it got from the SCM server that it
 * was talking to and also each of the mock server serviced one RPC call.
 * <p>
 * 7. Since the Register is done now, next calls to get task will return
 * HeartbeatTask, which sends heartbeats to SCM. We assert that we get right
 * task from sub-system below.
 *
 * @throws IOException
 */
@Test
public void testDatanodeStateContext() throws IOException, InterruptedException, ExecutionException, TimeoutException {
    // There is no mini cluster started in this test,
    // create a ID file so that state machine could load a fake datanode ID.
    File idPath = new File(conf.get(ScmConfigKeys.OZONE_SCM_DATANODE_ID_DIR), OzoneConsts.OZONE_SCM_DATANODE_ID_FILE_DEFAULT);
    idPath.delete();
    DatanodeDetails datanodeDetails = getNewDatanodeDetails();
    DatanodeDetails.Port port = DatanodeDetails.newPort(DatanodeDetails.Port.Name.STANDALONE, OzoneConfigKeys.DFS_CONTAINER_IPC_PORT_DEFAULT);
    datanodeDetails.setPort(port);
    ContainerUtils.writeDatanodeDetailsTo(datanodeDetails, idPath);
    try (DatanodeStateMachine stateMachine = new DatanodeStateMachine(datanodeDetails, conf, null, null, null)) {
        DatanodeStateMachine.DatanodeStates currentState = stateMachine.getContext().getState();
        Assert.assertEquals(DatanodeStateMachine.DatanodeStates.INIT, currentState);
        DatanodeState<DatanodeStateMachine.DatanodeStates> task = stateMachine.getContext().getTask();
        Assert.assertEquals(InitDatanodeState.class, task.getClass());
        task.execute(executorService);
        DatanodeStateMachine.DatanodeStates newState = task.await(2, TimeUnit.SECONDS);
        for (EndpointStateMachine endpoint : stateMachine.getConnectionManager().getValues()) {
            // We assert that each of the is in State GETVERSION.
            Assert.assertEquals(EndpointStateMachine.EndPointStates.GETVERSION, endpoint.getState());
        }
        // The Datanode has moved into Running State, since endpoints are created.
        // We move to running state when we are ready to issue RPC calls to SCMs.
        Assert.assertEquals(DatanodeStateMachine.DatanodeStates.RUNNING, newState);
        // If we had called context.execute instead of calling into each state
        // this would have happened automatically.
        stateMachine.getContext().setState(newState);
        task = stateMachine.getContext().getTask();
        Assert.assertEquals(RunningDatanodeState.class, task.getClass());
        // This execute will invoke getVersion calls against all SCM endpoints
        // that we know of.
        task.execute(executorService);
        newState = task.await(10, TimeUnit.SECONDS);
        // Wait for GetVersion call (called by task.execute) to finish. After
        // Earlier task.execute called into GetVersion. Wait for the execution
        // to finish and the endPointState to move to REGISTER state.
        GenericTestUtils.waitFor(() -> {
            for (EndpointStateMachine endpoint : stateMachine.getConnectionManager().getValues()) {
                if (endpoint.getState() != EndpointStateMachine.EndPointStates.REGISTER) {
                    return false;
                }
            }
            return true;
        }, 1000, 50000);
        // If we are in running state, we should be in running.
        Assert.assertEquals(DatanodeStateMachine.DatanodeStates.RUNNING, newState);
        for (EndpointStateMachine endpoint : stateMachine.getConnectionManager().getValues()) {
            // Since the earlier task.execute called into GetVersion, the
            // endPointState Machine should move to REGISTER state.
            Assert.assertEquals(EndpointStateMachine.EndPointStates.REGISTER, endpoint.getState());
            // We assert that each of the end points have gotten a version from the
            // SCM Server.
            Assert.assertNotNull(endpoint.getVersion());
        }
        // call at this point of time.
        for (ScmTestMock mock : mockServers) {
            Assert.assertEquals(1, mock.getRpcCount());
        }
        // This task is the Running task, but running task executes tasks based
        // on the state of Endpoints, hence this next call will be a Register at
        // the endpoint RPC level.
        task = stateMachine.getContext().getTask();
        task.execute(executorService);
        newState = task.await(2, TimeUnit.SECONDS);
        // If we are in running state, we should be in running.
        Assert.assertEquals(DatanodeStateMachine.DatanodeStates.RUNNING, newState);
        for (ScmTestMock mock : mockServers) {
            Assert.assertEquals(2, mock.getRpcCount());
        }
        // This task is the Running task, but running task executes tasks based
        // on the state of Endpoints, hence this next call will be a
        // HeartbeatTask at the endpoint RPC level.
        task = stateMachine.getContext().getTask();
        task.execute(executorService);
        newState = task.await(2, TimeUnit.SECONDS);
        // If we are in running state, we should be in running.
        Assert.assertEquals(DatanodeStateMachine.DatanodeStates.RUNNING, newState);
        for (ScmTestMock mock : mockServers) {
            Assert.assertEquals(1, mock.getHeartbeatCount());
        }
    }
}
Also used : EndpointStateMachine(org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) DatanodeStateMachine(org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine) File(java.io.File) Test(org.junit.Test)

Example 17 with EndpointStateMachine

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

the class ContainerTestUtils method createEndpoint.

/**
 * Creates an Endpoint class for testing purpose.
 *
 * @param conf - Conf
 * @param address - InetAddres
 * @param rpcTimeout - rpcTimeOut
 * @return EndPoint
 * @throws Exception
 */
public static EndpointStateMachine createEndpoint(Configuration conf, InetSocketAddress address, int rpcTimeout) throws Exception {
    RPC.setProtocolEngine(conf, StorageContainerDatanodeProtocolPB.class, ProtobufRpcEngine.class);
    long version = RPC.getProtocolVersion(StorageContainerDatanodeProtocolPB.class);
    StorageContainerDatanodeProtocolPB rpcProxy = RPC.getProtocolProxy(StorageContainerDatanodeProtocolPB.class, version, address, UserGroupInformation.getCurrentUser(), conf, NetUtils.getDefaultSocketFactory(conf), rpcTimeout, RetryPolicies.TRY_ONCE_THEN_FAIL).getProxy();
    StorageContainerDatanodeProtocolClientSideTranslatorPB rpcClient = new StorageContainerDatanodeProtocolClientSideTranslatorPB(rpcProxy);
    return new EndpointStateMachine(address, rpcClient, new LegacyHadoopConfigurationSource(conf));
}
Also used : EndpointStateMachine(org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine) StorageContainerDatanodeProtocolClientSideTranslatorPB(org.apache.hadoop.ozone.protocolPB.StorageContainerDatanodeProtocolClientSideTranslatorPB) LegacyHadoopConfigurationSource(org.apache.hadoop.hdds.utils.LegacyHadoopConfigurationSource) StorageContainerDatanodeProtocolPB(org.apache.hadoop.ozone.protocolPB.StorageContainerDatanodeProtocolPB)

Example 18 with EndpointStateMachine

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

the class TestDatanodeUpgradeToScmHA method callVersionEndpointTask.

/**
 * Get the cluster ID and SCM ID from SCM to the datanode.
 */
public void callVersionEndpointTask() throws Exception {
    try (EndpointStateMachine esm = ContainerTestUtils.createEndpoint(conf, address, 1000)) {
        VersionEndpointTask vet = new VersionEndpointTask(esm, conf, dsm.getContainer());
        esm.setState(EndpointStateMachine.EndPointStates.GETVERSION);
        vet.call();
    }
}
Also used : EndpointStateMachine(org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine) VersionEndpointTask(org.apache.hadoop.ozone.container.common.states.endpoint.VersionEndpointTask)

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