Search in sources :

Example 21 with OzoneManager

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));
}
Also used : OmMetadataManagerImpl(org.apache.hadoop.ozone.om.OmMetadataManagerImpl) OMLayoutVersionManager(org.apache.hadoop.ozone.om.upgrade.OMLayoutVersionManager) OzoneManager(org.apache.hadoop.ozone.om.OzoneManager) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) Before(org.junit.Before)

Example 22 with OzoneManager

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);
}
Also used : OmMetadataManagerImpl(org.apache.hadoop.ozone.om.OmMetadataManagerImpl) OzoneManager(org.apache.hadoop.ozone.om.OzoneManager) OzoneConfiguration(org.apache.hadoop.hdds.conf.OzoneConfiguration) Before(org.junit.Before)

Example 23 with OzoneManager

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);
}
Also used : Table(org.apache.hadoop.hdds.utils.db.Table) AtomicReference(java.util.concurrent.atomic.AtomicReference) OzoneOutputStream(org.apache.hadoop.ozone.client.io.OzoneOutputStream) OzoneManagerServiceProviderImpl(org.apache.hadoop.ozone.recon.spi.impl.OzoneManagerServiceProviderImpl) TableIterator(org.apache.hadoop.hdds.utils.db.TableIterator) ReconContainerMetadataManager(org.apache.hadoop.ozone.recon.spi.ReconContainerMetadataManager) OzoneManager(org.apache.hadoop.ozone.om.OzoneManager) ContainerKeyPrefix(org.apache.hadoop.ozone.recon.api.types.ContainerKeyPrefix) Test(org.junit.Test)

Example 24 with OzoneManager

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);
}
Also used : Path(java.nio.file.Path) AuditMessage(org.apache.hadoop.ozone.audit.AuditMessage) AuditLogger(org.apache.hadoop.ozone.audit.AuditLogger) OzoneManagerRatisServer(org.apache.hadoop.ozone.om.ratis.OzoneManagerRatisServer) Server(org.apache.hadoop.ipc.Server) OMMultiTenantManager(org.apache.hadoop.ozone.om.OMMultiTenantManager) OmMetadataManagerImpl(org.apache.hadoop.ozone.om.OmMetadataManagerImpl) OMRequest(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos.OMRequest) ServiceException(com.google.protobuf.ServiceException) OzoneManager(org.apache.hadoop.ozone.om.OzoneManager) TemporaryFolder(org.junit.rules.TemporaryFolder) OzoneManagerRatisServer(org.apache.hadoop.ozone.om.ratis.OzoneManagerRatisServer) File(java.io.File) Before(org.junit.Before)

Example 25 with OzoneManager

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());
    }
}
Also used : OmMetadataManagerImpl(org.apache.hadoop.ozone.om.OmMetadataManagerImpl) OzoneManager(org.apache.hadoop.ozone.om.OzoneManager) OzoneManagerProtocolProtos(org.apache.hadoop.ozone.protocol.proto.OzoneManagerProtocolProtos) OMException(org.apache.hadoop.ozone.om.exceptions.OMException) 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