Search in sources :

Example 16 with OzoneManager

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

the class TestBucketRequest 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);
    when(ozoneManager.isRatisEnabled()).thenReturn(true);
    OMLayoutVersionManager lvm = mock(OMLayoutVersionManager.class);
    when(lvm.getMetadataLayoutVersion()).thenReturn(0);
    when(ozoneManager.getVersionManager()).thenReturn(lvm);
    auditLogger = Mockito.mock(AuditLogger.class);
    when(ozoneManager.getAuditLogger()).thenReturn(auditLogger);
    Mockito.doNothing().when(auditLogger).logWrite(any(AuditMessage.class));
}
Also used : OmMetadataManagerImpl(org.apache.hadoop.ozone.om.OmMetadataManagerImpl) OMLayoutVersionManager(org.apache.hadoop.ozone.om.upgrade.OMLayoutVersionManager) 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) Before(org.junit.Before)

Example 17 with OzoneManager

use of org.apache.hadoop.ozone.om.OzoneManager 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);
    when(ozoneManager.getBucketInfo(anyString(), anyString())).thenReturn(new OmBucketInfo.Builder().setVolumeName("").setBucketName("").build());
    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.Builder blockBuilder = new AllocatedBlock.Builder().setPipeline(pipeline);
    when(scmBlockLocationProtocol.allocateBlock(anyLong(), anyInt(), any(ReplicationConfig.class), anyString(), any(ExcludeList.class))).thenAnswer(invocation -> {
        int num = invocation.getArgument(1);
        List<AllocatedBlock> allocatedBlocks = new ArrayList<>(num);
        for (int i = 0; i < num; i++) {
            blockBuilder.setContainerBlockID(new ContainerBlockID(CONTAINER_ID + i, LOCAL_ID + i));
            allocatedBlocks.add(blockBuilder.build());
        }
        return 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) ExcludeList(org.apache.hadoop.hdds.scm.container.common.helpers.ExcludeList) OMClientRequest(org.apache.hadoop.ozone.om.request.OMClientRequest) AuditLogger(org.apache.hadoop.ozone.audit.AuditLogger) ReplicationConfig(org.apache.hadoop.hdds.client.ReplicationConfig) StandaloneReplicationConfig(org.apache.hadoop.hdds.client.StandaloneReplicationConfig) 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 18 with OzoneManager

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

the class TestOMUpgradeFinalizer method testFinalizationWithFailingUpgradeAction.

@Test
public void testFinalizationWithFailingUpgradeAction() throws Exception {
    Optional<OmUpgradeAction> action = Optional.of(ignore -> {
        throw new IOException("Fail.");
    });
    OzoneManager om = mockOzoneManager(0);
    Iterable<OMLayoutFeature> lfs = mockFeatures("feature-1", "feature-2");
    when(lfs.iterator().next().action(ON_FINALIZE)).thenReturn(action);
    setupVersionManagerMockToFinalize(lfs);
    OMUpgradeFinalizer finalizer = new OMUpgradeFinalizer(versionManager);
    try {
        finalizer.finalize(CLIENT_ID, om);
        fail();
    } catch (Exception e) {
        assertThat(e, instanceOf(UpgradeException.class));
        assertThat(e.getMessage(), containsString(lfs.iterator().next().name()));
        assertEquals(((UpgradeException) e).getResult(), LAYOUT_FEATURE_FINALIZATION_FAILED);
    }
    if (finalizer.isFinalizationDone()) {
        when(versionManager.getUpgradeState()).thenReturn(FINALIZATION_DONE);
    }
    // Verify that we have never updated the layout version.
    Iterator<OMLayoutFeature> it = lfs.iterator();
    OMLayoutFeature f = it.next();
    verify(om.getOmStorage(), never()).setLayoutVersion(f.layoutVersion());
    // Verify that we never got to the second feature.
    f = it.next();
    verify(om.getOmStorage(), never()).setLayoutVersion(f.layoutVersion());
    StatusAndMessages status = finalizer.reportStatus(CLIENT_ID, false);
    assertEquals(FINALIZATION_DONE, status.status());
    assertFalse(status.msgs().isEmpty());
}
Also used : UpgradeException(org.apache.hadoop.ozone.upgrade.UpgradeException) OzoneManager(org.apache.hadoop.ozone.om.OzoneManager) StatusAndMessages(org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.StatusAndMessages) IOException(java.io.IOException) ExpectedException(org.junit.rules.ExpectedException) UpgradeException(org.apache.hadoop.ozone.upgrade.UpgradeException) IOException(java.io.IOException) Test(org.junit.Test)

Example 19 with OzoneManager

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

the class TestOMVersionManager method testOmUpgradeActionsRegistered.

@Test
public void testOmUpgradeActionsRegistered() throws Exception {
    // MLV >= 0
    OMLayoutVersionManager lvm = new OMLayoutVersionManager();
    assertFalse(lvm.needsFinalization());
    // INITIAL_VERSION is finalized, hence should not register.
    Optional<OmUpgradeAction> action = INITIAL_VERSION.action(VALIDATE_IN_PREFINALIZE);
    assertFalse(action.isPresent());
    lvm = mock(OMLayoutVersionManager.class);
    when(lvm.getMetadataLayoutVersion()).thenReturn(-1);
    doCallRealMethod().when(lvm).registerUpgradeActions(anyString());
    lvm.registerUpgradeActions(OM_UPGRADE_CLASS_PACKAGE);
    action = INITIAL_VERSION.action(VALIDATE_IN_PREFINALIZE);
    Assert.assertTrue(action.isPresent());
    Assert.assertEquals(MockOmUpgradeAction.class, action.get().getClass());
    OzoneManager omMock = mock(OzoneManager.class);
    action.get().execute(omMock);
    verify(omMock, times(1)).getVersion();
}
Also used : OzoneManager(org.apache.hadoop.ozone.om.OzoneManager) Test(org.junit.Test)

Example 20 with OzoneManager

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

the class TestOMVolumeRequest method setup.

@Before
public void setup() throws Exception {
    ozoneManager = 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);
    when(ozoneManager.getMaxUserVolumeCount()).thenReturn(10L);
    OMLayoutVersionManager lvm = mock(OMLayoutVersionManager.class);
    when(lvm.getMetadataLayoutVersion()).thenReturn(0);
    when(ozoneManager.getVersionManager()).thenReturn(lvm);
    when(ozoneManager.isRatisEnabled()).thenReturn(true);
    auditLogger = mock(AuditLogger.class);
    when(ozoneManager.getAuditLogger()).thenReturn(auditLogger);
    Mockito.doNothing().when(auditLogger).logWrite(any(AuditMessage.class));
}
Also used : OmMetadataManagerImpl(org.apache.hadoop.ozone.om.OmMetadataManagerImpl) OMLayoutVersionManager(org.apache.hadoop.ozone.om.upgrade.OMLayoutVersionManager) 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) Before(org.junit.Before)

Aggregations

OzoneManager (org.apache.hadoop.ozone.om.OzoneManager)39 OzoneConfiguration (org.apache.hadoop.hdds.conf.OzoneConfiguration)15 OmMetadataManagerImpl (org.apache.hadoop.ozone.om.OmMetadataManagerImpl)15 Before (org.junit.Before)14 Test (org.junit.Test)12 AuditLogger (org.apache.hadoop.ozone.audit.AuditLogger)9 AuditMessage (org.apache.hadoop.ozone.audit.AuditMessage)9 OMClientRequest (org.apache.hadoop.ozone.om.request.OMClientRequest)5 IOException (java.io.IOException)4 ResolvedBucket (org.apache.hadoop.ozone.om.ResolvedBucket)4 OMLayoutVersionManager (org.apache.hadoop.ozone.om.upgrade.OMLayoutVersionManager)4 KeyArgs (org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.KeyArgs)4 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 StorageContainerManager (org.apache.hadoop.hdds.scm.server.StorageContainerManager)2 RatisSnapshotInfo (org.apache.hadoop.ozone.common.ha.ratis.RatisSnapshotInfo)2 OMMultiTenantManager (org.apache.hadoop.ozone.om.OMMultiTenantManager)2 OMException (org.apache.hadoop.ozone.om.exceptions.OMException)2 BucketLayout (org.apache.hadoop.ozone.om.helpers.BucketLayout)2