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);
}
}
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);
}
}
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);
}
}
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);
}
}
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());
}
}
Aggregations