Search in sources :

Example 1 with VersionEndpointTask

use of org.apache.hadoop.ozone.container.common.states.endpoint.VersionEndpointTask 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 2 with VersionEndpointTask

use of org.apache.hadoop.ozone.container.common.states.endpoint.VersionEndpointTask in project ozone by apache.

the class RunningDatanodeState method initEndPointTask.

/**
 * Initialize end point tasks corresponding to each end point,
 * each end point state.
 */
private void initEndPointTask() {
    endpointTasks = new HashMap<>();
    for (EndpointStateMachine endpoint : connectionManager.getValues()) {
        EnumMap<EndPointStates, Callable<EndPointStates>> endpointTaskForState = new EnumMap<>(EndPointStates.class);
        for (EndPointStates state : EndPointStates.values()) {
            Callable<EndPointStates> endPointTask = null;
            switch(state) {
                case GETVERSION:
                    endPointTask = new VersionEndpointTask(endpoint, conf, context.getParent().getContainer());
                    break;
                case REGISTER:
                    endPointTask = RegisterEndpointTask.newBuilder().setConfig(conf).setEndpointStateMachine(endpoint).setContext(context).setDatanodeDetails(context.getParent().getDatanodeDetails()).setOzoneContainer(context.getParent().getContainer()).build();
                    break;
                case HEARTBEAT:
                    endPointTask = HeartbeatEndpointTask.newBuilder().setConfig(conf).setEndpointStateMachine(endpoint).setDatanodeDetails(context.getParent().getDatanodeDetails()).setContext(context).build();
                    break;
                default:
                    break;
            }
            if (endPointTask != null) {
                endpointTaskForState.put(state, endPointTask);
            }
        }
        endpointTasks.put(endpoint, endpointTaskForState);
    }
}
Also used : EndpointStateMachine(org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine) VersionEndpointTask(org.apache.hadoop.ozone.container.common.states.endpoint.VersionEndpointTask) EndPointStates(org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine.EndPointStates) EnumMap(java.util.EnumMap) Callable(java.util.concurrent.Callable)

Example 3 with VersionEndpointTask

use of org.apache.hadoop.ozone.container.common.states.endpoint.VersionEndpointTask in project ozone by apache.

the class TestEndPoint method testGetVersionToInvalidEndpoint.

@Test
public /**
 * This test makes a call to end point where there is no SCM server. We
 * expect that versionTask should be able to handle it.
 */
void testGetVersionToInvalidEndpoint() throws Exception {
    OzoneConfiguration conf = SCMTestUtils.getConf();
    InetSocketAddress nonExistentServerAddress = SCMTestUtils.getReuseableAddress();
    try (EndpointStateMachine rpcEndPoint = createEndpoint(conf, nonExistentServerAddress, 1000)) {
        rpcEndPoint.setState(EndpointStateMachine.EndPointStates.GETVERSION);
        DatanodeDetails datanodeDetails = randomDatanodeDetails();
        OzoneContainer ozoneContainer = new OzoneContainer(datanodeDetails, conf, getContext(datanodeDetails), null);
        VersionEndpointTask versionTask = new VersionEndpointTask(rpcEndPoint, conf, ozoneContainer);
        EndpointStateMachine.EndPointStates newState = versionTask.call();
        // This version call did NOT work, so endpoint should remain in the same
        // state.
        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) InetSocketAddress(java.net.InetSocketAddress) 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 VersionEndpointTask

use of org.apache.hadoop.ozone.container.common.states.endpoint.VersionEndpointTask in project ozone by apache.

the class TestEndPoint method testCheckVersionResponse.

@Test
public void testCheckVersionResponse() throws Exception {
    OzoneConfiguration conf = SCMTestUtils.getConf();
    conf.setBoolean(OzoneConfigKeys.DFS_CONTAINER_IPC_RANDOM_PORT, true);
    conf.setBoolean(OzoneConfigKeys.DFS_CONTAINER_RATIS_IPC_RANDOM_PORT, true);
    conf.setFromObject(new ReplicationConfig().setPort(0));
    try (EndpointStateMachine rpcEndPoint = createEndpoint(conf, serverAddress, 1000)) {
        GenericTestUtils.LogCapturer logCapturer = GenericTestUtils.LogCapturer.captureLogs(VersionEndpointTask.LOG);
        DatanodeDetails datanodeDetails = randomDatanodeDetails();
        OzoneContainer ozoneContainer = new OzoneContainer(datanodeDetails, conf, getContext(datanodeDetails), null);
        rpcEndPoint.setState(EndpointStateMachine.EndPointStates.GETVERSION);
        VersionEndpointTask versionTask = new VersionEndpointTask(rpcEndPoint, conf, ozoneContainer);
        EndpointStateMachine.EndPointStates newState = versionTask.call();
        // if version call worked the endpoint should automatically move to the
        // next state.
        Assert.assertEquals(EndpointStateMachine.EndPointStates.REGISTER, newState);
        // Now rpcEndpoint should remember the version it got from SCM
        Assert.assertNotNull(rpcEndPoint.getVersion());
        // Now change server cluster ID, so datanode cluster ID will be
        // different from SCM server response cluster ID.
        String newClusterId = UUID.randomUUID().toString();
        scmServerImpl.setClusterId(newClusterId);
        rpcEndPoint.setState(EndpointStateMachine.EndPointStates.GETVERSION);
        newState = versionTask.call();
        Assert.assertEquals(EndpointStateMachine.EndPointStates.SHUTDOWN, newState);
        List<HddsVolume> volumesList = StorageVolumeUtil.getHddsVolumesList(ozoneContainer.getVolumeSet().getFailedVolumesList());
        Assert.assertTrue(volumesList.size() == 1);
        Assert.assertTrue(logCapturer.getOutput().contains("org.apache.hadoop.ozone.common" + ".InconsistentStorageStateException: Mismatched ClusterIDs"));
        Assert.assertTrue(ozoneContainer.getVolumeSet().getVolumesList().size() == 0);
        Assert.assertTrue(ozoneContainer.getVolumeSet().getFailedVolumesList().size() == 1);
    }
}
Also used : EndpointStateMachine(org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine) HddsVolume(org.apache.hadoop.ozone.container.common.volume.HddsVolume) VersionEndpointTask(org.apache.hadoop.ozone.container.common.states.endpoint.VersionEndpointTask) ReplicationConfig(org.apache.hadoop.ozone.container.replication.ReplicationServer.ReplicationConfig) MockDatanodeDetails.randomDatanodeDetails(org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanodeDetails) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) GenericTestUtils(org.apache.ozone.test.GenericTestUtils) OzoneContainer(org.apache.hadoop.ozone.container.ozoneimpl.OzoneContainer) Test(org.junit.Test)

Example 5 with VersionEndpointTask

use of org.apache.hadoop.ozone.container.common.states.endpoint.VersionEndpointTask in project ozone by apache.

the class TestEndPoint method testGetVersionTask.

@Test
public /**
 * We make getVersion RPC call, but via the VersionEndpointTask which is
 * how the state machine would make the call.
 */
void testGetVersionTask() throws Exception {
    OzoneConfiguration conf = SCMTestUtils.getConf();
    conf.setFromObject(new ReplicationConfig().setPort(0));
    try (EndpointStateMachine rpcEndPoint = createEndpoint(conf, serverAddress, 1000)) {
        DatanodeDetails datanodeDetails = randomDatanodeDetails();
        OzoneContainer ozoneContainer = new OzoneContainer(datanodeDetails, conf, getContext(datanodeDetails), null);
        rpcEndPoint.setState(EndpointStateMachine.EndPointStates.GETVERSION);
        VersionEndpointTask versionTask = new VersionEndpointTask(rpcEndPoint, conf, ozoneContainer);
        EndpointStateMachine.EndPointStates newState = versionTask.call();
        // if version call worked the endpoint should automatically move to the
        // next state.
        Assert.assertEquals(EndpointStateMachine.EndPointStates.REGISTER, newState);
        // Now rpcEndpoint should remember the version it got from SCM
        Assert.assertNotNull(rpcEndPoint.getVersion());
    }
}
Also used : EndpointStateMachine(org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine) VersionEndpointTask(org.apache.hadoop.ozone.container.common.states.endpoint.VersionEndpointTask) ReplicationConfig(org.apache.hadoop.ozone.container.replication.ReplicationServer.ReplicationConfig) 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)

Aggregations

EndpointStateMachine (org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine)6 VersionEndpointTask (org.apache.hadoop.ozone.container.common.states.endpoint.VersionEndpointTask)6 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)4 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)4 MockDatanodeDetails.randomDatanodeDetails (org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanodeDetails)4 OzoneContainer (org.apache.hadoop.ozone.container.ozoneimpl.OzoneContainer)4 Test (org.junit.Test)4 ReplicationConfig (org.apache.hadoop.ozone.container.replication.ReplicationServer.ReplicationConfig)2 InetSocketAddress (java.net.InetSocketAddress)1 EnumMap (java.util.EnumMap)1 Callable (java.util.concurrent.Callable)1 EndPointStates (org.apache.hadoop.ozone.container.common.statemachine.EndpointStateMachine.EndPointStates)1 HddsVolume (org.apache.hadoop.ozone.container.common.volume.HddsVolume)1 GenericTestUtils (org.apache.ozone.test.GenericTestUtils)1