This is an automated email from the ASF dual-hosted git repository. dimas pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/polaris.git
The following commit(s) were added to refs/heads/main by this push: new 2256df0cd Simplify bootstrapServiceAndCreatePolarisPrincipalForRealm (#2172) 2256df0cd is described below commit 2256df0cd281be07a3c9d718d5d1291c2c24f6c5 Author: Christopher Lambert <xn...@gmx.de> AuthorDate: Thu Jul 24 21:52:05 2025 +0200 Simplify bootstrapServiceAndCreatePolarisPrincipalForRealm (#2172) this is a small follow-up to 5faa3712cb8f0ae8140d096565734432d5391eb1 because the same pattern existed for this method. note that we do some minor additional "formatting" changes to minimize the diff between the two files (as they were originally copy pasted). this could lead to having a common base class in the future. --- .../jdbc/JdbcMetaStoreManagerFactory.java | 31 +++++++++------------- .../LocalPolarisMetaStoreManagerFactory.java | 24 +++++++---------- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcMetaStoreManagerFactory.java b/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcMetaStoreManagerFactory.java index 86652b051..43de79ec1 100644 --- a/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcMetaStoreManagerFactory.java +++ b/persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcMetaStoreManagerFactory.java @@ -159,8 +159,7 @@ public class JdbcMetaStoreManagerFactory implements MetaStoreManagerFactory { initializeForRealm( datasourceOperations, realmContext, bootstrapOptions.rootCredentialsSet()); PrincipalSecretsResult secretsResult = - bootstrapServiceAndCreatePolarisPrincipalForRealm( - realmContext, metaStoreManagerMap.get(realm)); + bootstrapServiceAndCreatePolarisPrincipalForRealm(realmContext); results.put(realm, secretsResult); } } @@ -227,14 +226,14 @@ public class JdbcMetaStoreManagerFactory implements MetaStoreManagerFactory { * metastore and creates a root service principal. */ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm( - RealmContext realmContext, PolarisMetaStoreManager metaStoreManager) { + RealmContext realmContext) { // While bootstrapping we need to act as a fake privileged context since the real // CallContext may not have been resolved yet. + PolarisMetaStoreManager metaStoreManager = + metaStoreManagerMap.get(realmContext.getRealmIdentifier()); + BasePersistence metaStore = sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(); PolarisCallContext polarisContext = - new PolarisCallContext( - realmContext, - sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(), - diagServices); + new PolarisCallContext(realmContext, metaStore, diagServices); if (CallContext.getCurrentContext() == null) { CallContext.setCurrentContext(polarisContext); } @@ -263,13 +262,11 @@ public class JdbcMetaStoreManagerFactory implements MetaStoreManagerFactory { PolarisEntityType.PRINCIPAL, PolarisEntitySubType.NULL_SUBTYPE, PolarisEntityConstants.getRootPrincipalName()); - PrincipalSecretsResult secrets = - metaStoreManager.loadPrincipalSecrets( - polarisContext, - PolarisEntity.of(rootPrincipalLookup.getEntity()) - .getInternalPropertiesAsMap() - .get(PolarisEntityConstants.getClientIdPropertyName())); - return secrets; + return metaStoreManager.loadPrincipalSecrets( + polarisContext, + PolarisEntity.of(rootPrincipalLookup.getEntity()) + .getInternalPropertiesAsMap() + .get(PolarisEntityConstants.getClientIdPropertyName())); } /** @@ -282,11 +279,9 @@ public class JdbcMetaStoreManagerFactory implements MetaStoreManagerFactory { private void checkPolarisServiceBootstrappedForRealm(RealmContext realmContext) { PolarisMetaStoreManager metaStoreManager = metaStoreManagerMap.get(realmContext.getRealmIdentifier()); + BasePersistence metaStore = sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(); PolarisCallContext polarisContext = - new PolarisCallContext( - realmContext, - sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(), - diagServices); + new PolarisCallContext(realmContext, metaStore, diagServices); if (CallContext.getCurrentContext() == null) { CallContext.setCurrentContext(polarisContext); } 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 a5141224c..8b31096f7 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 @@ -114,8 +114,7 @@ public abstract class LocalPolarisMetaStoreManagerFactory<StoreType> if (!metaStoreManagerMap.containsKey(realm)) { initializeForRealm(realmContext, rootCredentialsSet); PrincipalSecretsResult secretsResult = - bootstrapServiceAndCreatePolarisPrincipalForRealm( - realmContext, metaStoreManagerMap.get(realm)); + bootstrapServiceAndCreatePolarisPrincipalForRealm(realmContext); results.put(realm, secretsResult); } } @@ -178,18 +177,17 @@ public abstract class LocalPolarisMetaStoreManagerFactory<StoreType> /** * This method bootstraps service for a given realm: i.e. creates all the needed entities in the - * metastore and creates a root service principal. After that we rotate the root principal - * credentials and print them to stdout + * metastore and creates a root service principal. */ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm( - RealmContext realmContext, PolarisMetaStoreManager metaStoreManager) { + RealmContext realmContext) { // While bootstrapping we need to act as a fake privileged context since the real // CallContext may not have been resolved yet. - var polarisContext = - new PolarisCallContext( - realmContext, - sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(), - diagServices); + PolarisMetaStoreManager metaStoreManager = + metaStoreManagerMap.get(realmContext.getRealmIdentifier()); + BasePersistence metaStore = sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(); + PolarisCallContext polarisContext = + new PolarisCallContext(realmContext, metaStore, diagServices); if (CallContext.getCurrentContext() == null) { CallContext.setCurrentContext(polarisContext); } @@ -235,11 +233,9 @@ public abstract class LocalPolarisMetaStoreManagerFactory<StoreType> private void checkPolarisServiceBootstrappedForRealm(RealmContext realmContext) { PolarisMetaStoreManager metaStoreManager = metaStoreManagerMap.get(realmContext.getRealmIdentifier()); + BasePersistence metaStore = sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(); PolarisCallContext polarisContext = - new PolarisCallContext( - realmContext, - sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(), - diagServices); + new PolarisCallContext(realmContext, metaStore, diagServices); if (CallContext.getCurrentContext() == null) { CallContext.setCurrentContext(polarisContext); }