Search in sources :

Example 6 with Handler

use of org.apache.hadoop.ozone.container.common.interfaces.Handler in project ozone by apache.

the class TestContainerMetrics method testContainerMetrics.

@Test
public void testContainerMetrics() throws Exception {
    XceiverServerGrpc server = null;
    XceiverClientGrpc client = null;
    long containerID = ContainerTestHelper.getTestContainerID();
    String path = GenericTestUtils.getRandomizedTempPath();
    try {
        final int interval = 1;
        Pipeline pipeline = MockPipeline.createSingleNodePipeline();
        OzoneConfiguration conf = new OzoneConfiguration();
        conf.setInt(OzoneConfigKeys.DFS_CONTAINER_IPC_PORT, pipeline.getFirstNode().getPort(DatanodeDetails.Port.Name.STANDALONE).getValue());
        conf.setInt(DFSConfigKeysLegacy.DFS_METRICS_PERCENTILES_INTERVALS_KEY, interval);
        DatanodeDetails datanodeDetails = randomDatanodeDetails();
        conf.set(ScmConfigKeys.HDDS_DATANODE_DIR_KEY, path);
        conf.set(OzoneConfigKeys.OZONE_METADATA_DIRS, path);
        VolumeSet volumeSet = new MutableVolumeSet(datanodeDetails.getUuidString(), conf, null, StorageVolume.VolumeType.DATA_VOLUME, null);
        ContainerSet containerSet = new ContainerSet();
        DatanodeStateMachine stateMachine = Mockito.mock(DatanodeStateMachine.class);
        StateContext context = Mockito.mock(StateContext.class);
        Mockito.when(stateMachine.getDatanodeDetails()).thenReturn(datanodeDetails);
        Mockito.when(context.getParent()).thenReturn(stateMachine);
        ContainerMetrics metrics = ContainerMetrics.create(conf);
        Map<ContainerProtos.ContainerType, Handler> handlers = Maps.newHashMap();
        for (ContainerProtos.ContainerType containerType : ContainerProtos.ContainerType.values()) {
            handlers.put(containerType, Handler.getHandlerForContainerType(containerType, conf, context.getParent().getDatanodeDetails().getUuidString(), containerSet, volumeSet, metrics, c -> {
            }));
        }
        HddsDispatcher dispatcher = new HddsDispatcher(conf, containerSet, volumeSet, handlers, context, metrics, null);
        dispatcher.setClusterId(UUID.randomUUID().toString());
        server = new XceiverServerGrpc(datanodeDetails, conf, dispatcher, null);
        client = new XceiverClientGrpc(pipeline, conf);
        server.start();
        client.connect();
        // Create container
        ContainerCommandRequestProto request = ContainerTestHelper.getCreateContainerRequest(containerID, pipeline);
        ContainerCommandResponseProto response = client.sendCommand(request);
        Assert.assertEquals(ContainerProtos.Result.SUCCESS, response.getResult());
        // Write Chunk
        BlockID blockID = ContainerTestHelper.getTestBlockID(containerID);
        ContainerTestHelper.getWriteChunkRequest(pipeline, blockID, 1024, null);
        ContainerProtos.ContainerCommandRequestProto writeChunkRequest = ContainerTestHelper.getWriteChunkRequest(pipeline, blockID, 1024, null);
        response = client.sendCommand(writeChunkRequest);
        Assert.assertEquals(ContainerProtos.Result.SUCCESS, response.getResult());
        // Read Chunk
        ContainerProtos.ContainerCommandRequestProto readChunkRequest = ContainerTestHelper.getReadChunkRequest(pipeline, writeChunkRequest.getWriteChunk());
        response = client.sendCommand(readChunkRequest);
        Assert.assertEquals(ContainerProtos.Result.SUCCESS, response.getResult());
        MetricsRecordBuilder containerMetrics = getMetrics("StorageContainerMetrics");
        assertCounter("NumOps", 3L, containerMetrics);
        assertCounter("numCreateContainer", 1L, containerMetrics);
        assertCounter("numWriteChunk", 1L, containerMetrics);
        assertCounter("numReadChunk", 1L, containerMetrics);
        assertCounter("bytesWriteChunk", 1024L, containerMetrics);
        assertCounter("bytesReadChunk", 1024L, containerMetrics);
        String sec = interval + "s";
        Thread.sleep((interval + 1) * 1000);
        assertQuantileGauges("WriteChunkNanos" + sec, containerMetrics);
        // Check VolumeIOStats metrics
        List<HddsVolume> volumes = StorageVolumeUtil.getHddsVolumesList(volumeSet.getVolumesList());
        HddsVolume hddsVolume = volumes.get(0);
        MetricsRecordBuilder volumeIOMetrics = getMetrics(hddsVolume.getVolumeIOStats().getMetricsSourceName());
        assertCounter("ReadBytes", 1024L, volumeIOMetrics);
        assertCounter("ReadOpCount", 1L, volumeIOMetrics);
        assertCounter("WriteBytes", 1024L, volumeIOMetrics);
        assertCounter("WriteOpCount", 1L, volumeIOMetrics);
    } finally {
        if (client != null) {
            client.close();
        }
        if (server != null) {
            server.stop();
        }
        // clean up volume dir
        File file = new File(path);
        if (file.exists()) {
            FileUtil.fullyDelete(file);
        }
    }
}
Also used : ScmConfigKeys(org.apache.hadoop.hdds.scm.ScmConfigKeys) HddsDispatcher(org.apache.hadoop.ozone.container.common.impl.HddsDispatcher) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) MockPipeline(org.apache.hadoop.hdds.scm.pipeline.MockPipeline) MockDatanodeDetails.randomDatanodeDetails(org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanodeDetails) BlockID(org.apache.hadoop.hdds.client.BlockID) StateContext(org.apache.hadoop.ozone.container.common.statemachine.StateContext) ContainerCommandResponseProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProto) ContainerSet(org.apache.hadoop.ozone.container.common.impl.ContainerSet) ContainerProtos(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos) MutableVolumeSet(org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet) MetricsAsserts.getMetrics(org.apache.hadoop.test.MetricsAsserts.getMetrics) HddsVolume(org.apache.hadoop.ozone.container.common.volume.HddsVolume) MetricsAsserts.assertCounter(org.apache.hadoop.test.MetricsAsserts.assertCounter) Handler(org.apache.hadoop.ozone.container.common.interfaces.Handler) MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder) Map(java.util.Map) Timeout(org.junit.rules.Timeout) DatanodeStateMachine(org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine) StorageVolumeUtil(org.apache.hadoop.ozone.container.common.utils.StorageVolumeUtil) FileUtil(org.apache.hadoop.fs.FileUtil) ContainerTestHelper(org.apache.hadoop.ozone.container.ContainerTestHelper) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) ContainerMetrics(org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) Test(org.junit.Test) UUID(java.util.UUID) XceiverServerGrpc(org.apache.hadoop.ozone.container.common.transport.server.XceiverServerGrpc) Maps(com.google.common.collect.Maps) File(java.io.File) XceiverClientGrpc(org.apache.hadoop.hdds.scm.XceiverClientGrpc) Mockito(org.mockito.Mockito) List(java.util.List) StorageVolume(org.apache.hadoop.ozone.container.common.volume.StorageVolume) VolumeSet(org.apache.hadoop.ozone.container.common.volume.VolumeSet) Rule(org.junit.Rule) MetricsAsserts.assertQuantileGauges(org.apache.hadoop.test.MetricsAsserts.assertQuantileGauges) OzoneConfigKeys(org.apache.hadoop.ozone.OzoneConfigKeys) ContainerCommandRequestProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto) Assert(org.junit.Assert) GenericTestUtils(org.apache.ozone.test.GenericTestUtils) DFSConfigKeysLegacy(org.apache.hadoop.hdds.DFSConfigKeysLegacy) ContainerCommandRequestProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto) HddsDispatcher(org.apache.hadoop.ozone.container.common.impl.HddsDispatcher) ContainerCommandResponseProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProto) MockDatanodeDetails.randomDatanodeDetails(org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanodeDetails) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) XceiverClientGrpc(org.apache.hadoop.hdds.scm.XceiverClientGrpc) ContainerCommandRequestProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto) DatanodeStateMachine(org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine) MutableVolumeSet(org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet) MutableVolumeSet(org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet) VolumeSet(org.apache.hadoop.ozone.container.common.volume.VolumeSet) MetricsRecordBuilder(org.apache.hadoop.metrics2.MetricsRecordBuilder) ContainerProtos(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos) StateContext(org.apache.hadoop.ozone.container.common.statemachine.StateContext) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) Handler(org.apache.hadoop.ozone.container.common.interfaces.Handler) XceiverServerGrpc(org.apache.hadoop.ozone.container.common.transport.server.XceiverServerGrpc) MockPipeline(org.apache.hadoop.hdds.scm.pipeline.MockPipeline) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) HddsVolume(org.apache.hadoop.ozone.container.common.volume.HddsVolume) ContainerSet(org.apache.hadoop.ozone.container.common.impl.ContainerSet) BlockID(org.apache.hadoop.hdds.client.BlockID) ContainerMetrics(org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics) File(java.io.File) Test(org.junit.Test)

Example 7 with Handler

use of org.apache.hadoop.ozone.container.common.interfaces.Handler in project ozone by apache.

the class TestSecureContainerServer method createDispatcher.

private static HddsDispatcher createDispatcher(DatanodeDetails dd, UUID scmId, OzoneConfiguration conf) throws IOException {
    ContainerSet containerSet = new ContainerSet();
    conf.set(HDDS_DATANODE_DIR_KEY, Paths.get(TEST_DIR, "dfs", "data", "hdds", RandomStringUtils.randomAlphabetic(4)).toString());
    conf.set(OZONE_METADATA_DIRS, TEST_DIR);
    VolumeSet volumeSet = new MutableVolumeSet(dd.getUuidString(), conf, null, StorageVolume.VolumeType.DATA_VOLUME, null);
    DatanodeStateMachine stateMachine = Mockito.mock(DatanodeStateMachine.class);
    StateContext context = Mockito.mock(StateContext.class);
    Mockito.when(stateMachine.getDatanodeDetails()).thenReturn(dd);
    Mockito.when(context.getParent()).thenReturn(stateMachine);
    ContainerMetrics metrics = ContainerMetrics.create(conf);
    Map<ContainerProtos.ContainerType, Handler> handlers = Maps.newHashMap();
    for (ContainerProtos.ContainerType containerType : ContainerProtos.ContainerType.values()) {
        handlers.put(containerType, Handler.getHandlerForContainerType(containerType, conf, dd.getUuid().toString(), containerSet, volumeSet, metrics, c -> {
        }));
    }
    HddsDispatcher hddsDispatcher = new HddsDispatcher(conf, containerSet, volumeSet, handlers, context, metrics, TokenVerifier.create(new SecurityConfig((conf)), caClient));
    hddsDispatcher.setClusterId(scmId.toString());
    return hddsDispatcher;
}
Also used : MockPipeline(org.apache.hadoop.hdds.scm.pipeline.MockPipeline) XceiverServerSpi(org.apache.hadoop.ozone.container.common.transport.server.XceiverServerSpi) ContainerTestHelper.newGetBlockRequestBuilder(org.apache.hadoop.ozone.container.ContainerTestHelper.newGetBlockRequestBuilder) ContainerCommandResponseProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProto) ContainerProtocolCalls(org.apache.hadoop.hdds.scm.storage.ContainerProtocolCalls) ContainerSet(org.apache.hadoop.ozone.container.common.impl.ContainerSet) DefaultMetricsSystem(org.apache.hadoop.metrics2.lib.DefaultMetricsSystem) MutableVolumeSet(org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet) Map(java.util.Map) After(org.junit.After) MockDatanodeDetails(org.apache.hadoop.hdds.protocol.MockDatanodeDetails) HddsConfigKeys(org.apache.hadoop.hdds.HddsConfigKeys) CheckedBiConsumer(org.apache.ratis.util.function.CheckedBiConsumer) XceiverServerRatis(org.apache.hadoop.ozone.container.common.transport.server.ratis.XceiverServerRatis) EnumSet(java.util.EnumSet) OZONE_METADATA_DIRS(org.apache.hadoop.hdds.HddsConfigKeys.OZONE_METADATA_DIRS) CertificateClientTestImpl(org.apache.hadoop.ozone.client.CertificateClientTestImpl) AfterClass(org.junit.AfterClass) SecurityConfig(org.apache.hadoop.hdds.security.x509.SecurityConfig) TokenVerifier(org.apache.hadoop.hdds.security.token.TokenVerifier) ContainerTestHelper.getCreateContainerRequest(org.apache.hadoop.ozone.container.ContainerTestHelper.getCreateContainerRequest) OZONE_SECURITY_ENABLED_KEY(org.apache.hadoop.ozone.OzoneConfigKeys.OZONE_SECURITY_ENABLED_KEY) UUID(java.util.UUID) XceiverServerGrpc(org.apache.hadoop.ozone.container.common.transport.server.XceiverServerGrpc) List(java.util.List) OzoneBlockTokenSecretManager(org.apache.hadoop.ozone.security.OzoneBlockTokenSecretManager) XceiverClientSpi(org.apache.hadoop.hdds.scm.XceiverClientSpi) HDDS_BLOCK_TOKEN_ENABLED(org.apache.hadoop.hdds.HddsConfigKeys.HDDS_BLOCK_TOKEN_ENABLED) OzoneConfigKeys(org.apache.hadoop.ozone.OzoneConfigKeys) RandomStringUtils(org.apache.commons.lang3.RandomStringUtils) ContainerCommandRequestProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto) GenericTestUtils(org.apache.ozone.test.GenericTestUtils) ContainerTestHelper.getTestBlockID(org.apache.hadoop.ozone.container.ContainerTestHelper.getTestBlockID) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) HddsDispatcher(org.apache.hadoop.ozone.container.common.impl.HddsDispatcher) RandomUtils(org.apache.commons.lang3.RandomUtils) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) RatisTestHelper(org.apache.hadoop.ozone.RatisTestHelper) BlockID(org.apache.hadoop.hdds.client.BlockID) ContainerController(org.apache.hadoop.ozone.container.ozoneimpl.ContainerController) BeforeClass(org.junit.BeforeClass) StateContext(org.apache.hadoop.ozone.container.common.statemachine.StateContext) ContainerTestHelper.newReadChunkRequestBuilder(org.apache.hadoop.ozone.container.ContainerTestHelper.newReadChunkRequestBuilder) ContainerProtos(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos) ArrayList(java.util.ArrayList) XceiverClientRatis(org.apache.hadoop.hdds.scm.XceiverClientRatis) Handler(org.apache.hadoop.ozone.container.common.interfaces.Handler) ContainerTestHelper.getTestContainerID(org.apache.hadoop.ozone.container.ContainerTestHelper.getTestContainerID) ContainerDispatcher(org.apache.hadoop.ozone.container.common.interfaces.ContainerDispatcher) DatanodeStateMachine(org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine) ContainerTestHelper.newGetCommittedBlockLengthBuilder(org.apache.hadoop.ozone.container.ContainerTestHelper.newGetCommittedBlockLengthBuilder) HddsUtils.isReadOnly(org.apache.hadoop.hdds.HddsUtils.isReadOnly) AccessModeProto(org.apache.hadoop.hdds.protocol.proto.HddsProtos.BlockTokenSecretProto.AccessModeProto) Assert.assertNotNull(org.junit.Assert.assertNotNull) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) ContainerMetrics(org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) ContainerID(org.apache.hadoop.hdds.scm.container.ContainerID) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) Token(org.apache.hadoop.security.token.Token) Maps(com.google.common.collect.Maps) File(java.io.File) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) XceiverClientGrpc(org.apache.hadoop.hdds.scm.XceiverClientGrpc) ContainerTokenSecretManager(org.apache.hadoop.hdds.security.token.ContainerTokenSecretManager) ContainerTestHelper.newPutBlockRequestBuilder(org.apache.hadoop.ozone.container.ContainerTestHelper.newPutBlockRequestBuilder) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Mockito(org.mockito.Mockito) OzoneBlockTokenIdentifier(org.apache.hadoop.hdds.security.token.OzoneBlockTokenIdentifier) StorageVolume(org.apache.hadoop.ozone.container.common.volume.StorageVolume) VolumeSet(org.apache.hadoop.ozone.container.common.volume.VolumeSet) Paths(java.nio.file.Paths) HDDS_DATANODE_DIR_KEY(org.apache.hadoop.hdds.scm.ScmConfigKeys.HDDS_DATANODE_DIR_KEY) ContainerTestHelper.newWriteChunkRequestBuilder(org.apache.hadoop.ozone.container.ContainerTestHelper.newWriteChunkRequestBuilder) RpcType(org.apache.ratis.rpc.RpcType) ExitUtils(org.apache.ratis.util.ExitUtils) GRPC(org.apache.ratis.rpc.SupportedRpcType.GRPC) Assert(org.junit.Assert) SUCCESS(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.Result.SUCCESS) Assert.assertEquals(org.junit.Assert.assertEquals) ContainerProtos(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos) StateContext(org.apache.hadoop.ozone.container.common.statemachine.StateContext) Handler(org.apache.hadoop.ozone.container.common.interfaces.Handler) HddsDispatcher(org.apache.hadoop.ozone.container.common.impl.HddsDispatcher) ContainerSet(org.apache.hadoop.ozone.container.common.impl.ContainerSet) SecurityConfig(org.apache.hadoop.hdds.security.x509.SecurityConfig) DatanodeStateMachine(org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine) MutableVolumeSet(org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet) ContainerMetrics(org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics) MutableVolumeSet(org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet) VolumeSet(org.apache.hadoop.ozone.container.common.volume.VolumeSet)

Example 8 with Handler

use of org.apache.hadoop.ozone.container.common.interfaces.Handler in project ozone by apache.

the class TestContainerServer method testClientServerWithContainerDispatcher.

@Test
public void testClientServerWithContainerDispatcher() throws Exception {
    XceiverServerGrpc server = null;
    XceiverClientGrpc client = null;
    UUID scmId = UUID.randomUUID();
    try {
        Pipeline pipeline = MockPipeline.createSingleNodePipeline();
        OzoneConfiguration conf = new OzoneConfiguration();
        conf.setInt(OzoneConfigKeys.DFS_CONTAINER_IPC_PORT, pipeline.getFirstNode().getPort(DatanodeDetails.Port.Name.STANDALONE).getValue());
        ContainerSet containerSet = new ContainerSet();
        VolumeSet volumeSet = mock(MutableVolumeSet.class);
        ContainerMetrics metrics = ContainerMetrics.create(conf);
        Map<ContainerProtos.ContainerType, Handler> handlers = Maps.newHashMap();
        DatanodeDetails datanodeDetails = randomDatanodeDetails();
        DatanodeStateMachine stateMachine = Mockito.mock(DatanodeStateMachine.class);
        StateContext context = Mockito.mock(StateContext.class);
        Mockito.when(stateMachine.getDatanodeDetails()).thenReturn(datanodeDetails);
        Mockito.when(context.getParent()).thenReturn(stateMachine);
        for (ContainerProtos.ContainerType containerType : ContainerProtos.ContainerType.values()) {
            handlers.put(containerType, Handler.getHandlerForContainerType(containerType, conf, context.getParent().getDatanodeDetails().getUuidString(), containerSet, volumeSet, metrics, c -> {
            }));
        }
        HddsDispatcher dispatcher = new HddsDispatcher(conf, containerSet, volumeSet, handlers, context, metrics, null);
        dispatcher.setClusterId(scmId.toString());
        dispatcher.init();
        server = new XceiverServerGrpc(datanodeDetails, conf, dispatcher, caClient);
        client = new XceiverClientGrpc(pipeline, conf);
        server.start();
        client.connect();
        ContainerCommandRequestProto request = ContainerTestHelper.getCreateContainerRequest(ContainerTestHelper.getTestContainerID(), pipeline);
        ContainerCommandResponseProto response = client.sendCommand(request);
        Assert.assertEquals(ContainerProtos.Result.SUCCESS, response.getResult());
    } finally {
        if (client != null) {
            client.close();
        }
        if (server != null) {
            server.stop();
        }
    }
}
Also used : MockPipeline(org.apache.hadoop.hdds.scm.pipeline.MockPipeline) XceiverServerSpi(org.apache.hadoop.ozone.container.common.transport.server.XceiverServerSpi) MockDatanodeDetails.randomDatanodeDetails(org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanodeDetails) NETTY(org.apache.ratis.rpc.SupportedRpcType.NETTY) ContainerCommandResponseProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProto) ContainerSet(org.apache.hadoop.ozone.container.common.impl.ContainerSet) MutableVolumeSet(org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet) DispatcherContext(org.apache.hadoop.ozone.container.common.transport.server.ratis.DispatcherContext) DNCertificateClient(org.apache.hadoop.hdds.security.x509.certificate.client.DNCertificateClient) Map(java.util.Map) HddsConfigKeys(org.apache.hadoop.hdds.HddsConfigKeys) CheckedBiConsumer(org.apache.ratis.util.function.CheckedBiConsumer) XceiverServerRatis(org.apache.hadoop.ozone.container.common.transport.server.ratis.XceiverServerRatis) ContainerTestHelper(org.apache.hadoop.ozone.container.ContainerTestHelper) CertificateClient(org.apache.hadoop.hdds.security.x509.certificate.client.CertificateClient) SecurityConfig(org.apache.hadoop.hdds.security.x509.SecurityConfig) UUID(java.util.UUID) XceiverServerGrpc(org.apache.hadoop.ozone.container.common.transport.server.XceiverServerGrpc) List(java.util.List) XceiverClientSpi(org.apache.hadoop.hdds.scm.XceiverClientSpi) StorageContainerException(org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException) OzoneConfigKeys(org.apache.hadoop.ozone.OzoneConfigKeys) ContainerCommandRequestProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto) GenericTestUtils(org.apache.ozone.test.GenericTestUtils) Mockito.mock(org.mockito.Mockito.mock) HddsDispatcher(org.apache.hadoop.ozone.container.common.impl.HddsDispatcher) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) RatisTestHelper(org.apache.hadoop.ozone.RatisTestHelper) ContainerController(org.apache.hadoop.ozone.container.ozoneimpl.ContainerController) BeforeClass(org.junit.BeforeClass) StateContext(org.apache.hadoop.ozone.container.common.statemachine.StateContext) ContainerProtos(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos) ArrayList(java.util.ArrayList) XceiverClientRatis(org.apache.hadoop.hdds.scm.XceiverClientRatis) Handler(org.apache.hadoop.ozone.container.common.interfaces.Handler) ContainerDispatcher(org.apache.hadoop.ozone.container.common.interfaces.ContainerDispatcher) DatanodeStateMachine(org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) ContainerMetrics(org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics) IOException(java.io.IOException) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) Test(org.junit.Test) Maps(com.google.common.collect.Maps) File(java.io.File) XceiverClientGrpc(org.apache.hadoop.hdds.scm.XceiverClientGrpc) Mockito(org.mockito.Mockito) VolumeSet(org.apache.hadoop.ozone.container.common.volume.VolumeSet) Ignore(org.junit.Ignore) RpcType(org.apache.ratis.rpc.RpcType) GRPC(org.apache.ratis.rpc.SupportedRpcType.GRPC) Assert(org.junit.Assert) ContainerProtos(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos) StateContext(org.apache.hadoop.ozone.container.common.statemachine.StateContext) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) Handler(org.apache.hadoop.ozone.container.common.interfaces.Handler) XceiverServerGrpc(org.apache.hadoop.ozone.container.common.transport.server.XceiverServerGrpc) HddsDispatcher(org.apache.hadoop.ozone.container.common.impl.HddsDispatcher) MockPipeline(org.apache.hadoop.hdds.scm.pipeline.MockPipeline) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) ContainerCommandResponseProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProto) ContainerSet(org.apache.hadoop.ozone.container.common.impl.ContainerSet) MockDatanodeDetails.randomDatanodeDetails(org.apache.hadoop.hdds.protocol.MockDatanodeDetails.randomDatanodeDetails) DatanodeDetails(org.apache.hadoop.hdds.protocol.DatanodeDetails) XceiverClientGrpc(org.apache.hadoop.hdds.scm.XceiverClientGrpc) ContainerCommandRequestProto(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto) DatanodeStateMachine(org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine) UUID(java.util.UUID) ContainerMetrics(org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics) MutableVolumeSet(org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet) VolumeSet(org.apache.hadoop.ozone.container.common.volume.VolumeSet) Test(org.junit.Test)

Example 9 with Handler

use of org.apache.hadoop.ozone.container.common.interfaces.Handler in project ozone by apache.

the class ClosedContainerReplicator method initializeReplicationSupervisor.

@NotNull
private void initializeReplicationSupervisor(ConfigurationSource conf) throws IOException {
    String fakeDatanodeUuid = datanode;
    if (fakeDatanodeUuid.isEmpty()) {
        fakeDatanodeUuid = UUID.randomUUID().toString();
    }
    ContainerSet containerSet = new ContainerSet();
    ContainerMetrics metrics = ContainerMetrics.create(conf);
    MutableVolumeSet volumeSet = new MutableVolumeSet(fakeDatanodeUuid, conf, null, StorageVolume.VolumeType.DATA_VOLUME, null);
    Map<ContainerType, Handler> handlers = new HashMap<>();
    for (ContainerType containerType : ContainerType.values()) {
        final Handler handler = Handler.getHandlerForContainerType(containerType, conf, fakeDatanodeUuid, containerSet, volumeSet, metrics, containerReplicaProto -> {
        });
        handler.setClusterID(UUID.randomUUID().toString());
        handlers.put(containerType, handler);
    }
    ContainerController controller = new ContainerController(containerSet, handlers);
    ContainerReplicator replicator = new DownloadAndImportReplicator(containerSet, controller, new SimpleContainerDownloader(conf, null), new TarContainerPacker());
    supervisor = new ReplicationSupervisor(containerSet, replicator, 10);
}
Also used : ReplicationSupervisor(org.apache.hadoop.ozone.container.replication.ReplicationSupervisor) HashMap(java.util.HashMap) DownloadAndImportReplicator(org.apache.hadoop.ozone.container.replication.DownloadAndImportReplicator) ContainerType(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerType) Handler(org.apache.hadoop.ozone.container.common.interfaces.Handler) ContainerController(org.apache.hadoop.ozone.container.ozoneimpl.ContainerController) SimpleContainerDownloader(org.apache.hadoop.ozone.container.replication.SimpleContainerDownloader) TarContainerPacker(org.apache.hadoop.ozone.container.keyvalue.TarContainerPacker) ContainerSet(org.apache.hadoop.ozone.container.common.impl.ContainerSet) MutableVolumeSet(org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet) ContainerMetrics(org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics) ContainerReplicator(org.apache.hadoop.ozone.container.replication.ContainerReplicator) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with Handler

use of org.apache.hadoop.ozone.container.common.interfaces.Handler in project ozone by apache.

the class HddsDispatcher method validateContainerCommand.

/**
 * This will be called as a part of creating the log entry during
 * startTransaction in Ratis on the leader node. In such cases, if the
 * container is not in open state for writing we should just fail.
 * Leader will propagate the exception to client.
 * @param msg  container command proto
 * @throws StorageContainerException In case container state is open for write
 *         requests and in invalid state for read requests.
 */
@Override
public void validateContainerCommand(ContainerCommandRequestProto msg) throws StorageContainerException {
    long containerID = msg.getContainerID();
    Container container = getContainer(containerID);
    if (container == null) {
        return;
    }
    ContainerType containerType = container.getContainerType();
    Type cmdType = msg.getCmdType();
    AuditAction action = ContainerCommandRequestPBHelper.getAuditAction(cmdType);
    EventType eventType = getEventType(msg);
    Map<String, String> params = ContainerCommandRequestPBHelper.getAuditParams(msg);
    Handler handler = getHandler(containerType);
    if (handler == null) {
        StorageContainerException ex = new StorageContainerException("Invalid " + "ContainerType " + containerType, ContainerProtos.Result.CONTAINER_INTERNAL_ERROR);
        audit(action, eventType, params, AuditEventStatus.FAILURE, ex);
        throw ex;
    }
    State containerState = container.getContainerState();
    if (!HddsUtils.isReadOnly(msg) && containerState != State.OPEN) {
        switch(cmdType) {
            case CreateContainer:
                // Create Container is idempotent. There is nothing to validate.
                break;
            case CloseContainer:
                // while execution. Nothing to validate here.
                break;
            default:
                // if the container is not open, no updates can happen. Just throw
                // an exception
                ContainerNotOpenException cex = new ContainerNotOpenException("Container " + containerID + " in " + containerState + " state");
                audit(action, eventType, params, AuditEventStatus.FAILURE, cex);
                throw cex;
        }
    } else if (HddsUtils.isReadOnly(msg) && containerState == State.INVALID) {
        InvalidContainerStateException iex = new InvalidContainerStateException("Container " + containerID + " in " + containerState + " state");
        audit(action, eventType, params, AuditEventStatus.FAILURE, iex);
        throw iex;
    }
    try {
        validateToken(msg);
    } catch (IOException ioe) {
        throw new StorageContainerException("Block token verification failed. " + ioe.getMessage(), ioe, ContainerProtos.Result.BLOCK_TOKEN_VERIFICATION_FAILED);
    }
}
Also used : ContainerType(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerType) Handler(org.apache.hadoop.ozone.container.common.interfaces.Handler) IOException(java.io.IOException) ContainerNotOpenException(org.apache.hadoop.hdds.scm.container.common.helpers.ContainerNotOpenException) AuditAction(org.apache.hadoop.ozone.audit.AuditAction) InvalidContainerStateException(org.apache.hadoop.hdds.scm.container.common.helpers.InvalidContainerStateException) Container(org.apache.hadoop.ozone.container.common.interfaces.Container) AuditLoggerType(org.apache.hadoop.ozone.audit.AuditLoggerType) Type(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.Type) ContainerType(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerType) State(org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerDataProto.State) StorageContainerException(org.apache.hadoop.hdds.scm.container.common.helpers.StorageContainerException)

Aggregations

Handler (org.apache.hadoop.ozone.container.common.interfaces.Handler)11 ContainerType (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerType)7 ContainerMetrics (org.apache.hadoop.ozone.container.common.helpers.ContainerMetrics)7 MutableVolumeSet (org.apache.hadoop.ozone.container.common.volume.MutableVolumeSet)7 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)6 ContainerCommandResponseProto (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandResponseProto)5 ContainerSet (org.apache.hadoop.ozone.container.common.impl.ContainerSet)5 DatanodeStateMachine (org.apache.hadoop.ozone.container.common.statemachine.DatanodeStateMachine)5 StateContext (org.apache.hadoop.ozone.container.common.statemachine.StateContext)5 File (java.io.File)4 IOException (java.io.IOException)4 UUID (java.util.UUID)4 DatanodeDetails (org.apache.hadoop.hdds.protocol.DatanodeDetails)4 ContainerProtos (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos)4 ContainerCommandRequestProto (org.apache.hadoop.hdds.protocol.datanode.proto.ContainerProtos.ContainerCommandRequestProto)4 HddsDispatcher (org.apache.hadoop.ozone.container.common.impl.HddsDispatcher)4 VolumeSet (org.apache.hadoop.ozone.container.common.volume.VolumeSet)4 ContainerController (org.apache.hadoop.ozone.container.ozoneimpl.ContainerController)4 Test (org.junit.Test)4 Maps (com.google.common.collect.Maps)3