Skip to content

Commit

Permalink
Remove CallContextCatalogFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
adutra committed Jan 7, 2025
1 parent 5905ba1 commit af16d32
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 320 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
import org.apache.polaris.service.catalog.io.FileIOFactory;
import org.apache.polaris.service.config.DefaultConfigurationStore;
import org.apache.polaris.service.config.RealmEntityManagerFactory;
import org.apache.polaris.service.context.CallContextCatalogFactory;
import org.apache.polaris.service.context.PolarisCallContextCatalogFactory;
import org.apache.polaris.service.persistence.InMemoryPolarisMetaStoreManagerFactory;
import org.apache.polaris.service.quarkus.catalog.io.TestFileIOFactory;
import org.apache.polaris.service.storage.PolarisStorageIntegrationProviderImpl;
Expand Down Expand Up @@ -98,28 +96,19 @@ public static TestServices inMemory(FileIOFactory ioFactory, Map<String, Object>
PolarisEntityManager entityManager =
realmEntityManagerFactory.getOrCreateEntityManager(testRealm);

CallContextCatalogFactory callContextFactory =
new PolarisCallContextCatalogFactory(
entityManager,
metaStoreManager,
session,
configurationStore,
polarisDiagnostics,
Mockito.mock(TaskExecutor.class),
ioFactory);

PolarisAuthorizer authorizer = Mockito.mock(PolarisAuthorizer.class);

IcebergRestCatalogApiService service =
new IcebergCatalogAdapter(
testRealm,
callContextFactory,
entityManager,
metaStoreManager,
session,
configurationStore,
polarisDiagnostics,
authorizer);
authorizer,
Mockito.mock(TaskExecutor.class),
ioFactory);

IcebergRestCatalogApi restApi = new IcebergRestCatalogApi(service);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
import io.quarkus.test.junit.QuarkusMock;
import io.quarkus.test.junit.QuarkusTestProfile;
import jakarta.annotation.Nonnull;
import jakarta.enterprise.context.RequestScoped;
import jakarta.enterprise.inject.Alternative;
import jakarta.inject.Inject;
import java.io.IOException;
import java.util.Date;
Expand All @@ -37,7 +35,6 @@
import java.util.function.Function;
import org.apache.iceberg.CatalogProperties;
import org.apache.iceberg.Schema;
import org.apache.iceberg.catalog.Catalog;
import org.apache.iceberg.catalog.Namespace;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.exceptions.ForbiddenException;
Expand Down Expand Up @@ -66,17 +63,13 @@
import org.apache.polaris.core.persistence.PolarisEntityManager;
import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
import org.apache.polaris.core.persistence.PolarisMetaStoreSession;
import org.apache.polaris.core.persistence.resolver.PolarisResolutionManifest;
import org.apache.polaris.service.admin.PolarisAdminService;
import org.apache.polaris.service.catalog.BasePolarisCatalog;
import org.apache.polaris.service.catalog.io.DefaultFileIOFactory;
import org.apache.polaris.service.catalog.io.FileIOFactory;
import org.apache.polaris.service.config.DefaultConfigurationStore;
import org.apache.polaris.service.config.RealmEntityManagerFactory;
import org.apache.polaris.service.context.PolarisCallContextCatalogFactory;
import org.apache.polaris.service.quarkus.catalog.PolarisPassthroughResolutionView;
import org.apache.polaris.service.storage.PolarisStorageIntegrationProviderImpl;
import org.apache.polaris.service.task.TaskExecutor;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -89,11 +82,6 @@ public abstract class PolarisAuthzTestBase {

public static class Profile implements QuarkusTestProfile {

@Override
public Set<Class<?>> getEnabledAlternatives() {
return Set.of(TestPolarisCallContextCatalogFactory.class);
}

@Override
public Map<String, String> getConfigOverrides() {
return Map.of(
Expand Down Expand Up @@ -228,6 +216,8 @@ public void before(TestInfo testInfo) {
.setName(CATALOG_NAME)
.setCatalogType("INTERNAL")
.setDefaultBaseLocation(storageLocation)
.addProperty(
CatalogProperties.FILE_IO_IMPL, "org.apache.iceberg.inmemory.InMemoryFileIO")
.setStorageConfigurationInfo(storageConfigModel, storageLocation)
.build());

Expand Down Expand Up @@ -385,52 +375,6 @@ private void initBaseCatalog() {
CatalogProperties.FILE_IO_IMPL, "org.apache.iceberg.inmemory.InMemoryFileIO"));
}

@Alternative
@RequestScoped
public static class TestPolarisCallContextCatalogFactory
extends PolarisCallContextCatalogFactory {

public TestPolarisCallContextCatalogFactory() {
super(null, null, null, null, null, null, null);
}

@Inject
public TestPolarisCallContextCatalogFactory(
PolarisEntityManager entityManager,
PolarisMetaStoreManager metaStoreManager,
PolarisMetaStoreSession metaStoreSession,
PolarisConfigurationStore configurationStore,
PolarisDiagnostics diagnostics,
TaskExecutor taskExecutor,
FileIOFactory fileIOFactory) {
super(
entityManager,
metaStoreManager,
metaStoreSession,
configurationStore,
diagnostics,
taskExecutor,
fileIOFactory);
}

@Override
public Catalog createCallContextCatalog(
RealmContext realmContext,
AuthenticatedPolarisPrincipal authenticatedPolarisPrincipal,
final PolarisResolutionManifest resolvedManifest) {
// This depends on the BasePolarisCatalog allowing calling initialize multiple times
// to override the previous config.
Catalog catalog =
super.createCallContextCatalog(
realmContext, authenticatedPolarisPrincipal, resolvedManifest);
catalog.initialize(
CATALOG_NAME,
ImmutableMap.of(
CatalogProperties.FILE_IO_IMPL, "org.apache.iceberg.inmemory.InMemoryFileIO"));
return catalog;
}
}

/**
* Tests each "sufficient" privilege individually by invoking {@code grantAction} for each set of
* privileges, running the action being tested, revoking after each test set, and also ensuring
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.polaris.service.quarkus.catalog;

import com.google.common.collect.ImmutableMap;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import java.time.Instant;
Expand All @@ -33,7 +32,6 @@
import org.apache.iceberg.SortOrder;
import org.apache.iceberg.TableMetadata;
import org.apache.iceberg.TableMetadataParser;
import org.apache.iceberg.catalog.Catalog;
import org.apache.iceberg.catalog.Namespace;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.iceberg.exceptions.ForbiddenException;
Expand All @@ -53,17 +51,13 @@
import org.apache.polaris.core.admin.model.PrincipalWithCredentialsCredentials;
import org.apache.polaris.core.admin.model.StorageConfigInfo;
import org.apache.polaris.core.auth.AuthenticatedPolarisPrincipal;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.entity.CatalogEntity;
import org.apache.polaris.core.entity.CatalogRoleEntity;
import org.apache.polaris.core.entity.PolarisPrivilege;
import org.apache.polaris.core.entity.PrincipalEntity;
import org.apache.polaris.core.persistence.PolarisMetaStoreManager;
import org.apache.polaris.core.persistence.resolver.PolarisResolutionManifest;
import org.apache.polaris.service.catalog.PolarisCatalogHandlerWrapper;
import org.apache.polaris.service.catalog.io.DefaultFileIOFactory;
import org.apache.polaris.service.context.CallContextCatalogFactory;
import org.apache.polaris.service.context.PolarisCallContextCatalogFactory;
import org.apache.polaris.service.quarkus.admin.PolarisAuthzTestBase;
import org.apache.polaris.service.types.NotificationRequest;
import org.apache.polaris.service.types.NotificationType;
Expand All @@ -89,28 +83,23 @@ private PolarisCatalogHandlerWrapper newWrapper() {
}

private PolarisCatalogHandlerWrapper newWrapper(Set<String> activatedPrincipalRoles) {
return newWrapper(activatedPrincipalRoles, CATALOG_NAME, newCatalogFactory());
return newWrapper(activatedPrincipalRoles, CATALOG_NAME);
}

private PolarisCatalogHandlerWrapper newWrapper(
Set<String> activatedPrincipalRoles, String catalogName, CallContextCatalogFactory factory) {
AuthenticatedPolarisPrincipal authenticatedPrincipal) {
return newWrapper(authenticatedPrincipal, CATALOG_NAME);
}

private PolarisCatalogHandlerWrapper newWrapper(
Set<String> activatedPrincipalRoles, String catalogName) {
final AuthenticatedPolarisPrincipal authenticatedPrincipal =
new AuthenticatedPolarisPrincipal(principalEntity, activatedPrincipalRoles);
return new PolarisCatalogHandlerWrapper(
realmContext,
metaStoreSession,
configurationStore,
diagServices,
entityManager,
metaStoreManager,
authenticatedPrincipal,
factory,
catalogName,
polarisAuthorizer);
return newWrapper(authenticatedPrincipal, catalogName);
}

private PolarisCatalogHandlerWrapper newWrapper(
AuthenticatedPolarisPrincipal authenticatedPrincipal) {
AuthenticatedPolarisPrincipal authenticatedPrincipal, String catalogName) {
return new PolarisCatalogHandlerWrapper(
realmContext,
metaStoreSession,
Expand All @@ -119,18 +108,8 @@ private PolarisCatalogHandlerWrapper newWrapper(
entityManager,
metaStoreManager,
authenticatedPrincipal,
newCatalogFactory(),
CATALOG_NAME,
polarisAuthorizer);
}

private CallContextCatalogFactory newCatalogFactory() {
return new TestPolarisCallContextCatalogFactory(
entityManager,
metaStoreManager,
metaStoreSession,
configurationStore,
diagServices,
catalogName,
polarisAuthorizer,
Mockito.mock(),
new DefaultFileIOFactory());
}
Expand Down Expand Up @@ -1631,6 +1610,8 @@ public void testSendNotificationSufficientPrivileges() {
.setName(externalCatalog)
.setDefaultBaseLocation(storageLocation)
.setStorageConfigurationInfo(storageConfigModel, storageLocation)
.addProperty(
CatalogProperties.FILE_IO_IMPL, "org.apache.iceberg.inmemory.InMemoryFileIO")
.setCatalogType("EXTERNAL")
.build());
adminService.createCatalogRole(
Expand Down Expand Up @@ -1693,47 +1674,23 @@ public void testSendNotificationSufficientPrivileges() {
validatePayload.setTimestamp(530950845L);
validateRequest.setPayload(validatePayload);

PolarisCallContextCatalogFactory factory =
new PolarisCallContextCatalogFactory(
entityManager,
metaStoreManager,
metaStoreSession,
configurationStore,
diagServices,
Mockito.mock(),
new DefaultFileIOFactory()) {
@Override
public Catalog createCallContextCatalog(
RealmContext realmContext,
AuthenticatedPolarisPrincipal authenticatedPolarisPrincipal,
PolarisResolutionManifest resolvedManifest) {
Catalog catalog =
super.createCallContextCatalog(
realmContext, authenticatedPolarisPrincipal, resolvedManifest);
String fileIoImpl = "org.apache.iceberg.inmemory.InMemoryFileIO";
catalog.initialize(
externalCatalog, ImmutableMap.of(CatalogProperties.FILE_IO_IMPL, fileIoImpl));

try (FileIO fileIO =
CatalogUtil.loadFileIO(fileIoImpl, Map.of(), new Configuration())) {
TableMetadata tableMetadata =
TableMetadata.buildFromEmpty()
.addSchema(SCHEMA, SCHEMA.highestFieldId())
.setLocation(
String.format(
"%s/bucket/table/metadata/v1.metadata.json", storageLocation))
.addPartitionSpec(PartitionSpec.unpartitioned())
.addSortOrder(SortOrder.unsorted())
.assignUUID()
.build();
TableMetadataParser.overwrite(
tableMetadata, fileIO.newOutputFile(createPayload.getMetadataLocation()));
TableMetadataParser.overwrite(
tableMetadata, fileIO.newOutputFile(updatePayload.getMetadataLocation()));
}
return catalog;
}
};
try (FileIO fileIO =
CatalogUtil.loadFileIO(
"org.apache.iceberg.inmemory.InMemoryFileIO", Map.of(), new Configuration())) {
TableMetadata tableMetadata =
TableMetadata.buildFromEmpty()
.addSchema(SCHEMA, SCHEMA.highestFieldId())
.setLocation(
String.format("%s/bucket/table/metadata/v1.metadata.json", storageLocation))
.addPartitionSpec(PartitionSpec.unpartitioned())
.addSortOrder(SortOrder.unsorted())
.assignUUID()
.build();
TableMetadataParser.overwrite(
tableMetadata, fileIO.newOutputFile(createPayload.getMetadataLocation()));
TableMetadataParser.overwrite(
tableMetadata, fileIO.newOutputFile(updatePayload.getMetadataLocation()));
}

List<Set<PolarisPrivilege>> sufficientPrivilegeSets =
List.of(
Expand All @@ -1757,19 +1714,18 @@ public Catalog createCallContextCatalog(
doTestSufficientPrivilegeSets(
sufficientPrivilegeSets,
() -> {
newWrapper(Set.of(PRINCIPAL_ROLE1), externalCatalog, factory)
newWrapper(Set.of(PRINCIPAL_ROLE1), externalCatalog)
.sendNotification(table, createRequest);
newWrapper(Set.of(PRINCIPAL_ROLE1), externalCatalog, factory)
newWrapper(Set.of(PRINCIPAL_ROLE1), externalCatalog)
.sendNotification(table, updateRequest);
newWrapper(Set.of(PRINCIPAL_ROLE1), externalCatalog, factory)
.sendNotification(table, dropRequest);
newWrapper(Set.of(PRINCIPAL_ROLE1), externalCatalog, factory)
newWrapper(Set.of(PRINCIPAL_ROLE1), externalCatalog).sendNotification(table, dropRequest);
newWrapper(Set.of(PRINCIPAL_ROLE1), externalCatalog)
.sendNotification(table, validateRequest);
},
() -> {
newWrapper(Set.of(PRINCIPAL_ROLE2), externalCatalog, factory)
newWrapper(Set.of(PRINCIPAL_ROLE2), externalCatalog)
.dropNamespace(Namespace.of("extns1", "extns2"));
newWrapper(Set.of(PRINCIPAL_ROLE2), externalCatalog, factory)
newWrapper(Set.of(PRINCIPAL_ROLE2), externalCatalog)
.dropNamespace(Namespace.of("extns1"));
},
PRINCIPAL_NAME,
Expand All @@ -1779,7 +1735,7 @@ public Catalog createCallContextCatalog(
doTestSufficientPrivilegeSets(
sufficientPrivilegeSets,
() -> {
newWrapper(Set.of(PRINCIPAL_ROLE1), externalCatalog, factory)
newWrapper(Set.of(PRINCIPAL_ROLE1), externalCatalog)
.sendNotification(table, validateRequest);
},
null /* cleanupAction */,
Expand Down
Loading

0 comments on commit af16d32

Please sign in to comment.