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));
}
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));
}
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());
}
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();
}
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));
}
Aggregations