Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.apache.polaris.core.PolarisDefaultDiagServiceImpl;
import org.apache.polaris.core.PolarisDiagnostics;
import org.apache.polaris.core.config.PolarisConfigurationStore;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.entity.PolarisPrincipalSecrets;
import org.apache.polaris.core.persistence.BasePolarisMetaStoreManagerTest;
import org.apache.polaris.core.persistence.PolarisTestMetaStoreManager;
Expand Down Expand Up @@ -90,6 +91,7 @@ protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() {
return new PolarisTestMetaStoreManager(
new TransactionalMetaStoreManagerImpl(),
new PolarisCallContext(
Mockito.mock(RealmContext.class),
session,
diagServices,
new PolarisConfigurationStore() {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public Map<String, BaseResult> purgeRealms(Iterable<String> realms) {
PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(() -> realm);
BasePersistence session = getOrCreateSessionSupplier(() -> realm).get();

PolarisCallContext callContext = new PolarisCallContext(session, diagServices);
PolarisCallContext callContext = new PolarisCallContext(() -> realm, session, diagServices);
BaseResult result = metaStoreManager.purge(callContext);
results.put(realm, result);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.polaris.core.PolarisDefaultDiagServiceImpl;
import org.apache.polaris.core.PolarisDiagnostics;
import org.apache.polaris.core.config.PolarisConfigurationStore;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.persistence.AtomicOperationMetaStoreManager;
import org.apache.polaris.core.persistence.BasePolarisMetaStoreManagerTest;
import org.apache.polaris.core.persistence.PolarisTestMetaStoreManager;
Expand Down Expand Up @@ -61,6 +62,7 @@ protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() {
return new PolarisTestMetaStoreManager(
new AtomicOperationMetaStoreManager(),
new PolarisCallContext(
Mockito.mock(RealmContext.class),
basePersistence,
diagServices,
new PolarisConfigurationStore() {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,6 @@ public PolarisCallContext(
this.clock = clock;
}

@Deprecated
public PolarisCallContext(
@Nonnull BasePersistence metaStore,
@Nonnull PolarisDiagnostics diagServices,
@Nonnull PolarisConfigurationStore configurationStore,
@Nonnull Clock clock) {
this.metaStore = metaStore;
this.diagServices = diagServices;
this.configurationStore = configurationStore;
this.clock = clock;
}

public PolarisCallContext(
@Nonnull RealmContext realmContext,
@Nonnull BasePersistence metaStore,
Expand All @@ -81,15 +69,6 @@ public PolarisCallContext(
this.clock = Clock.system(ZoneId.systemDefault());
}

@Deprecated
public PolarisCallContext(
@Nonnull BasePersistence metaStore, @Nonnull PolarisDiagnostics diagServices) {
this.metaStore = metaStore;
this.diagServices = diagServices;
this.configurationStore = new PolarisConfigurationStore() {};
this.clock = Clock.system(ZoneId.systemDefault());
}

public BasePersistence getMetaStore() {
return metaStore;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,6 @@ static void unsetCurrentContext() {
CURRENT_CONTEXT.remove();
}

// only tests are using this method now, we can get rid of them easily in a followup
static CallContext of(
final RealmContext realmContext, final PolarisCallContext polarisCallContext) {
return new CallContext() {
@Override
public RealmContext getRealmContext() {
return realmContext;
}

@Override
public PolarisCallContext getPolarisCallContext() {
return polarisCallContext;
}
};
}

/** Copy the {@link CallContext}. */
static CallContext copyOf(CallContext base) {
String realmId = base.getRealmContext().getRealmIdentifier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public Map<String, BaseResult> purgeRealms(Iterable<String> realms) {
PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(() -> realm);
TransactionalPersistence session = getOrCreateSessionSupplier(() -> realm).get();

PolarisCallContext callContext = new PolarisCallContext(session, diagServices);
PolarisCallContext callContext = new PolarisCallContext(() -> realm, session, diagServices);
BaseResult result = metaStoreManager.purge(callContext);
results.put(realm, result);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.polaris.core.PolarisDefaultDiagServiceImpl;
import org.apache.polaris.core.PolarisDiagnostics;
import org.apache.polaris.core.config.PolarisConfigurationStore;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.persistence.transactional.TreeMapMetaStore;
import org.apache.polaris.core.persistence.transactional.TreeMapTransactionalPersistenceImpl;
import org.mockito.Mockito;
Expand All @@ -37,6 +38,7 @@ public PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() {
TreeMapMetaStore store = new TreeMapMetaStore(diagServices);
PolarisCallContext callCtx =
new PolarisCallContext(
Mockito.mock(RealmContext.class),
new TreeMapTransactionalPersistenceImpl(store, Mockito.mock(), RANDOM_SECRETS),
diagServices,
new PolarisConfigurationStore() {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.polaris.core.PolarisDefaultDiagServiceImpl;
import org.apache.polaris.core.PolarisDiagnostics;
import org.apache.polaris.core.config.PolarisConfigurationStore;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.persistence.transactional.TransactionalMetaStoreManagerImpl;
import org.apache.polaris.core.persistence.transactional.TreeMapMetaStore;
import org.apache.polaris.core.persistence.transactional.TreeMapTransactionalPersistenceImpl;
Expand All @@ -37,6 +38,7 @@ public PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() {
TreeMapMetaStore store = new TreeMapMetaStore(diagServices);
PolarisCallContext callCtx =
new PolarisCallContext(
Mockito.mock(RealmContext.class),
new TreeMapTransactionalPersistenceImpl(store, Mockito.mock(), RANDOM_SECRETS),
diagServices,
new PolarisConfigurationStore() {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected PolarisCallContext callCtx() {
TreeMapMetaStore store = new TreeMapMetaStore(diagServices);
TreeMapTransactionalPersistenceImpl metaStore =
new TreeMapTransactionalPersistenceImpl(store, Mockito.mock(), RANDOM_SECRETS);
callCtx = new PolarisCallContext(metaStore, diagServices);
callCtx = new PolarisCallContext(() -> "realm", metaStore, diagServices);
}
return callCtx;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public InMemoryEntityCacheTest() {
diagServices = new PolarisDefaultDiagServiceImpl();
store = new TreeMapMetaStore(diagServices);
metaStore = new TreeMapTransactionalPersistenceImpl(store, Mockito.mock(), RANDOM_SECRETS);
callCtx = new PolarisCallContext(metaStore, diagServices);
callCtx = new PolarisCallContext(() -> "realm", metaStore, diagServices);
metaStoreManager = new TransactionalMetaStoreManagerImpl();

// bootstrap the mata store with our test schema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public void testValidateAccessToLocationsWithWildcard() {
Map<String, Boolean> config = Map.of("ALLOW_WILDCARD_LOCATION", true);
PolarisCallContext polarisCallContext =
new PolarisCallContext(
() -> "realm",
Mockito.mock(),
new PolarisDefaultDiagServiceImpl(),
new PolarisConfigurationStore() {
Expand All @@ -106,7 +107,7 @@ public void testValidateAccessToLocationsWithWildcard() {
}
},
Clock.systemUTC());
CallContext.setCurrentContext(CallContext.of(() -> "realm", polarisCallContext));
CallContext.setCurrentContext(polarisCallContext);
Map<String, Map<PolarisStorageActions, PolarisStorageIntegration.ValidationResult>> result =
storage.validateAccessToLocations(
new FileStorageConfigurationInfo(List.of("file://", "*")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public StorageCredentialCacheTest() {
// to interact with the metastore
TransactionalPersistence metaStore =
new TreeMapTransactionalPersistenceImpl(store, Mockito.mock(), RANDOM_SECRETS);
callCtx = new PolarisCallContext(metaStore, diagServices);
callCtx = new PolarisCallContext(() -> "realm", metaStore, diagServices);
metaStoreManager = Mockito.mock(PolarisMetaStoreManager.class);
storageCredentialCache = new StorageCredentialCache();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,8 @@ protected void testBrowse() {

@Test
protected void testCreateEntities() {
setCallContext();
PolarisMetaStoreManager metaStoreManager = polarisTestMetaStoreManager.polarisMetaStoreManager;
CallContext callCtx =
CallContext.of(() -> "testRealm", polarisTestMetaStoreManager.polarisCallContext);
if (CallContext.getCurrentContext() == null) {
CallContext.setCurrentContext(callCtx);
}
TaskEntity task1 = createTask("task1", 100L);
TaskEntity task2 = createTask("task2", 101L);
List<PolarisBaseEntity> createdEntities =
Expand Down Expand Up @@ -152,14 +148,24 @@ protected void testCreateEntities() {
task2.getSubTypeCode()));
}

private void setCallContext() {
if (CallContext.getCurrentContext() == null) {
var oldCtx = polarisTestMetaStoreManager.polarisCallContext;
var ctx =
new PolarisCallContext(
() -> "testRealm",
oldCtx.getMetaStore(),
oldCtx.getDiagServices(),
oldCtx.getConfigurationStore(),
oldCtx.getClock());
CallContext.setCurrentContext(ctx);
}
}

@Test
protected void testCreateEntitiesAlreadyExisting() {
setCallContext();
PolarisMetaStoreManager metaStoreManager = polarisTestMetaStoreManager.polarisMetaStoreManager;
CallContext callCtx =
CallContext.of(() -> "testRealm", polarisTestMetaStoreManager.polarisCallContext);
if (CallContext.getCurrentContext() == null) {
CallContext.setCurrentContext(callCtx);
}
TaskEntity task1 = createTask("task1", 100L);
TaskEntity task2 = createTask("task2", 101L);
List<PolarisBaseEntity> createdEntities =
Expand Down Expand Up @@ -193,12 +199,8 @@ protected void testCreateEntitiesAlreadyExisting() {

@Test
protected void testCreateEntitiesWithConflict() {
setCallContext();
PolarisMetaStoreManager metaStoreManager = polarisTestMetaStoreManager.polarisMetaStoreManager;
CallContext callCtx =
CallContext.of(() -> "testRealm", polarisTestMetaStoreManager.polarisCallContext);
if (CallContext.getCurrentContext() == null) {
CallContext.setCurrentContext(callCtx);
}
TaskEntity task1 = createTask("task1", 100L);
TaskEntity task2 = createTask("task2", 101L);
TaskEntity task3 = createTask("task3", 103L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ public void setup() {
.build();
PolarisCallContext polarisCallContext =
new PolarisCallContext(
fakeServices.realmContext(),
fakeServices
.metaStoreManagerFactory()
.getOrCreateSessionSupplier(fakeServices.realmContext())
.get(),
fakeServices.polarisDiagnostics(),
fakeServices.configurationStore(),
Mockito.mock(Clock.class));
CallContext.setCurrentContext(CallContext.of(fakeServices.realmContext(), polarisCallContext));
CallContext.setCurrentContext(polarisCallContext);
services =
TestServices.builder()
.config(Map.of("SUPPORTED_CATALOG_STORAGE_TYPES", List.of("S3", "GCS", "AZURE")))
Expand Down Expand Up @@ -185,6 +186,7 @@ private PolarisCallContext setupCallContext(PolarisMetaStoreManager metaStoreMan
MetaStoreManagerFactory metaStoreManagerFactory = services.metaStoreManagerFactory();
RealmContext realmContext = services.realmContext();
return new PolarisCallContext(
realmContext,
metaStoreManagerFactory.getOrCreateSessionSupplier(realmContext).get(),
services.polarisDiagnostics());
}
Expand All @@ -193,7 +195,7 @@ private PolarisAdminService setupPolarisAdminService(
PolarisMetaStoreManager metaStoreManager, PolarisCallContext callContext) {
RealmContext realmContext = services.realmContext();
return new PolarisAdminService(
CallContext.of(realmContext, callContext),
callContext,
services.entityManagerFactory().getOrCreateEntityManager(realmContext),
metaStoreManager,
new UnsafeInMemorySecretsManager(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,14 @@ public void before(TestInfo testInfo) {

polarisContext =
new PolarisCallContext(
realmContext,
managerFactory.getOrCreateSessionSupplier(realmContext).get(),
diagServices,
configurationStore,
clock);
callContext = polarisContext;
this.entityManager = realmEntityManagerFactory.getOrCreateEntityManager(realmContext);

callContext = CallContext.of(realmContext, polarisContext);
CallContext.setCurrentContext(callContext);

PrincipalEntity rootEntity =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.security.interfaces.RSAPublicKey;
import org.apache.polaris.core.PolarisCallContext;
import org.apache.polaris.core.config.PolarisConfigurationStore;
import org.apache.polaris.core.context.RealmContext;
import org.apache.polaris.core.entity.PolarisBaseEntity;
import org.apache.polaris.core.entity.PolarisEntitySubType;
import org.apache.polaris.core.entity.PolarisEntityType;
Expand Down Expand Up @@ -61,7 +62,8 @@ public void testSuccessfulTokenGeneration() throws Exception {
final String scope = "PRINCIPAL_ROLE:TEST";

PolarisCallContext polarisCallContext =
new PolarisCallContext(null, null, configurationStore, null);
new PolarisCallContext(
Mockito.mock(RealmContext.class), null, null, configurationStore, null);
PolarisMetaStoreManager metastoreManager = Mockito.mock(PolarisMetaStoreManager.class);
String mainSecret = "client-secret";
PolarisPrincipalSecrets principalSecrets =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class JWTSymmetricKeyGeneratorTest {
/** Sanity test to verify that we can generate a token */
@Test
public void testJWTSymmetricKeyGenerator() {
PolarisCallContext polarisCallContext = new PolarisCallContext(null, null, null, null);
PolarisCallContext polarisCallContext = Mockito.mock(PolarisCallContext.class);
PolarisMetaStoreManager metastoreManager = Mockito.mock(PolarisMetaStoreManager.class);
String mainSecret = "test_secret";
String clientId = "test_client_id";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,17 @@ public void before(TestInfo testInfo) {
userSecretsManager = userSecretsManagerFactory.getOrCreateUserSecretsManager(realmContext);
polarisContext =
new PolarisCallContext(
realmContext,
managerFactory.getOrCreateSessionSupplier(realmContext).get(),
diagServices,
configurationStore,
Clock.systemDefaultZone());
callContext = polarisContext;

entityManager =
new PolarisEntityManager(
metaStoreManager, new StorageCredentialCache(), createEntityCache(metaStoreManager));

callContext = CallContext.of(realmContext, polarisContext);

PrincipalEntity rootEntity =
new PrincipalEntity(
PolarisEntity.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public void before(TestInfo testInfo) {
userSecretsManager = userSecretsManagerFactory.getOrCreateUserSecretsManager(realmContext);
polarisContext =
new PolarisCallContext(
realmContext,
managerFactory.getOrCreateSessionSupplier(realmContext).get(),
diagServices,
configurationStore,
Expand All @@ -181,8 +182,7 @@ public void before(TestInfo testInfo) {
new StorageCredentialCache(),
new InMemoryEntityCache(metaStoreManager));

CallContext callContext = CallContext.of(realmContext, polarisContext);
CallContext.setCurrentContext(callContext);
CallContext.setCurrentContext(polarisContext);

PrincipalEntity rootEntity =
new PrincipalEntity(
Expand All @@ -206,7 +206,7 @@ public void before(TestInfo testInfo) {

PolarisAdminService adminService =
new PolarisAdminService(
callContext,
polarisContext,
entityManager,
metaStoreManager,
userSecretsManager,
Expand All @@ -232,7 +232,7 @@ public void before(TestInfo testInfo) {

PolarisPassthroughResolutionView passthroughView =
new PolarisPassthroughResolutionView(
callContext, entityManager, securityContext, CATALOG_NAME);
polarisContext, entityManager, securityContext, CATALOG_NAME);
FileIOFactory fileIOFactory =
new DefaultFileIOFactory(
new RealmEntityManagerFactory(managerFactory), managerFactory, configurationStore);
Expand All @@ -242,7 +242,7 @@ public void before(TestInfo testInfo) {
new IcebergCatalog(
entityManager,
metaStoreManager,
callContext,
polarisContext,
passthroughView,
securityContext,
Mockito.mock(),
Expand Down
Loading
Loading