diff --git a/extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/EclipseLinkPolarisMetaStoreManagerFactory.java b/extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/EclipseLinkPolarisMetaStoreManagerFactory.java index 851320eb6..d5b396fac 100644 --- a/extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/EclipseLinkPolarisMetaStoreManagerFactory.java +++ b/extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/EclipseLinkPolarisMetaStoreManagerFactory.java @@ -27,7 +27,7 @@ import java.time.Clock; import org.apache.polaris.core.PolarisConfigurationStore; import org.apache.polaris.core.PolarisDiagnostics; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.persistence.LocalPolarisMetaStoreManagerFactory; import org.apache.polaris.core.persistence.PolarisCredentialsBootstrap; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; @@ -71,16 +71,16 @@ protected PolarisEclipseLinkStore createBackingStore(@Nonnull PolarisDiagnostics @Override protected PolarisMetaStoreSession createMetaStoreSession( @Nonnull PolarisEclipseLinkStore store, - @Nonnull RealmId realmId, + @Nonnull Realm realm, @Nullable PolarisCredentialsBootstrap credentialsBootstrap, @Nonnull PolarisDiagnostics diagnostics) { return new PolarisEclipseLinkMetaStoreSessionImpl( store, storageIntegrationProvider, - realmId, + realm, configurationFile(), persistenceUnitName(), - secretsGenerator(realmId, credentialsBootstrap), + secretsGenerator(realm, credentialsBootstrap), diagnostics); } diff --git a/extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreSessionImpl.java b/extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreSessionImpl.java index 20ad64692..2745b549c 100644 --- a/extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreSessionImpl.java +++ b/extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreSessionImpl.java @@ -38,7 +38,7 @@ import java.util.function.Supplier; import java.util.stream.Collectors; import org.apache.polaris.core.PolarisDiagnostics; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisChangeTrackingVersions; import org.apache.polaris.core.entity.PolarisEntitiesActiveKey; @@ -88,21 +88,21 @@ public class PolarisEclipseLinkMetaStoreSessionImpl implements PolarisMetaStoreS * * @param store Backing store of EclipseLink implementation * @param storageIntegrationProvider Storage integration provider - * @param realmId Realm context used to communicate with different database. + * @param realm Realm used to communicate with different database. * @param confFile Optional EclipseLink configuration file. Default to 'META-INF/persistence.xml'. * @param persistenceUnitName Optional persistence-unit name in confFile. Default to 'polaris'. */ public PolarisEclipseLinkMetaStoreSessionImpl( @Nonnull PolarisEclipseLinkStore store, @Nonnull PolarisStorageIntegrationProvider storageIntegrationProvider, - @Nonnull RealmId realmId, + @Nonnull Realm realm, @Nullable String confFile, @Nullable String persistenceUnitName, @Nonnull PrincipalSecretsGenerator secretsGenerator, @Nonnull PolarisDiagnostics diagnostics) { this.diagnostics = diagnostics; - LOGGER.debug("Creating EclipseLink Meta Store Session for realm {}", realmId.id()); - emf = createEntityManagerFactory(realmId, confFile, persistenceUnitName); + LOGGER.debug("Creating EclipseLink Meta Store Session for realm {}", realm.name()); + emf = createEntityManagerFactory(realm, confFile, persistenceUnitName); // init store this.store = store; @@ -120,16 +120,15 @@ public PolarisEclipseLinkMetaStoreSessionImpl( * realm. */ private EntityManagerFactory createEntityManagerFactory( - @Nonnull RealmId realmId, @Nullable String confFile, @Nullable String persistenceUnitName) { - String realm = realmId.id(); + @Nonnull Realm realm, @Nullable String confFile, @Nullable String persistenceUnitName) { return realmFactories.computeIfAbsent( - realm, + realm.name(), key -> { try { PolarisEclipseLinkPersistenceUnit persistenceUnit = PolarisEclipseLinkPersistenceUnit.locatePersistenceUnit( confFile, persistenceUnitName); - return persistenceUnit.createEntityManagerFactory(realmId); + return persistenceUnit.createEntityManagerFactory(realm); } catch (IOException e) { throw new UncheckedIOException(e); } diff --git a/extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkPersistenceUnit.java b/extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkPersistenceUnit.java index 20ac6795f..b5ec68b29 100644 --- a/extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkPersistenceUnit.java +++ b/extension/persistence/eclipselink/src/main/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkPersistenceUnit.java @@ -43,7 +43,7 @@ import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.extension.persistence.impl.eclipselink.PolarisEclipseLinkPersistenceUnit.ClasspathResourcePolarisEclipseLinkPersistenceUnit; import org.apache.polaris.extension.persistence.impl.eclipselink.PolarisEclipseLinkPersistenceUnit.FileSystemPolarisEclipseLinkPersistenceUnit; import org.apache.polaris.extension.persistence.impl.eclipselink.PolarisEclipseLinkPersistenceUnit.JarFilePolarisEclipseLinkPersistenceUnit; @@ -57,15 +57,15 @@ sealed interface PolarisEclipseLinkPersistenceUnit FileSystemPolarisEclipseLinkPersistenceUnit, JarFilePolarisEclipseLinkPersistenceUnit { - EntityManagerFactory createEntityManagerFactory(RealmId realmId) throws IOException; + EntityManagerFactory createEntityManagerFactory(Realm realm) throws IOException; record ClasspathResourcePolarisEclipseLinkPersistenceUnit( URL resource, String resourceName, String persistenceUnitName) implements PolarisEclipseLinkPersistenceUnit { @Override - public EntityManagerFactory createEntityManagerFactory(RealmId realmId) throws IOException { - Map properties = loadProperties(resource, persistenceUnitName, realmId); + public EntityManagerFactory createEntityManagerFactory(Realm realm) throws IOException { + Map properties = loadProperties(resource, persistenceUnitName, realm); properties.put(ECLIPSELINK_PERSISTENCE_XML, resourceName); return Persistence.createEntityManagerFactory(persistenceUnitName, properties); } @@ -75,9 +75,9 @@ record FileSystemPolarisEclipseLinkPersistenceUnit(Path path, String persistence implements PolarisEclipseLinkPersistenceUnit { @Override - public EntityManagerFactory createEntityManagerFactory(RealmId realmId) throws IOException { + public EntityManagerFactory createEntityManagerFactory(Realm realm) throws IOException { Map properties = - loadProperties(path.toUri().toURL(), persistenceUnitName, realmId); + loadProperties(path.toUri().toURL(), persistenceUnitName, realm); Path archiveDirectory = path.getParent(); String descriptorPath = archiveDirectory.getParent().relativize(path).toString(); properties.put(ECLIPSELINK_PERSISTENCE_XML, descriptorPath); @@ -99,8 +99,8 @@ record JarFilePolarisEclipseLinkPersistenceUnit( implements PolarisEclipseLinkPersistenceUnit { @Override - public EntityManagerFactory createEntityManagerFactory(RealmId realmId) throws IOException { - Map properties = loadProperties(confUrl, persistenceUnitName, realmId); + public EntityManagerFactory createEntityManagerFactory(Realm realm) throws IOException { + Map properties = loadProperties(confUrl, persistenceUnitName, realm); properties.put(ECLIPSELINK_PERSISTENCE_XML, descriptorPath); ClassLoader prevClassLoader = Thread.currentThread().getContextClassLoader(); try (URLClassLoader currentClassLoader = @@ -180,7 +180,7 @@ private static URL classpathResource(String resourceName) throws IOException { /** Load the persistence unit properties from a given configuration file */ private static Map loadProperties( - @Nonnull URL confFile, @Nonnull String persistenceUnitName, @Nonnull RealmId realmId) + @Nonnull URL confFile, @Nonnull String persistenceUnitName, @Nonnull Realm realm) throws IOException { try (InputStream input = confFile.openStream()) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); @@ -200,7 +200,7 @@ private static Map loadProperties( } // Replace database name in JDBC URL with realm if (properties.containsKey(JDBC_URL)) { - properties.put(JDBC_URL, properties.get(JDBC_URL).replace("{realm}", realmId.id())); + properties.put(JDBC_URL, properties.get(JDBC_URL).replace("{realm}", realm.name())); } return properties; } catch (XPathExpressionException diff --git a/extension/persistence/eclipselink/src/test/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreManagerTest.java b/extension/persistence/eclipselink/src/test/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreManagerTest.java index 3458bdf7a..97fd4ad36 100644 --- a/extension/persistence/eclipselink/src/test/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreManagerTest.java +++ b/extension/persistence/eclipselink/src/test/java/org/apache/polaris/extension/persistence/impl/eclipselink/PolarisEclipseLinkMetaStoreManagerTest.java @@ -38,7 +38,7 @@ import org.apache.polaris.core.PolarisConfigurationStore; import org.apache.polaris.core.PolarisDefaultDiagServiceImpl; import org.apache.polaris.core.PolarisDiagnostics; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.PolarisPrincipalSecrets; import org.apache.polaris.core.persistence.BasePolarisMetaStoreManagerTest; import org.apache.polaris.core.persistence.PolarisMetaStoreManagerImpl; @@ -101,13 +101,13 @@ static void deleteConfFiles() throws IOException { protected PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() { PolarisDiagnostics diagServices = new PolarisDefaultDiagServiceImpl(); PolarisEclipseLinkStore store = new PolarisEclipseLinkStore(diagServices); - RealmId realmId = RealmId.newRealmId("realm"); + Realm realm = Realm.fromName("realm"); PolarisMetaStoreSession session = new PolarisEclipseLinkMetaStoreSessionImpl( - store, Mockito.mock(), realmId, null, "polaris", RANDOM_SECRETS, diagServices); + store, Mockito.mock(), realm, null, "polaris", RANDOM_SECRETS, diagServices); return new PolarisTestMetaStoreManager( new PolarisMetaStoreManagerImpl( - realmId, + realm, diagServices, new PolarisConfigurationStore() {}, timeSource.withZone(ZoneId.systemDefault())), @@ -128,7 +128,7 @@ void testCreateStoreSession(String confFile, boolean success) { new PolarisEclipseLinkMetaStoreSessionImpl( store, Mockito.mock(), - RealmId.newRealmId("realm"), + Realm.fromName("realm"), confFile, "polaris", RANDOM_SECRETS, diff --git a/integration-tests/src/main/java/org/apache/polaris/service/it/env/Server.java b/integration-tests/src/main/java/org/apache/polaris/service/it/env/Server.java index 22fecf163..e804456cf 100644 --- a/integration-tests/src/main/java/org/apache/polaris/service/it/env/Server.java +++ b/integration-tests/src/main/java/org/apache/polaris/service/it/env/Server.java @@ -25,7 +25,7 @@ * the provided admin credentials or create new principals. */ public interface Server extends AutoCloseable { - String realmId(); + String realm(); /** * The base URI to all Polaris APIs (e.g. the common base of the Iceberg REST API endpoints and diff --git a/integration-tests/src/main/java/org/apache/polaris/service/it/ext/PolarisIntegrationTestExtension.java b/integration-tests/src/main/java/org/apache/polaris/service/it/ext/PolarisIntegrationTestExtension.java index e2b6c43b7..97dbc6c61 100644 --- a/integration-tests/src/main/java/org/apache/polaris/service/it/ext/PolarisIntegrationTestExtension.java +++ b/integration-tests/src/main/java/org/apache/polaris/service/it/ext/PolarisIntegrationTestExtension.java @@ -92,7 +92,7 @@ private static class Env implements CloseableResource { private Env(Server server) { this.server = server; - this.endpoints = new PolarisApiEndpoints(server.baseUri(), server.realmId()); + this.endpoints = new PolarisApiEndpoints(server.baseUri(), server.realm()); } PolarisApiEndpoints endpoints() { diff --git a/integration-tests/src/main/java/org/apache/polaris/service/it/ext/PolarisServerManager.java b/integration-tests/src/main/java/org/apache/polaris/service/it/ext/PolarisServerManager.java index 85e99e0c1..2c6b99cf8 100644 --- a/integration-tests/src/main/java/org/apache/polaris/service/it/ext/PolarisServerManager.java +++ b/integration-tests/src/main/java/org/apache/polaris/service/it/ext/PolarisServerManager.java @@ -42,9 +42,9 @@ public interface PolarisServerManager { * Returns server connection parameters for the tests under the specified context. * *

Implementations may reuse the same server for multiple contexts (with the same of different - * {@link Server#realmId() realm IDs}) or create a fresh server for each context. In any case, - * {@link Server#close()} will be invoked when the context provided as the argument to this call - * is closed. + * {@link Server#realm() realm}) or create a fresh server for each context. In any case, {@link + * Server#close()} will be invoked when the context provided as the argument to this call is + * closed. * *

Note: {@link Server} objects are generally attached to the test {@code class} context, but * this is not guaranteed. diff --git a/polaris-core/src/main/java/org/apache/polaris/core/PolarisConfigurationStore.java b/polaris-core/src/main/java/org/apache/polaris/core/PolarisConfigurationStore.java index 9e7f43c2e..162851f4a 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/PolarisConfigurationStore.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/PolarisConfigurationStore.java @@ -23,7 +23,7 @@ import jakarta.annotation.Nullable; import java.util.ArrayList; import java.util.List; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.CatalogEntity; /** @@ -35,11 +35,11 @@ public interface PolarisConfigurationStore { * Retrieve the current value for a configuration key. May be null if not set. * * @param the type of the configuration value - * @param realmId the realm context to check for overrides; may be null. + * @param realm the realm to check for overrides; may be null. * @param configName the name of the configuration key to check * @return the current value set for the configuration key or null if not set */ - default @Nullable T getConfiguration(@Nullable RealmId realmId, String configName) { + default @Nullable T getConfiguration(@Nullable Realm realm, String configName) { return null; } @@ -48,15 +48,15 @@ public interface PolarisConfigurationStore { * value. * * @param the type of the configuration value - * @param realmId the realm context to check for overrides; may be null. + * @param realm the realm to check for overrides; may be null. * @param configName the name of the configuration key to check * @param defaultValue the default value if the configuration key has no value * @return the current value or the supplied default value */ default @Nonnull T getConfiguration( - @Nullable RealmId realmId, String configName, @Nonnull T defaultValue) { + @Nullable Realm realm, String configName, @Nonnull T defaultValue) { Preconditions.checkNotNull(defaultValue, "Cannot pass null as a default value"); - T configValue = getConfiguration(realmId, configName); + T configValue = getConfiguration(realm, configName); return configValue != null ? configValue : defaultValue; } @@ -88,13 +88,12 @@ public interface PolarisConfigurationStore { * Retrieve the current value for a configuration. * * @param the type of the configuration value - * @param realmId the realm context to check for overrides; may be null. + * @param realm the realm to check for overrides; may be null. * @param config the configuration to load * @return the current value set for the configuration key or null if not set */ - default @Nonnull T getConfiguration( - @Nullable RealmId realmId, PolarisConfiguration config) { - T result = getConfiguration(realmId, config.key, config.defaultValue); + default @Nonnull T getConfiguration(@Nullable Realm realm, PolarisConfiguration config) { + T result = getConfiguration(realm, config.key, config.defaultValue); return tryCast(config, result); } @@ -103,20 +102,18 @@ public interface PolarisConfigurationStore { * present. * * @param the type of the configuration value - * @param realmId the realm context to check for overrides; may be null. + * @param realm the realm to check for overrides; may be null. * @param catalogEntity the catalog to check for an override * @param config the configuration to load * @return the current value set for the configuration key or null if not set */ default @Nonnull T getConfiguration( - @Nullable RealmId realmId, - @Nonnull CatalogEntity catalogEntity, - PolarisConfiguration config) { + @Nullable Realm realm, @Nonnull CatalogEntity catalogEntity, PolarisConfiguration config) { if (config.hasCatalogConfig() && catalogEntity.getPropertiesAsMap().containsKey(config.catalogConfig())) { return tryCast(config, catalogEntity.getPropertiesAsMap().get(config.catalogConfig())); } else { - return getConfiguration(realmId, config); + return getConfiguration(realm, config); } } } diff --git a/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizer.java b/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizer.java index 245f07b62..e6c327d51 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizer.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizer.java @@ -22,7 +22,7 @@ import jakarta.annotation.Nullable; import java.util.List; import java.util.Set; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.persistence.PolarisResolvedPathWrapper; @@ -30,7 +30,7 @@ public interface PolarisAuthorizer { void authorizeOrThrow( - @Nonnull RealmId realmId, + @Nonnull Realm realm, @Nonnull AuthenticatedPolarisPrincipal authenticatedPrincipal, @Nonnull Set activatedEntities, @Nonnull PolarisAuthorizableOperation authzOp, @@ -38,7 +38,7 @@ void authorizeOrThrow( @Nullable PolarisResolvedPathWrapper secondary); void authorizeOrThrow( - @Nonnull RealmId realmId, + @Nonnull Realm realm, @Nonnull AuthenticatedPolarisPrincipal authenticatedPrincipal, @Nonnull Set activatedEntities, @Nonnull PolarisAuthorizableOperation authzOp, diff --git a/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizerImpl.java b/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizerImpl.java index 199b73d60..4016b4b20 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizerImpl.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizerImpl.java @@ -100,7 +100,7 @@ import org.apache.iceberg.exceptions.ForbiddenException; import org.apache.polaris.core.PolarisConfiguration; import org.apache.polaris.core.PolarisConfigurationStore; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisEntityConstants; import org.apache.polaris.core.entity.PolarisEntityCore; @@ -487,14 +487,14 @@ public boolean matchesOrIsSubsumedBy( @Override public void authorizeOrThrow( - @Nonnull RealmId realmId, + @Nonnull Realm realm, @Nonnull AuthenticatedPolarisPrincipal authenticatedPrincipal, @Nonnull Set activatedEntities, @Nonnull PolarisAuthorizableOperation authzOp, @Nullable PolarisResolvedPathWrapper target, @Nullable PolarisResolvedPathWrapper secondary) { authorizeOrThrow( - realmId, + realm, authenticatedPrincipal, activatedEntities, authzOp, @@ -504,7 +504,7 @@ public void authorizeOrThrow( @Override public void authorizeOrThrow( - @Nonnull RealmId realmId, + @Nonnull Realm realm, @Nonnull AuthenticatedPolarisPrincipal authenticatedPrincipal, @Nonnull Set activatedEntities, @Nonnull PolarisAuthorizableOperation authzOp, @@ -512,7 +512,7 @@ public void authorizeOrThrow( @Nullable List secondaries) { boolean enforceCredentialRotationRequiredState = featureConfig.getConfiguration( - realmId, PolarisConfiguration.ENFORCE_PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_CHECKING); + realm, PolarisConfiguration.ENFORCE_PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_CHECKING); if (enforceCredentialRotationRequiredState && authenticatedPrincipal .getPrincipalEntity() diff --git a/polaris-core/src/main/java/org/apache/polaris/core/context/RealmId.java b/polaris-core/src/main/java/org/apache/polaris/core/context/Realm.java similarity index 73% rename from polaris-core/src/main/java/org/apache/polaris/core/context/RealmId.java rename to polaris-core/src/main/java/org/apache/polaris/core/context/Realm.java index 56bedbd3e..6fa308cfe 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/context/RealmId.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/context/Realm.java @@ -25,23 +25,23 @@ import org.immutables.value.Value; /** - * Represents the ID of the realm used in a REST request associated with routing to independent and - * isolated "universes". + * Represents an isolated "universe" within the system, such as different deployments (e.g., + * production, staging, QA) or distinct accounts. */ @PolarisImmutable -@JsonSerialize(as = ImmutableRealmId.class) -@JsonDeserialize(as = ImmutableRealmId.class) -public interface RealmId { +@JsonSerialize(as = ImmutableRealm.class) +@JsonDeserialize(as = ImmutableRealm.class) +public interface Realm { - static RealmId newRealmId(String id) { - return ImmutableRealmId.of(id); + static Realm fromName(String name) { + return ImmutableRealm.of(name); } - static RealmId copyOf(RealmId realmId) { - return ImmutableRealmId.copyOf(realmId); + static Realm copyOf(Realm realm) { + return ImmutableRealm.copyOf(realm); } @Value.Parameter @JsonValue - String id(); + String name(); } diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java index 2d64e45b0..f0e98702b 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java @@ -28,7 +28,7 @@ import org.apache.polaris.core.PolarisConfigurationStore; import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.auth.PolarisSecretsManager.PrincipalSecretsResult; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.PolarisEntity; import org.apache.polaris.core.entity.PolarisEntityConstants; import org.apache.polaris.core.entity.PolarisEntitySubType; @@ -70,29 +70,28 @@ protected LocalPolarisMetaStoreManagerFactory( protected abstract PolarisMetaStoreSession createMetaStoreSession( @Nonnull StoreType store, - @Nonnull RealmId realmId, + @Nonnull Realm realm, @Nullable PolarisCredentialsBootstrap credentialsBootstrap, @Nonnull PolarisDiagnostics diagnostics); protected PrincipalSecretsGenerator secretsGenerator( - RealmId realmId, @Nullable PolarisCredentialsBootstrap credentialsBootstrap) { + Realm realm, @Nullable PolarisCredentialsBootstrap credentialsBootstrap) { if (credentialsBootstrap != null) { - return PrincipalSecretsGenerator.bootstrap(realmId.id(), credentialsBootstrap); + return PrincipalSecretsGenerator.bootstrap(realm.name(), credentialsBootstrap); } else { return PrincipalSecretsGenerator.RANDOM_SECRETS; } } - private void initializeForRealm( - RealmId realmId, PolarisCredentialsBootstrap credentialsBootstrap) { + private void initializeForRealm(Realm realm, PolarisCredentialsBootstrap credentialsBootstrap) { final StoreType backingStore = createBackingStore(diagnostics); sessionSupplierMap.put( - realmId.id(), - () -> createMetaStoreSession(backingStore, realmId, credentialsBootstrap, diagnostics)); + realm.name(), + () -> createMetaStoreSession(backingStore, realm, credentialsBootstrap, diagnostics)); PolarisMetaStoreManager metaStoreManager = - new PolarisMetaStoreManagerImpl(realmId, diagnostics, configurationStore, clock); - metaStoreManagerMap.put(realmId.id(), metaStoreManager); + new PolarisMetaStoreManagerImpl(realm, diagnostics, configurationStore, clock); + metaStoreManagerMap.put(realm.name(), metaStoreManager); } @Override @@ -100,14 +99,14 @@ public synchronized Map bootstrapRealms( List realms, PolarisCredentialsBootstrap credentialsBootstrap) { Map results = new HashMap<>(); - for (String realm : realms) { - RealmId realmId = RealmId.newRealmId(realm); - if (!metaStoreManagerMap.containsKey(realmId.id())) { - initializeForRealm(realmId, credentialsBootstrap); + for (String realmName : realms) { + Realm realm = Realm.fromName(realmName); + if (!metaStoreManagerMap.containsKey(realm.name())) { + initializeForRealm(realm, credentialsBootstrap); PrincipalSecretsResult secretsResult = bootstrapServiceAndCreatePolarisPrincipalForRealm( - realmId, metaStoreManagerMap.get(realmId.id())); - results.put(realmId.id(), secretsResult); + realm, metaStoreManagerMap.get(realm.name())); + results.put(realm.name(), secretsResult); } } @@ -117,9 +116,8 @@ public synchronized Map bootstrapRealms( @Override public void purgeRealms(List realms) { for (String realm : realms) { - PolarisMetaStoreManager metaStoreManager = - getOrCreateMetaStoreManager(RealmId.newRealmId(realm)); - PolarisMetaStoreSession session = getOrCreateSessionSupplier(RealmId.newRealmId(realm)).get(); + PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(Realm.fromName(realm)); + PolarisMetaStoreSession session = getOrCreateSessionSupplier(Realm.fromName(realm)).get(); metaStoreManager.purge(session); @@ -130,44 +128,43 @@ public void purgeRealms(List realms) { } @Override - public synchronized PolarisMetaStoreManager getOrCreateMetaStoreManager(RealmId realmId) { - if (!metaStoreManagerMap.containsKey(realmId.id())) { - initializeForRealm(realmId, null); - checkPolarisServiceBootstrappedForRealm(realmId, metaStoreManagerMap.get(realmId.id())); + public synchronized PolarisMetaStoreManager getOrCreateMetaStoreManager(Realm realm) { + if (!metaStoreManagerMap.containsKey(realm.name())) { + initializeForRealm(realm, null); + checkPolarisServiceBootstrappedForRealm(realm, metaStoreManagerMap.get(realm.name())); } - return metaStoreManagerMap.get(realmId.id()); + return metaStoreManagerMap.get(realm.name()); } @Override - public synchronized Supplier getOrCreateSessionSupplier( - RealmId realmId) { - if (!sessionSupplierMap.containsKey(realmId.id())) { - initializeForRealm(realmId, null); - checkPolarisServiceBootstrappedForRealm(realmId, metaStoreManagerMap.get(realmId.id())); + public synchronized Supplier getOrCreateSessionSupplier(Realm realm) { + if (!sessionSupplierMap.containsKey(realm.name())) { + initializeForRealm(realm, null); + checkPolarisServiceBootstrappedForRealm(realm, metaStoreManagerMap.get(realm.name())); } else { - checkPolarisServiceBootstrappedForRealm(realmId, metaStoreManagerMap.get(realmId.id())); + checkPolarisServiceBootstrappedForRealm(realm, metaStoreManagerMap.get(realm.name())); } - return sessionSupplierMap.get(realmId.id()); + return sessionSupplierMap.get(realm.name()); } @Override - public synchronized StorageCredentialCache getOrCreateStorageCredentialCache(RealmId realmId) { - if (!storageCredentialCacheMap.containsKey(realmId.id())) { + public synchronized StorageCredentialCache getOrCreateStorageCredentialCache(Realm realm) { + if (!storageCredentialCacheMap.containsKey(realm.name())) { storageCredentialCacheMap.put( - realmId.id(), new StorageCredentialCache(diagnostics, configurationStore)); + realm.name(), new StorageCredentialCache(diagnostics, configurationStore)); } - return storageCredentialCacheMap.get(realmId.id()); + return storageCredentialCacheMap.get(realm.name()); } @Override - public synchronized EntityCache getOrCreateEntityCache(RealmId realmId) { - if (!entityCacheMap.containsKey(realmId.id())) { - PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(realmId); - entityCacheMap.put(realmId.id(), new EntityCache(metaStoreManager, diagnostics)); + public synchronized EntityCache getOrCreateEntityCache(Realm realm) { + if (!entityCacheMap.containsKey(realm.name())) { + PolarisMetaStoreManager metaStoreManager = getOrCreateMetaStoreManager(realm); + entityCacheMap.put(realm.name(), new EntityCache(metaStoreManager, diagnostics)); } - return entityCacheMap.get(realmId.id()); + return entityCacheMap.get(realm.name()); } /** @@ -176,8 +173,8 @@ public synchronized EntityCache getOrCreateEntityCache(RealmId realmId) { * credentials and print them to stdout */ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm( - RealmId realmId, PolarisMetaStoreManager metaStoreManager) { - PolarisMetaStoreSession metaStoreSession = sessionSupplierMap.get(realmId.id()).get(); + Realm realm, PolarisMetaStoreManager metaStoreManager) { + PolarisMetaStoreSession metaStoreSession = sessionSupplierMap.get(realm.name()).get(); PolarisMetaStoreManager.EntityResult preliminaryRootPrincipalLookup = metaStoreManager.readEntityByName( @@ -229,9 +226,9 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm * entities */ private void checkPolarisServiceBootstrappedForRealm( - RealmId realmId, PolarisMetaStoreManager metaStoreManager) { + Realm realm, PolarisMetaStoreManager metaStoreManager) { - PolarisMetaStoreSession metaStoreSession = sessionSupplierMap.get(realmId.id()).get(); + PolarisMetaStoreSession metaStoreSession = sessionSupplierMap.get(realm.name()).get(); PolarisMetaStoreManager.EntityResult rootPrincipalLookup = metaStoreManager.readEntityByName( @@ -244,7 +241,7 @@ private void checkPolarisServiceBootstrappedForRealm( if (!rootPrincipalLookup.isSuccess()) { LOGGER.error( "\n\n Realm {} is not bootstrapped, could not load root principal. Please run Bootstrap command. \n\n", - realmId.id()); + realm.name()); throw new IllegalStateException( "Realm is not bootstrapped, please run server in bootstrap mode."); } diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/MetaStoreManagerFactory.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/MetaStoreManagerFactory.java index bcf87bd6e..6cefb0e0f 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/MetaStoreManagerFactory.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/MetaStoreManagerFactory.java @@ -22,20 +22,20 @@ import java.util.Map; import java.util.function.Supplier; import org.apache.polaris.core.auth.PolarisSecretsManager.PrincipalSecretsResult; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.persistence.cache.EntityCache; import org.apache.polaris.core.storage.cache.StorageCredentialCache; /** Configuration interface for configuring the {@link PolarisMetaStoreManager}. */ public interface MetaStoreManagerFactory { - PolarisMetaStoreManager getOrCreateMetaStoreManager(RealmId realmId); + PolarisMetaStoreManager getOrCreateMetaStoreManager(Realm realm); - Supplier getOrCreateSessionSupplier(RealmId realmId); + Supplier getOrCreateSessionSupplier(Realm realm); - StorageCredentialCache getOrCreateStorageCredentialCache(RealmId realmId); + StorageCredentialCache getOrCreateStorageCredentialCache(Realm realm); - EntityCache getOrCreateEntityCache(RealmId realmId); + EntityCache getOrCreateEntityCache(Realm realm); Map bootstrapRealms( List realms, PolarisCredentialsBootstrap credentialsBootstrap); diff --git a/polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisMetaStoreManagerImpl.java b/polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisMetaStoreManagerImpl.java index 83979d4ae..b441c4042 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisMetaStoreManagerImpl.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/persistence/PolarisMetaStoreManagerImpl.java @@ -38,7 +38,7 @@ import java.util.stream.Collectors; import org.apache.polaris.core.PolarisConfigurationStore; import org.apache.polaris.core.PolarisDiagnostics; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.AsyncTaskType; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisChangeTrackingVersions; @@ -76,17 +76,17 @@ public class PolarisMetaStoreManagerImpl implements PolarisMetaStoreManager { /** use synchronous drop for entities */ private static final boolean USE_SYNCHRONOUS_DROP = true; - private final RealmId realmId; + private final Realm realm; private final PolarisDiagnostics diagnostics; private final PolarisConfigurationStore configurationStore; private final Clock clock; public PolarisMetaStoreManagerImpl( - RealmId realmId, + Realm realm, PolarisDiagnostics diagnostics, PolarisConfigurationStore configurationStore, Clock clock) { - this.realmId = realmId; + this.realm = realm; this.diagnostics = diagnostics; this.configurationStore = configurationStore; this.clock = clock; @@ -1815,7 +1815,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( PolarisObjectMapperUtil.parseTaskState(entity); long taskAgeTimeout = configurationStore.getConfiguration( - realmId, + realm, PolarisTaskConstants.TASK_TIMEOUT_MILLIS_CONFIG, PolarisTaskConstants.TASK_TIMEOUT_MILLIS); return taskState == null @@ -1888,7 +1888,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( try { EnumMap creds = storageIntegration.getSubscopedCreds( - realmId, + realm, diagnostics, storageConfigurationInfo, allowListOperation, @@ -1935,7 +1935,7 @@ private PolarisEntityResolver resolveSecurableToRoleGrant( readStorageConfiguration(diagnostics, reloadedEntity.getEntity()); Map validateLocationAccess = storageIntegration - .validateAccessToLocations(realmId, storageConfigurationInfo, actions, locations) + .validateAccessToLocations(realm, storageConfigurationInfo, actions, locations) .entrySet() .stream() .collect( diff --git a/polaris-core/src/main/java/org/apache/polaris/core/storage/InMemoryStorageIntegration.java b/polaris-core/src/main/java/org/apache/polaris/core/storage/InMemoryStorageIntegration.java index 5570d85a8..4a93c3460 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/storage/InMemoryStorageIntegration.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/storage/InMemoryStorageIntegration.java @@ -26,11 +26,11 @@ import java.util.function.Function; import java.util.stream.Collectors; import org.apache.polaris.core.PolarisConfigurationStore; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; /** * Base class for in-memory implementations of {@link PolarisStorageIntegration}. A basic - * implementation of {@link PolarisStorageIntegration#validateAccessToLocations(RealmId, + * implementation of {@link PolarisStorageIntegration#validateAccessToLocations(Realm, * PolarisStorageConfigurationInfo, Set, Set)} is provided that checks to see that the list of * locations being accessed is among the list of {@link * PolarisStorageConfigurationInfo#getAllowedLocations()}. Locations being accessed must be equal to @@ -53,7 +53,7 @@ public InMemoryStorageIntegration( * Check that the locations being accessed are all equal to or subdirectories of at least one of * the {@link PolarisStorageConfigurationInfo#getAllowedLocations}. * - * @param realmId + * @param realm * @param configurationStore * @param actions a set of operation actions to validate, like LIST/READ/DELETE/WRITE/ALL * @param locations a set of locations to get access to @@ -63,7 +63,7 @@ public InMemoryStorageIntegration( */ public static Map> validateSubpathsOfAllowedLocations( - @Nonnull RealmId realmId, + @Nonnull Realm realm, @Nonnull PolarisConfigurationStore configurationStore, @Nonnull PolarisStorageConfigurationInfo storageConfig, @Nonnull Set actions, @@ -86,7 +86,7 @@ public InMemoryStorageIntegration( allowedLocationStrings.stream().map(StorageLocation::of).collect(Collectors.toList()); boolean allowWildcardLocation = - configurationStore.getConfiguration(realmId, "ALLOW_WILDCARD_LOCATION", false); + configurationStore.getConfiguration(realm, "ALLOW_WILDCARD_LOCATION", false); if (allowWildcardLocation && allowedLocationStrings.contains("*")) { return locations.stream() @@ -129,11 +129,11 @@ public InMemoryStorageIntegration( @Override @Nonnull public Map> validateAccessToLocations( - @Nonnull RealmId realmId, + @Nonnull Realm realm, @Nonnull T storageConfig, @Nonnull Set actions, @Nonnull Set locations) { return validateSubpathsOfAllowedLocations( - realmId, configurationStore, storageConfig, actions, locations); + realm, configurationStore, storageConfig, actions, locations); } } diff --git a/polaris-core/src/main/java/org/apache/polaris/core/storage/PolarisStorageConfigurationInfo.java b/polaris-core/src/main/java/org/apache/polaris/core/storage/PolarisStorageConfigurationInfo.java index f56677dfd..8b19c0a1b 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/storage/PolarisStorageConfigurationInfo.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/storage/PolarisStorageConfigurationInfo.java @@ -40,7 +40,7 @@ import org.apache.polaris.core.PolarisConfigurationStore; import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.admin.model.Catalog; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.CatalogEntity; import org.apache.polaris.core.entity.PolarisEntity; import org.apache.polaris.core.entity.PolarisEntityConstants; @@ -137,7 +137,7 @@ public static PolarisStorageConfigurationInfo deserialize( } public static Optional forEntityPath( - RealmId realmId, + Realm realm, PolarisConfigurationStore configurationStore, PolarisDiagnostics diagnostics, List entityPath) { @@ -167,7 +167,7 @@ public static Optional forEntityPath( CatalogEntity catalog = CatalogEntity.of(entityPath.get(0)); boolean allowEscape = configurationStore.getConfiguration( - realmId, catalog, PolarisConfiguration.ALLOW_UNSTRUCTURED_TABLE_LOCATION); + realm, catalog, PolarisConfiguration.ALLOW_UNSTRUCTURED_TABLE_LOCATION); if (!allowEscape && catalog.getCatalogType() != Catalog.TypeEnum.EXTERNAL && baseLocation != null) { diff --git a/polaris-core/src/main/java/org/apache/polaris/core/storage/PolarisStorageIntegration.java b/polaris-core/src/main/java/org/apache/polaris/core/storage/PolarisStorageIntegration.java index 0ea08d78e..f7f7017a8 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/storage/PolarisStorageIntegration.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/storage/PolarisStorageIntegration.java @@ -24,7 +24,7 @@ import java.util.Objects; import java.util.Set; import org.apache.polaris.core.PolarisDiagnostics; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; /** * Abstract of Polaris Storage Integration. It holds the reference to an object that having the @@ -47,7 +47,7 @@ public String getStorageIdentifierOrId() { /** * Subscope the creds against the allowed read and write locations. * - * @param realmId the realm context + * @param realm the realm * @param diagnostics the diagnostics service * @param storageConfig storage configuration * @param allowListOperation whether to allow LIST on all the provided allowed read/write @@ -57,7 +57,7 @@ public String getStorageIdentifierOrId() { * @return An enum map including the scoped credentials */ public abstract EnumMap getSubscopedCreds( - @Nonnull RealmId realmId, + @Nonnull Realm realm, @Nonnull PolarisDiagnostics diagnostics, @Nonnull T storageConfig, boolean allowListOperation, @@ -67,7 +67,7 @@ public abstract EnumMap getSubscopedCreds( /** * Validate access for the provided operation actions and locations. * - * @param realmId + * @param realm * @param actions a set of operation actions to validate, like LIST/READ/DELETE/WRITE/ALL * @param locations a set of locations to get access to * @return A Map of string, representing the result of validation, the key value is {@code @@ -99,13 +99,13 @@ public abstract EnumMap getSubscopedCreds( @Nonnull public abstract Map> validateAccessToLocations( - RealmId realmId, + Realm realm, @Nonnull T storageConfig, @Nonnull Set actions, @Nonnull Set locations); /** - * Result of calling {@link PolarisStorageIntegration#validateAccessToLocations(RealmId, + * Result of calling {@link PolarisStorageIntegration#validateAccessToLocations(Realm, * PolarisStorageConfigurationInfo, Set, Set)} */ public static final class ValidationResult { diff --git a/polaris-core/src/main/java/org/apache/polaris/core/storage/aws/AwsCredentialsStorageIntegration.java b/polaris-core/src/main/java/org/apache/polaris/core/storage/aws/AwsCredentialsStorageIntegration.java index 45b406ba5..dbaff09ab 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/storage/aws/AwsCredentialsStorageIntegration.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/storage/aws/AwsCredentialsStorageIntegration.java @@ -30,7 +30,7 @@ import java.util.stream.Stream; import org.apache.polaris.core.PolarisConfigurationStore; import org.apache.polaris.core.PolarisDiagnostics; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.storage.InMemoryStorageIntegration; import org.apache.polaris.core.storage.PolarisCredentialProperty; import org.apache.polaris.core.storage.StorageUtil; @@ -60,7 +60,7 @@ public AwsCredentialsStorageIntegration( /** {@inheritDoc} */ @Override public EnumMap getSubscopedCreds( - @Nonnull RealmId realmId, + @Nonnull Realm realm, @Nonnull PolarisDiagnostics diagnostics, @Nonnull AwsStorageConfigurationInfo storageConfig, boolean allowListOperation, @@ -80,8 +80,7 @@ public EnumMap getSubscopedCreds( allowedWriteLocations) .toJson()) .durationSeconds( - configurationStore.getConfiguration( - realmId, STORAGE_CREDENTIAL_DURATION_SECONDS)) + configurationStore.getConfiguration(realm, STORAGE_CREDENTIAL_DURATION_SECONDS)) .build()); EnumMap credentialMap = new EnumMap<>(PolarisCredentialProperty.class); diff --git a/polaris-core/src/main/java/org/apache/polaris/core/storage/azure/AzureCredentialsStorageIntegration.java b/polaris-core/src/main/java/org/apache/polaris/core/storage/azure/AzureCredentialsStorageIntegration.java index 4e82a792e..dd20a7a5b 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/storage/azure/AzureCredentialsStorageIntegration.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/storage/azure/AzureCredentialsStorageIntegration.java @@ -48,7 +48,7 @@ import org.apache.polaris.core.PolarisConfiguration; import org.apache.polaris.core.PolarisConfigurationStore; import org.apache.polaris.core.PolarisDiagnostics; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.storage.InMemoryStorageIntegration; import org.apache.polaris.core.storage.PolarisCredentialProperty; import org.slf4j.Logger; @@ -75,7 +75,7 @@ public AzureCredentialsStorageIntegration(PolarisConfigurationStore configuratio @Override public EnumMap getSubscopedCreds( - @Nonnull RealmId realmId, + @Nonnull Realm realm, @Nonnull PolarisDiagnostics diagnostics, @Nonnull AzureStorageConfigurationInfo storageConfig, boolean allowListOperation, @@ -132,7 +132,7 @@ public EnumMap getSubscopedCreds( OffsetDateTime startTime = start.truncatedTo(ChronoUnit.SECONDS).atOffset(ZoneOffset.UTC); int intendedDurationSeconds = configurationStore.getConfiguration( - realmId, PolarisConfiguration.STORAGE_CREDENTIAL_DURATION_SECONDS); + realm, PolarisConfiguration.STORAGE_CREDENTIAL_DURATION_SECONDS); OffsetDateTime intendedEndTime = start.plusSeconds(intendedDurationSeconds).atOffset(ZoneOffset.UTC); OffsetDateTime maxAllowedEndTime = diff --git a/polaris-core/src/main/java/org/apache/polaris/core/storage/gcp/GcpCredentialsStorageIntegration.java b/polaris-core/src/main/java/org/apache/polaris/core/storage/gcp/GcpCredentialsStorageIntegration.java index 224b850d2..18c2b24a2 100644 --- a/polaris-core/src/main/java/org/apache/polaris/core/storage/gcp/GcpCredentialsStorageIntegration.java +++ b/polaris-core/src/main/java/org/apache/polaris/core/storage/gcp/GcpCredentialsStorageIntegration.java @@ -40,7 +40,7 @@ import java.util.stream.Stream; import org.apache.polaris.core.PolarisConfigurationStore; import org.apache.polaris.core.PolarisDiagnostics; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.storage.InMemoryStorageIntegration; import org.apache.polaris.core.storage.PolarisCredentialProperty; import org.apache.polaris.core.storage.PolarisStorageIntegration; @@ -74,7 +74,7 @@ public GcpCredentialsStorageIntegration( @Override public EnumMap getSubscopedCreds( - @Nonnull RealmId realmId, + @Nonnull Realm realm, @Nonnull PolarisDiagnostics diagnostics, @Nonnull GcpStorageConfigurationInfo storageConfig, boolean allowListOperation, diff --git a/polaris-core/src/test/java/org/apache/polaris/core/persistence/EntityCacheTest.java b/polaris-core/src/test/java/org/apache/polaris/core/persistence/EntityCacheTest.java index c87eb5e7f..6670d44ee 100644 --- a/polaris-core/src/test/java/org/apache/polaris/core/persistence/EntityCacheTest.java +++ b/polaris-core/src/test/java/org/apache/polaris/core/persistence/EntityCacheTest.java @@ -26,7 +26,7 @@ import org.apache.polaris.core.PolarisConfigurationStore; import org.apache.polaris.core.PolarisDefaultDiagServiceImpl; import org.apache.polaris.core.PolarisDiagnostics; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisEntitySubType; import org.apache.polaris.core.entity.PolarisEntityType; @@ -85,7 +85,7 @@ public EntityCacheTest() { new PolarisTreeMapMetaStoreSessionImpl(store, Mockito.mock(), RANDOM_SECRETS, diagServices); metaStoreManager = new PolarisMetaStoreManagerImpl( - RealmId.newRealmId("test"), + Realm.fromName("test"), diagServices, new PolarisConfigurationStore() {}, Clock.systemUTC()); diff --git a/polaris-core/src/test/java/org/apache/polaris/core/persistence/PolarisTreeMapMetaStoreManagerTest.java b/polaris-core/src/test/java/org/apache/polaris/core/persistence/PolarisTreeMapMetaStoreManagerTest.java index ac84bb3f4..728ba6f54 100644 --- a/polaris-core/src/test/java/org/apache/polaris/core/persistence/PolarisTreeMapMetaStoreManagerTest.java +++ b/polaris-core/src/test/java/org/apache/polaris/core/persistence/PolarisTreeMapMetaStoreManagerTest.java @@ -24,7 +24,7 @@ import org.apache.polaris.core.PolarisConfigurationStore; import org.apache.polaris.core.PolarisDefaultDiagServiceImpl; import org.apache.polaris.core.PolarisDiagnostics; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.mockito.Mockito; public class PolarisTreeMapMetaStoreManagerTest extends BasePolarisMetaStoreManagerTest { @@ -36,7 +36,7 @@ public PolarisTestMetaStoreManager createPolarisTestMetaStoreManager() { new PolarisTreeMapMetaStoreSessionImpl(store, Mockito.mock(), RANDOM_SECRETS, diagServices); return new PolarisTestMetaStoreManager( new PolarisMetaStoreManagerImpl( - RealmId.newRealmId("test"), + Realm.fromName("test"), diagServices, new PolarisConfigurationStore() {}, timeSource.withZone(ZoneId.systemDefault())), diff --git a/polaris-core/src/test/java/org/apache/polaris/core/persistence/ResolverTest.java b/polaris-core/src/test/java/org/apache/polaris/core/persistence/ResolverTest.java index 6eef9dc9a..9535a7268 100644 --- a/polaris-core/src/test/java/org/apache/polaris/core/persistence/ResolverTest.java +++ b/polaris-core/src/test/java/org/apache/polaris/core/persistence/ResolverTest.java @@ -37,7 +37,7 @@ import org.apache.polaris.core.PolarisDefaultDiagServiceImpl; import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.auth.AuthenticatedPolarisPrincipal; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisEntityCore; import org.apache.polaris.core.entity.PolarisEntitySubType; @@ -106,7 +106,7 @@ public ResolverTest() { new PolarisTreeMapMetaStoreSessionImpl(store, Mockito.mock(), RANDOM_SECRETS, diagServices); metaStoreManager = new PolarisMetaStoreManagerImpl( - RealmId.newRealmId("test"), + Realm.fromName("test"), diagServices, new PolarisConfigurationStore() {}, Clock.systemUTC()); diff --git a/polaris-core/src/test/java/org/apache/polaris/core/storage/InMemoryStorageIntegrationTest.java b/polaris-core/src/test/java/org/apache/polaris/core/storage/InMemoryStorageIntegrationTest.java index c0c686bbc..a033c0ec3 100644 --- a/polaris-core/src/test/java/org/apache/polaris/core/storage/InMemoryStorageIntegrationTest.java +++ b/polaris-core/src/test/java/org/apache/polaris/core/storage/InMemoryStorageIntegrationTest.java @@ -26,14 +26,14 @@ import java.util.Set; import org.apache.polaris.core.PolarisConfigurationStore; import org.apache.polaris.core.PolarisDiagnostics; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.storage.aws.AwsStorageConfigurationInfo; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; class InMemoryStorageIntegrationTest { - private final RealmId realmId = RealmId.newRealmId("test"); + private final Realm realm = Realm.fromName("test"); @Test public void testValidateAccessToLocations() { @@ -41,7 +41,7 @@ public void testValidateAccessToLocations() { new MockInMemoryStorageIntegration(new PolarisConfigurationStore() {}); Map> result = storage.validateAccessToLocations( - realmId, + realm, new AwsStorageConfigurationInfo( PolarisStorageConfigurationInfo.StorageType.S3, List.of( @@ -96,14 +96,14 @@ public void testValidateAccessToLocationsWithWildcard() { new PolarisConfigurationStore() { @SuppressWarnings("unchecked") @Override - public @Nullable T getConfiguration(RealmId realmId, String configName) { + public @Nullable T getConfiguration(Realm realm, String configName) { return (T) config.get(configName); } }; MockInMemoryStorageIntegration storage = new MockInMemoryStorageIntegration(configurationStore); Map> result = storage.validateAccessToLocations( - realmId, + realm, new FileStorageConfigurationInfo(List.of("file://", "*")), Set.of(PolarisStorageActions.READ), Set.of( @@ -144,7 +144,7 @@ public void testValidateAccessToLocationsNoAllowedLocations() { new MockInMemoryStorageIntegration(new PolarisConfigurationStore() {}); Map> result = storage.validateAccessToLocations( - realmId, + realm, new AwsStorageConfigurationInfo( PolarisStorageConfigurationInfo.StorageType.S3, List.of(), @@ -180,7 +180,7 @@ public void testValidateAccessToLocationsWithPrefixOfAllowedLocation() { new MockInMemoryStorageIntegration(new PolarisConfigurationStore() {}); Map> result = storage.validateAccessToLocations( - realmId, + realm, new AwsStorageConfigurationInfo( PolarisStorageConfigurationInfo.StorageType.S3, List.of("s3://bucket/path/to/warehouse"), @@ -206,7 +206,7 @@ public MockInMemoryStorageIntegration(PolarisConfigurationStore configurationSto @Override public EnumMap getSubscopedCreds( - @Nonnull RealmId realmId, + @Nonnull Realm realm, @Nonnull PolarisDiagnostics diagnostics, @Nonnull PolarisStorageConfigurationInfo storageConfig, boolean allowListOperation, diff --git a/polaris-core/src/test/java/org/apache/polaris/service/storage/PolarisConfigurationStoreTest.java b/polaris-core/src/test/java/org/apache/polaris/service/storage/PolarisConfigurationStoreTest.java index a438e6058..406fc50eb 100644 --- a/polaris-core/src/test/java/org/apache/polaris/service/storage/PolarisConfigurationStoreTest.java +++ b/polaris-core/src/test/java/org/apache/polaris/service/storage/PolarisConfigurationStoreTest.java @@ -22,14 +22,14 @@ import java.util.List; import org.apache.polaris.core.PolarisConfiguration; import org.apache.polaris.core.PolarisConfigurationStore; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; /** Unit test for the default behaviors of the PolarisConfigurationStore interface. */ public class PolarisConfigurationStoreTest { - private final RealmId realmId = RealmId.newRealmId("test"); + private final Realm realm = Realm.fromName("test"); @Test public void testConfigsCanBeCastedFromString() { @@ -48,7 +48,7 @@ public void testConfigsCanBeCastedFromString() { */ @SuppressWarnings("unchecked") @Override - public @Nullable T getConfiguration(RealmId realmId, String configName) { + public @Nullable T getConfiguration(Realm realm, String configName) { for (PolarisConfiguration c : configs) { if (c.key.equals(configName)) { return (T) String.valueOf(c.defaultValue); @@ -65,7 +65,7 @@ public void testConfigsCanBeCastedFromString() { // Ensure that we can fetch all the configs and that the value is what we expect, which // is the config's default value based on how we've implemented PolarisConfigurationStore above. for (PolarisConfiguration c : configs) { - Assertions.assertEquals(c.defaultValue, store.getConfiguration(realmId, c)); + Assertions.assertEquals(c.defaultValue, store.getConfiguration(realm, c)); } } @@ -79,14 +79,13 @@ public void testInvalidCastThrowsException() { new PolarisConfigurationStore() { @SuppressWarnings("unchecked") @Override - public T getConfiguration(RealmId realmId, String configName) { + public T getConfiguration(Realm realm, String configName) { return (T) "abc123"; } }; for (PolarisConfiguration c : configs) { - Assertions.assertThrows( - NumberFormatException.class, () -> store.getConfiguration(realmId, c)); + Assertions.assertThrows(NumberFormatException.class, () -> store.getConfiguration(realm, c)); } } diff --git a/polaris-core/src/test/java/org/apache/polaris/service/storage/aws/AwsCredentialsStorageIntegrationTest.java b/polaris-core/src/test/java/org/apache/polaris/service/storage/aws/AwsCredentialsStorageIntegrationTest.java index 27e6602b0..f940e960f 100644 --- a/polaris-core/src/test/java/org/apache/polaris/service/storage/aws/AwsCredentialsStorageIntegrationTest.java +++ b/polaris-core/src/test/java/org/apache/polaris/service/storage/aws/AwsCredentialsStorageIntegrationTest.java @@ -26,7 +26,7 @@ import java.util.Set; import org.apache.polaris.core.PolarisConfigurationStore; import org.apache.polaris.core.PolarisDiagnostics; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.storage.PolarisCredentialProperty; import org.apache.polaris.core.storage.PolarisStorageConfigurationInfo; import org.apache.polaris.core.storage.aws.AwsCredentialsStorageIntegration; @@ -61,7 +61,7 @@ class AwsCredentialsStorageIntegrationTest { .build(); public static final String AWS_PARTITION = "aws"; - private static final RealmId REALM_CONTEXT = RealmId.newRealmId("realm"); + private static final Realm REALM = Realm.fromName("realm"); @Test public void testGetSubscopedCreds() { @@ -82,7 +82,7 @@ public void testGetSubscopedCreds() { EnumMap credentials = new AwsCredentialsStorageIntegration(new PolarisConfigurationStore() {}, stsClient) .getSubscopedCreds( - REALM_CONTEXT, + REALM, Mockito.mock(PolarisDiagnostics.class), new AwsStorageConfigurationInfo( PolarisStorageConfigurationInfo.StorageType.S3, @@ -221,7 +221,7 @@ public void testGetSubscopedCredsInlinePolicy(String awsPartition) { EnumMap credentials = new AwsCredentialsStorageIntegration(new PolarisConfigurationStore() {}, stsClient) .getSubscopedCreds( - REALM_CONTEXT, + REALM, Mockito.mock(PolarisDiagnostics.class), new AwsStorageConfigurationInfo( storageType, @@ -316,7 +316,7 @@ public void testGetSubscopedCredsInlinePolicyWithoutList() { EnumMap credentials = new AwsCredentialsStorageIntegration(new PolarisConfigurationStore() {}, stsClient) .getSubscopedCreds( - REALM_CONTEXT, + REALM, Mockito.mock(PolarisDiagnostics.class), new AwsStorageConfigurationInfo( PolarisStorageConfigurationInfo.StorageType.S3, @@ -409,7 +409,7 @@ public void testGetSubscopedCredsInlinePolicyWithoutWrites() { EnumMap credentials = new AwsCredentialsStorageIntegration(new PolarisConfigurationStore() {}, stsClient) .getSubscopedCreds( - REALM_CONTEXT, + REALM, Mockito.mock(PolarisDiagnostics.class), new AwsStorageConfigurationInfo( storageType, @@ -472,7 +472,7 @@ public void testGetSubscopedCredsInlinePolicyWithEmptyReadAndWrite() { EnumMap credentials = new AwsCredentialsStorageIntegration(new PolarisConfigurationStore() {}, stsClient) .getSubscopedCreds( - REALM_CONTEXT, + REALM, Mockito.mock(PolarisDiagnostics.class), new AwsStorageConfigurationInfo( PolarisStorageConfigurationInfo.StorageType.S3, @@ -506,7 +506,7 @@ public void testClientRegion() { EnumMap credentials = new AwsCredentialsStorageIntegration(new PolarisConfigurationStore() {}, stsClient) .getSubscopedCreds( - REALM_CONTEXT, + REALM, Mockito.mock(PolarisDiagnostics.class), new AwsStorageConfigurationInfo( PolarisStorageConfigurationInfo.StorageType.S3, @@ -537,7 +537,7 @@ public void testNoClientRegion() { EnumMap credentials = new AwsCredentialsStorageIntegration(new PolarisConfigurationStore() {}, stsClient) .getSubscopedCreds( - REALM_CONTEXT, + REALM, Mockito.mock(PolarisDiagnostics.class), new AwsStorageConfigurationInfo( PolarisStorageConfigurationInfo.StorageType.S3, diff --git a/polaris-core/src/test/java/org/apache/polaris/service/storage/azure/AzureCredentialStorageIntegrationTest.java b/polaris-core/src/test/java/org/apache/polaris/service/storage/azure/AzureCredentialStorageIntegrationTest.java index f0b296e4b..63c82f610 100644 --- a/polaris-core/src/test/java/org/apache/polaris/service/storage/azure/AzureCredentialStorageIntegrationTest.java +++ b/polaris-core/src/test/java/org/apache/polaris/service/storage/azure/AzureCredentialStorageIntegrationTest.java @@ -49,7 +49,7 @@ import java.util.stream.Stream; import org.apache.polaris.core.PolarisConfigurationStore; import org.apache.polaris.core.PolarisDefaultDiagServiceImpl; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.storage.PolarisCredentialProperty; import org.apache.polaris.core.storage.azure.AzureCredentialsStorageIntegration; import org.apache.polaris.core.storage.azure.AzureStorageConfigurationInfo; @@ -68,7 +68,7 @@ public class AzureCredentialStorageIntegrationTest { private final String clientId = System.getenv("AZURE_CLIENT_ID"); private final String clientSecret = System.getenv("AZURE_CLIENT_SECRET"); private final String tenantId = System.getenv("AZURE_TENANT_ID"); - private final RealmId realmId = RealmId.newRealmId("realm"); + private final Realm realm = Realm.fromName("realm"); private void assumeEnvVariablesNotNull() { Assumptions.assumeThat( @@ -88,7 +88,7 @@ public void testNegativeCases() { Assertions.assertThatThrownBy( () -> subscopedCredsForOperations( - realmId, differentEndpointList, /* allowedWriteLoc= */ new ArrayList<>(), true)) + realm, differentEndpointList, /* allowedWriteLoc= */ new ArrayList<>(), true)) .isInstanceOf(RuntimeException.class); List differentStorageAccts = @@ -98,7 +98,7 @@ public void testNegativeCases() { Assertions.assertThatThrownBy( () -> subscopedCredsForOperations( - realmId, differentStorageAccts, /* allowedWriteLoc= */ new ArrayList<>(), true)) + realm, differentStorageAccts, /* allowedWriteLoc= */ new ArrayList<>(), true)) .isInstanceOf(RuntimeException.class); List differentContainers = Arrays.asList( @@ -108,7 +108,7 @@ public void testNegativeCases() { Assertions.assertThatThrownBy( () -> subscopedCredsForOperations( - realmId, differentContainers, /* allowedWriteLoc= */ new ArrayList<>(), true)) + realm, differentContainers, /* allowedWriteLoc= */ new ArrayList<>(), true)) .isInstanceOf(RuntimeException.class); } @@ -125,8 +125,8 @@ public void testGetSubscopedTokenList(boolean allowListAction, String service) { service)); Map credsMap = subscopedCredsForOperations( - /* allowedReadLoc= */ realmId, - allowedLoc, + realm, + /* allowedReadLoc= */ allowedLoc, /* allowedWriteLoc= */ new ArrayList<>(), allowListAction); Assertions.assertThat(credsMap).hasSize(2); @@ -197,7 +197,7 @@ public void testGetSubscopedTokenRead( service, allowedPrefix)); Map credsMap = subscopedCredsForOperations( - /* allowedReadLoc= */ realmId, + /* allowedReadLoc= */ realm, allowedLoc, /* allowedWriteLoc= */ new ArrayList<>(), /* allowListAction= */ false); @@ -268,7 +268,7 @@ public void testGetSubscopedTokenWrite( service, allowedPrefix)); Map credsMap = subscopedCredsForOperations( - /* allowedReadLoc= */ realmId, + /* allowedReadLoc= */ realm, new ArrayList<>(), /* allowedWriteLoc= */ allowedLoc, /* allowListAction= */ false); @@ -345,7 +345,7 @@ public void testGetSubscopedTokenWrite( } private Map subscopedCredsForOperations( - RealmId realmId, + Realm realm, List allowedReadLoc, List allowedWriteLoc, boolean allowListAction) { @@ -358,7 +358,7 @@ private Map subscopedCredsForOperations( new AzureCredentialsStorageIntegration(new PolarisConfigurationStore() {}); EnumMap credsMap = azureCredsIntegration.getSubscopedCreds( - realmId, + realm, new PolarisDefaultDiagServiceImpl(), azureConfig, allowListAction, diff --git a/polaris-core/src/test/java/org/apache/polaris/service/storage/gcp/GcpCredentialsStorageIntegrationTest.java b/polaris-core/src/test/java/org/apache/polaris/service/storage/gcp/GcpCredentialsStorageIntegrationTest.java index 44f316531..dda55f230 100644 --- a/polaris-core/src/test/java/org/apache/polaris/service/storage/gcp/GcpCredentialsStorageIntegrationTest.java +++ b/polaris-core/src/test/java/org/apache/polaris/service/storage/gcp/GcpCredentialsStorageIntegrationTest.java @@ -50,7 +50,7 @@ import java.util.Set; import org.apache.polaris.core.PolarisConfigurationStore; import org.apache.polaris.core.PolarisDefaultDiagServiceImpl; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.storage.PolarisCredentialProperty; import org.apache.polaris.core.storage.gcp.GcpCredentialsStorageIntegration; import org.apache.polaris.core.storage.gcp.GcpStorageConfigurationInfo; @@ -73,7 +73,7 @@ public void testSubscope(boolean allowedListAction) throws Exception { .describedAs("Environment variable GOOGLE_APPLICATION_CREDENTIALS not exits") .isNotNull() .isNotEmpty(); - RealmId realmId = RealmId.newRealmId("realm"); + Realm realm = Realm.fromName("realm"); List allowedRead = Arrays.asList( "gs://sfc-dev1-regtest/polaris-test/subscoped-test/read1/", @@ -82,8 +82,7 @@ public void testSubscope(boolean allowedListAction) throws Exception { Arrays.asList( "gs://sfc-dev1-regtest/polaris-test/subscoped-test/write1/", "gs://sfc-dev1-regtest/polaris-test/subscoped-test/write2/"); - Storage storageClient = - setupStorageClient(realmId, allowedRead, allowedWrite, allowedListAction); + Storage storageClient = setupStorageClient(realm, allowedRead, allowedWrite, allowedListAction); BlobInfo blobInfoGoodWrite = createStorageBlob("sfc-dev1-regtest", "polaris-test/subscoped-test/write1/", "file.txt"); BlobInfo blobInfoBad = @@ -126,7 +125,7 @@ public void testSubscope(boolean allowedListAction) throws Exception { "gs://sfc-dev1-regtest/polaris-test/subscoped-test/write2/", "gs://sfc-dev1-regtest/polaris-test/subscoped-test/write3/"); Storage clientForDelete = - setupStorageClient(realmId, List.of(), allowedWrite2, allowedListAction); + setupStorageClient(realm, List.of(), allowedWrite2, allowedListAction); // can not delete because it is not in allowed write path for this client Assertions.assertThatThrownBy(() -> clientForDelete.delete(blobInfoGoodWrite.getBlobId())) @@ -138,13 +137,13 @@ public void testSubscope(boolean allowedListAction) throws Exception { } private Storage setupStorageClient( - RealmId realmId, + Realm realm, List allowedReadLoc, List allowedWriteLoc, boolean allowListAction) throws IOException { Map credsMap = - subscopedCredsForOperations(realmId, allowedReadLoc, allowedWriteLoc, allowListAction); + subscopedCredsForOperations(realm, allowedReadLoc, allowedWriteLoc, allowListAction); return createStorageClient(credsMap); } @@ -167,7 +166,7 @@ private Storage createStorageClient(Map creds } private Map subscopedCredsForOperations( - RealmId realmId, + Realm realm, List allowedReadLoc, List allowedWriteLoc, boolean allowListAction) @@ -183,7 +182,7 @@ private Map subscopedCredsForOperations( ServiceOptions.getFromServiceLoader(HttpTransportFactory.class, NetHttpTransport::new)); EnumMap credsMap = gcpCredsIntegration.getSubscopedCreds( - realmId, + realm, new PolarisDefaultDiagServiceImpl(), gcpConfig, allowListAction, diff --git a/quarkus/defaults/src/main/resources/application.properties b/quarkus/defaults/src/main/resources/application.properties index 5c7afdf99..45d827c89 100644 --- a/quarkus/defaults/src/main/resources/application.properties +++ b/quarkus/defaults/src/main/resources/application.properties @@ -44,11 +44,11 @@ quarkus.log.level=INFO quarkus.log.console.enable=true quarkus.log.console.level=ALL quarkus.log.console.json=false -quarkus.log.console.format=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] [%X{requestId},%X{realmId}] [%X{traceId},%X{parentId},%X{spanId},%X{sampled}] (%t) %s%e%n +quarkus.log.console.format=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] [%X{requestId},%X{realm}] [%X{traceId},%X{parentId},%X{spanId},%X{sampled}] (%t) %s%e%n quarkus.log.file.enable=true quarkus.log.file.level=ALL quarkus.log.file.json=false -quarkus.log.file.format=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] [%X{requestId},%X{realmId}] [%X{traceId},%X{parentId},%X{spanId},%X{sampled}] (%t) %s%e%n +quarkus.log.file.format=%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] [%X{requestId},%X{realm}] [%X{traceId},%X{parentId},%X{spanId},%X{sampled}] (%t) %s%e%n quarkus.log.file.path=./logs/polaris.log quarkus.log.file.rotation.file-suffix=.yyyy-MM-dd.gz quarkus.log.file.rotation.max-file-size=10M diff --git a/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/config/QuarkusProducers.java b/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/config/QuarkusProducers.java index 446d73716..0551abe25 100644 --- a/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/config/QuarkusProducers.java +++ b/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/config/QuarkusProducers.java @@ -39,7 +39,7 @@ import org.apache.polaris.core.auth.AuthenticatedPolarisPrincipal; import org.apache.polaris.core.auth.PolarisAuthorizer; import org.apache.polaris.core.auth.PolarisAuthorizerImpl; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.persistence.MetaStoreManagerFactory; import org.apache.polaris.core.persistence.PolarisEntityManager; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; @@ -53,7 +53,7 @@ import org.apache.polaris.service.catalog.io.FileIOFactory; import org.apache.polaris.service.config.RealmEntityManagerFactory; import org.apache.polaris.service.context.RealmContextConfiguration; -import org.apache.polaris.service.context.RealmIdResolver; +import org.apache.polaris.service.context.RealmResolver; import org.apache.polaris.service.persistence.InMemoryPolarisMetaStoreManagerFactory; import org.apache.polaris.service.quarkus.auth.QuarkusAuthenticationConfiguration; import org.apache.polaris.service.quarkus.catalog.io.QuarkusFileIOConfiguration; @@ -100,8 +100,8 @@ public PolarisDiagnostics polarisDiagnostics() { @Produces @RequestScoped - public RealmId realmId(@Context HttpServerRequest request, RealmIdResolver realmIdResolver) { - return realmIdResolver.resolveRealmContext( + public Realm realm(@Context HttpServerRequest request, RealmResolver realmResolver) { + return realmResolver.resolveRealmContext( request.absoluteURI(), request.method().name(), request.path(), @@ -112,50 +112,49 @@ public RealmId realmId(@Context HttpServerRequest request, RealmIdResolver realm @Produces @RequestScoped public PolarisMetaStoreSession metaStoreSession( - MetaStoreManagerFactory metaStoreManagerFactory, RealmId realmId) { - return metaStoreManagerFactory.getOrCreateSessionSupplier(realmId).get(); + MetaStoreManagerFactory metaStoreManagerFactory, Realm realm) { + return metaStoreManagerFactory.getOrCreateSessionSupplier(realm).get(); } @Produces @RequestScoped // TODO break into separate beans public PolarisMetaStoreManager polarisMetaStoreManager( - MetaStoreManagerFactory metaStoreManagerFactory, RealmId realmId) { - return metaStoreManagerFactory.getOrCreateMetaStoreManager(realmId); + MetaStoreManagerFactory metaStoreManagerFactory, Realm realm) { + return metaStoreManagerFactory.getOrCreateMetaStoreManager(realm); } @Produces @RequestScoped public StorageCredentialCache storageCredentialCache( - MetaStoreManagerFactory metaStoreManagerFactory, RealmId realmId) { - return metaStoreManagerFactory.getOrCreateStorageCredentialCache(realmId); + MetaStoreManagerFactory metaStoreManagerFactory, Realm realm) { + return metaStoreManagerFactory.getOrCreateStorageCredentialCache(realm); } @Produces @RequestScoped - public EntityCache entityCache(MetaStoreManagerFactory metaStoreManagerFactory, RealmId realmId) { - return metaStoreManagerFactory.getOrCreateEntityCache(realmId); + public EntityCache entityCache(MetaStoreManagerFactory metaStoreManagerFactory, Realm realm) { + return metaStoreManagerFactory.getOrCreateEntityCache(realm); } @Produces @RequestScoped public PolarisEntityManager polarisEntityManager( - RealmEntityManagerFactory realmEntityManagerFactory, RealmId realmId) { - return realmEntityManagerFactory.getOrCreateEntityManager(realmId); + RealmEntityManagerFactory realmEntityManagerFactory, Realm realm) { + return realmEntityManagerFactory.getOrCreateEntityManager(realm); } @Produces @RequestScoped - public TokenBroker tokenBroker(TokenBrokerFactory tokenBrokerFactory, RealmId realmId) { - return tokenBrokerFactory.apply(realmId); + public TokenBroker tokenBroker(TokenBrokerFactory tokenBrokerFactory, Realm realm) { + return tokenBrokerFactory.apply(realm); } // Polaris service beans - selected from @Identifier-annotated beans @Produces - public RealmIdResolver realmContextResolver( - QuarkusRealmContextConfiguration config, - @Any Instance realmContextResolvers) { + public RealmResolver realmContextResolver( + QuarkusRealmContextConfiguration config, @Any Instance realmContextResolvers) { return realmContextResolvers.select(Identifier.Literal.of(config.type())).get(); } diff --git a/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/context/QuarkusRealmContextConfiguration.java b/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/context/QuarkusRealmContextConfiguration.java index a05cf57a8..2d5e199f3 100644 --- a/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/context/QuarkusRealmContextConfiguration.java +++ b/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/context/QuarkusRealmContextConfiguration.java @@ -21,15 +21,14 @@ import io.quarkus.runtime.annotations.StaticInitSafe; import io.smallrye.config.ConfigMapping; import org.apache.polaris.service.context.RealmContextConfiguration; -import org.apache.polaris.service.context.RealmIdResolver; +import org.apache.polaris.service.context.RealmResolver; @StaticInitSafe @ConfigMapping(prefix = "polaris.realm-context") public interface QuarkusRealmContextConfiguration extends RealmContextConfiguration { /** - * The type of the realm context resolver. Must be a registered {@link RealmIdResolver} - * identifier. + * The type of the realm context resolver. Must be a registered {@link RealmResolver} identifier. */ String type(); } diff --git a/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/logging/QuarkusLoggingMDCFilter.java b/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/logging/QuarkusLoggingMDCFilter.java index 79664c705..5518dd99e 100644 --- a/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/logging/QuarkusLoggingMDCFilter.java +++ b/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/logging/QuarkusLoggingMDCFilter.java @@ -22,7 +22,7 @@ import io.vertx.ext.web.RoutingContext; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.slf4j.MDC; @ApplicationScoped @@ -33,7 +33,7 @@ public class QuarkusLoggingMDCFilter { private static final String REQUEST_ID_KEY = "requestId"; private static final String REALM_ID_KEY = "realmId"; - @Inject RealmId realmId; + @Inject Realm realm; @Inject QuarkusLoggingConfiguration loggingConfiguration; @@ -41,7 +41,7 @@ public static String requestId(RoutingContext rc) { return rc.get(REQUEST_ID_KEY); } - public static String realmId(RoutingContext rc) { + public static String realm(RoutingContext rc) { return rc.get(REALM_ID_KEY); } @@ -57,8 +57,8 @@ public void applyMDCContext(RoutingContext rc) { MDC.put(REQUEST_ID_KEY, requestId); rc.put(REQUEST_ID_KEY, requestId); } - MDC.put(REALM_ID_KEY, realmId.id()); - rc.put(REALM_ID_KEY, realmId.id()); + MDC.put(REALM_ID_KEY, realm.name()); + rc.put(REALM_ID_KEY, realm.name()); // Do not explicitly remove the MDC values from the request context with an end handler, // as this could remove MDC context still in use in TaskExecutor threads // rc.addEndHandler( diff --git a/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/metrics/QuarkusValueExpressionResolver.java b/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/metrics/QuarkusValueExpressionResolver.java index bbbeb7cbc..5f01ad750 100644 --- a/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/metrics/QuarkusValueExpressionResolver.java +++ b/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/metrics/QuarkusValueExpressionResolver.java @@ -22,7 +22,7 @@ import io.micrometer.common.lang.Nullable; import jakarta.annotation.Nonnull; import jakarta.enterprise.context.ApplicationScoped; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; @ApplicationScoped public class QuarkusValueExpressionResolver implements ValueExpressionResolver { @@ -30,8 +30,8 @@ public class QuarkusValueExpressionResolver implements ValueExpressionResolver { @Override public String resolve(@Nonnull String expression, @Nullable Object parameter) { // TODO maybe replace with CEL of some expression engine and make this more generic - if (parameter instanceof RealmId realmId && expression.equals("realm.id")) { - return realmId.id(); + if (parameter instanceof Realm realm && expression.equals("realm.id")) { + return realm.name(); } return null; } diff --git a/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/metrics/RealmIdTagContributor.java b/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/metrics/RealmIdTagContributor.java index df7b1f137..fa4927427 100644 --- a/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/metrics/RealmIdTagContributor.java +++ b/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/metrics/RealmIdTagContributor.java @@ -24,26 +24,26 @@ import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import java.util.HashMap; -import org.apache.polaris.core.context.RealmId; -import org.apache.polaris.service.context.RealmIdResolver; +import org.apache.polaris.core.context.Realm; +import org.apache.polaris.service.context.RealmResolver; @ApplicationScoped public class RealmIdTagContributor implements HttpServerMetricsTagsContributor { public static final String TAG_REALM = "realm_id"; - @Inject RealmIdResolver realmIdResolver; + @Inject RealmResolver realmResolver; @Override public Tags contribute(Context context) { // FIXME request scope does not work here, so we have to resolve the realm context manually HttpServerRequest request = context.request(); - RealmId realmId = resolveRealmContext(request); - return Tags.of(TAG_REALM, realmId.id()); + Realm realm = resolveRealmContext(request); + return Tags.of(TAG_REALM, realm.name()); } - private RealmId resolveRealmContext(HttpServerRequest request) { - return realmIdResolver.resolveRealmContext( + private Realm resolveRealmContext(HttpServerRequest request) { + return realmResolver.resolveRealmContext( request.absoluteURI(), request.method().name(), request.path(), diff --git a/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/task/QuarkusTaskExecutorImpl.java b/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/task/QuarkusTaskExecutorImpl.java index a9c5c1efd..3ab94e6b5 100644 --- a/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/task/QuarkusTaskExecutorImpl.java +++ b/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/task/QuarkusTaskExecutorImpl.java @@ -30,7 +30,7 @@ import java.util.concurrent.ExecutorService; import org.apache.polaris.core.PolarisConfigurationStore; import org.apache.polaris.core.PolarisDiagnostics; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.persistence.MetaStoreManagerFactory; import org.apache.polaris.service.quarkus.tracing.QuarkusTracingFilter; import org.apache.polaris.service.task.TaskExecutorImpl; @@ -71,17 +71,17 @@ public void init() { } @Override - protected void handleTask(long taskEntityId, RealmId realmId, int attempt) { + protected void handleTask(long taskEntityId, Realm realm, int attempt) { Span span = tracer .spanBuilder("polaris.task") .setParent(Context.current()) - .setAttribute(QuarkusTracingFilter.REALM_ID_ATTRIBUTE, realmId.id()) + .setAttribute(QuarkusTracingFilter.REALM_ID_ATTRIBUTE, realm.name()) .setAttribute("polaris.task.entity.id", taskEntityId) .setAttribute("polaris.task.attempt", attempt) .startSpan(); try (Scope ignored = span.makeCurrent()) { - super.handleTask(taskEntityId, realmId, attempt); + super.handleTask(taskEntityId, realm, attempt); } finally { span.end(); } diff --git a/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/tracing/QuarkusTracingFilter.java b/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/tracing/QuarkusTracingFilter.java index 28811ad91..7ddbac153 100644 --- a/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/tracing/QuarkusTracingFilter.java +++ b/quarkus/service/src/main/java/org/apache/polaris/service/quarkus/tracing/QuarkusTracingFilter.java @@ -39,11 +39,11 @@ public void applySpanAttributes(RoutingContext rc) { if (!sdkDisabled) { Span span = Span.current(); String requestId = QuarkusLoggingMDCFilter.requestId(rc); - String realmId = QuarkusLoggingMDCFilter.realmId(rc); + String realm = QuarkusLoggingMDCFilter.realm(rc); if (requestId != null) { span.setAttribute(REQUEST_ID_ATTRIBUTE, requestId); } - span.setAttribute(REALM_ID_ATTRIBUTE, realmId); + span.setAttribute(REALM_ID_ATTRIBUTE, realm); } rc.next(); } diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/TestServices.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/TestServices.java index 81d34dd51..bf2291e02 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/TestServices.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/TestServices.java @@ -30,7 +30,7 @@ import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.auth.AuthenticatedPolarisPrincipal; import org.apache.polaris.core.auth.PolarisAuthorizer; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.PolarisEntity; import org.apache.polaris.core.entity.PrincipalEntity; import org.apache.polaris.core.persistence.PolarisEntityManager; @@ -53,10 +53,10 @@ public record TestServices( IcebergRestCatalogApi restApi, PolarisCatalogsApi catalogsApi, - RealmId realmId, + Realm realm, SecurityContext securityContext) { - private static final RealmId testRealm = RealmId.newRealmId("test-realm"); + private static final Realm testRealm = Realm.fromName("test-realm"); public static TestServices inMemory(Map config) { return inMemory(new TestFileIOFactory(), config); diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/TimedApplicationEventListenerTest.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/TimedApplicationEventListenerTest.java index 36e84ac17..53b03747f 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/TimedApplicationEventListenerTest.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/TimedApplicationEventListenerTest.java @@ -18,7 +18,7 @@ */ package org.apache.polaris.service.quarkus; -import static org.apache.polaris.service.context.TestRealmIdResolver.REALM_PROPERTY_KEY; +import static org.apache.polaris.service.context.TestRealmResolver.REALM_PROPERTY_KEY; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.InstanceOfAssertFactories.type; diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/ManagementServiceTest.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/ManagementServiceTest.java index 4af7b2331..0c34457b5 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/ManagementServiceTest.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/ManagementServiceTest.java @@ -62,7 +62,7 @@ public void testCreateCatalogWithDisallowedStorageConfig() { .catalogsApi() .createCatalog( new CreateCatalogRequest(catalog), - services.realmId(), + services.realm(), services.securityContext())) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Unsupported storage type: FILE"); @@ -90,9 +90,7 @@ public void testUpdateCatalogWithDisallowedStorageConfig() { services .catalogsApi() .createCatalog( - new CreateCatalogRequest(catalog), - services.realmId(), - services.securityContext())) { + new CreateCatalogRequest(catalog), services.realm(), services.securityContext())) { assertThat(response).returns(Response.Status.CREATED.getStatusCode(), Response::getStatus); } @@ -101,7 +99,7 @@ public void testUpdateCatalogWithDisallowedStorageConfig() { try (Response response = services .catalogsApi() - .getCatalog(catalogName, services.realmId(), services.securityContext())) { + .getCatalog(catalogName, services.realm(), services.securityContext())) { assertThat(response).returns(Response.Status.OK.getStatusCode(), Response::getStatus); fetchedCatalog = (Catalog) response.getEntity(); @@ -127,7 +125,7 @@ public void testUpdateCatalogWithDisallowedStorageConfig() { services .catalogsApi() .updateCatalog( - catalogName, updateRequest, services.realmId(), services.securityContext())) + catalogName, updateRequest, services.realm(), services.securityContext())) .isInstanceOf(IllegalArgumentException.class) .hasMessage("Unsupported storage type: FILE"); } diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/PolarisAdminServiceAuthzTest.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/PolarisAdminServiceAuthzTest.java index d92ce3c8e..e3af7e38f 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/PolarisAdminServiceAuthzTest.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/PolarisAdminServiceAuthzTest.java @@ -49,7 +49,7 @@ private PolarisAdminService newTestAdminService(Set activatedPrincipalRo final AuthenticatedPolarisPrincipal authenticatedPrincipal = new AuthenticatedPolarisPrincipal(principalEntity, activatedPrincipalRoles); return new PolarisAdminService( - realmId, + realm, entityManager, metaStoreManager, metaStoreSession, diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/PolarisAuthzTestBase.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/PolarisAuthzTestBase.java index 485f46348..10e186142 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/PolarisAuthzTestBase.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/PolarisAuthzTestBase.java @@ -51,7 +51,7 @@ import org.apache.polaris.core.auth.AuthenticatedPolarisPrincipal; import org.apache.polaris.core.auth.PolarisAuthorizer; import org.apache.polaris.core.auth.PolarisAuthorizerImpl; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.CatalogEntity; import org.apache.polaris.core.entity.CatalogRoleEntity; import org.apache.polaris.core.entity.PolarisBaseEntity; @@ -162,7 +162,7 @@ public Map getConfigOverrides() { protected PolarisMetaStoreSession metaStoreSession; protected PolarisBaseEntity catalogEntity; protected PrincipalEntity principalEntity; - protected RealmId realmId; + protected Realm realm; protected AuthenticatedPolarisPrincipal authenticatedRoot; @BeforeAll @@ -177,10 +177,10 @@ public static void setUpMocks() { @BeforeEach public void before(TestInfo testInfo) { - realmId = testInfo::getDisplayName; - metaStoreManager = managerFactory.getOrCreateMetaStoreManager(realmId); - metaStoreSession = managerFactory.getOrCreateSessionSupplier(realmId).get(); - entityManager = realmEntityManagerFactory.getOrCreateEntityManager(realmId); + realm = testInfo::getDisplayName; + metaStoreManager = managerFactory.getOrCreateMetaStoreManager(realm); + metaStoreSession = managerFactory.getOrCreateSessionSupplier(realm).get(); + entityManager = realmEntityManagerFactory.getOrCreateEntityManager(realm); PrincipalEntity rootEntity = new PrincipalEntity( @@ -198,7 +198,7 @@ public void before(TestInfo testInfo) { this.adminService = new PolarisAdminService( - realmId, + realm, entityManager, metaStoreManager, metaStoreSession, @@ -387,7 +387,7 @@ private void initBaseCatalog() { entityManager, metaStoreSession, securityContext, CATALOG_NAME); this.baseCatalog = new BasePolarisCatalog( - realmId, + realm, entityManager, metaStoreManager, metaStoreSession, diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/PolarisOverlappingCatalogTest.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/PolarisOverlappingCatalogTest.java index 61a3fdc53..198812ab5 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/PolarisOverlappingCatalogTest.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/PolarisOverlappingCatalogTest.java @@ -80,7 +80,7 @@ private Response createCatalog( return services .catalogsApi() .createCatalog( - new CreateCatalogRequest(catalog), services.realmId(), services.securityContext()); + new CreateCatalogRequest(catalog), services.realm(), services.securityContext()); } @ParameterizedTest diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/PolarisOverlappingTableTest.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/PolarisOverlappingTableTest.java index 2791bfa73..fe3996c32 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/PolarisOverlappingTableTest.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/admin/PolarisOverlappingTableTest.java @@ -63,7 +63,7 @@ private int createTable(TestServices services, String location) { namespace, createTableRequest, null, - services.realmId(), + services.realm(), services.securityContext())) { return response.getStatus(); } catch (ForbiddenException e) { @@ -130,7 +130,7 @@ void testTableLocationRestrictions( .catalogsApi() .createCatalog( new CreateCatalogRequest(catalogObject), - services.realmId(), + services.realm(), services.securityContext())) { assertThat(response.getStatus()).isEqualTo(Response.Status.CREATED.getStatusCode()); } @@ -141,7 +141,7 @@ void testTableLocationRestrictions( services .restApi() .createNamespace( - catalog, createNamespaceRequest, services.realmId(), services.securityContext())) { + catalog, createNamespaceRequest, services.realm(), services.securityContext())) { assertThat(response.getStatus()).isEqualTo(Response.Status.OK.getStatusCode()); } diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/auth/TokenUtils.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/auth/TokenUtils.java index bd860af11..9ecc6d8b0 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/auth/TokenUtils.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/auth/TokenUtils.java @@ -19,7 +19,7 @@ package org.apache.polaris.service.quarkus.auth; import static org.apache.polaris.service.auth.BasePolarisAuthenticator.PRINCIPAL_ROLE_ALL; -import static org.apache.polaris.service.context.TestRealmIdResolver.REALM_PROPERTY_KEY; +import static org.apache.polaris.service.context.TestRealmResolver.REALM_PROPERTY_KEY; import static org.assertj.core.api.Assertions.assertThat; import jakarta.ws.rs.client.Client; diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/BasePolarisCatalogTest.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/BasePolarisCatalogTest.java index 38580b9a1..f3f6d2044 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/BasePolarisCatalogTest.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/BasePolarisCatalogTest.java @@ -74,7 +74,7 @@ import org.apache.polaris.core.auth.AuthenticatedPolarisPrincipal; import org.apache.polaris.core.auth.PolarisAuthorizerImpl; import org.apache.polaris.core.auth.PolarisSecretsManager.PrincipalSecretsResult; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.CatalogEntity; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisEntity; @@ -158,7 +158,7 @@ public Map getConfigOverrides() { @Inject Clock clock; private BasePolarisCatalog catalog; - private RealmId realmId; + private Realm realm; private PolarisMetaStoreManager metaStoreManager; private PolarisMetaStoreSession metaStoreSession; private PolarisAdminService adminService; @@ -182,10 +182,10 @@ public void before(TestInfo testInfo) { "realm_%s_%s" .formatted( testInfo.getTestMethod().map(Method::getName).orElse("test"), System.nanoTime()); - realmId = RealmId.newRealmId(realmName); - metaStoreManager = managerFactory.getOrCreateMetaStoreManager(realmId); - metaStoreSession = managerFactory.getOrCreateSessionSupplier(realmId).get(); - entityManager = entityManagerFactory.getOrCreateEntityManager(realmId); + realm = Realm.fromName(realmName); + metaStoreManager = managerFactory.getOrCreateMetaStoreManager(realm); + metaStoreSession = managerFactory.getOrCreateSessionSupplier(realm).get(); + entityManager = entityManagerFactory.getOrCreateEntityManager(realm); PrincipalEntity rootEntity = new PrincipalEntity( @@ -206,7 +206,7 @@ public void before(TestInfo testInfo) { when(securityContext.isUserInRole(isA(String.class))).thenReturn(true); adminService = new PolarisAdminService( - realmId, + realm, entityManager, metaStoreManager, metaStoreSession, @@ -243,7 +243,7 @@ public void before(TestInfo testInfo) { TaskExecutor taskExecutor = Mockito.mock(); this.catalog = new BasePolarisCatalog( - realmId, + realm, entityManager, metaStoreManager, metaStoreSession, @@ -308,22 +308,22 @@ protected boolean supportsNotifications() { private MetaStoreManagerFactory createMockMetaStoreManagerFactory() { return new MetaStoreManagerFactory() { @Override - public PolarisMetaStoreManager getOrCreateMetaStoreManager(RealmId realmId) { + public PolarisMetaStoreManager getOrCreateMetaStoreManager(Realm realm) { return metaStoreManager; } @Override - public Supplier getOrCreateSessionSupplier(RealmId realmId) { + public Supplier getOrCreateSessionSupplier(Realm realm) { return () -> metaStoreSession; } @Override - public StorageCredentialCache getOrCreateStorageCredentialCache(RealmId realmId) { + public StorageCredentialCache getOrCreateStorageCredentialCache(Realm realm) { return new StorageCredentialCache(diagServices, configurationStore); } @Override - public EntityCache getOrCreateEntityCache(RealmId realmId) { + public EntityCache getOrCreateEntityCache(Realm realm) { return new EntityCache(metaStoreManager, diagServices); } @@ -512,7 +512,7 @@ public void testValidateNotificationFailToCreateFileIO() throws IOException { FileIOFactory fileIoFactory = spy(new DefaultFileIOFactory()); BasePolarisCatalog catalog = new BasePolarisCatalog( - realmId, + realm, entityManager, metaStoreManager, metaStoreSession, @@ -840,7 +840,7 @@ public void testUpdateNotificationCreateTableWithLocalFilePrefix() { TaskExecutor taskExecutor = Mockito.mock(); BasePolarisCatalog catalog = new BasePolarisCatalog( - realmId, + realm, entityManager, metaStoreManager, metaStoreSession, @@ -874,7 +874,7 @@ public void testUpdateNotificationCreateTableWithLocalFilePrefix() { TableMetadataParser.toJson(createSampleTableMetadata(metadataLocation)).getBytes(UTF_8)); if (!configurationStore - .getConfiguration(realmId, PolarisConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES) + .getConfiguration(realm, PolarisConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES) .contains("FILE")) { Assertions.assertThatThrownBy(() -> catalog.sendNotification(table, request)) .isInstanceOf(ForbiddenException.class) @@ -905,7 +905,7 @@ public void testUpdateNotificationCreateTableWithHttpPrefix() { TaskExecutor taskExecutor = Mockito.mock(); BasePolarisCatalog catalog = new BasePolarisCatalog( - realmId, + realm, entityManager, metaStoreManager, metaStoreSession, @@ -941,7 +941,7 @@ public void testUpdateNotificationCreateTableWithHttpPrefix() { TableMetadataParser.toJson(createSampleTableMetadata(metadataLocation)).getBytes(UTF_8)); if (!configurationStore - .getConfiguration(realmId, PolarisConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES) + .getConfiguration(realm, PolarisConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES) .contains("FILE")) { Assertions.assertThatThrownBy(() -> catalog.sendNotification(table, request)) .isInstanceOf(ForbiddenException.class) @@ -961,7 +961,7 @@ public void testUpdateNotificationCreateTableWithHttpPrefix() { TableMetadataParser.toJson(createSampleTableMetadata(metadataLocation)).getBytes(UTF_8)); if (!configurationStore - .getConfiguration(realmId, PolarisConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES) + .getConfiguration(realm, PolarisConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES) .contains("FILE")) { Assertions.assertThatThrownBy(() -> catalog.sendNotification(table, newRequest)) .isInstanceOf(ForbiddenException.class) @@ -1409,7 +1409,7 @@ public void testDropTableWithPurge() { FileIO fileIO = new TaskFileIOSupplier( createMockMetaStoreManagerFactory(), new DefaultFileIOFactory(), configurationStore) - .apply(taskEntity, realmId); + .apply(taskEntity, realm); Assertions.assertThat(fileIO).isNotNull().isInstanceOf(InMemoryFileIO.class); } @@ -1441,7 +1441,7 @@ public void testDropTableWithPurgeDisabled() { entityManager, metaStoreSession, securityContext, noPurgeCatalogName); BasePolarisCatalog noPurgeCatalog = new BasePolarisCatalog( - realmId, + realm, entityManager, metaStoreManager, metaStoreSession, @@ -1525,7 +1525,7 @@ public void testFileIOWrapper() { TestFileIOFactory measured = new TestFileIOFactory(); BasePolarisCatalog catalog = new BasePolarisCatalog( - realmId, + realm, entityManager, metaStoreManager, metaStoreSession, @@ -1573,7 +1573,7 @@ public void testFileIOWrapper() { .loadTasks(metaStoreSession, "testExecutor", 1) .getEntities() .getFirst()), - realmId); + realm); Assertions.assertThat(measured.getNumDeletedFiles()).as("A table was deleted").isGreaterThan(0); } } diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/BasePolarisCatalogViewTest.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/BasePolarisCatalogViewTest.java index b6bbefef0..e2176c8f4 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/BasePolarisCatalogViewTest.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/BasePolarisCatalogViewTest.java @@ -44,7 +44,7 @@ import org.apache.polaris.core.admin.model.StorageConfigInfo; import org.apache.polaris.core.auth.AuthenticatedPolarisPrincipal; import org.apache.polaris.core.auth.PolarisAuthorizerImpl; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.CatalogEntity; import org.apache.polaris.core.entity.PolarisEntity; import org.apache.polaris.core.entity.PolarisEntitySubType; @@ -121,10 +121,10 @@ public void before(TestInfo testInfo) { "realm_%s_%s" .formatted( testInfo.getTestMethod().map(Method::getName).orElse("test"), System.nanoTime()); - RealmId realmId = RealmId.newRealmId(realmName); + Realm realm = Realm.fromName(realmName); - metaStoreManager = managerFactory.getOrCreateMetaStoreManager(realmId); - metaStoreSession = managerFactory.getOrCreateSessionSupplier(realmId).get(); + metaStoreManager = managerFactory.getOrCreateMetaStoreManager(realm); + metaStoreSession = managerFactory.getOrCreateSessionSupplier(realm).get(); PrincipalEntity rootEntity = new PrincipalEntity( @@ -140,14 +140,14 @@ public void before(TestInfo testInfo) { AuthenticatedPolarisPrincipal authenticatedRoot = new AuthenticatedPolarisPrincipal(rootEntity, Set.of()); - PolarisEntityManager entityManager = entityManagerFactory.getOrCreateEntityManager(realmId); + PolarisEntityManager entityManager = entityManagerFactory.getOrCreateEntityManager(realm); SecurityContext securityContext = Mockito.mock(SecurityContext.class); when(securityContext.getUserPrincipal()).thenReturn(authenticatedRoot); when(securityContext.isUserInRole(Mockito.anyString())).thenReturn(true); PolarisAdminService adminService = new PolarisAdminService( - realmId, + realm, entityManager, metaStoreManager, metaStoreSession, @@ -173,7 +173,7 @@ public void before(TestInfo testInfo) { entityManager, metaStoreSession, securityContext, CATALOG_NAME); this.catalog = new BasePolarisCatalog( - realmId, + realm, entityManager, metaStoreManager, metaStoreSession, diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/PolarisCatalogHandlerWrapperAuthzTest.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/PolarisCatalogHandlerWrapperAuthzTest.java index 5f6b0dec0..6797dd1e1 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/PolarisCatalogHandlerWrapperAuthzTest.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/PolarisCatalogHandlerWrapperAuthzTest.java @@ -107,7 +107,7 @@ private PolarisCatalogHandlerWrapper newWrapper(SecurityContext securityContext) private PolarisCatalogHandlerWrapper newWrapper( SecurityContext securityContext, String catalogName) { return new PolarisCatalogHandlerWrapper( - realmId, + realm, metaStoreSession, configurationStore, diagServices, diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/io/FileIOExceptionsTest.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/io/FileIOExceptionsTest.java index 13349c825..368524363 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/io/FileIOExceptionsTest.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/io/FileIOExceptionsTest.java @@ -80,9 +80,7 @@ public static void beforeAll() { services .catalogsApi() .createCatalog( - new CreateCatalogRequest(catalog), - services.realmId(), - services.securityContext())) { + new CreateCatalogRequest(catalog), services.realm(), services.securityContext())) { assertThat(res.getStatus()).isEqualTo(201); } @@ -92,7 +90,7 @@ public static void beforeAll() { .createNamespace( FileIOExceptionsTest.catalog, CreateNamespaceRequest.builder().withNamespace(Namespace.of("ns1")).build(), - services.realmId(), + services.realm(), services.securityContext())) { assertThat(res.getStatus()).isEqualTo(200); } @@ -112,7 +110,7 @@ private static void requestCreateTable() { services .restApi() .createTable( - catalog, "ns1", request, null, services.realmId(), services.securityContext()); + catalog, "ns1", request, null, services.realm(), services.securityContext()); res.close(); } diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/config/DefaultConfigurationStoreTest.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/config/DefaultConfigurationStoreTest.java index ac2f72132..d8a5e8c5c 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/config/DefaultConfigurationStoreTest.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/config/DefaultConfigurationStoreTest.java @@ -21,7 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.Map; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.service.config.DefaultConfigurationStore; import org.junit.jupiter.api.Test; @@ -31,16 +31,15 @@ public class DefaultConfigurationStoreTest { public void testGetConfiguration() { DefaultConfigurationStore defaultConfigurationStore = new DefaultConfigurationStore(Map.of("key1", 1, "key2", "value")); - RealmId realmId = RealmId.newRealmId("test"); - Object value = defaultConfigurationStore.getConfiguration(realmId, "missingKeyWithoutDefault"); + Realm realm = Realm.fromName("test"); + Object value = defaultConfigurationStore.getConfiguration(realm, "missingKeyWithoutDefault"); assertThat(value).isNull(); Object defaultValue = - defaultConfigurationStore.getConfiguration( - realmId, "missingKeyWithDefault", "defaultValue"); + defaultConfigurationStore.getConfiguration(realm, "missingKeyWithDefault", "defaultValue"); assertThat(defaultValue).isEqualTo("defaultValue"); - Integer keyOne = defaultConfigurationStore.getConfiguration(realmId, "key1"); + Integer keyOne = defaultConfigurationStore.getConfiguration(realm, "key1"); assertThat(keyOne).isEqualTo(1); - String keyTwo = defaultConfigurationStore.getConfiguration(realmId, "key2"); + String keyTwo = defaultConfigurationStore.getConfiguration(realm, "key2"); assertThat(keyTwo).isEqualTo("value"); } @@ -62,30 +61,29 @@ public void testGetRealmConfiguration() { Map.of("key1", realm2KeyOneValue, "key2", realm2KeyTwoValue))); // check realm1 values - RealmId realmId = RealmId.newRealmId("realm1"); - Object value = defaultConfigurationStore.getConfiguration(realmId, "missingKeyWithoutDefault"); + Realm realm = Realm.fromName("realm1"); + Object value = defaultConfigurationStore.getConfiguration(realm, "missingKeyWithoutDefault"); assertThat(value).isNull(); Object defaultValue = - defaultConfigurationStore.getConfiguration( - realmId, "missingKeyWithDefault", "defaultValue"); + defaultConfigurationStore.getConfiguration(realm, "missingKeyWithDefault", "defaultValue"); assertThat(defaultValue).isEqualTo("defaultValue"); - Integer keyOneRealm1 = defaultConfigurationStore.getConfiguration(realmId, "key1"); + Integer keyOneRealm1 = defaultConfigurationStore.getConfiguration(realm, "key1"); assertThat(keyOneRealm1).isEqualTo(realm1KeyOneValue); - String keyTwoRealm1 = defaultConfigurationStore.getConfiguration(realmId, "key2"); + String keyTwoRealm1 = defaultConfigurationStore.getConfiguration(realm, "key2"); assertThat(keyTwoRealm1).isEqualTo(defaultKeyTwoValue); // check realm2 values - realmId = RealmId.newRealmId("realm2"); - Integer keyOneRealm2 = defaultConfigurationStore.getConfiguration(realmId, "key1"); + realm = Realm.fromName("realm2"); + Integer keyOneRealm2 = defaultConfigurationStore.getConfiguration(realm, "key1"); assertThat(keyOneRealm2).isEqualTo(realm2KeyOneValue); - String keyTwoRealm2 = defaultConfigurationStore.getConfiguration(realmId, "key2"); + String keyTwoRealm2 = defaultConfigurationStore.getConfiguration(realm, "key2"); assertThat(keyTwoRealm2).isEqualTo(realm2KeyTwoValue); // realm3 has no realm-overrides, so just returns default values - realmId = RealmId.newRealmId("realm3"); - Integer keyOneRealm3 = defaultConfigurationStore.getConfiguration(realmId, "key1"); + realm = Realm.fromName("realm3"); + Integer keyOneRealm3 = defaultConfigurationStore.getConfiguration(realm, "key1"); assertThat(keyOneRealm3).isEqualTo(defaultKeyOneValue); - String keyTwoRealm3 = defaultConfigurationStore.getConfiguration(realmId, "key2"); + String keyTwoRealm3 = defaultConfigurationStore.getConfiguration(realm, "key2"); assertThat(keyTwoRealm3).isEqualTo(defaultKeyTwoValue); } } diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/ratelimiter/TestUtil.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/ratelimiter/TestUtil.java index 35c90e600..c2ec347a7 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/ratelimiter/TestUtil.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/ratelimiter/TestUtil.java @@ -18,7 +18,7 @@ */ package org.apache.polaris.service.quarkus.ratelimiter; -import static org.apache.polaris.service.context.TestRealmIdResolver.REALM_PROPERTY_KEY; +import static org.apache.polaris.service.context.TestRealmResolver.REALM_PROPERTY_KEY; import static org.assertj.core.api.Assertions.assertThat; import jakarta.ws.rs.core.Response; diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/task/ManifestFileCleanupTaskHandlerTest.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/task/ManifestFileCleanupTaskHandlerTest.java index 1c16b8864..d0b69e6a7 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/task/ManifestFileCleanupTaskHandlerTest.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/task/ManifestFileCleanupTaskHandlerTest.java @@ -46,7 +46,7 @@ import org.apache.iceberg.io.OutputFile; import org.apache.iceberg.io.PositionOutputStream; import org.apache.polaris.core.PolarisDiagnostics; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.AsyncTaskType; import org.apache.polaris.core.entity.TaskEntity; import org.apache.polaris.service.task.ManifestFileCleanupTaskHandler; @@ -58,7 +58,7 @@ class ManifestFileCleanupTaskHandlerTest { @Inject PolarisDiagnostics diagnostics; - private final RealmId realmId = RealmId.newRealmId("realmName"); + private final Realm realm = Realm.fromName("realmName"); @Test public void testCleanupFileNotExists() throws IOException { @@ -81,7 +81,7 @@ public void testCleanupFileNotExists() throws IOException { .setName(UUID.randomUUID().toString()) .build(); assertThat(handler.canHandleTask(task)).isTrue(); - assertThat(handler.handleTask(task, realmId)).isTrue(); + assertThat(handler.handleTask(task, realm)).isTrue(); } @Test @@ -104,7 +104,7 @@ public void testCleanupFileManifestExistsDataFilesDontExist() throws IOException .setName(UUID.randomUUID().toString()) .build(); assertThat(handler.canHandleTask(task)).isTrue(); - assertThat(handler.handleTask(task, realmId)).isTrue(); + assertThat(handler.handleTask(task, realm)).isTrue(); } @Test @@ -142,7 +142,7 @@ public void close() { .setName(UUID.randomUUID().toString()) .build(); assertThat(handler.canHandleTask(task)).isTrue(); - assertThat(handler.handleTask(task, realmId)).isTrue(); + assertThat(handler.handleTask(task, realm)).isTrue(); assertThat(TaskUtils.exists(dataFile1Path, fileIO)).isFalse(); assertThat(TaskUtils.exists(dataFile2Path, fileIO)).isFalse(); } @@ -196,7 +196,7 @@ public void deleteFile(String location) { .setName(UUID.randomUUID().toString()) .build(); assertThat(handler.canHandleTask(task)).isTrue(); - assertThat(handler.handleTask(task, realmId)).isTrue(); + assertThat(handler.handleTask(task, realm)).isTrue(); assertThat(TaskUtils.exists(dataFile1Path, fileIO)).isFalse(); assertThat(TaskUtils.exists(dataFile2Path, fileIO)).isFalse(); } @@ -288,7 +288,7 @@ public void close() { .build(); assertThat(handler.canHandleTask(task)).isTrue(); - assertThat(handler.handleTask(task, realmId)).isTrue(); + assertThat(handler.handleTask(task, realm)).isTrue(); assertThat(TaskUtils.exists(firstMetadataFile, fileIO)).isFalse(); assertThat(TaskUtils.exists(statisticsFile1.path(), fileIO)).isFalse(); @@ -330,7 +330,7 @@ public void testMetadataFileCleanupIfFileNotExist() throws IOException { .setName(UUID.randomUUID().toString()) .build(); assertThat(handler.canHandleTask(task)).isTrue(); - assertThat(handler.handleTask(task, realmId)).isTrue(); + assertThat(handler.handleTask(task, realm)).isTrue(); } @Test @@ -390,7 +390,7 @@ public void deleteFile(String location) { CompletableFuture.runAsync( () -> { assertThat(handler.canHandleTask(task)).isTrue(); - handler.handleTask(task, realmId); // this will schedule the batch deletion + handler.handleTask(task, realm); // this will schedule the batch deletion }, executor); // Wait for all async tasks to finish diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/task/TableCleanupTaskHandlerTest.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/task/TableCleanupTaskHandlerTest.java index 5b9032918..1b6391b7c 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/task/TableCleanupTaskHandlerTest.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/task/TableCleanupTaskHandlerTest.java @@ -38,7 +38,7 @@ import org.apache.iceberg.io.FileIO; import org.apache.polaris.core.PolarisConfigurationStore; import org.apache.polaris.core.PolarisDiagnostics; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.AsyncTaskType; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisEntityType; @@ -60,12 +60,12 @@ class TableCleanupTaskHandlerTest { @Inject PolarisConfigurationStore configurationStore; @Inject PolarisDiagnostics diagnostics; - private final RealmId realmId = RealmId.newRealmId("realmName"); + private final Realm realm = Realm.fromName("realmName"); @Test public void testTableCleanup() throws IOException { PolarisMetaStoreSession metaStoreSession = - metaStoreManagerFactory.getOrCreateSessionSupplier(realmId).get(); + metaStoreManagerFactory.getOrCreateSessionSupplier(realm).get(); FileIO fileIO = new InMemoryFileIO(); TableIdentifier tableIdentifier = TableIdentifier.of(Namespace.of("db1", "schema1"), "table1"); TableCleanupTaskHandler handler = @@ -105,11 +105,11 @@ public void testTableCleanup() throws IOException { .build(); Assertions.assertThatPredicate(handler::canHandleTask).accepts(task); - handler.handleTask(task, realmId); + handler.handleTask(task, realm); assertThat( metaStoreManagerFactory - .getOrCreateMetaStoreManager(realmId) + .getOrCreateMetaStoreManager(realm) .loadTasks(metaStoreSession, "test", 2) .getEntities()) .hasSize(2) @@ -148,7 +148,7 @@ public void testTableCleanup() throws IOException { @Test public void testTableCleanupHandlesAlreadyDeletedMetadata() throws IOException { PolarisMetaStoreSession metaStoreSession = - metaStoreManagerFactory.getOrCreateSessionSupplier(realmId).get(); + metaStoreManagerFactory.getOrCreateSessionSupplier(realm).get(); FileIO fileIO = new InMemoryFileIO() { @Override @@ -191,13 +191,13 @@ public void close() { // handle the same task twice // the first one should successfully delete the metadata List results = - List.of(handler.handleTask(task, realmId), handler.handleTask(task, realmId)); + List.of(handler.handleTask(task, realm), handler.handleTask(task, realm)); assertThat(results).containsExactly(true, true); // both tasks successfully executed, but only one should queue subtasks assertThat( metaStoreManagerFactory - .getOrCreateMetaStoreManager(realmId) + .getOrCreateMetaStoreManager(realm) .loadTasks(metaStoreSession, "test", 5) .getEntities()) .hasSize(1); @@ -206,7 +206,7 @@ public void close() { @Test public void testTableCleanupDuplicatesTasksIfFileStillExists() throws IOException { PolarisMetaStoreSession metaStoreSession = - metaStoreManagerFactory.getOrCreateSessionSupplier(realmId).get(); + metaStoreManagerFactory.getOrCreateSessionSupplier(realm).get(); FileIO fileIO = new InMemoryFileIO() { @Override @@ -257,13 +257,13 @@ public void close() { // handle the same task twice // the first one should successfully delete the metadata List results = - List.of(handler.handleTask(task, realmId), handler.handleTask(task, realmId)); + List.of(handler.handleTask(task, realm), handler.handleTask(task, realm)); assertThat(results).containsExactly(true, true); // both tasks successfully executed, but only one should queue subtasks assertThat( metaStoreManagerFactory - .getOrCreateMetaStoreManager(realmId) + .getOrCreateMetaStoreManager(realm) .loadTasks(metaStoreSession, "test", 5) .getEntities()) .hasSize(2) @@ -303,7 +303,7 @@ public void close() { @Test public void testTableCleanupMultipleSnapshots() throws IOException { PolarisMetaStoreSession metaStoreSession = - metaStoreManagerFactory.getOrCreateSessionSupplier(realmId).get(); + metaStoreManagerFactory.getOrCreateSessionSupplier(realm).get(); FileIO fileIO = new InMemoryFileIO(); TableIdentifier tableIdentifier = TableIdentifier.of(Namespace.of("db1", "schema1"), "table1"); TableCleanupTaskHandler handler = @@ -365,11 +365,11 @@ public void testTableCleanupMultipleSnapshots() throws IOException { .build(); Assertions.assertThatPredicate(handler::canHandleTask).accepts(task); - handler.handleTask(task, realmId); + handler.handleTask(task, realm); List entities = metaStoreManagerFactory - .getOrCreateMetaStoreManager(realmId) + .getOrCreateMetaStoreManager(realm) .loadTasks(metaStoreSession, "test", 5) .getEntities(); @@ -452,7 +452,7 @@ public void testTableCleanupMultipleSnapshots() throws IOException { @Test public void testTableCleanupMultipleMetadata() throws IOException { PolarisMetaStoreSession metaStoreSession = - metaStoreManagerFactory.getOrCreateSessionSupplier(realmId).get(); + metaStoreManagerFactory.getOrCreateSessionSupplier(realm).get(); FileIO fileIO = new InMemoryFileIO(); TableIdentifier tableIdentifier = TableIdentifier.of(Namespace.of("db1", "schema1"), "table1"); TableCleanupTaskHandler handler = @@ -528,11 +528,11 @@ public void testTableCleanupMultipleMetadata() throws IOException { Assertions.assertThatPredicate(handler::canHandleTask).accepts(task); - handler.handleTask(task, realmId); + handler.handleTask(task, realm); List entities = metaStoreManagerFactory - .getOrCreateMetaStoreManager(realmId) + .getOrCreateMetaStoreManager(realm) .loadTasks(metaStoreSession, "test", 6) .getEntities(); diff --git a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/test/PolarisIntegrationTestFixture.java b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/test/PolarisIntegrationTestFixture.java index ea064ade2..dcdccd1c1 100644 --- a/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/test/PolarisIntegrationTestFixture.java +++ b/quarkus/service/src/test/java/org/apache/polaris/service/quarkus/test/PolarisIntegrationTestFixture.java @@ -18,7 +18,7 @@ */ package org.apache.polaris.service.quarkus.test; -import static org.apache.polaris.service.context.TestRealmIdResolver.REALM_PROPERTY_KEY; +import static org.apache.polaris.service.context.TestRealmResolver.REALM_PROPERTY_KEY; import static org.assertj.core.api.Assertions.assertThat; import com.fasterxml.jackson.core.JsonProcessingException; @@ -35,7 +35,7 @@ import org.apache.polaris.core.admin.model.Principal; import org.apache.polaris.core.admin.model.PrincipalRole; import org.apache.polaris.core.admin.model.PrincipalWithCredentials; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.PolarisEntityConstants; import org.apache.polaris.core.entity.PolarisEntitySubType; import org.apache.polaris.core.entity.PolarisEntityType; @@ -97,15 +97,15 @@ public PolarisIntegrationTestFixture( private PolarisPrincipalSecrets fetchAdminSecrets() { if (!(helper.metaStoreManagerFactory instanceof InMemoryPolarisMetaStoreManagerFactory)) { helper.metaStoreManagerFactory.bootstrapRealms( - List.of(realm), PolarisCredentialsBootstrap.fromEnvironment()); + List.of(this.realm), PolarisCredentialsBootstrap.fromEnvironment()); } - RealmId realmId = RealmId.newRealmId(realm); + Realm realm = Realm.fromName(this.realm); PolarisMetaStoreSession metaStoreSession = - helper.metaStoreManagerFactory.getOrCreateSessionSupplier(realmId).get(); + helper.metaStoreManagerFactory.getOrCreateSessionSupplier(realm).get(); PolarisMetaStoreManager metaStoreManager = - helper.metaStoreManagerFactory.getOrCreateMetaStoreManager(realmId); + helper.metaStoreManagerFactory.getOrCreateMetaStoreManager(realm); PolarisMetaStoreManager.EntityResult principal = metaStoreManager.readEntityByName( metaStoreSession, diff --git a/quarkus/service/src/testFixtures/java/org/apache/polaris/service/quarkus/it/QuarkusServerManager.java b/quarkus/service/src/testFixtures/java/org/apache/polaris/service/quarkus/it/QuarkusServerManager.java index 38a3e3e07..839c90c87 100644 --- a/quarkus/service/src/testFixtures/java/org/apache/polaris/service/quarkus/it/QuarkusServerManager.java +++ b/quarkus/service/src/testFixtures/java/org/apache/polaris/service/quarkus/it/QuarkusServerManager.java @@ -35,7 +35,7 @@ public Server serverForContext(ExtensionContext context) { return new Server() { @Override - public String realmId() { + public String realm() { return TEST_REALM; } diff --git a/server-templates/api.mustache b/server-templates/api.mustache index bf694284a..ef2eb3afb 100644 --- a/server-templates/api.mustache +++ b/server-templates/api.mustache @@ -55,7 +55,7 @@ import {{javaxPackage}}.ws.rs.core.SecurityContext; import {{javaxPackage}}.inject.Inject; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -107,7 +107,7 @@ public class {{classname}} { @Consumes({ {{#consumes}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/consumes}} }){{/hasConsumes}}{{#hasProduces}} @Produces({ {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} }){{/hasProduces}} @Timed("{{metricsPrefix}}.{{baseName}}.{{nickname}}") - public Response {{nickname}}({{#isMultipart}}MultipartFormDataInput input,{{/isMultipart}}{{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{^isMultipart}}{{>formParams}},{{/isMultipart}}{{#isMultipart}}{{^isFormParam}},{{/isFormParam}}{{/isMultipart}}{{/allParams}}@Context @MeterTag(key="realm_id",expression="realm.id") RealmId realmId,@Context SecurityContext securityContext) { + public Response {{nickname}}({{#isMultipart}}MultipartFormDataInput input,{{/isMultipart}}{{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{^isMultipart}}{{>formParams}},{{/isMultipart}}{{#isMultipart}}{{^isFormParam}},{{/isFormParam}}{{/isMultipart}}{{/allParams}}@Context @MeterTag(key="realm_id",expression="realm.id") Realm realm,@Context SecurityContext securityContext) { {{! Don't log form or header params in case there are secrets, e.g., OAuth tokens }} LOGGER.atDebug().setMessage("Invoking {{baseName}} with params") .addKeyValue("operation", "{{nickname}}"){{#allParams}}{{^isHeaderParam}}{{^isFormParam}} @@ -115,7 +115,7 @@ public class {{classname}} { .log(); Response ret = - service.{{nickname}}({{#isMultipart}}input,{{/isMultipart}}{{#allParams}}{{^isMultipart}}{{paramName}},{{/isMultipart}}{{#isMultipart}}{{^isFormParam}}{{paramName}},{{/isFormParam}}{{/isMultipart}}{{/allParams}}realmId,securityContext); + service.{{nickname}}({{#isMultipart}}input,{{/isMultipart}}{{#allParams}}{{^isMultipart}}{{paramName}},{{/isMultipart}}{{#isMultipart}}{{^isFormParam}}{{paramName}},{{/isFormParam}}{{/isMultipart}}{{/allParams}}realm,securityContext); LOGGER.debug("Completed execution of {{nickname}} API with status code {}", ret.getStatus()); return ret; } diff --git a/server-templates/apiService.mustache b/server-templates/apiService.mustache index 6489b9536..04aac5763 100644 --- a/server-templates/apiService.mustache +++ b/server-templates/apiService.mustache @@ -35,7 +35,7 @@ import {{javaxPackage}}.validation.Valid; import {{javaxPackage}}.ws.rs.core.Response; import {{javaxPackage}}.ws.rs.core.SecurityContext; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; {{! Note that this template is copied from https://github.com/OpenAPITools/openapi-generator/blob/783e68c7acbbdcbb2282d167d1644b069f12d486/modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/apiService.mustache @@ -54,7 +54,7 @@ It is here to remove some unsupported imports and to update the default implemen {{#operations}} public interface {{classname}}Service { {{#operation}} - default Response {{nickname}}({{#isMultipart}}MultipartFormDataInput input,{{/isMultipart}}{{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{^isMultipart}}{{>serviceFormParams}},{{/isMultipart}}{{#isMultipart}}{{^isFormParam}},{{/isFormParam}}{{/isMultipart}}{{/allParams}}RealmId realmId,SecurityContext securityContext) { + default Response {{nickname}}({{#isMultipart}}MultipartFormDataInput input,{{/isMultipart}}{{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{^isMultipart}}{{>serviceFormParams}},{{/isMultipart}}{{#isMultipart}}{{^isFormParam}},{{/isFormParam}}{{/isMultipart}}{{/allParams}}Realm realm,SecurityContext securityContext) { return Response.status(501).build(); // not implemented } {{/operation}} diff --git a/server-templates/apiServiceImpl.mustache b/server-templates/apiServiceImpl.mustache index ce42416e6..9a0877098 100644 --- a/server-templates/apiServiceImpl.mustache +++ b/server-templates/apiServiceImpl.mustache @@ -36,7 +36,7 @@ import {{javaxPackage}}.validation.Valid; import {{javaxPackage}}.ws.rs.core.Response; import {{javaxPackage}}.ws.rs.core.SecurityContext; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; {{! Note that this template is copied from https://github.com/OpenAPITools/openapi-generator/blob/783e68c7acbbdcbb2282d167d1644b069f12d486/modules/openapi-generator/src/main/resources/JavaJaxRS/resteasy/apiServiceImpl.mustache @@ -55,7 +55,7 @@ It is here to remove some unsupported imports (ApiResponseMessage, openapi.tools {{#operations}} public class {{classname}}ServiceImpl implements {{classname}}Service { {{#operation}} - public Response {{nickname}}({{#isMultipart}}MultipartFormDataInput input,{{/isMultipart}}{{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{^isMultipart}}{{>serviceFormParams}},{{/isMultipart}}{{#isMultipart}}{{^isFormParam}},{{/isFormParam}}{{/isMultipart}}{{/allParams}}RealmId realmId,SecurityContext securityContext) { + public Response {{nickname}}({{#isMultipart}}MultipartFormDataInput input,{{/isMultipart}}{{#allParams}}{{>serviceQueryParams}}{{>servicePathParams}}{{>serviceHeaderParams}}{{>serviceBodyParams}}{{^isMultipart}}{{>serviceFormParams}},{{/isMultipart}}{{#isMultipart}}{{^isFormParam}},{{/isFormParam}}{{/isMultipart}}{{/allParams}}Realm realm,SecurityContext securityContext) { return Response.status(501).build(); // not implemented } {{/operation}} diff --git a/service/common/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java b/service/common/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java index 4a3f278bd..ad0dd8c05 100644 --- a/service/common/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java +++ b/service/common/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java @@ -66,7 +66,7 @@ import org.apache.polaris.core.auth.PolarisAuthorizer; import org.apache.polaris.core.auth.PolarisGrantManager.LoadGrantsResult; import org.apache.polaris.core.catalog.PolarisCatalogHelpers; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.CatalogEntity; import org.apache.polaris.core.entity.CatalogRoleEntity; import org.apache.polaris.core.entity.NamespaceEntity; @@ -107,7 +107,7 @@ public class PolarisAdminService { private static final Logger LOGGER = LoggerFactory.getLogger(PolarisAdminService.class); - private final RealmId realmId; + private final Realm realm; private final PolarisMetaStoreSession metaStoreSession; private final PolarisConfigurationStore configurationStore; private final PolarisEntityManager entityManager; @@ -120,7 +120,7 @@ public class PolarisAdminService { private PolarisResolutionManifest resolutionManifest = null; public PolarisAdminService( - RealmId realmId, + Realm realm, PolarisEntityManager entityManager, PolarisMetaStoreManager metaStoreManager, PolarisMetaStoreSession metaStoreSession, @@ -128,7 +128,7 @@ public PolarisAdminService( PolarisDiagnostics diagServices, SecurityContext securityContext, PolarisAuthorizer authorizer) { - this.realmId = realmId; + this.realm = realm; this.metaStoreSession = metaStoreSession; this.configurationStore = configurationStore; this.entityManager = entityManager; @@ -176,7 +176,7 @@ private void authorizeBasicRootOperationOrThrow(PolarisAuthorizableOperation op) PolarisResolvedPathWrapper rootContainerWrapper = resolutionManifest.getResolvedRootContainerEntityAsPath(); authorizer.authorizeOrThrow( - realmId, + realm, authenticatedPrincipal, resolutionManifest.getAllActivatedPrincipalRoleEntities(), op, @@ -222,7 +222,7 @@ private void authorizeBasicTopLevelEntityOperationOrThrow( return; } authorizer.authorizeOrThrow( - realmId, + realm, authenticatedPrincipal, resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(), op, @@ -243,7 +243,7 @@ private void authorizeBasicCatalogRoleOperationOrThrow( throw new NotFoundException("CatalogRole does not exist: %s", catalogRoleName); } authorizer.authorizeOrThrow( - realmId, + realm, authenticatedPrincipal, resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(), op, @@ -274,7 +274,7 @@ private void authorizeGrantOnRootContainerToPrincipalRoleOperationOrThrow( principalRoleName, PolarisEntityType.PRINCIPAL_ROLE); authorizer.authorizeOrThrow( - realmId, + realm, authenticatedPrincipal, resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(), op, @@ -311,7 +311,7 @@ private void authorizeGrantOnTopLevelEntityToPrincipalRoleOperationOrThrow( principalRoleName, PolarisEntityType.PRINCIPAL_ROLE); authorizer.authorizeOrThrow( - realmId, + realm, authenticatedPrincipal, resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(), op, @@ -342,7 +342,7 @@ private void authorizeGrantOnPrincipalRoleToPrincipalOperationOrThrow( resolutionManifest.getResolvedTopLevelEntity(principalName, PolarisEntityType.PRINCIPAL); authorizer.authorizeOrThrow( - realmId, + realm, authenticatedPrincipal, resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(), op, @@ -381,7 +381,7 @@ private void authorizeGrantOnCatalogRoleToPrincipalRoleOperationOrThrow( resolutionManifest.getResolvedPath(catalogRoleName, true); authorizer.authorizeOrThrow( - realmId, + realm, authenticatedPrincipal, resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(), op, @@ -411,7 +411,7 @@ private void authorizeGrantOnCatalogOperationOrThrow( PolarisResolvedPathWrapper catalogRoleWrapper = resolutionManifest.getResolvedPath(catalogRoleName, true); authorizer.authorizeOrThrow( - realmId, + realm, authenticatedPrincipal, resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(), op, @@ -451,7 +451,7 @@ private void authorizeGrantOnNamespaceOperationOrThrow( resolutionManifest.getResolvedPath(catalogRoleName, true); authorizer.authorizeOrThrow( - realmId, + realm, authenticatedPrincipal, resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(), op, @@ -496,7 +496,7 @@ private void authorizeGrantOnTableLikeOperationOrThrow( resolutionManifest.getResolvedPath(catalogRoleName, true); authorizer.authorizeOrThrow( - realmId, + realm, authenticatedPrincipal, resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(), op, @@ -535,7 +535,7 @@ private String terminateWithSlash(String path) { private boolean catalogOverlapsWithExistingCatalog(CatalogEntity catalogEntity) { boolean allowOverlappingCatalogUrls = configurationStore.getConfiguration( - realmId, PolarisConfiguration.ALLOW_OVERLAPPING_CATALOG_URLS); + realm, PolarisConfiguration.ALLOW_OVERLAPPING_CATALOG_URLS); if (allowOverlappingCatalogUrls) { return false; @@ -602,7 +602,7 @@ public void deleteCatalog(String name) { .orElseThrow(() -> new NotFoundException("Catalog %s not found", name)); // TODO: Handle return value in case of concurrent modification boolean cleanup = - configurationStore.getConfiguration(realmId, PolarisConfiguration.CLEANUP_ON_CATALOG_DROP); + configurationStore.getConfiguration(realm, PolarisConfiguration.CLEANUP_ON_CATALOG_DROP); PolarisMetaStoreManager.DropEntityResult dropEntityResult = metaStoreManager.dropEntityIfExists(metaStoreSession, null, entity, Map.of(), cleanup); diff --git a/service/common/src/main/java/org/apache/polaris/service/admin/PolarisServiceImpl.java b/service/common/src/main/java/org/apache/polaris/service/admin/PolarisServiceImpl.java index fb195e95d..60b73f33c 100644 --- a/service/common/src/main/java/org/apache/polaris/service/admin/PolarisServiceImpl.java +++ b/service/common/src/main/java/org/apache/polaris/service/admin/PolarisServiceImpl.java @@ -59,7 +59,7 @@ import org.apache.polaris.core.admin.model.ViewGrant; import org.apache.polaris.core.auth.AuthenticatedPolarisPrincipal; import org.apache.polaris.core.auth.PolarisAuthorizer; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.CatalogEntity; import org.apache.polaris.core.entity.CatalogRoleEntity; import org.apache.polaris.core.entity.PolarisPrivilege; @@ -105,7 +105,7 @@ public PolarisServiceImpl( this.diagnostics = diagnostics; } - private PolarisAdminService newAdminService(RealmId realmId, SecurityContext securityContext) { + private PolarisAdminService newAdminService(Realm realm, SecurityContext securityContext) { AuthenticatedPolarisPrincipal authenticatedPrincipal = (AuthenticatedPolarisPrincipal) securityContext.getUserPrincipal(); if (authenticatedPrincipal == null) { @@ -113,7 +113,7 @@ private PolarisAdminService newAdminService(RealmId realmId, SecurityContext sec } return new PolarisAdminService( - realmId, + realm, entityManager, metaStoreManager, session, @@ -126,10 +126,10 @@ private PolarisAdminService newAdminService(RealmId realmId, SecurityContext sec /** From PolarisCatalogsApiService */ @Override public Response createCatalog( - CreateCatalogRequest request, RealmId realmId, SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + CreateCatalogRequest request, Realm realm, SecurityContext securityContext) { + PolarisAdminService adminService = newAdminService(realm, securityContext); Catalog catalog = request.getCatalog(); - validateStorageConfig(catalog.getStorageConfigInfo(), realmId); + validateStorageConfig(catalog.getStorageConfigInfo(), realm); Catalog newCatalog = new CatalogEntity(adminService.createCatalog(CatalogEntity.fromCatalog(catalog))) .asCatalog(); @@ -137,10 +137,10 @@ public Response createCatalog( return Response.status(Response.Status.CREATED).build(); } - private void validateStorageConfig(StorageConfigInfo storageConfigInfo, RealmId realmId) { + private void validateStorageConfig(StorageConfigInfo storageConfigInfo, Realm realm) { List allowedStorageTypes = configurationStore.getConfiguration( - realmId, PolarisConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES); + realm, PolarisConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES); if (!allowedStorageTypes.contains(storageConfigInfo.getStorageType().name())) { LOGGER .atWarn() @@ -153,17 +153,16 @@ private void validateStorageConfig(StorageConfigInfo storageConfigInfo, RealmId /** From PolarisCatalogsApiService */ @Override - public Response deleteCatalog( - String catalogName, RealmId realmId, SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + public Response deleteCatalog(String catalogName, Realm realm, SecurityContext securityContext) { + PolarisAdminService adminService = newAdminService(realm, securityContext); adminService.deleteCatalog(catalogName); return Response.status(Response.Status.NO_CONTENT).build(); } /** From PolarisCatalogsApiService */ @Override - public Response getCatalog(String catalogName, RealmId realmId, SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + public Response getCatalog(String catalogName, Realm realm, SecurityContext securityContext) { + PolarisAdminService adminService = newAdminService(realm, securityContext); return Response.ok(adminService.getCatalog(catalogName).asCatalog()).build(); } @@ -172,19 +171,19 @@ public Response getCatalog(String catalogName, RealmId realmId, SecurityContext public Response updateCatalog( String catalogName, UpdateCatalogRequest updateRequest, - RealmId realmId, + Realm realm, SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + PolarisAdminService adminService = newAdminService(realm, securityContext); if (updateRequest.getStorageConfigInfo() != null) { - validateStorageConfig(updateRequest.getStorageConfigInfo(), realmId); + validateStorageConfig(updateRequest.getStorageConfigInfo(), realm); } return Response.ok(adminService.updateCatalog(catalogName, updateRequest).asCatalog()).build(); } /** From PolarisCatalogsApiService */ @Override - public Response listCatalogs(RealmId realmId, SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + public Response listCatalogs(Realm realm, SecurityContext securityContext) { + PolarisAdminService adminService = newAdminService(realm, securityContext); List catalogList = adminService.listCatalogs().stream() .map(CatalogEntity::new) @@ -198,8 +197,8 @@ public Response listCatalogs(RealmId realmId, SecurityContext securityContext) { /** From PolarisPrincipalsApiService */ @Override public Response createPrincipal( - CreatePrincipalRequest request, RealmId realmId, SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + CreatePrincipalRequest request, Realm realm, SecurityContext securityContext) { + PolarisAdminService adminService = newAdminService(realm, securityContext); PrincipalEntity principal = PrincipalEntity.fromPrincipal(request.getPrincipal()); if (Boolean.TRUE.equals(request.getCredentialRotationRequired())) { principal = @@ -213,17 +212,16 @@ public Response createPrincipal( /** From PolarisPrincipalsApiService */ @Override public Response deletePrincipal( - String principalName, RealmId realmId, SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + String principalName, Realm realm, SecurityContext securityContext) { + PolarisAdminService adminService = newAdminService(realm, securityContext); adminService.deletePrincipal(principalName); return Response.status(Response.Status.NO_CONTENT).build(); } /** From PolarisPrincipalsApiService */ @Override - public Response getPrincipal( - String principalName, RealmId realmId, SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + public Response getPrincipal(String principalName, Realm realm, SecurityContext securityContext) { + PolarisAdminService adminService = newAdminService(realm, securityContext); return Response.ok(adminService.getPrincipal(principalName).asPrincipal()).build(); } @@ -232,9 +230,9 @@ public Response getPrincipal( public Response updatePrincipal( String principalName, UpdatePrincipalRequest updateRequest, - RealmId realmId, + Realm realm, SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + PolarisAdminService adminService = newAdminService(realm, securityContext); return Response.ok(adminService.updatePrincipal(principalName, updateRequest).asPrincipal()) .build(); } @@ -242,15 +240,15 @@ public Response updatePrincipal( /** From PolarisPrincipalsApiService */ @Override public Response rotateCredentials( - String principalName, RealmId realmId, SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + String principalName, Realm realm, SecurityContext securityContext) { + PolarisAdminService adminService = newAdminService(realm, securityContext); return Response.ok(adminService.rotateCredentials(principalName)).build(); } /** From PolarisPrincipalsApiService */ @Override - public Response listPrincipals(RealmId realmId, SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + public Response listPrincipals(Realm realm, SecurityContext securityContext) { + PolarisAdminService adminService = newAdminService(realm, securityContext); List principalList = adminService.listPrincipals().stream() .map(PrincipalEntity::new) @@ -264,8 +262,8 @@ public Response listPrincipals(RealmId realmId, SecurityContext securityContext) /** From PolarisPrincipalRolesApiService */ @Override public Response createPrincipalRole( - CreatePrincipalRoleRequest request, RealmId realmId, SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + CreatePrincipalRoleRequest request, Realm realm, SecurityContext securityContext) { + PolarisAdminService adminService = newAdminService(realm, securityContext); PrincipalRole newPrincipalRole = new PrincipalRoleEntity( adminService.createPrincipalRole( @@ -278,8 +276,8 @@ public Response createPrincipalRole( /** From PolarisPrincipalRolesApiService */ @Override public Response deletePrincipalRole( - String principalRoleName, RealmId realmId, SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + String principalRoleName, Realm realm, SecurityContext securityContext) { + PolarisAdminService adminService = newAdminService(realm, securityContext); adminService.deletePrincipalRole(principalRoleName); return Response.status(Response.Status.NO_CONTENT).build(); } @@ -287,8 +285,8 @@ public Response deletePrincipalRole( /** From PolarisPrincipalRolesApiService */ @Override public Response getPrincipalRole( - String principalRoleName, RealmId realmId, SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + String principalRoleName, Realm realm, SecurityContext securityContext) { + PolarisAdminService adminService = newAdminService(realm, securityContext); return Response.ok(adminService.getPrincipalRole(principalRoleName).asPrincipalRole()).build(); } @@ -297,9 +295,9 @@ public Response getPrincipalRole( public Response updatePrincipalRole( String principalRoleName, UpdatePrincipalRoleRequest updateRequest, - RealmId realmId, + Realm realm, SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + PolarisAdminService adminService = newAdminService(realm, securityContext); return Response.ok( adminService.updatePrincipalRole(principalRoleName, updateRequest).asPrincipalRole()) .build(); @@ -307,8 +305,8 @@ public Response updatePrincipalRole( /** From PolarisPrincipalRolesApiService */ @Override - public Response listPrincipalRoles(RealmId realmId, SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + public Response listPrincipalRoles(Realm realm, SecurityContext securityContext) { + PolarisAdminService adminService = newAdminService(realm, securityContext); List principalRoleList = adminService.listPrincipalRoles().stream() .map(PrincipalRoleEntity::new) @@ -324,9 +322,9 @@ public Response listPrincipalRoles(RealmId realmId, SecurityContext securityCont public Response createCatalogRole( String catalogName, CreateCatalogRoleRequest request, - RealmId realmId, + Realm realm, SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + PolarisAdminService adminService = newAdminService(realm, securityContext); CatalogRole newCatalogRole = new CatalogRoleEntity( adminService.createCatalogRole( @@ -339,11 +337,8 @@ public Response createCatalogRole( /** From PolarisCatalogsApiService */ @Override public Response deleteCatalogRole( - String catalogName, - String catalogRoleName, - RealmId realmId, - SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + String catalogName, String catalogRoleName, Realm realm, SecurityContext securityContext) { + PolarisAdminService adminService = newAdminService(realm, securityContext); adminService.deleteCatalogRole(catalogName, catalogRoleName); return Response.status(Response.Status.NO_CONTENT).build(); } @@ -351,11 +346,8 @@ public Response deleteCatalogRole( /** From PolarisCatalogsApiService */ @Override public Response getCatalogRole( - String catalogName, - String catalogRoleName, - RealmId realmId, - SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + String catalogName, String catalogRoleName, Realm realm, SecurityContext securityContext) { + PolarisAdminService adminService = newAdminService(realm, securityContext); return Response.ok(adminService.getCatalogRole(catalogName, catalogRoleName).asCatalogRole()) .build(); } @@ -366,9 +358,9 @@ public Response updateCatalogRole( String catalogName, String catalogRoleName, UpdateCatalogRoleRequest updateRequest, - RealmId realmId, + Realm realm, SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + PolarisAdminService adminService = newAdminService(realm, securityContext); return Response.ok( adminService .updateCatalogRole(catalogName, catalogRoleName, updateRequest) @@ -379,8 +371,8 @@ public Response updateCatalogRole( /** From PolarisCatalogsApiService */ @Override public Response listCatalogRoles( - String catalogName, RealmId realmId, SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + String catalogName, Realm realm, SecurityContext securityContext) { + PolarisAdminService adminService = newAdminService(realm, securityContext); List catalogRoleList = adminService.listCatalogRoles(catalogName).stream() .map(CatalogRoleEntity::new) @@ -396,13 +388,13 @@ public Response listCatalogRoles( public Response assignPrincipalRole( String principalName, GrantPrincipalRoleRequest request, - RealmId realmId, + Realm realm, SecurityContext securityContext) { LOGGER.info( "Assigning principalRole {} to principal {}", request.getPrincipalRole().getName(), principalName); - PolarisAdminService adminService = newAdminService(realmId, securityContext); + PolarisAdminService adminService = newAdminService(realm, securityContext); adminService.assignPrincipalRole(principalName, request.getPrincipalRole().getName()); return Response.status(Response.Status.CREATED).build(); } @@ -412,10 +404,10 @@ public Response assignPrincipalRole( public Response revokePrincipalRole( String principalName, String principalRoleName, - RealmId realmId, + Realm realm, SecurityContext securityContext) { LOGGER.info("Revoking principalRole {} from principal {}", principalRoleName, principalName); - PolarisAdminService adminService = newAdminService(realmId, securityContext); + PolarisAdminService adminService = newAdminService(realm, securityContext); adminService.revokePrincipalRole(principalName, principalRoleName); return Response.status(Response.Status.NO_CONTENT).build(); } @@ -423,8 +415,8 @@ public Response revokePrincipalRole( /** From PolarisPrincipalsApiService */ @Override public Response listPrincipalRolesAssigned( - String principalName, RealmId realmId, SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + String principalName, Realm realm, SecurityContext securityContext) { + PolarisAdminService adminService = newAdminService(realm, securityContext); List principalRoleList = adminService.listPrincipalRolesAssigned(principalName).stream() .map(PrincipalRoleEntity::new) @@ -441,14 +433,14 @@ public Response assignCatalogRoleToPrincipalRole( String principalRoleName, String catalogName, GrantCatalogRoleRequest request, - RealmId realmId, + Realm realm, SecurityContext securityContext) { LOGGER.info( "Assigning catalogRole {} in catalog {} to principalRole {}", request.getCatalogRole().getName(), catalogName, principalRoleName); - PolarisAdminService adminService = newAdminService(realmId, securityContext); + PolarisAdminService adminService = newAdminService(realm, securityContext); adminService.assignCatalogRoleToPrincipalRole( principalRoleName, catalogName, request.getCatalogRole().getName()); return Response.status(Response.Status.CREATED).build(); @@ -460,14 +452,14 @@ public Response revokeCatalogRoleFromPrincipalRole( String principalRoleName, String catalogName, String catalogRoleName, - RealmId realmId, + Realm realm, SecurityContext securityContext) { LOGGER.info( "Revoking catalogRole {} in catalog {} from principalRole {}", catalogRoleName, catalogName, principalRoleName); - PolarisAdminService adminService = newAdminService(realmId, securityContext); + PolarisAdminService adminService = newAdminService(realm, securityContext); adminService.revokeCatalogRoleFromPrincipalRole( principalRoleName, catalogName, catalogRoleName); return Response.status(Response.Status.NO_CONTENT).build(); @@ -476,8 +468,8 @@ public Response revokeCatalogRoleFromPrincipalRole( /** From PolarisPrincipalRolesApiService */ @Override public Response listAssigneePrincipalsForPrincipalRole( - String principalRoleName, RealmId realmId, SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + String principalRoleName, Realm realm, SecurityContext securityContext) { + PolarisAdminService adminService = newAdminService(realm, securityContext); List principalList = adminService.listAssigneePrincipalsForPrincipalRole(principalRoleName).stream() .map(PrincipalEntity::new) @@ -491,11 +483,8 @@ public Response listAssigneePrincipalsForPrincipalRole( /** From PolarisPrincipalRolesApiService */ @Override public Response listCatalogRolesForPrincipalRole( - String principalRoleName, - String catalogName, - RealmId realmId, - SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + String principalRoleName, String catalogName, Realm realm, SecurityContext securityContext) { + PolarisAdminService adminService = newAdminService(realm, securityContext); List catalogRoleList = adminService.listCatalogRolesForPrincipalRole(principalRoleName, catalogName).stream() .map(CatalogRoleEntity::new) @@ -512,14 +501,14 @@ public Response addGrantToCatalogRole( String catalogName, String catalogRoleName, AddGrantRequest grantRequest, - RealmId realmId, + Realm realm, SecurityContext securityContext) { LOGGER.info( "Adding grant {} to catalogRole {} in catalog {}", grantRequest, catalogRoleName, catalogName); - PolarisAdminService adminService = newAdminService(realmId, securityContext); + PolarisAdminService adminService = newAdminService(realm, securityContext); switch (grantRequest.getGrant()) { // The per-securable-type Privilege enums must be exact String match for a subset of all // PolarisPrivilege values. @@ -583,7 +572,7 @@ public Response revokeGrantFromCatalogRole( String catalogRoleName, Boolean cascade, RevokeGrantRequest grantRequest, - RealmId realmId, + Realm realm, SecurityContext securityContext) { LOGGER.info( "Revoking grant {} from catalogRole {} in catalog {}", @@ -595,7 +584,7 @@ public Response revokeGrantFromCatalogRole( return Response.status(501).build(); // not implemented } - PolarisAdminService adminService = newAdminService(realmId, securityContext); + PolarisAdminService adminService = newAdminService(realm, securityContext); switch (grantRequest.getGrant()) { // The per-securable-type Privilege enums must be exact String match for a subset of all // PolarisPrivilege values. @@ -655,11 +644,8 @@ public Response revokeGrantFromCatalogRole( /** From PolarisCatalogsApiService */ @Override public Response listAssigneePrincipalRolesForCatalogRole( - String catalogName, - String catalogRoleName, - RealmId realmId, - SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + String catalogName, String catalogRoleName, Realm realm, SecurityContext securityContext) { + PolarisAdminService adminService = newAdminService(realm, securityContext); List principalRoleList = adminService.listAssigneePrincipalRolesForCatalogRole(catalogName, catalogRoleName).stream() .map(PrincipalRoleEntity::new) @@ -673,11 +659,8 @@ public Response listAssigneePrincipalRolesForCatalogRole( /** From PolarisCatalogsApiService */ @Override public Response listGrantsForCatalogRole( - String catalogName, - String catalogRoleName, - RealmId realmId, - SecurityContext securityContext) { - PolarisAdminService adminService = newAdminService(realmId, securityContext); + String catalogName, String catalogRoleName, Realm realm, SecurityContext securityContext) { + PolarisAdminService adminService = newAdminService(realm, securityContext); List grantList = adminService.listGrantsForCatalogRole(catalogName, catalogRoleName); GrantResources grantResources = new GrantResources(grantList); diff --git a/service/common/src/main/java/org/apache/polaris/service/auth/BasePolarisAuthenticator.java b/service/common/src/main/java/org/apache/polaris/service/auth/BasePolarisAuthenticator.java index 7d188f2f8..12fb32650 100644 --- a/service/common/src/main/java/org/apache/polaris/service/auth/BasePolarisAuthenticator.java +++ b/service/common/src/main/java/org/apache/polaris/service/auth/BasePolarisAuthenticator.java @@ -26,7 +26,7 @@ import org.apache.iceberg.exceptions.NotAuthorizedException; import org.apache.iceberg.exceptions.ServiceFailureException; import org.apache.polaris.core.auth.AuthenticatedPolarisPrincipal; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.PolarisEntity; import org.apache.polaris.core.entity.PolarisEntitySubType; import org.apache.polaris.core.entity.PolarisEntityType; @@ -39,7 +39,7 @@ /** * Base implementation of {@link Authenticator} constructs a {@link AuthenticatedPolarisPrincipal} * from the token parsed by subclasses. The {@link AuthenticatedPolarisPrincipal} is read from the - * {@link PolarisMetaStoreManager} for the current {@link RealmId}. If the token defines a non-empty + * {@link PolarisMetaStoreManager} for the current {@link Realm}. If the token defines a non-empty * set of scopes, only the principal roles specified in the scopes will be active for the current * principal. Only the grants assigned to these roles will be active in the current request. */ diff --git a/service/common/src/main/java/org/apache/polaris/service/auth/DefaultActiveRolesProvider.java b/service/common/src/main/java/org/apache/polaris/service/auth/DefaultActiveRolesProvider.java index 4c282affe..67f84126e 100644 --- a/service/common/src/main/java/org/apache/polaris/service/auth/DefaultActiveRolesProvider.java +++ b/service/common/src/main/java/org/apache/polaris/service/auth/DefaultActiveRolesProvider.java @@ -28,7 +28,7 @@ import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.auth.AuthenticatedPolarisPrincipal; import org.apache.polaris.core.auth.PolarisGrantManager; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.PolarisEntity; import org.apache.polaris.core.entity.PrincipalRoleEntity; import org.apache.polaris.core.persistence.MetaStoreManagerFactory; @@ -47,7 +47,7 @@ public class DefaultActiveRolesProvider implements ActiveRolesProvider { private static final Logger LOGGER = LoggerFactory.getLogger(DefaultActiveRolesProvider.class); - @Inject RealmId realmId; + @Inject Realm realm; @Inject MetaStoreManagerFactory metaStoreManagerFactory; @Inject PolarisDiagnostics diagnostics; @@ -57,8 +57,8 @@ public Set getActiveRoles(AuthenticatedPolarisPrincipal principal) { loadActivePrincipalRoles( principal.getActivatedPrincipalRoleNames(), principal.getPrincipalEntity(), - metaStoreManagerFactory.getOrCreateMetaStoreManager(realmId), - metaStoreManagerFactory.getOrCreateSessionSupplier(realmId).get()); + metaStoreManagerFactory.getOrCreateMetaStoreManager(realm), + metaStoreManagerFactory.getOrCreateSessionSupplier(realm).get()); return activeRoles.stream().map(PrincipalRoleEntity::getName).collect(Collectors.toSet()); } diff --git a/service/common/src/main/java/org/apache/polaris/service/auth/DefaultOAuth2ApiService.java b/service/common/src/main/java/org/apache/polaris/service/auth/DefaultOAuth2ApiService.java index edfe2fe01..a623cc6da 100644 --- a/service/common/src/main/java/org/apache/polaris/service/auth/DefaultOAuth2ApiService.java +++ b/service/common/src/main/java/org/apache/polaris/service/auth/DefaultOAuth2ApiService.java @@ -27,7 +27,7 @@ import jakarta.ws.rs.core.SecurityContext; import org.apache.commons.codec.binary.Base64; import org.apache.iceberg.rest.responses.OAuthTokenResponse; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.service.catalog.api.IcebergRestOAuth2ApiService; import org.apache.polaris.service.types.TokenType; import org.slf4j.Logger; @@ -65,10 +65,10 @@ public Response getToken( TokenType subjectTokenType, String actorToken, TokenType actorTokenType, - RealmId realmId, + Realm realm, SecurityContext securityContext) { - TokenBroker tokenBroker = tokenBrokerFactory.apply(realmId); + TokenBroker tokenBroker = tokenBrokerFactory.apply(realm); if (!tokenBroker.supportsGrantType(grantType)) { return OAuthUtils.getResponseFromError(OAuthTokenErrorResponse.Error.unsupported_grant_type); } diff --git a/service/common/src/main/java/org/apache/polaris/service/auth/JWTRSAKeyPairFactory.java b/service/common/src/main/java/org/apache/polaris/service/auth/JWTRSAKeyPairFactory.java index 9f959a219..5b165ff17 100644 --- a/service/common/src/main/java/org/apache/polaris/service/auth/JWTRSAKeyPairFactory.java +++ b/service/common/src/main/java/org/apache/polaris/service/auth/JWTRSAKeyPairFactory.java @@ -25,7 +25,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.security.NoSuchAlgorithmException; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.persistence.MetaStoreManagerFactory; import org.apache.polaris.service.auth.AuthenticationConfiguration.TokenBrokerConfiguration; import org.apache.polaris.service.auth.AuthenticationConfiguration.TokenBrokerConfiguration.RSAKeyPairConfiguration; @@ -53,10 +53,10 @@ public JWTRSAKeyPairFactory( } @Override - public TokenBroker apply(RealmId realmId) { + public TokenBroker apply(Realm realm) { return new JWTRSAKeyPair( - metaStoreManagerFactory.getOrCreateMetaStoreManager(realmId), - metaStoreManagerFactory.getOrCreateSessionSupplier(realmId).get(), + metaStoreManagerFactory.getOrCreateMetaStoreManager(realm), + metaStoreManagerFactory.getOrCreateSessionSupplier(realm).get(), (int) tokenBrokerConfiguration.maxTokenGeneration().toSeconds(), keyPairConfiguration.publicKeyFile(), keyPairConfiguration.privateKeyFile()); diff --git a/service/common/src/main/java/org/apache/polaris/service/auth/JWTSymmetricKeyFactory.java b/service/common/src/main/java/org/apache/polaris/service/auth/JWTSymmetricKeyFactory.java index 21f991190..0a54bf03a 100644 --- a/service/common/src/main/java/org/apache/polaris/service/auth/JWTSymmetricKeyFactory.java +++ b/service/common/src/main/java/org/apache/polaris/service/auth/JWTSymmetricKeyFactory.java @@ -28,7 +28,7 @@ import java.nio.file.Path; import java.time.Duration; import java.util.function.Supplier; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.persistence.MetaStoreManagerFactory; import org.apache.polaris.service.auth.AuthenticationConfiguration.TokenBrokerConfiguration.SymmetricKeyConfiguration; @@ -58,10 +58,10 @@ public JWTSymmetricKeyFactory( } @Override - public TokenBroker apply(RealmId realmId) { + public TokenBroker apply(Realm realm) { return new JWTSymmetricKeyBroker( - metaStoreManagerFactory.getOrCreateMetaStoreManager(realmId), - metaStoreManagerFactory.getOrCreateSessionSupplier(realmId).get(), + metaStoreManagerFactory.getOrCreateMetaStoreManager(realm), + metaStoreManagerFactory.getOrCreateSessionSupplier(realm).get(), (int) maxTokenGeneration.toSeconds(), secretSupplier); } diff --git a/service/common/src/main/java/org/apache/polaris/service/auth/NoneTokenBrokerFactory.java b/service/common/src/main/java/org/apache/polaris/service/auth/NoneTokenBrokerFactory.java index e8f16f32c..c9720a48a 100644 --- a/service/common/src/main/java/org/apache/polaris/service/auth/NoneTokenBrokerFactory.java +++ b/service/common/src/main/java/org/apache/polaris/service/auth/NoneTokenBrokerFactory.java @@ -20,7 +20,7 @@ import io.smallrye.common.annotation.Identifier; import jakarta.enterprise.context.ApplicationScoped; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.service.types.TokenType; /** Default {@link TokenBrokerFactory} that produces token brokers that do not do anything. */ @@ -59,7 +59,7 @@ public DecodedToken verify(String token) { }; @Override - public TokenBroker apply(RealmId realmId) { + public TokenBroker apply(Realm realm) { return NONE_TOKEN_BROKER; } } diff --git a/service/common/src/main/java/org/apache/polaris/service/auth/TestOAuth2ApiService.java b/service/common/src/main/java/org/apache/polaris/service/auth/TestOAuth2ApiService.java index d04632311..07fa8687d 100644 --- a/service/common/src/main/java/org/apache/polaris/service/auth/TestOAuth2ApiService.java +++ b/service/common/src/main/java/org/apache/polaris/service/auth/TestOAuth2ApiService.java @@ -28,7 +28,7 @@ import java.util.Objects; import org.apache.iceberg.exceptions.NotAuthorizedException; import org.apache.polaris.core.auth.PolarisSecretsManager.PrincipalSecretsResult; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.PolarisEntitySubType; import org.apache.polaris.core.entity.PolarisEntityType; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; @@ -58,7 +58,7 @@ public Response getToken( TokenType subjectTokenType, String actorToken, TokenType actorTokenType, - RealmId realmId, + Realm realm, SecurityContext securityContext) { Map response = new HashMap<>(); String principalName = getPrincipalName(clientId); @@ -69,7 +69,7 @@ public Response getToken( + ";password:" + clientSecret + ";realm:" - + realmId.id() + + realm.name() + ";role:" + scope.replaceAll(BasePolarisAuthenticator.PRINCIPAL_ROLE_PREFIX, "")); response.put("token_type", "bearer"); diff --git a/service/common/src/main/java/org/apache/polaris/service/auth/TokenBrokerFactory.java b/service/common/src/main/java/org/apache/polaris/service/auth/TokenBrokerFactory.java index 60624e70a..8b40baed6 100644 --- a/service/common/src/main/java/org/apache/polaris/service/auth/TokenBrokerFactory.java +++ b/service/common/src/main/java/org/apache/polaris/service/auth/TokenBrokerFactory.java @@ -19,10 +19,10 @@ package org.apache.polaris.service.auth; import java.util.function.Function; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; /** * Factory that creates a {@link TokenBroker} for generating and parsing. The {@link TokenBroker} is * created based on the realm context. */ -public interface TokenBrokerFactory extends Function {} +public interface TokenBrokerFactory extends Function {} diff --git a/service/common/src/main/java/org/apache/polaris/service/catalog/BasePolarisCatalog.java b/service/common/src/main/java/org/apache/polaris/service/catalog/BasePolarisCatalog.java index 06bbc84d6..022914b4a 100644 --- a/service/common/src/main/java/org/apache/polaris/service/catalog/BasePolarisCatalog.java +++ b/service/common/src/main/java/org/apache/polaris/service/catalog/BasePolarisCatalog.java @@ -79,7 +79,7 @@ import org.apache.polaris.core.admin.model.StorageConfigInfo; import org.apache.polaris.core.auth.AuthenticatedPolarisPrincipal; import org.apache.polaris.core.catalog.PolarisCatalogHelpers; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.CatalogEntity; import org.apache.polaris.core.entity.NamespaceEntity; import org.apache.polaris.core.entity.PolarisEntity; @@ -154,7 +154,7 @@ public class BasePolarisCatalog extends BaseMetastoreViewCatalog private final PolarisMetaStoreSession metaStoreSession; private final PolarisConfigurationStore configurationStore; private final PolarisDiagnostics diagnostics; - private final RealmId realmId; + private final Realm realm; private final PolarisResolutionManifestCatalogView resolvedEntityView; private final CatalogEntity catalogEntity; private final TaskExecutor taskExecutor; @@ -172,7 +172,7 @@ public class BasePolarisCatalog extends BaseMetastoreViewCatalog private Map tableDefaultProperties; /** - * @param realmId the current RealmId + * @param realm the current Realm * @param entityManager provides handle to underlying PolarisMetaStoreManager with which to * perform mutations on entities. * @param resolvedEntityView accessor to resolved entity paths that have been pre-vetted to ensure @@ -180,7 +180,7 @@ public class BasePolarisCatalog extends BaseMetastoreViewCatalog * @param taskExecutor Executor we use to register cleanup task handlers */ public BasePolarisCatalog( - RealmId realmId, + Realm realm, PolarisEntityManager entityManager, PolarisMetaStoreManager metaStoreManager, PolarisMetaStoreSession metaStoreSession, @@ -190,7 +190,7 @@ public BasePolarisCatalog( SecurityContext securityContext, TaskExecutor taskExecutor, FileIOFactory fileIOFactory) { - this.realmId = realmId; + this.realm = realm; this.entityManager = entityManager; this.metaStoreManager = metaStoreManager; this.metaStoreSession = metaStoreSession; @@ -450,7 +450,7 @@ public boolean dropTable(TableIdentifier tableIdentifier, boolean purge) { "Scheduled cleanup task {} for table {}", dropEntityResult.getCleanupTaskId(), tableIdentifier); - taskExecutor.addTaskHandlerContext(dropEntityResult.getCleanupTaskId(), realmId); + taskExecutor.addTaskHandlerContext(dropEntityResult.getCleanupTaskId(), realm); } return true; @@ -514,7 +514,7 @@ private void createNamespaceInternal( .setBaseLocation(baseLocation) .build(); if (!configurationStore.getConfiguration( - realmId, PolarisConfiguration.ALLOW_NAMESPACE_LOCATION_OVERLAP)) { + realm, PolarisConfiguration.ALLOW_NAMESPACE_LOCATION_OVERLAP)) { LOGGER.debug("Validating no overlap for {} with sibling tables or namespaces", namespace); validateNoLocationOverlap( entity.getBaseLocation(), resolvedParent.getRawFullPath(), entity.getName()); @@ -639,7 +639,7 @@ public boolean dropNamespace(Namespace namespace) throws NamespaceNotEmptyExcept leafEntity, Map.of(), configurationStore.getConfiguration( - realmId, PolarisConfiguration.CLEANUP_ON_NAMESPACE_DROP)); + realm, PolarisConfiguration.CLEANUP_ON_NAMESPACE_DROP)); if (!dropEntityResult.isSuccess() && dropEntityResult.failedBecauseNotEmpty()) { throw new NamespaceNotEmptyException("Namespace %s is not empty", namespace); @@ -665,7 +665,7 @@ public boolean setProperties(Namespace namespace, Map properties new PolarisEntity.Builder(entity).setProperties(newProperties).build(); if (!configurationStore.getConfiguration( - realmId, PolarisConfiguration.ALLOW_NAMESPACE_LOCATION_OVERLAP)) { + realm, PolarisConfiguration.ALLOW_NAMESPACE_LOCATION_OVERLAP)) { LOGGER.debug("Validating no overlap with sibling tables or namespaces"); validateNoLocationOverlap( NamespaceEntity.of(updatedEntity).getBaseLocation(), @@ -953,14 +953,14 @@ private void validateLocationsForTableLike( PolarisResolvedPathWrapper resolvedStorageEntity) { Optional optStorageConfiguration = PolarisStorageConfigurationInfo.forEntityPath( - realmId, configurationStore, diagnostics, resolvedStorageEntity.getRawFullPath()); + realm, configurationStore, diagnostics, resolvedStorageEntity.getRawFullPath()); optStorageConfiguration.ifPresentOrElse( storageConfigInfo -> { Map> validationResults = InMemoryStorageIntegration.validateSubpathsOfAllowedLocations( - realmId, + realm, configurationStore, storageConfigInfo, Set.of(PolarisStorageActions.ALL), @@ -1007,7 +1007,7 @@ private void validateLocationsForTableLike( () -> { List allowedStorageTypes = configurationStore.getConfiguration( - realmId, PolarisConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES); + realm, PolarisConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES); if (!allowedStorageTypes.contains(StorageConfigInfo.StorageTypeEnum.FILE.name())) { List invalidLocations = locations.stream() @@ -1032,7 +1032,7 @@ private void validateNoLocationOverlap( List resolvedNamespace, String location) { if (configurationStore.getConfiguration( - realmId, catalog, PolarisConfiguration.ALLOW_TABLE_LOCATION_OVERLAP)) { + realm, catalog, PolarisConfiguration.ALLOW_TABLE_LOCATION_OVERLAP)) { LOGGER.debug("Skipping location overlap validation for identifier '{}'", identifier); } else { // if (entity.getSubType().equals(PolarisEntitySubType.TABLE)) { // TODO - is this necessary for views? overlapping views do not expose subdirectories via the @@ -1399,10 +1399,10 @@ private void validateMetadataFileInTableDir( TableIdentifier identifier, TableMetadata metadata, CatalogEntity catalog) { boolean allowEscape = configurationStore.getConfiguration( - realmId, PolarisConfiguration.ALLOW_EXTERNAL_TABLE_LOCATION); + realm, PolarisConfiguration.ALLOW_EXTERNAL_TABLE_LOCATION); if (!allowEscape && !configurationStore.getConfiguration( - realmId, PolarisConfiguration.ALLOW_EXTERNAL_METADATA_FILE_LOCATION)) { + realm, PolarisConfiguration.ALLOW_EXTERNAL_METADATA_FILE_LOCATION)) { LOGGER.debug( "Validating base location {} for table {} in metadata file {}", metadata.location(), @@ -1836,7 +1836,7 @@ private void updateTableLike(TableIdentifier identifier, PolarisEntity entity) { if (catalogPath != null && !catalogPath.isEmpty() && purge) { boolean dropWithPurgeEnabled = configurationStore.getConfiguration( - realmId, catalogEntity, PolarisConfiguration.DROP_WITH_PURGE_ENABLED); + realm, catalogEntity, PolarisConfiguration.DROP_WITH_PURGE_ENABLED); if (!dropWithPurgeEnabled) { throw new ForbiddenException( String.format( @@ -2055,7 +2055,7 @@ private void blockedUserSpecifiedWriteLocation(Map properties) { /** Helper to retrieve dynamic context-based configuration that has a boolean value. */ private Boolean getBooleanContextConfiguration(String configKey, boolean defaultValue) { - return configurationStore.getConfiguration(realmId, configKey, defaultValue); + return configurationStore.getConfiguration(realm, configKey, defaultValue); } /** diff --git a/service/common/src/main/java/org/apache/polaris/service/catalog/IcebergCatalogAdapter.java b/service/common/src/main/java/org/apache/polaris/service/catalog/IcebergCatalogAdapter.java index 10727a7cf..e15d915ba 100644 --- a/service/common/src/main/java/org/apache/polaris/service/catalog/IcebergCatalogAdapter.java +++ b/service/common/src/main/java/org/apache/polaris/service/catalog/IcebergCatalogAdapter.java @@ -58,7 +58,7 @@ import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.auth.AuthenticatedPolarisPrincipal; import org.apache.polaris.core.auth.PolarisAuthorizer; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.PolarisEntity; import org.apache.polaris.core.persistence.PolarisEntityManager; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; @@ -79,7 +79,7 @@ /** * {@link IcebergRestCatalogApiService} implementation that delegates operations to {@link * org.apache.iceberg.rest.CatalogHandlers} after finding the appropriate {@link Catalog} for the - * current {@link RealmId}. + * current {@link Realm}. */ @RequestScoped public class IcebergCatalogAdapter @@ -119,7 +119,7 @@ public class IcebergCatalogAdapter .add(Endpoint.create("POST", ResourcePaths.V1_TRANSACTIONS_COMMIT)) .build(); - private final RealmId realmId; + private final Realm realm; private final PolarisMetaStoreManager metaStoreManager; private final PolarisEntityManager entityManager; private final PolarisMetaStoreSession session; @@ -131,7 +131,7 @@ public class IcebergCatalogAdapter @Inject public IcebergCatalogAdapter( - RealmId realmId, + Realm realm, PolarisEntityManager entityManager, PolarisMetaStoreManager metaStoreManager, PolarisMetaStoreSession session, @@ -140,7 +140,7 @@ public IcebergCatalogAdapter( PolarisAuthorizer polarisAuthorizer, TaskExecutor taskExecutor, FileIOFactory fileIOFactory) { - this.realmId = realmId; + this.realm = realm; this.entityManager = entityManager; this.metaStoreManager = metaStoreManager; this.session = session; @@ -179,7 +179,7 @@ private PolarisCatalogHandlerWrapper newHandlerWrapper( } return new PolarisCatalogHandlerWrapper( - realmId, + realm, session, configurationStore, diagnostics, @@ -196,7 +196,7 @@ private PolarisCatalogHandlerWrapper newHandlerWrapper( public Response createNamespace( String prefix, CreateNamespaceRequest createNamespaceRequest, - RealmId realmId, + Realm realm, SecurityContext securityContext) { return withCatalog( securityContext, @@ -210,7 +210,7 @@ public Response listNamespaces( String pageToken, Integer pageSize, String parent, - RealmId realmId, + Realm realm, SecurityContext securityContext) { Optional namespaceOptional = Optional.ofNullable(parent).map(IcebergCatalogAdapter::decodeNamespace); @@ -223,7 +223,7 @@ public Response listNamespaces( @Override public Response loadNamespaceMetadata( - String prefix, String namespace, RealmId realmId, SecurityContext securityContext) { + String prefix, String namespace, Realm realm, SecurityContext securityContext) { Namespace ns = decodeNamespace(namespace); return withCatalog( securityContext, prefix, catalog -> Response.ok(catalog.loadNamespaceMetadata(ns)).build()); @@ -235,7 +235,7 @@ private static Namespace decodeNamespace(String namespace) { @Override public Response namespaceExists( - String prefix, String namespace, RealmId realmId, SecurityContext securityContext) { + String prefix, String namespace, Realm realm, SecurityContext securityContext) { Namespace ns = decodeNamespace(namespace); return withCatalog( securityContext, @@ -248,7 +248,7 @@ public Response namespaceExists( @Override public Response dropNamespace( - String prefix, String namespace, RealmId realmId, SecurityContext securityContext) { + String prefix, String namespace, Realm realm, SecurityContext securityContext) { Namespace ns = decodeNamespace(namespace); return withCatalog( securityContext, @@ -264,7 +264,7 @@ public Response updateProperties( String prefix, String namespace, UpdateNamespacePropertiesRequest updateNamespacePropertiesRequest, - RealmId realmId, + Realm realm, SecurityContext securityContext) { Namespace ns = decodeNamespace(namespace); return withCatalog( @@ -291,7 +291,7 @@ public Response createTable( String namespace, CreateTableRequest createTableRequest, String accessDelegationMode, - RealmId realmId, + Realm realm, SecurityContext securityContext) { EnumSet delegationModes = parseAccessDelegationModes(accessDelegationMode); @@ -323,7 +323,7 @@ public Response listTables( String namespace, String pageToken, Integer pageSize, - RealmId realmId, + Realm realm, SecurityContext securityContext) { Namespace ns = decodeNamespace(namespace); return withCatalog( @@ -337,7 +337,7 @@ public Response loadTable( String table, String accessDelegationMode, String snapshots, - RealmId realmId, + Realm realm, SecurityContext securityContext) { EnumSet delegationModes = parseAccessDelegationModes(accessDelegationMode); @@ -358,11 +358,7 @@ public Response loadTable( @Override public Response tableExists( - String prefix, - String namespace, - String table, - RealmId realmId, - SecurityContext securityContext) { + String prefix, String namespace, String table, Realm realm, SecurityContext securityContext) { Namespace ns = decodeNamespace(namespace); TableIdentifier tableIdentifier = TableIdentifier.of(ns, RESTUtil.decodeString(table)); return withCatalog( @@ -380,7 +376,7 @@ public Response dropTable( String namespace, String table, Boolean purgeRequested, - RealmId realmId, + Realm realm, SecurityContext securityContext) { Namespace ns = decodeNamespace(namespace); TableIdentifier tableIdentifier = TableIdentifier.of(ns, RESTUtil.decodeString(table)); @@ -402,7 +398,7 @@ public Response registerTable( String prefix, String namespace, RegisterTableRequest registerTableRequest, - RealmId realmId, + Realm realm, SecurityContext securityContext) { Namespace ns = decodeNamespace(namespace); return withCatalog( @@ -415,7 +411,7 @@ public Response registerTable( public Response renameTable( String prefix, RenameTableRequest renameTableRequest, - RealmId realmId, + Realm realm, SecurityContext securityContext) { return withCatalog( securityContext, @@ -432,7 +428,7 @@ public Response updateTable( String namespace, String table, CommitTableRequest commitTableRequest, - RealmId realmId, + Realm realm, SecurityContext securityContext) { Namespace ns = decodeNamespace(namespace); TableIdentifier tableIdentifier = TableIdentifier.of(ns, RESTUtil.decodeString(table)); @@ -455,7 +451,7 @@ public Response createView( String prefix, String namespace, CreateViewRequest createViewRequest, - RealmId realmId, + Realm realm, SecurityContext securityContext) { Namespace ns = decodeNamespace(namespace); return withCatalog( @@ -470,7 +466,7 @@ public Response listViews( String namespace, String pageToken, Integer pageSize, - RealmId realmId, + Realm realm, SecurityContext securityContext) { Namespace ns = decodeNamespace(namespace); return withCatalog( @@ -479,11 +475,7 @@ public Response listViews( @Override public Response loadView( - String prefix, - String namespace, - String view, - RealmId realmId, - SecurityContext securityContext) { + String prefix, String namespace, String view, Realm realm, SecurityContext securityContext) { Namespace ns = decodeNamespace(namespace); TableIdentifier tableIdentifier = TableIdentifier.of(ns, RESTUtil.decodeString(view)); return withCatalog( @@ -492,11 +484,7 @@ public Response loadView( @Override public Response viewExists( - String prefix, - String namespace, - String view, - RealmId realmId, - SecurityContext securityContext) { + String prefix, String namespace, String view, Realm realm, SecurityContext securityContext) { Namespace ns = decodeNamespace(namespace); TableIdentifier tableIdentifier = TableIdentifier.of(ns, RESTUtil.decodeString(view)); return withCatalog( @@ -510,11 +498,7 @@ public Response viewExists( @Override public Response dropView( - String prefix, - String namespace, - String view, - RealmId realmId, - SecurityContext securityContext) { + String prefix, String namespace, String view, Realm realm, SecurityContext securityContext) { Namespace ns = decodeNamespace(namespace); TableIdentifier tableIdentifier = TableIdentifier.of(ns, RESTUtil.decodeString(view)); return withCatalog( @@ -530,7 +514,7 @@ public Response dropView( public Response renameView( String prefix, RenameTableRequest renameTableRequest, - RealmId realmId, + Realm realm, SecurityContext securityContext) { return withCatalog( securityContext, @@ -547,7 +531,7 @@ public Response replaceView( String namespace, String view, CommitViewRequest commitViewRequest, - RealmId realmId, + Realm realm, SecurityContext securityContext) { Namespace ns = decodeNamespace(namespace); TableIdentifier tableIdentifier = TableIdentifier.of(ns, RESTUtil.decodeString(view)); @@ -561,7 +545,7 @@ public Response replaceView( public Response commitTransaction( String prefix, CommitTransactionRequest commitTransactionRequest, - RealmId realmId, + Realm realm, SecurityContext securityContext) { return withCatalog( securityContext, @@ -578,7 +562,7 @@ public Response reportMetrics( String namespace, String table, ReportMetricsRequest reportMetricsRequest, - RealmId realmId, + Realm realm, SecurityContext securityContext) { return Response.status(Response.Status.NO_CONTENT).build(); } @@ -589,7 +573,7 @@ public Response sendNotification( String namespace, String table, NotificationRequest notificationRequest, - RealmId realmId, + Realm realm, SecurityContext securityContext) { Namespace ns = decodeNamespace(namespace); TableIdentifier tableIdentifier = TableIdentifier.of(ns, RESTUtil.decodeString(table)); @@ -604,7 +588,7 @@ public Response sendNotification( /** From IcebergRestConfigurationApiService. */ @Override - public Response getConfig(String warehouse, RealmId realmId, SecurityContext securityContext) { + public Response getConfig(String warehouse, Realm realm, SecurityContext securityContext) { // 'warehouse' as an input here is catalogName. // 'warehouse' as an output will be treated by the client as a default catalog // storage diff --git a/service/common/src/main/java/org/apache/polaris/service/catalog/PolarisCatalogHandlerWrapper.java b/service/common/src/main/java/org/apache/polaris/service/catalog/PolarisCatalogHandlerWrapper.java index ea014f2cc..eb090b2c5 100644 --- a/service/common/src/main/java/org/apache/polaris/service/catalog/PolarisCatalogHandlerWrapper.java +++ b/service/common/src/main/java/org/apache/polaris/service/catalog/PolarisCatalogHandlerWrapper.java @@ -82,7 +82,7 @@ import org.apache.polaris.core.auth.PolarisAuthorizableOperation; import org.apache.polaris.core.auth.PolarisAuthorizer; import org.apache.polaris.core.catalog.PolarisCatalogHelpers; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.CatalogEntity; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisEntitySubType; @@ -120,7 +120,7 @@ public class PolarisCatalogHandlerWrapper implements AutoCloseable { private static final Logger LOGGER = LoggerFactory.getLogger(PolarisCatalogHandlerWrapper.class); - private final RealmId realmId; + private final Realm realm; private final PolarisMetaStoreSession session; private final PolarisConfigurationStore configurationStore; private final PolarisDiagnostics diagnostics; @@ -143,7 +143,7 @@ public class PolarisCatalogHandlerWrapper implements AutoCloseable { private ViewCatalog viewCatalog = null; public PolarisCatalogHandlerWrapper( - RealmId realmId, + Realm realm, PolarisMetaStoreSession session, PolarisConfigurationStore configurationStore, PolarisDiagnostics diagnostics, @@ -154,7 +154,7 @@ public PolarisCatalogHandlerWrapper( PolarisAuthorizer authorizer, TaskExecutor taskExecutor, FileIOFactory fileIOFactory) { - this.realmId = realmId; + this.realm = realm; this.session = session; this.entityManager = entityManager; this.metaStoreManager = metaStoreManager; @@ -208,7 +208,7 @@ private void initializeCatalog() { resolutionManifest.getResolvedReferenceCatalogEntity().getRawLeafEntity(); CatalogEntity catalog = CatalogEntity.of(baseCatalogEntity); - String realm = realmId.id(); + String realm = this.realm.name(); String catalogKey = realm + "/" + catalogName; LOGGER.info("Initializing new BasePolarisCatalog for key: {}", catalogKey); @@ -235,7 +235,7 @@ protected Catalog createBasePolarisCatalog(Map catalogProperties BasePolarisCatalog catalogInstance = new BasePolarisCatalog( - realmId, + realm, entityManager, metaStoreManager, session, @@ -291,7 +291,7 @@ private void authorizeBasicNamespaceOperationOrThrow( throw new NoSuchNamespaceException("Namespace does not exist: %s", namespace); } authorizer.authorizeOrThrow( - realmId, + realm, authenticatedPrincipal, resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(), op, @@ -325,7 +325,7 @@ private void authorizeCreateNamespaceUnderNamespaceOperationOrThrow( throw new NoSuchNamespaceException("Namespace does not exist: %s", parentNamespace); } authorizer.authorizeOrThrow( - realmId, + realm, authenticatedPrincipal, resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(), op, @@ -363,7 +363,7 @@ private void authorizeCreateTableLikeUnderNamespaceOperationOrThrow( throw new NoSuchNamespaceException("Namespace does not exist: %s", namespace); } authorizer.authorizeOrThrow( - realmId, + realm, authenticatedPrincipal, resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(), op, @@ -396,7 +396,7 @@ private void authorizeBasicTableLikeOperationOrThrow( } } authorizer.authorizeOrThrow( - realmId, + realm, authenticatedPrincipal, resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(), op, @@ -450,7 +450,7 @@ private void authorizeCollectionOfTableLikeOperationOrThrow( "View does not exist: %s", identifier))) .toList(); authorizer.authorizeOrThrow( - realmId, + realm, authenticatedPrincipal, resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(), op, @@ -511,7 +511,7 @@ private void authorizeRenameTableLikeOperationOrThrow( PolarisResolvedPathWrapper secondary = resolutionManifest.getResolvedPath(dst.namespace(), true); authorizer.authorizeOrThrow( - realmId, + realm, authenticatedPrincipal, resolutionManifest.getAllActivatedCatalogRoleAndPrincipalRoles(), op, @@ -872,9 +872,7 @@ public LoadTableResponse loadTableWithAccessDelegation( .getCatalogType() .equals(org.apache.polaris.core.admin.model.Catalog.TypeEnum.EXTERNAL) && !configurationStore.getConfiguration( - realmId, - catalogEntity, - PolarisConfiguration.ALLOW_EXTERNAL_CATALOG_CREDENTIAL_VENDING)) { + realm, catalogEntity, PolarisConfiguration.ALLOW_EXTERNAL_CATALOG_CREDENTIAL_VENDING)) { throw new ForbiddenException( "Access Delegation is not enabled for this catalog. Please consult applicable " + "documentation for the catalog config property '%s' to enable this feature", @@ -1083,7 +1081,7 @@ public void commitTransaction(CommitTransactionRequest commitTransactionRequest) .location() .equals(((MetadataUpdate.SetLocation) singleUpdate).location()) && !configurationStore.getConfiguration( - realmId, PolarisConfiguration.ALLOW_NAMESPACE_LOCATION_OVERLAP)) { + realm, PolarisConfiguration.ALLOW_NAMESPACE_LOCATION_OVERLAP)) { throw new BadRequestException( "Unsupported operation: commitTransaction containing SetLocation" + " for table '%s' and new location '%s'", diff --git a/service/common/src/main/java/org/apache/polaris/service/config/DefaultConfigurationStore.java b/service/common/src/main/java/org/apache/polaris/service/config/DefaultConfigurationStore.java index def080261..d88ef380d 100644 --- a/service/common/src/main/java/org/apache/polaris/service/config/DefaultConfigurationStore.java +++ b/service/common/src/main/java/org/apache/polaris/service/config/DefaultConfigurationStore.java @@ -24,7 +24,7 @@ import jakarta.inject.Inject; import java.util.Map; import org.apache.polaris.core.PolarisConfigurationStore; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; @ApplicationScoped public class DefaultConfigurationStore implements PolarisConfigurationStore { @@ -53,11 +53,11 @@ public DefaultConfigurationStore( } @Override - public @Nullable T getConfiguration(@Nullable RealmId realmId, String configName) { + public @Nullable T getConfiguration(@Nullable Realm realm, String configName) { Object rawValue = defaults.get(configName); - if (realmId != null) { + if (realm != null) { rawValue = - realmOverrides.getOrDefault(realmId.id(), Map.of()).getOrDefault(configName, rawValue); + realmOverrides.getOrDefault(realm.name(), Map.of()).getOrDefault(configName, rawValue); } @SuppressWarnings("unchecked") T value = (T) rawValue; diff --git a/service/common/src/main/java/org/apache/polaris/service/config/RealmEntityManagerFactory.java b/service/common/src/main/java/org/apache/polaris/service/config/RealmEntityManagerFactory.java index c38504f32..188bf9fbf 100644 --- a/service/common/src/main/java/org/apache/polaris/service/config/RealmEntityManagerFactory.java +++ b/service/common/src/main/java/org/apache/polaris/service/config/RealmEntityManagerFactory.java @@ -23,13 +23,13 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.apache.polaris.core.PolarisDiagnostics; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.persistence.MetaStoreManagerFactory; import org.apache.polaris.core.persistence.PolarisEntityManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** Gets or creates PolarisEntityManager instances based on config values and RealmId. */ +/** Gets or creates PolarisEntityManager instances based on config values and Realm. */ @ApplicationScoped public class RealmEntityManagerFactory { @@ -38,7 +38,7 @@ public class RealmEntityManagerFactory { private final MetaStoreManagerFactory metaStoreManagerFactory; private final PolarisDiagnostics diagnostics; - // Key: realmIdentifier + // Key: realm private final Map cachedEntityManagers = new ConcurrentHashMap<>(); @Inject @@ -48,8 +48,8 @@ public RealmEntityManagerFactory( this.diagnostics = diagnostics; } - public PolarisEntityManager getOrCreateEntityManager(RealmId context) { - String realm = context.id(); + public PolarisEntityManager getOrCreateEntityManager(Realm context) { + String realm = context.name(); LOGGER.debug("Looking up PolarisEntityManager for realm {}", realm); diff --git a/service/common/src/main/java/org/apache/polaris/service/context/DefaultRealmIdResolver.java b/service/common/src/main/java/org/apache/polaris/service/context/DefaultRealmResolver.java similarity index 85% rename from service/common/src/main/java/org/apache/polaris/service/context/DefaultRealmIdResolver.java rename to service/common/src/main/java/org/apache/polaris/service/context/DefaultRealmResolver.java index 7e6a3b424..1917db8d1 100644 --- a/service/common/src/main/java/org/apache/polaris/service/context/DefaultRealmIdResolver.java +++ b/service/common/src/main/java/org/apache/polaris/service/context/DefaultRealmResolver.java @@ -22,21 +22,21 @@ import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import java.util.Map; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; @ApplicationScoped @Identifier("default") -public class DefaultRealmIdResolver implements RealmIdResolver { +public class DefaultRealmResolver implements RealmResolver { private final RealmContextConfiguration configuration; @Inject - public DefaultRealmIdResolver(RealmContextConfiguration configuration) { + public DefaultRealmResolver(RealmContextConfiguration configuration) { this.configuration = configuration; } @Override - public RealmId resolveRealmContext( + public Realm resolveRealmContext( String requestURL, String method, String path, Map headers) { String realm; @@ -50,6 +50,6 @@ public RealmId resolveRealmContext( realm = configuration.defaultRealm(); } - return RealmId.newRealmId(realm); + return Realm.fromName(realm); } } diff --git a/service/common/src/main/java/org/apache/polaris/service/context/RealmIdResolver.java b/service/common/src/main/java/org/apache/polaris/service/context/RealmResolver.java similarity index 89% rename from service/common/src/main/java/org/apache/polaris/service/context/RealmIdResolver.java rename to service/common/src/main/java/org/apache/polaris/service/context/RealmResolver.java index 7ee2d8050..cbc3cf3ef 100644 --- a/service/common/src/main/java/org/apache/polaris/service/context/RealmIdResolver.java +++ b/service/common/src/main/java/org/apache/polaris/service/context/RealmResolver.java @@ -19,10 +19,10 @@ package org.apache.polaris.service.context; import java.util.Map; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; -public interface RealmIdResolver { +public interface RealmResolver { - RealmId resolveRealmContext( + Realm resolveRealmContext( String requestURL, String method, String path, Map headers); } diff --git a/service/common/src/main/java/org/apache/polaris/service/context/TestRealmIdResolver.java b/service/common/src/main/java/org/apache/polaris/service/context/TestRealmResolver.java similarity index 88% rename from service/common/src/main/java/org/apache/polaris/service/context/TestRealmIdResolver.java rename to service/common/src/main/java/org/apache/polaris/service/context/TestRealmResolver.java index 6962ae38e..4af81c0be 100644 --- a/service/common/src/main/java/org/apache/polaris/service/context/TestRealmIdResolver.java +++ b/service/common/src/main/java/org/apache/polaris/service/context/TestRealmResolver.java @@ -24,7 +24,7 @@ import jakarta.inject.Inject; import java.util.HashMap; import java.util.Map; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,25 +36,25 @@ */ @ApplicationScoped @Identifier("test") -public class TestRealmIdResolver implements RealmIdResolver { - private static final Logger LOGGER = LoggerFactory.getLogger(DefaultRealmIdResolver.class); +public class TestRealmResolver implements RealmResolver { + private static final Logger LOGGER = LoggerFactory.getLogger(DefaultRealmResolver.class); public static final String REALM_PROPERTY_KEY = "realm"; private final RealmContextConfiguration configuration; @Inject - public TestRealmIdResolver(RealmContextConfiguration configuration) { + public TestRealmResolver(RealmContextConfiguration configuration) { this.configuration = configuration; } @Override - public RealmId resolveRealmContext( + public Realm resolveRealmContext( String requestURL, String method, String path, Map headers) { // Since this default resolver is strictly for use in test/dev environments, we'll consider // it safe to log all contents. Any "real" resolver used in a prod environment should make // sure to only log non-sensitive contents. - LOGGER.debug("Resolving RealmId for method: {}, path: {}, headers: {}", method, path, headers); + LOGGER.debug("Resolving Realm for method: {}, path: {}, headers: {}", method, path, headers); Map parsedProperties = parseBearerTokenAsKvPairs(headers); if (!parsedProperties.containsKey(REALM_PROPERTY_KEY) @@ -69,8 +69,8 @@ public RealmId resolveRealmContext( configuration.defaultRealm()); parsedProperties.put(REALM_PROPERTY_KEY, configuration.defaultRealm()); } - String realmId = parsedProperties.get(REALM_PROPERTY_KEY); - return RealmId.newRealmId(realmId); + String realm = parsedProperties.get(REALM_PROPERTY_KEY); + return Realm.fromName(realm); } /** diff --git a/service/common/src/main/java/org/apache/polaris/service/persistence/InMemoryPolarisMetaStoreManagerFactory.java b/service/common/src/main/java/org/apache/polaris/service/persistence/InMemoryPolarisMetaStoreManagerFactory.java index c5ce47593..863fd362a 100644 --- a/service/common/src/main/java/org/apache/polaris/service/persistence/InMemoryPolarisMetaStoreManagerFactory.java +++ b/service/common/src/main/java/org/apache/polaris/service/persistence/InMemoryPolarisMetaStoreManagerFactory.java @@ -32,7 +32,7 @@ import org.apache.polaris.core.PolarisConfigurationStore; import org.apache.polaris.core.PolarisDiagnostics; import org.apache.polaris.core.auth.PolarisSecretsManager.PrincipalSecretsResult; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.persistence.LocalPolarisMetaStoreManagerFactory; import org.apache.polaris.core.persistence.PolarisCredentialsBootstrap; import org.apache.polaris.core.persistence.PolarisMetaStoreManager; @@ -76,28 +76,27 @@ protected PolarisTreeMapStore createBackingStore(@Nonnull PolarisDiagnostics dia @Override protected PolarisMetaStoreSession createMetaStoreSession( @Nonnull PolarisTreeMapStore store, - @Nonnull RealmId realmId, + @Nonnull Realm realm, @Nullable PolarisCredentialsBootstrap credentialsBootstrap, @Nonnull PolarisDiagnostics diagnostics) { return new PolarisTreeMapMetaStoreSessionImpl( - store, storageIntegration, secretsGenerator(realmId, credentialsBootstrap), diagnostics); + store, storageIntegration, secretsGenerator(realm, credentialsBootstrap), diagnostics); } @Override - public synchronized PolarisMetaStoreManager getOrCreateMetaStoreManager(RealmId realmId) { - if (!bootstrappedRealms.contains(realmId.id())) { - bootstrapRealmsAndPrintCredentials(List.of(realmId.id())); + public synchronized PolarisMetaStoreManager getOrCreateMetaStoreManager(Realm realm) { + if (!bootstrappedRealms.contains(realm.name())) { + bootstrapRealmsAndPrintCredentials(List.of(realm.name())); } - return super.getOrCreateMetaStoreManager(realmId); + return super.getOrCreateMetaStoreManager(realm); } @Override - public synchronized Supplier getOrCreateSessionSupplier( - RealmId realmId) { - if (!bootstrappedRealms.contains(realmId.id())) { - bootstrapRealmsAndPrintCredentials(List.of(realmId.id())); + public synchronized Supplier getOrCreateSessionSupplier(Realm realm) { + if (!bootstrappedRealms.contains(realm.name())) { + bootstrapRealmsAndPrintCredentials(List.of(realm.name())); } - return super.getOrCreateSessionSupplier(realmId); + return super.getOrCreateSessionSupplier(realm); } private void bootstrapRealmsAndPrintCredentials(List realms) { @@ -107,13 +106,13 @@ private void bootstrapRealmsAndPrintCredentials(List realms) { this.bootstrapRealms(realms, credentialsBootstrap); bootstrappedRealms.addAll(realms); - for (String realmId : realms) { - PrincipalSecretsResult principalSecrets = results.get(realmId); + for (String realm : realms) { + PrincipalSecretsResult principalSecrets = results.get(realm); String msg = String.format( "realm: %1s root principal credentials: %2s:%3s", - realmId, + realm, principalSecrets.getPrincipalSecrets().getPrincipalClientId(), principalSecrets.getPrincipalSecrets().getMainSecret()); System.out.println(msg); diff --git a/service/common/src/main/java/org/apache/polaris/service/ratelimiter/DefaultTokenBucketFactory.java b/service/common/src/main/java/org/apache/polaris/service/ratelimiter/DefaultTokenBucketFactory.java index 6b93cf4b4..054cc1d0f 100644 --- a/service/common/src/main/java/org/apache/polaris/service/ratelimiter/DefaultTokenBucketFactory.java +++ b/service/common/src/main/java/org/apache/polaris/service/ratelimiter/DefaultTokenBucketFactory.java @@ -25,7 +25,7 @@ import java.time.Duration; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; @ApplicationScoped @Identifier("default") @@ -48,9 +48,9 @@ public DefaultTokenBucketFactory(long requestsPerSecond, Duration window, Clock } @Override - public TokenBucket getOrCreateTokenBucket(RealmId realmId) { + public TokenBucket getOrCreateTokenBucket(Realm realm) { return perRealmBuckets.computeIfAbsent( - realmId.id(), + realm.name(), k -> new TokenBucket( requestsPerSecond, diff --git a/service/common/src/main/java/org/apache/polaris/service/ratelimiter/RealmTokenBucketRateLimiter.java b/service/common/src/main/java/org/apache/polaris/service/ratelimiter/RealmTokenBucketRateLimiter.java index 657a4e557..ad0727d65 100644 --- a/service/common/src/main/java/org/apache/polaris/service/ratelimiter/RealmTokenBucketRateLimiter.java +++ b/service/common/src/main/java/org/apache/polaris/service/ratelimiter/RealmTokenBucketRateLimiter.java @@ -21,7 +21,7 @@ import io.smallrye.common.annotation.Identifier; import jakarta.enterprise.context.RequestScoped; import jakarta.inject.Inject; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; /** * Rate limiter that maps the request's realm identifier to its own TokenBucket, with its own @@ -32,12 +32,12 @@ public class RealmTokenBucketRateLimiter implements RateLimiter { private final TokenBucketFactory tokenBucketFactory; - private final RealmId realmId; + private final Realm realm; @Inject - public RealmTokenBucketRateLimiter(TokenBucketFactory tokenBucketFactory, RealmId realmId) { + public RealmTokenBucketRateLimiter(TokenBucketFactory tokenBucketFactory, Realm realm) { this.tokenBucketFactory = tokenBucketFactory; - this.realmId = realmId; + this.realm = realm; } /** @@ -48,6 +48,6 @@ public RealmTokenBucketRateLimiter(TokenBucketFactory tokenBucketFactory, RealmI */ @Override public boolean canProceed() { - return tokenBucketFactory.getOrCreateTokenBucket(realmId).tryAcquire(); + return tokenBucketFactory.getOrCreateTokenBucket(realm).tryAcquire(); } } diff --git a/service/common/src/main/java/org/apache/polaris/service/ratelimiter/TokenBucketFactory.java b/service/common/src/main/java/org/apache/polaris/service/ratelimiter/TokenBucketFactory.java index 6b62cc71f..447b838a2 100644 --- a/service/common/src/main/java/org/apache/polaris/service/ratelimiter/TokenBucketFactory.java +++ b/service/common/src/main/java/org/apache/polaris/service/ratelimiter/TokenBucketFactory.java @@ -18,10 +18,10 @@ */ package org.apache.polaris.service.ratelimiter; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; /** Factory for creating token buckets per realm. */ public interface TokenBucketFactory { - TokenBucket getOrCreateTokenBucket(RealmId realmId); + TokenBucket getOrCreateTokenBucket(Realm realm); } diff --git a/service/common/src/main/java/org/apache/polaris/service/storage/PolarisStorageIntegrationProviderImpl.java b/service/common/src/main/java/org/apache/polaris/service/storage/PolarisStorageIntegrationProviderImpl.java index 8b967df7f..acad326af 100644 --- a/service/common/src/main/java/org/apache/polaris/service/storage/PolarisStorageIntegrationProviderImpl.java +++ b/service/common/src/main/java/org/apache/polaris/service/storage/PolarisStorageIntegrationProviderImpl.java @@ -32,7 +32,7 @@ import java.util.function.Supplier; import org.apache.polaris.core.PolarisConfigurationStore; import org.apache.polaris.core.PolarisDiagnostics; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.storage.PolarisCredentialProperty; import org.apache.polaris.core.storage.PolarisStorageActions; import org.apache.polaris.core.storage.PolarisStorageConfigurationInfo; @@ -102,7 +102,7 @@ public PolarisStorageIntegrationProviderImpl( new PolarisStorageIntegration<>("file") { @Override public EnumMap getSubscopedCreds( - @Nonnull RealmId realmId, + @Nonnull Realm realm, @Nonnull PolarisDiagnostics diagnostics, @Nonnull T storageConfig, boolean allowListOperation, @@ -114,7 +114,7 @@ public EnumMap getSubscopedCreds( @Override public @Nonnull Map> validateAccessToLocations( - @Nonnull RealmId realmId, + @Nonnull Realm realm, @Nonnull T storageConfig, @Nonnull Set actions, @Nonnull Set locations) { diff --git a/service/common/src/main/java/org/apache/polaris/service/task/ManifestFileCleanupTaskHandler.java b/service/common/src/main/java/org/apache/polaris/service/task/ManifestFileCleanupTaskHandler.java index 2cd5c6e40..0bcdde4de 100644 --- a/service/common/src/main/java/org/apache/polaris/service/task/ManifestFileCleanupTaskHandler.java +++ b/service/common/src/main/java/org/apache/polaris/service/task/ManifestFileCleanupTaskHandler.java @@ -37,7 +37,7 @@ import org.apache.iceberg.catalog.TableIdentifier; import org.apache.iceberg.io.FileIO; import org.apache.polaris.core.PolarisDiagnostics; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.AsyncTaskType; import org.apache.polaris.core.entity.TaskEntity; import org.slf4j.Logger; @@ -56,12 +56,12 @@ public class ManifestFileCleanupTaskHandler implements TaskHandler { public static final int FILE_DELETION_RETRY_MILLIS = 100; private static final Logger LOGGER = LoggerFactory.getLogger(ManifestFileCleanupTaskHandler.class); - private final BiFunction fileIOSupplier; + private final BiFunction fileIOSupplier; private final ExecutorService executorService; private final PolarisDiagnostics diagnostics; public ManifestFileCleanupTaskHandler( - BiFunction fileIOSupplier, + BiFunction fileIOSupplier, ExecutorService executorService, PolarisDiagnostics diagnostics) { this.fileIOSupplier = fileIOSupplier; @@ -76,10 +76,10 @@ public boolean canHandleTask(TaskEntity task) { } @Override - public boolean handleTask(TaskEntity task, RealmId realmId) { + public boolean handleTask(TaskEntity task, Realm realm) { ManifestCleanupTask cleanupTask = task.readData(diagnostics, ManifestCleanupTask.class); TableIdentifier tableId = cleanupTask.getTableId(); - try (FileIO authorizedFileIO = fileIOSupplier.apply(task, realmId)) { + try (FileIO authorizedFileIO = fileIOSupplier.apply(task, realm)) { if (task.getTaskType(diagnostics) == AsyncTaskType.MANIFEST_FILE_CLEANUP) { ManifestFile manifestFile = decodeManifestData(cleanupTask.getManifestFileData()); return cleanUpManifestFile(manifestFile, authorizedFileIO, tableId); diff --git a/service/common/src/main/java/org/apache/polaris/service/task/TableCleanupTaskHandler.java b/service/common/src/main/java/org/apache/polaris/service/task/TableCleanupTaskHandler.java index 94e8d3946..f22e34ce9 100644 --- a/service/common/src/main/java/org/apache/polaris/service/task/TableCleanupTaskHandler.java +++ b/service/common/src/main/java/org/apache/polaris/service/task/TableCleanupTaskHandler.java @@ -33,7 +33,7 @@ import org.apache.iceberg.io.FileIO; import org.apache.polaris.core.PolarisConfigurationStore; import org.apache.polaris.core.PolarisDiagnostics; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.AsyncTaskType; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisEntity; @@ -59,7 +59,7 @@ public class TableCleanupTaskHandler implements TaskHandler { private final MetaStoreManagerFactory metaStoreManagerFactory; private final PolarisConfigurationStore configurationStore; private final PolarisDiagnostics diagnostics; - private final BiFunction fileIOSupplier; + private final BiFunction fileIOSupplier; private final Clock clock; public TableCleanupTaskHandler( @@ -67,7 +67,7 @@ public TableCleanupTaskHandler( MetaStoreManagerFactory metaStoreManagerFactory, PolarisConfigurationStore configurationStore, PolarisDiagnostics diagnostics, - BiFunction fileIOSupplier, + BiFunction fileIOSupplier, Clock clock) { this.taskExecutor = taskExecutor; this.metaStoreManagerFactory = metaStoreManagerFactory; @@ -89,12 +89,12 @@ private boolean taskEntityIsTable(TaskEntity task) { } @Override - public boolean handleTask(TaskEntity cleanupTask, RealmId realmId) { + public boolean handleTask(TaskEntity cleanupTask, Realm realm) { PolarisBaseEntity entity = cleanupTask.readData(diagnostics, PolarisBaseEntity.class); PolarisMetaStoreManager metaStoreManager = - metaStoreManagerFactory.getOrCreateMetaStoreManager(realmId); + metaStoreManagerFactory.getOrCreateMetaStoreManager(realm); PolarisMetaStoreSession metaStoreSession = - metaStoreManagerFactory.getOrCreateSessionSupplier(realmId).get(); + metaStoreManagerFactory.getOrCreateSessionSupplier(realm).get(); TableLikeEntity tableEntity = TableLikeEntity.of(entity); LOGGER @@ -106,7 +106,7 @@ public boolean handleTask(TaskEntity cleanupTask, RealmId realmId) { // It's likely the cleanupTask has already been completed, but wasn't dropped successfully. // Log a // warning and move on - try (FileIO fileIO = fileIOSupplier.apply(cleanupTask, realmId)) { + try (FileIO fileIO = fileIOSupplier.apply(cleanupTask, realm)) { if (!TaskUtils.exists(tableEntity.getMetadataLocation(), fileIO)) { LOGGER .atWarn() @@ -132,7 +132,7 @@ public boolean handleTask(TaskEntity cleanupTask, RealmId realmId) { // TODO: handle partition statistics files Stream metadataFileCleanupTasks = getMetadataTaskStream( - realmId, + realm, cleanupTask, tableMetadata, tableEntity, @@ -157,7 +157,7 @@ public boolean handleTask(TaskEntity cleanupTask, RealmId realmId) { .log( "Successfully queued tasks to delete manifests, previous metadata, and statistics files - deleting table metadata file"); for (PolarisBaseEntity createdTask : createdTasks) { - taskExecutor.addTaskHandlerContext(createdTask.getId(), realmId); + taskExecutor.addTaskHandlerContext(createdTask.getId(), realm); } fileIO.deleteFile(tableEntity.getMetadataLocation()); @@ -222,7 +222,7 @@ private Stream getManifestTaskStream( } private Stream getMetadataTaskStream( - RealmId realmId, + Realm realm, TaskEntity cleanupTask, TableMetadata tableMetadata, TableLikeEntity tableEntity, @@ -230,7 +230,7 @@ private Stream getMetadataTaskStream( PolarisMetaStoreSession metaStoreSession, PolarisConfigurationStore configurationStore, Clock clock) { - int batchSize = configurationStore.getConfiguration(realmId, BATCH_SIZE_CONFIG_KEY, 10); + int batchSize = configurationStore.getConfiguration(realm, BATCH_SIZE_CONFIG_KEY, 10); return getMetadataFileBatches(tableMetadata, batchSize).stream() .map( metadataBatch -> { diff --git a/service/common/src/main/java/org/apache/polaris/service/task/TaskExecutor.java b/service/common/src/main/java/org/apache/polaris/service/task/TaskExecutor.java index d3e10b815..121c3a894 100644 --- a/service/common/src/main/java/org/apache/polaris/service/task/TaskExecutor.java +++ b/service/common/src/main/java/org/apache/polaris/service/task/TaskExecutor.java @@ -18,12 +18,12 @@ */ package org.apache.polaris.service.task; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; /** * Execute a task asynchronously with a provided context. The context must be cloned so that callers * can close their own context and closables */ public interface TaskExecutor { - void addTaskHandlerContext(long taskEntityId, RealmId realmId); + void addTaskHandlerContext(long taskEntityId, Realm realm); } diff --git a/service/common/src/main/java/org/apache/polaris/service/task/TaskExecutorImpl.java b/service/common/src/main/java/org/apache/polaris/service/task/TaskExecutorImpl.java index 68be1b458..73e68e7c3 100644 --- a/service/common/src/main/java/org/apache/polaris/service/task/TaskExecutorImpl.java +++ b/service/common/src/main/java/org/apache/polaris/service/task/TaskExecutorImpl.java @@ -30,7 +30,7 @@ import java.util.concurrent.TimeUnit; import org.apache.polaris.core.PolarisConfigurationStore; import org.apache.polaris.core.PolarisDiagnostics; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.PolarisBaseEntity; import org.apache.polaris.core.entity.PolarisEntity; import org.apache.polaris.core.entity.PolarisEntityType; @@ -43,7 +43,7 @@ /** * Given a list of registered {@link TaskHandler}s, execute tasks asynchronously with the provided - * {@link RealmId}. + * {@link Realm}. */ public class TaskExecutorImpl implements TaskExecutor { private static final Logger LOGGER = LoggerFactory.getLogger(TaskExecutorImpl.class); @@ -91,39 +91,39 @@ public void addTaskHandler(TaskHandler taskHandler) { } /** - * Register a {@link RealmId} for a specific task id. That task will be loaded and executed - * asynchronously with a copy of the provided {@link RealmId} (because the realm context is a - * request-scoped component). + * Register a {@link Realm} for a specific task id. That task will be loaded and executed + * asynchronously with a copy of the provided {@link Realm} (because the realm is a request-scoped + * component). */ @Override - public void addTaskHandlerContext(long taskEntityId, RealmId realmId) { + public void addTaskHandlerContext(long taskEntityId, Realm realm) { // Realm id is a request-scoped component, so we need to copy it to ensure it is available when // the task is executed, even if the original realm id is no longer available because the // request has completed. - tryHandleTask(taskEntityId, RealmId.copyOf(realmId), null, 1); + tryHandleTask(taskEntityId, Realm.copyOf(realm), null, 1); } private @Nonnull CompletableFuture tryHandleTask( - long taskEntityId, RealmId realmId, Throwable e, int attempt) { + long taskEntityId, Realm realm, Throwable e, int attempt) { if (attempt > 3) { return CompletableFuture.failedFuture(e); } - return CompletableFuture.runAsync(() -> handleTask(taskEntityId, realmId, attempt), executor) + return CompletableFuture.runAsync(() -> handleTask(taskEntityId, realm, attempt), executor) .exceptionallyComposeAsync( (t) -> { LOGGER.warn("Failed to handle task entity id {}", taskEntityId, t); - return tryHandleTask(taskEntityId, realmId, t, attempt + 1); + return tryHandleTask(taskEntityId, realm, t, attempt + 1); }, CompletableFuture.delayedExecutor( TASK_RETRY_DELAY * (long) attempt, TimeUnit.MILLISECONDS, executor)); } - protected void handleTask(long taskEntityId, RealmId realmId, int attempt) { + protected void handleTask(long taskEntityId, Realm realm, int attempt) { LOGGER.info("Handling task entity id {}", taskEntityId); PolarisMetaStoreManager metaStoreManager = - metaStoreManagerFactory.getOrCreateMetaStoreManager(realmId); + metaStoreManagerFactory.getOrCreateMetaStoreManager(realm); PolarisMetaStoreSession metaStoreSession = - metaStoreManagerFactory.getOrCreateSessionSupplier(realmId).get(); + metaStoreManagerFactory.getOrCreateSessionSupplier(realm).get(); PolarisBaseEntity taskEntity = metaStoreManager.loadEntity(metaStoreSession, 0L, taskEntityId).getEntity(); if (!PolarisEntityType.TASK.equals(taskEntity.getType())) { @@ -141,7 +141,7 @@ protected void handleTask(long taskEntityId, RealmId realmId, int attempt) { return; } TaskHandler handler = handlerOpt.get(); - boolean success = handler.handleTask(task, realmId); + boolean success = handler.handleTask(task, realm); if (success) { LOGGER .atInfo() diff --git a/service/common/src/main/java/org/apache/polaris/service/task/TaskFileIOSupplier.java b/service/common/src/main/java/org/apache/polaris/service/task/TaskFileIOSupplier.java index 71d2660eb..6fb5781ca 100644 --- a/service/common/src/main/java/org/apache/polaris/service/task/TaskFileIOSupplier.java +++ b/service/common/src/main/java/org/apache/polaris/service/task/TaskFileIOSupplier.java @@ -28,7 +28,7 @@ import org.apache.iceberg.io.FileIO; import org.apache.polaris.core.PolarisConfiguration; import org.apache.polaris.core.PolarisConfigurationStore; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.PolarisTaskConstants; import org.apache.polaris.core.entity.TaskEntity; import org.apache.polaris.core.persistence.MetaStoreManagerFactory; @@ -37,7 +37,7 @@ import org.apache.polaris.service.catalog.io.FileIOFactory; @ApplicationScoped -public class TaskFileIOSupplier implements BiFunction { +public class TaskFileIOSupplier implements BiFunction { private final MetaStoreManagerFactory metaStoreManagerFactory; private final FileIOFactory fileIOFactory; private final PolarisConfigurationStore configurationStore; @@ -53,25 +53,25 @@ public TaskFileIOSupplier( } @Override - public FileIO apply(TaskEntity task, RealmId realmId) { + public FileIO apply(TaskEntity task, Realm realm) { Map internalProperties = task.getInternalPropertiesAsMap(); String location = internalProperties.get(PolarisTaskConstants.STORAGE_LOCATION); PolarisMetaStoreManager metaStoreManager = - metaStoreManagerFactory.getOrCreateMetaStoreManager(realmId); + metaStoreManagerFactory.getOrCreateMetaStoreManager(realm); PolarisMetaStoreSession metaStoreSession = - metaStoreManagerFactory.getOrCreateSessionSupplier(realmId).get(); + metaStoreManagerFactory.getOrCreateSessionSupplier(realm).get(); Map properties = new HashMap<>(internalProperties); Boolean skipCredentialSubscopingIndirection = configurationStore.getConfiguration( - realmId, + realm, PolarisConfiguration.SKIP_CREDENTIAL_SUBSCOPING_INDIRECTION.key, PolarisConfiguration.SKIP_CREDENTIAL_SUBSCOPING_INDIRECTION.defaultValue); if (!skipCredentialSubscopingIndirection) { properties.putAll( metaStoreManagerFactory - .getOrCreateStorageCredentialCache(realmId) + .getOrCreateStorageCredentialCache(realm) .getOrGenerateSubScopeCreds( metaStoreManager, metaStoreSession, diff --git a/service/common/src/main/java/org/apache/polaris/service/task/TaskHandler.java b/service/common/src/main/java/org/apache/polaris/service/task/TaskHandler.java index 2c8dbfab0..75c1dc207 100644 --- a/service/common/src/main/java/org/apache/polaris/service/task/TaskHandler.java +++ b/service/common/src/main/java/org/apache/polaris/service/task/TaskHandler.java @@ -18,11 +18,11 @@ */ package org.apache.polaris.service.task; -import org.apache.polaris.core.context.RealmId; +import org.apache.polaris.core.context.Realm; import org.apache.polaris.core.entity.TaskEntity; public interface TaskHandler { boolean canHandleTask(TaskEntity task); - boolean handleTask(TaskEntity task, RealmId realmId); + boolean handleTask(TaskEntity task, Realm realm); } diff --git a/site/content/in-dev/unreleased/telemetry.md b/site/content/in-dev/unreleased/telemetry.md index eae7037b9..766a44b96 100644 --- a/site/content/in-dev/unreleased/telemetry.md +++ b/site/content/in-dev/unreleased/telemetry.md @@ -133,7 +133,7 @@ The log message format for both console and file output is highly configurable. is: ``` -%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] [%X{requestId},%X{realmId}] [%X{traceId},%X{parentId},%X{spanId},%X{sampled}] (%t) %s%e%n +%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c{3.}] [%X{requestId},%X{realm}] [%X{traceId},%X{parentId},%X{spanId},%X{sampled}] (%t) %s%e%n ``` Refer to the [Logging format](https://quarkus.io/guides/logging#logging-format) guide for more @@ -146,7 +146,7 @@ following MDC keys are available: - `requestId`: The unique identifier of the request, if set by the caller through the `Polaris-Request-Id` header. -- `realmId`: The unique identifier of the realm. Always set. +- `realm`: The unique identifier of the realm. Always set. - `traceId`: The unique identifier of the trace. Present if tracing is enabled and the message is originating from a traced context. - `parentId`: The unique identifier of the parent span. Present if tracing is enabled and the