Search in sources :

Example 1 with SCMClientProtocolServer

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()));
}
Also used : StorageContainerManager(org.apache.hadoop.hdds.scm.server.StorageContainerManager) ContainerInfo(org.apache.hadoop.hdds.scm.container.ContainerInfo) TestStorageContainerManagerHelper(org.apache.hadoop.ozone.TestStorageContainerManagerHelper) SCMClientProtocolServer(org.apache.hadoop.hdds.scm.server.SCMClientProtocolServer) SCMSafeModeManager(org.apache.hadoop.hdds.scm.safemode.SCMSafeModeManager) Test(org.junit.Test)

Example 2 with SCMClientProtocolServer

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();
    }
}
Also used : SCMClientProtocolServer(org.apache.hadoop.hdds.scm.server.SCMClientProtocolServer) ContainerNotFoundException(org.apache.hadoop.hdds.scm.container.ContainerNotFoundException) ContainerWithPipeline(org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline) AuthenticationException(org.apache.hadoop.security.authentication.client.AuthenticationException) SCMException(org.apache.hadoop.hdds.scm.exceptions.SCMException) IOException(java.io.IOException) ContainerNotFoundException(org.apache.hadoop.hdds.scm.container.ContainerNotFoundException) ExpectedException(org.junit.rules.ExpectedException)

Aggregations

SCMClientProtocolServer (org.apache.hadoop.hdds.scm.server.SCMClientProtocolServer)2 IOException (java.io.IOException)1 ContainerInfo (org.apache.hadoop.hdds.scm.container.ContainerInfo)1 ContainerNotFoundException (org.apache.hadoop.hdds.scm.container.ContainerNotFoundException)1 ContainerWithPipeline (org.apache.hadoop.hdds.scm.container.common.helpers.ContainerWithPipeline)1 SCMException (org.apache.hadoop.hdds.scm.exceptions.SCMException)1 SCMSafeModeManager (org.apache.hadoop.hdds.scm.safemode.SCMSafeModeManager)1 StorageContainerManager (org.apache.hadoop.hdds.scm.server.StorageContainerManager)1 TestStorageContainerManagerHelper (org.apache.hadoop.ozone.TestStorageContainerManagerHelper)1 AuthenticationException (org.apache.hadoop.security.authentication.client.AuthenticationException)1 Test (org.junit.Test)1 ExpectedException (org.junit.rules.ExpectedException)1