use of org.apache.hadoop.ozone.om.OzoneManager in project ozone by apache.
the class TestSetRangerServiceVersionRequest method setUp.
@Before
public void setUp() throws Exception {
ozoneManager = Mockito.mock(OzoneManager.class);
Mockito.when(ozoneManager.getVersionManager()).thenReturn(new OMLayoutVersionManager(1));
final OzoneConfiguration conf = new OzoneConfiguration();
conf.set(OMConfigKeys.OZONE_OM_DB_DIRS, folder.newFolder().getAbsolutePath());
Mockito.when(ozoneManager.getMetadataManager()).thenReturn(new OmMetadataManagerImpl(conf));
}
use of org.apache.hadoop.ozone.om.OzoneManager in project ozone by apache.
the class TestOMDelegationTokenRequest method setup.
@Before
public void setup() throws Exception {
ozoneManager = Mockito.mock(OzoneManager.class);
conf = new OzoneConfiguration();
((OzoneConfiguration) conf).set(OZONE_OM_DB_DIRS, folder.newFolder().getAbsolutePath());
omMetadataManager = new OmMetadataManagerImpl((OzoneConfiguration) conf);
when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
}
use of org.apache.hadoop.ozone.om.OzoneManager in project ozone by apache.
the class TestReconWithOzoneManagerHA method testReconGetsSnapshotFromLeader.
@Test
public void testReconGetsSnapshotFromLeader() throws Exception {
AtomicReference<OzoneManager> ozoneManager = new AtomicReference<>();
// Wait for OM leader election to finish
GenericTestUtils.waitFor(() -> {
OzoneManager om = cluster.getOMLeader();
ozoneManager.set(om);
return om != null;
}, 100, 120000);
Assert.assertNotNull("Timed out waiting OM leader election to finish: " + "no leader or more than one leader.", ozoneManager);
Assert.assertTrue("Should have gotten the leader!", ozoneManager.get().isLeaderReady());
OzoneManagerServiceProviderImpl impl = (OzoneManagerServiceProviderImpl) cluster.getReconServer().getOzoneManagerServiceProvider();
String hostname = ozoneManager.get().getHttpServer().getHttpAddress().getHostName();
String expectedUrl = "http://" + (hostname.equals("0.0.0.0") ? "localhost" : hostname) + ":" + ozoneManager.get().getHttpServer().getHttpAddress().getPort() + OZONE_DB_CHECKPOINT_HTTP_ENDPOINT;
String snapshotUrl = impl.getOzoneManagerSnapshotUrl();
Assert.assertEquals("OM Snapshot should be requested from the leader.", expectedUrl, snapshotUrl);
// Write some data
String keyPrefix = "ratis";
OzoneOutputStream key = objectStore.getVolume(VOL_NAME).getBucket(VOL_NAME).createKey(keyPrefix, 1024, ReplicationType.RATIS, ReplicationFactor.ONE, new HashMap<>());
key.write(keyPrefix.getBytes(UTF_8));
key.flush();
key.close();
// Sync data to Recon
impl.syncDataFromOM();
ReconContainerMetadataManager reconContainerMetadataManager = cluster.getReconServer().getReconContainerMetadataManager();
TableIterator iterator = reconContainerMetadataManager.getContainerTableIterator();
String reconKeyPrefix = null;
while (iterator.hasNext()) {
Table.KeyValue<ContainerKeyPrefix, Integer> keyValue = (Table.KeyValue<ContainerKeyPrefix, Integer>) iterator.next();
reconKeyPrefix = keyValue.getKey().getKeyPrefix();
}
Assert.assertEquals("Container data should be synced to recon.", String.format("/%s/%s/%s", VOL_NAME, VOL_NAME, keyPrefix), reconKeyPrefix);
}
use of org.apache.hadoop.ozone.om.OzoneManager in project ozone by apache.
the class TestRangerBGSyncService method setUp.
@Before
public void setUp() throws IOException {
KerberosName.setRuleMechanism(DEFAULT_MECHANISM);
KerberosName.setRules("RULE:[2:$1@$0](.*@EXAMPLE.COM)s/@.*//\n" + "RULE:[1:$1@$0](.*@EXAMPLE.COM)s/@.*//\n" + "DEFAULT");
ugiAlice = UserGroupInformation.createRemoteUser(USER_ALICE);
Assert.assertEquals(USER_ALICE_SHORT, ugiAlice.getShortUserName());
ozoneManager = mock(OzoneManager.class);
Server.Call call = spy(new Server.Call(1, 1, null, null, RPC.RpcKind.RPC_BUILTIN, new byte[] { 1, 2, 3 }));
// Run as alice, so that Server.getRemoteUser() won't return null.
when(call.getRemoteUser()).thenReturn(ugiAlice);
Server.getCurCall().set(call);
String omID = UUID.randomUUID().toString();
final String path = GenericTestUtils.getTempPath(omID);
Path metaDirPath = Paths.get(path, "om-meta");
conf.set(HddsConfigKeys.OZONE_METADATA_DIRS, metaDirPath.toString());
omMetrics = OMMetrics.create();
folder = new TemporaryFolder(new File("/tmp"));
folder.create();
conf.set(OMConfigKeys.OZONE_OM_DB_DIRS, folder.newFolder().getAbsolutePath());
// No need to conf.set(OzoneConfigKeys.OZONE_ADMINISTRATORS, ...) here
// as we did the trick earlier with mockito.
omMetadataManager = new OmMetadataManagerImpl(conf);
when(ozoneManager.getMetrics()).thenReturn(omMetrics);
when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
when(ozoneManager.isRatisEnabled()).thenReturn(true);
auditLogger = mock(AuditLogger.class);
when(ozoneManager.getAuditLogger()).thenReturn(auditLogger);
doNothing().when(auditLogger).logWrite(any(AuditMessage.class));
// Multi-tenant related initializations
omMultiTenantManager = mock(OMMultiTenantManager.class);
tenant = mock(Tenant.class);
when(ozoneManager.getMultiTenantManager()).thenReturn(omMultiTenantManager);
when(ozoneManager.getConfiguration()).thenReturn(conf);
when(ozoneManager.isLeaderReady()).thenReturn(true);
when(omMultiTenantManager.getTenantVolumeName(TENANT_ID)).thenReturn(TENANT_ID);
when(omMultiTenantManager.getTenantUserRoleName(TENANT_ID)).thenReturn(OMMultiTenantManager.getDefaultUserRoleName(TENANT_ID));
when(omMultiTenantManager.getTenantAdminRoleName(TENANT_ID)).thenReturn(OMMultiTenantManager.getDefaultAdminRoleName(TENANT_ID));
when(omMultiTenantManager.newDefaultVolumeAccessPolicy(eq(TENANT_ID), Mockito.any(OzoneTenantRolePrincipal.class), Mockito.any(OzoneTenantRolePrincipal.class))).thenReturn(newVolumeAccessPolicy(TENANT_ID, TENANT_ID));
when(omMultiTenantManager.newDefaultBucketAccessPolicy(eq(TENANT_ID), Mockito.any(OzoneTenantRolePrincipal.class))).thenReturn(newBucketAccessPolicy(TENANT_ID, TENANT_ID));
when(omMultiTenantManager.getAuthorizerLock()).thenReturn(new AuthorizerLockImpl());
// Raft client request handling
OzoneManagerRatisServer omRatisServer = mock(OzoneManagerRatisServer.class);
when(omRatisServer.getRaftPeerId()).thenReturn(RaftPeerId.valueOf("peerId"));
when(omRatisServer.getRaftGroupId()).thenReturn(RaftGroupId.randomId());
when(ozoneManager.getOmRatisServer()).thenReturn(omRatisServer);
try {
doAnswer(invocation -> {
OMRequest request = invocation.getArgument(0);
long v = request.getSetRangerServiceVersionRequest().getRangerServiceVersion();
LOG.info("Writing Ranger Ozone Service Version to DB: {}", v);
ozoneManager.getMetadataManager().getMetaTable().put(OzoneConsts.RANGER_OZONE_SERVICE_VERSION_KEY, String.valueOf(v));
return null;
}).when(omRatisServer).submitRequest(Mockito.any(), Mockito.any());
} catch (ServiceException e) {
throw new RuntimeException(e);
}
when(tenant.getTenantAccessPolicies()).thenReturn(new ArrayList<>());
auth = new MultiTenantAccessAuthorizerRangerPlugin();
auth.init(conf);
}
use of org.apache.hadoop.ozone.om.OzoneManager in project ozone by apache.
the class TestOzoneManagerRatisRequest method testRequestWithNonExistentBucket.
@Test(timeout = 300_000)
public void testRequestWithNonExistentBucket() throws Exception {
ozoneManager = Mockito.mock(OzoneManager.class);
ozoneConfiguration.set(OMConfigKeys.OZONE_OM_DB_DIRS, folder.newFolder().getAbsolutePath());
omMetadataManager = new OmMetadataManagerImpl(ozoneConfiguration);
when(ozoneManager.getMetadataManager()).thenReturn(omMetadataManager);
String volumeName = "vol1";
String bucketName = "invalidBuck";
// Add entry to Volume Table.
omMetadataManager.getVolumeTable().addCacheEntry(new CacheKey<>(omMetadataManager.getVolumeKey(volumeName)), new CacheValue<>(Optional.of(OmVolumeArgs.newBuilder().setVolume(volumeName).setOwnerName("owner").setAdminName("admin").build()), 100L));
OzoneManagerProtocolProtos.OMRequest omRequest = OMRequestTestUtils.createCompleteMPURequest(volumeName, bucketName, "mpuKey", "mpuKeyID", new ArrayList<>());
try {
// Request creation flow should throw exception if the bucket associated
// with the request doesn't exist.
OzoneManagerRatisUtils.createClientRequest(omRequest, ozoneManager);
fail("Expected OMException: Bucket not found");
} catch (OMException oe) {
// Expected exception.
Assert.assertEquals(OMException.ResultCodes.BUCKET_NOT_FOUND, oe.getResult());
}
}
Aggregations