use of org.apache.hadoop.hdds.scm.server.SCMClientProtocolServer in project ozone by apache.
the class TestScmSafeMode method testSCMSafeModeRestrictedOp.
@Test(timeout = 300_000)
public void testSCMSafeModeRestrictedOp() throws Exception {
cluster.stop();
cluster = builder.build();
StorageContainerManager scm = cluster.getStorageContainerManager();
assertTrue(scm.isInSafeMode());
LambdaTestUtils.intercept(SCMException.class, "SafeModePrecheck failed for allocateContainer", () -> {
scm.getClientProtocolServer().allocateContainer(ReplicationType.STAND_ALONE, ReplicationFactor.ONE, "");
});
cluster.startHddsDatanodes();
cluster.waitForClusterToBeReady();
cluster.waitTobeOutOfSafeMode();
assertFalse(scm.isInSafeMode());
TestStorageContainerManagerHelper helper = new TestStorageContainerManagerHelper(cluster, conf);
helper.createKeys(10, 4096);
SCMClientProtocolServer clientProtocolServer = cluster.getStorageContainerManager().getClientProtocolServer();
assertFalse((scm.getClientProtocolServer()).getSafeModeStatus());
final List<ContainerInfo> containers = scm.getContainerManager().getContainers();
scm.getEventQueue().fireEvent(SCMEvents.SAFE_MODE_STATUS, new SCMSafeModeManager.SafeModeStatus(true, true));
GenericTestUtils.waitFor(() -> {
return clientProtocolServer.getSafeModeStatus();
}, 50, 1000 * 30);
assertTrue(clientProtocolServer.getSafeModeStatus());
cluster.shutdownHddsDatanodes();
Thread.sleep(30000);
LambdaTestUtils.intercept(SCMException.class, "Open container " + containers.get(0).getContainerID() + " " + "doesn't have enough replicas to service this operation in Safe" + " mode.", () -> clientProtocolServer.getContainerWithPipeline(containers.get(0).getContainerID()));
}
use of org.apache.hadoop.hdds.scm.server.SCMClientProtocolServer in project ozone by apache.
the class TestStorageContainerManager method testRpcPermissionWithConf.
private void testRpcPermissionWithConf(OzoneConfiguration ozoneConf, String fakeRemoteUsername, boolean expectPermissionDenied) throws Exception {
MiniOzoneCluster cluster = MiniOzoneCluster.newBuilder(ozoneConf).build();
cluster.waitForClusterToBeReady();
try {
SCMClientProtocolServer mockClientServer = Mockito.spy(cluster.getStorageContainerManager().getClientProtocolServer());
when(mockClientServer.getRemoteUser()).thenReturn(UserGroupInformation.createRemoteUser(fakeRemoteUsername));
try {
mockClientServer.deleteContainer(ContainerTestHelper.getTestContainerID());
fail("Operation should fail, expecting an IOException here.");
} catch (Exception e) {
if (expectPermissionDenied) {
verifyPermissionDeniedException(e, fakeRemoteUsername);
} else {
// If passes permission check, it should fail with
// container not exist exception.
Assert.assertTrue(e instanceof ContainerNotFoundException);
}
}
try {
ContainerWithPipeline container2 = mockClientServer.allocateContainer(SCMTestUtils.getReplicationType(ozoneConf), HddsProtos.ReplicationFactor.ONE, OzoneConsts.OZONE);
if (expectPermissionDenied) {
fail("Operation should fail, expecting an IOException here.");
} else {
Assert.assertEquals(1, container2.getPipeline().getNodes().size());
}
} catch (Exception e) {
verifyPermissionDeniedException(e, fakeRemoteUsername);
}
try {
ContainerWithPipeline container3 = mockClientServer.allocateContainer(SCMTestUtils.getReplicationType(ozoneConf), HddsProtos.ReplicationFactor.ONE, OzoneConsts.OZONE);
if (expectPermissionDenied) {
fail("Operation should fail, expecting an IOException here.");
} else {
Assert.assertEquals(1, container3.getPipeline().getNodes().size());
}
} catch (Exception e) {
verifyPermissionDeniedException(e, fakeRemoteUsername);
}
try {
mockClientServer.getContainer(ContainerTestHelper.getTestContainerID());
fail("Operation should fail, expecting an IOException here.");
} catch (Exception e) {
if (expectPermissionDenied) {
verifyPermissionDeniedException(e, fakeRemoteUsername);
} else {
// If passes permission check, it should fail with
// key not exist exception.
Assert.assertTrue(e instanceof ContainerNotFoundException);
}
}
} finally {
cluster.shutdown();
}
}
Aggregations