Search in sources :

Example 1 with ResolvedBucket

use of org.apache.hadoop.ozone.om.ResolvedBucket in project ozone by apache.

the class TestOMKeyRequest method setup.

@Before
public void setup() throws Exception {
    ozoneManager = Mockito.mock(OzoneManager.class);
    omMetrics = OMMetrics.create();
    OzoneConfiguration ozoneConfiguration = getOzoneConfiguration();
    ozoneConfiguration.set(OMConfigKeys.OZONE_OM_DB_DIRS, folder.newFolder().getAbsolutePath());
    ozoneConfiguration.set(OzoneConfigKeys.OZONE_METADATA_DIRS, folder.newFolder().getAbsolutePath());
    omMetadataManager = new OmMetadataManagerImpl(ozoneConfiguration);
    when(ozoneManager.getMetrics()).thenReturn(omMetrics);
    when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
    when(ozoneManager.getConfiguration()).thenReturn(ozoneConfiguration);
    OMLayoutVersionManager lvm = mock(OMLayoutVersionManager.class);
    when(lvm.getMetadataLayoutVersion()).thenReturn(0);
    when(ozoneManager.getVersionManager()).thenReturn(lvm);
    when(ozoneManager.isRatisEnabled()).thenReturn(true);
    auditLogger = Mockito.mock(AuditLogger.class);
    when(ozoneManager.getAuditLogger()).thenReturn(auditLogger);
    when(ozoneManager.isAdmin(any(String.class))).thenReturn(true);
    when(ozoneManager.isAdmin(any(UserGroupInformation.class))).thenReturn(true);
    Mockito.doNothing().when(auditLogger).logWrite(any(AuditMessage.class));
    scmClient = Mockito.mock(ScmClient.class);
    ozoneBlockTokenSecretManager = Mockito.mock(OzoneBlockTokenSecretManager.class);
    scmBlockLocationProtocol = Mockito.mock(ScmBlockLocationProtocol.class);
    keyManager = new KeyManagerImpl(ozoneManager, scmClient, ozoneConfiguration, "");
    when(ozoneManager.getScmClient()).thenReturn(scmClient);
    when(ozoneManager.getBlockTokenSecretManager()).thenReturn(ozoneBlockTokenSecretManager);
    when(ozoneManager.getScmBlockSize()).thenReturn(scmBlockSize);
    when(ozoneManager.getPreallocateBlocksMax()).thenReturn(2);
    when(ozoneManager.isGrpcBlockTokenEnabled()).thenReturn(false);
    when(ozoneManager.getOMNodeId()).thenReturn(UUID.randomUUID().toString());
    when(scmClient.getBlockClient()).thenReturn(scmBlockLocationProtocol);
    when(ozoneManager.getKeyManager()).thenReturn(keyManager);
    prepareState = new OzoneManagerPrepareState(ozoneConfiguration);
    when(ozoneManager.getPrepareState()).thenReturn(prepareState);
    Pipeline pipeline = Pipeline.newBuilder().setState(Pipeline.PipelineState.OPEN).setId(PipelineID.randomId()).setReplicationConfig(StandaloneReplicationConfig.getInstance(ReplicationFactor.ONE)).setNodes(new ArrayList<>()).build();
    AllocatedBlock allocatedBlock = new AllocatedBlock.Builder().setContainerBlockID(new ContainerBlockID(CONTAINER_ID, LOCAL_ID)).setPipeline(pipeline).build();
    List<AllocatedBlock> allocatedBlocks = new ArrayList<>();
    allocatedBlocks.add(allocatedBlock);
    when(scmBlockLocationProtocol.allocateBlock(anyLong(), anyInt(), any(), anyString(), any())).thenReturn(allocatedBlocks);
    volumeName = UUID.randomUUID().toString();
    bucketName = UUID.randomUUID().toString();
    keyName = UUID.randomUUID().toString();
    replicationFactor = HddsProtos.ReplicationFactor.ONE;
    replicationType = HddsProtos.ReplicationType.RATIS;
    clientID = Time.now();
    dataSize = 1000L;
    random = new Random();
    version = 0L;
    Pair<String, String> volumeAndBucket = Pair.of(volumeName, bucketName);
    when(ozoneManager.resolveBucketLink(any(KeyArgs.class), any(OMClientRequest.class))).thenReturn(new ResolvedBucket(volumeAndBucket, volumeAndBucket));
    when(ozoneManager.resolveBucketLink(any(Pair.class), any(OMClientRequest.class))).thenReturn(new ResolvedBucket(volumeAndBucket, volumeAndBucket));
}
Also used : AuditMessage(org.apache.hadoop.ozone.audit.AuditMessage) ArrayList(java.util.ArrayList) OzoneManagerPrepareState(org.apache.hadoop.ozone.om.OzoneManagerPrepareState) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) OMLayoutVersionManager(org.apache.hadoop.ozone.om.upgrade.OMLayoutVersionManager) Random(java.util.Random) OzoneManager(org.apache.hadoop.ozone.om.OzoneManager) ContainerBlockID(org.apache.hadoop.hdds.client.ContainerBlockID) ResolvedBucket(org.apache.hadoop.ozone.om.ResolvedBucket) UserGroupInformation(org.apache.hadoop.security.UserGroupInformation) Pair(org.apache.commons.lang3.tuple.Pair) OMClientRequest(org.apache.hadoop.ozone.om.request.OMClientRequest) AuditLogger(org.apache.hadoop.ozone.audit.AuditLogger) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) KeyArgs(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs) ScmClient(org.apache.hadoop.ozone.om.ScmClient) Pipeline(org.apache.hadoop.hdds.scm.pipeline.Pipeline) OmMetadataManagerImpl(org.apache.hadoop.ozone.om.OmMetadataManagerImpl) KeyManagerImpl(org.apache.hadoop.ozone.om.KeyManagerImpl) ScmBlockLocationProtocol(org.apache.hadoop.hdds.scm.protocol.ScmBlockLocationProtocol) AllocatedBlock(org.apache.hadoop.hdds.scm.container.common.helpers.AllocatedBlock) OzoneBlockTokenSecretManager(org.apache.hadoop.ozone.security.OzoneBlockTokenSecretManager) Before(org.junit.Before)

Example 2 with ResolvedBucket

use of org.apache.hadoop.ozone.om.ResolvedBucket in project ozone by apache.

the class TestS3MultipartRequest method setup.

@Before
public void setup() throws Exception {
    ozoneManager = Mockito.mock(OzoneManager.class);
    omMetrics = OMMetrics.create();
    OzoneConfiguration ozoneConfiguration = new OzoneConfiguration();
    ozoneConfiguration.set(OMConfigKeys.OZONE_OM_DB_DIRS, folder.newFolder().getAbsolutePath());
    omMetadataManager = new OmMetadataManagerImpl(ozoneConfiguration);
    when(ozoneManager.getMetrics()).thenReturn(omMetrics);
    when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
    auditLogger = Mockito.mock(AuditLogger.class);
    when(ozoneManager.getAuditLogger()).thenReturn(auditLogger);
    Mockito.doNothing().when(auditLogger).logWrite(any(AuditMessage.class));
    when(ozoneManager.resolveBucketLink(any(KeyArgs.class), any(OMClientRequest.class))).thenAnswer(inv -> {
        KeyArgs args = (KeyArgs) inv.getArguments()[0];
        return new ResolvedBucket(Pair.of(args.getVolumeName(), args.getBucketName()), Pair.of(args.getVolumeName(), args.getBucketName()));
    });
}
Also used : OmMetadataManagerImpl(org.apache.hadoop.ozone.om.OmMetadataManagerImpl) OMClientRequest(org.apache.hadoop.ozone.om.request.OMClientRequest) AuditMessage(org.apache.hadoop.ozone.audit.AuditMessage) AuditLogger(org.apache.hadoop.ozone.audit.AuditLogger) OzoneManager(org.apache.hadoop.ozone.om.OzoneManager) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) KeyArgs(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs) ResolvedBucket(org.apache.hadoop.ozone.om.ResolvedBucket) Before(org.junit.Before)

Example 3 with ResolvedBucket

use of org.apache.hadoop.ozone.om.ResolvedBucket in project ozone by apache.

the class TestOMDirectoryCreateRequest method setup.

@Before
public void setup() throws Exception {
    ozoneManager = Mockito.mock(OzoneManager.class);
    omMetrics = OMMetrics.create();
    OzoneConfiguration ozoneConfiguration = new OzoneConfiguration();
    ozoneConfiguration.set(OMConfigKeys.OZONE_OM_DB_DIRS, folder.newFolder().getAbsolutePath());
    omMetadataManager = new OmMetadataManagerImpl(ozoneConfiguration);
    when(ozoneManager.getMetrics()).thenReturn(omMetrics);
    when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
    auditLogger = Mockito.mock(AuditLogger.class);
    when(ozoneManager.getAuditLogger()).thenReturn(auditLogger);
    Mockito.doNothing().when(auditLogger).logWrite(any(AuditMessage.class));
    when(ozoneManager.resolveBucketLink(any(KeyArgs.class), any(OMClientRequest.class))).thenReturn(new ResolvedBucket(Pair.of("", ""), Pair.of("", "")));
}
Also used : OmMetadataManagerImpl(org.apache.hadoop.ozone.om.OmMetadataManagerImpl) OMClientRequest(org.apache.hadoop.ozone.om.request.OMClientRequest) AuditMessage(org.apache.hadoop.ozone.audit.AuditMessage) AuditLogger(org.apache.hadoop.ozone.audit.AuditLogger) OzoneManager(org.apache.hadoop.ozone.om.OzoneManager) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) KeyArgs(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs) ResolvedBucket(org.apache.hadoop.ozone.om.ResolvedBucket) Before(org.junit.Before)

Example 4 with ResolvedBucket

use of org.apache.hadoop.ozone.om.ResolvedBucket in project ozone by apache.

the class TestOMDirectoryCreateRequestWithFSO method setup.

@Before
public void setup() throws Exception {
    ozoneManager = Mockito.mock(OzoneManager.class);
    omMetrics = OMMetrics.create();
    OzoneConfiguration ozoneConfiguration = new OzoneConfiguration();
    ozoneConfiguration.set(OMConfigKeys.OZONE_OM_DB_DIRS, folder.newFolder().getAbsolutePath());
    OMRequestTestUtils.configureFSOptimizedPaths(ozoneConfiguration, true);
    omMetadataManager = new OmMetadataManagerImpl(ozoneConfiguration);
    when(ozoneManager.getMetrics()).thenReturn(omMetrics);
    when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
    auditLogger = Mockito.mock(AuditLogger.class);
    when(ozoneManager.getAuditLogger()).thenReturn(auditLogger);
    Mockito.doNothing().when(auditLogger).logWrite(any(AuditMessage.class));
    when(ozoneManager.resolveBucketLink(any(KeyArgs.class), any(OMClientRequest.class))).thenReturn(new ResolvedBucket(Pair.of("", ""), Pair.of("", "")));
}
Also used : OmMetadataManagerImpl(org.apache.hadoop.ozone.om.OmMetadataManagerImpl) OMClientRequest(org.apache.hadoop.ozone.om.request.OMClientRequest) AuditMessage(org.apache.hadoop.ozone.audit.AuditMessage) AuditLogger(org.apache.hadoop.ozone.audit.AuditLogger) OzoneManager(org.apache.hadoop.ozone.om.OzoneManager) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) KeyArgs(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs) ResolvedBucket(org.apache.hadoop.ozone.om.ResolvedBucket) Before(org.junit.Before)

Example 5 with ResolvedBucket

use of org.apache.hadoop.ozone.om.ResolvedBucket in project ozone by apache.

the class OMKeyRequest method generateRequiredEncryptionInfo.

/**
 * Generate EncryptionInfo and set in to newKeyArgs.
 * @param keyArgs
 * @param newKeyArgs
 * @param ozoneManager
 */
protected void generateRequiredEncryptionInfo(KeyArgs keyArgs, KeyArgs.Builder newKeyArgs, OzoneManager ozoneManager) throws IOException {
    String volumeName = keyArgs.getVolumeName();
    String bucketName = keyArgs.getBucketName();
    boolean acquireLock = false;
    OMMetadataManager omMetadataManager = ozoneManager.getMetadataManager();
    // When TDE is enabled, we are doing a DB read in pre-execute. As for
    // most of the operations we don't read from DB because of our isLeader
    // semantics. This issue will be solved with implementation of leader
    // leases which provider strong leader semantics in the system.
    // If KMS is not enabled, follow the normal approach of execution of not
    // reading DB in pre-execute.
    OmBucketInfo bucketInfo = null;
    if (ozoneManager.getKmsProvider() != null) {
        try {
            acquireLock = omMetadataManager.getLock().acquireReadLock(BUCKET_LOCK, volumeName, bucketName);
            bucketInfo = omMetadataManager.getBucketTable().get(omMetadataManager.getBucketKey(volumeName, bucketName));
            // volume/bucket.
            if (bucketInfo.isLink()) {
                ResolvedBucket resolvedBucket = ozoneManager.resolveBucketLink(Pair.of(keyArgs.getVolumeName(), keyArgs.getBucketName()));
                bucketInfo = omMetadataManager.getBucketTable().get(omMetadataManager.getBucketKey(resolvedBucket.realVolume(), resolvedBucket.realBucket()));
            }
        } finally {
            if (acquireLock) {
                omMetadataManager.getLock().releaseReadLock(BUCKET_LOCK, volumeName, bucketName);
            }
        }
        if (bucketInfo != null) {
            Optional<FileEncryptionInfo> encryptionInfo = getFileEncryptionInfo(ozoneManager, bucketInfo);
            if (encryptionInfo.isPresent()) {
                newKeyArgs.setFileEncryptionInfo(OMPBHelper.convert(encryptionInfo.get()));
            }
        }
    }
}
Also used : OmBucketInfo(org.apache.hadoop.ozone.om.helpers.OmBucketInfo) OMMetadataManager(org.apache.hadoop.ozone.om.OMMetadataManager) ResolvedBucket(org.apache.hadoop.ozone.om.ResolvedBucket) FileEncryptionInfo(org.apache.hadoop.fs.FileEncryptionInfo)

Aggregations

ResolvedBucket (org.apache.hadoop.ozone.om.ResolvedBucket)11 AuditLogger (org.apache.hadoop.ozone.audit.AuditLogger)7 OMMetadataManager (org.apache.hadoop.ozone.om.OMMetadataManager)6 OzoneManager (org.apache.hadoop.ozone.om.OzoneManager)5 OMClientRequest (org.apache.hadoop.ozone.om.request.OMClientRequest)5 KeyArgs (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs)5 Before (org.junit.Before)5 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)4 AuditMessage (org.apache.hadoop.ozone.audit.AuditMessage)4 OmMetadataManagerImpl (org.apache.hadoop.ozone.om.OmMetadataManagerImpl)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 OmKeyInfo (org.apache.hadoop.ozone.om.helpers.OmKeyInfo)3 OMClientResponse (org.apache.hadoop.ozone.om.response.OMClientResponse)3 OMResponse (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMResponse)3 LinkedHashMap (java.util.LinkedHashMap)2 OMMetrics (org.apache.hadoop.ozone.om.OMMetrics)2 OmBucketInfo (org.apache.hadoop.ozone.om.helpers.OmBucketInfo)2 HashMap (java.util.HashMap)1 Random (java.util.Random)1