Search in sources :

Example 36 with OzoneManager

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

the class TestOMUpgradeFinalizer method testFinalizationWithUpgradeAction.

@Test
public void testFinalizationWithUpgradeAction() throws Exception {
    Optional<OmUpgradeAction> action = Optional.of(om -> om.getVersion());
    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);
    finalizer.finalize(CLIENT_ID, om);
    Iterator<OMLayoutFeature> it = lfs.iterator();
    OMLayoutFeature f = it.next();
    // the first feature has an upgrade action, and the action execution is
    // checked by verifying on om.getVersion
    verify(om.getOmStorage(), once()).setLayoutVersion(f.layoutVersion());
    verify(om, once()).getVersion();
    // The second feature has a NOOP, but should update the layout version.
    f = it.next();
    verify(om.getOmStorage(), once()).setLayoutVersion(f.layoutVersion());
    if (finalizer.isFinalizationDone()) {
        when(versionManager.getUpgradeState()).thenReturn(FINALIZATION_DONE);
    }
    StatusAndMessages status = finalizer.reportStatus(CLIENT_ID, false);
    assertEquals(FINALIZATION_DONE, status.status());
    assertFalse(status.msgs().isEmpty());
}
Also used : OzoneManager(org.apache.hadoop.ozone.om.OzoneManager) StatusAndMessages(org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.StatusAndMessages) Test(org.junit.Test)

Example 37 with OzoneManager

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

the class TestOMUpgradeFinalizer method mockOzoneManager.

private OzoneManager mockOzoneManager(int initialLayoutVersion) {
    OzoneManager mock = mock(OzoneManager.class);
    OMStorage st = mock(OMStorage.class);
    storedLayoutVersion = initialLayoutVersion;
    doAnswer((Answer<Void>) inv -> {
        storedLayoutVersion = inv.getArgument(0, Integer.class);
        return null;
    }).when(st).setLayoutVersion(anyInt());
    when(st.getLayoutVersion()).thenAnswer((Answer<Integer>) ignore -> storedLayoutVersion);
    when(mock.getOmStorage()).thenReturn(st);
    return mock;
}
Also used : UpgradeFinalizer(org.apache.hadoop.ozone.upgrade.UpgradeFinalizer) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) LAYOUT_FEATURE_FINALIZATION_FAILED(org.apache.hadoop.ozone.upgrade.UpgradeException.ResultCodes.LAYOUT_FEATURE_FINALIZATION_FAILED) OzoneManager(org.apache.hadoop.ozone.om.OzoneManager) ALREADY_FINALIZED(org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.Status.ALREADY_FINALIZED) ArrayList(java.util.ArrayList) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) Answer(org.mockito.stubbing.Answer) FINALIZATION_DONE(org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.Status.FINALIZATION_DONE) Mockito.doAnswer(org.mockito.Mockito.doAnswer) StatusAndMessages(org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.StatusAndMessages) Assert.fail(org.junit.Assert.fail) ExpectedException(org.junit.rules.ExpectedException) ArgumentMatchers.anyInt(org.mockito.ArgumentMatchers.anyInt) OMStorage(org.apache.hadoop.ozone.om.OMStorage) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Iterator(java.util.Iterator) UpgradeException(org.apache.hadoop.ozone.upgrade.UpgradeException) Test(org.junit.Test) IOException(java.io.IOException) ON_FINALIZE(org.apache.hadoop.ozone.upgrade.LayoutFeature.UpgradeActionType.ON_FINALIZE) Mockito.times(org.mockito.Mockito.times) STARTING_FINALIZATION(org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.Status.STARTING_FINALIZATION) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) VerificationMode(org.mockito.verification.VerificationMode) List(java.util.List) Mockito.never(org.mockito.Mockito.never) Rule(org.junit.Rule) FINALIZATION_REQUIRED(org.apache.hadoop.ozone.upgrade.UpgradeFinalizer.Status.FINALIZATION_REQUIRED) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) OzoneManager(org.apache.hadoop.ozone.om.OzoneManager) OMStorage(org.apache.hadoop.ozone.om.OMStorage)

Example 38 with OzoneManager

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

the class TestOMVersionManager method testOMLayoutFeaturesHaveIncreasingLayoutVersion.

@Test
public void testOMLayoutFeaturesHaveIncreasingLayoutVersion() throws Exception {
    OMLayoutFeature[] values = OMLayoutFeature.values();
    int currVersion = Integer.MIN_VALUE;
    OMLayoutFeature lastFeature = null;
    for (OMLayoutFeature lf : values) {
        assertTrue(currVersion < lf.layoutVersion());
        currVersion = lf.layoutVersion();
        lastFeature = lf;
    }
    for (UpgradeActionType type : UpgradeActionType.values()) {
        lastFeature.addAction(type, arg -> {
            String v = arg.getVersion();
        });
    }
    OzoneManager omMock = mock(OzoneManager.class);
    for (UpgradeActionType type : UpgradeActionType.values()) {
        lastFeature.action(type).get().execute(omMock);
    }
    verify(omMock, times(UpgradeActionType.values().length)).getVersion();
}
Also used : OzoneManager(org.apache.hadoop.ozone.om.OzoneManager) UpgradeActionType(org.apache.hadoop.ozone.upgrade.LayoutFeature.UpgradeActionType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 39 with OzoneManager

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

the class TestOMLayoutFeatureAspect method testPreExecuteLayoutCheck.

@Test
public void testPreExecuteLayoutCheck() throws Exception {
    OzoneManager om = mock(OzoneManager.class);
    OMLayoutVersionManager lvm = mock(OMLayoutVersionManager.class);
    when(lvm.isAllowed(anyString())).thenReturn(false);
    when(lvm.getFeature(anyString())).thenReturn(INITIAL_VERSION);
    when(om.getVersionManager()).thenReturn(lvm);
    MockOmRequest mockOmRequest = new MockOmRequest();
    OMLayoutFeatureAspect aspect = new OMLayoutFeatureAspect();
    JoinPoint joinPoint = mock(JoinPoint.class);
    when(joinPoint.getArgs()).thenReturn(new Object[] { om });
    when(joinPoint.getTarget()).thenReturn(mockOmRequest);
    LambdaTestUtils.intercept(OMException.class, "cannot be invoked before finalization", () -> aspect.beforeRequestApplyTxn(joinPoint));
}
Also used : OzoneManager(org.apache.hadoop.ozone.om.OzoneManager) JoinPoint(org.aspectj.lang.JoinPoint) Test(org.junit.Test)

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