Skip to content

Commit 2256df0

Browse files
authored
Simplify bootstrapServiceAndCreatePolarisPrincipalForRealm (#2172)
this is a small follow-up to 5faa371 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.
1 parent 45a7e3e commit 2256df0

File tree

2 files changed

+23
-32
lines changed

2 files changed

+23
-32
lines changed

persistence/relational-jdbc/src/main/java/org/apache/polaris/persistence/relational/jdbc/JdbcMetaStoreManagerFactory.java

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ public synchronized Map<String, PrincipalSecretsResult> bootstrapRealms(
159159
initializeForRealm(
160160
datasourceOperations, realmContext, bootstrapOptions.rootCredentialsSet());
161161
PrincipalSecretsResult secretsResult =
162-
bootstrapServiceAndCreatePolarisPrincipalForRealm(
163-
realmContext, metaStoreManagerMap.get(realm));
162+
bootstrapServiceAndCreatePolarisPrincipalForRealm(realmContext);
164163
results.put(realm, secretsResult);
165164
}
166165
}
@@ -227,14 +226,14 @@ public synchronized EntityCache getOrCreateEntityCache(
227226
* metastore and creates a root service principal.
228227
*/
229228
private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm(
230-
RealmContext realmContext, PolarisMetaStoreManager metaStoreManager) {
229+
RealmContext realmContext) {
231230
// While bootstrapping we need to act as a fake privileged context since the real
232231
// CallContext may not have been resolved yet.
232+
PolarisMetaStoreManager metaStoreManager =
233+
metaStoreManagerMap.get(realmContext.getRealmIdentifier());
234+
BasePersistence metaStore = sessionSupplierMap.get(realmContext.getRealmIdentifier()).get();
233235
PolarisCallContext polarisContext =
234-
new PolarisCallContext(
235-
realmContext,
236-
sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(),
237-
diagServices);
236+
new PolarisCallContext(realmContext, metaStore, diagServices);
238237
if (CallContext.getCurrentContext() == null) {
239238
CallContext.setCurrentContext(polarisContext);
240239
}
@@ -263,13 +262,11 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm
263262
PolarisEntityType.PRINCIPAL,
264263
PolarisEntitySubType.NULL_SUBTYPE,
265264
PolarisEntityConstants.getRootPrincipalName());
266-
PrincipalSecretsResult secrets =
267-
metaStoreManager.loadPrincipalSecrets(
268-
polarisContext,
269-
PolarisEntity.of(rootPrincipalLookup.getEntity())
270-
.getInternalPropertiesAsMap()
271-
.get(PolarisEntityConstants.getClientIdPropertyName()));
272-
return secrets;
265+
return metaStoreManager.loadPrincipalSecrets(
266+
polarisContext,
267+
PolarisEntity.of(rootPrincipalLookup.getEntity())
268+
.getInternalPropertiesAsMap()
269+
.get(PolarisEntityConstants.getClientIdPropertyName()));
273270
}
274271

275272
/**
@@ -282,11 +279,9 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm
282279
private void checkPolarisServiceBootstrappedForRealm(RealmContext realmContext) {
283280
PolarisMetaStoreManager metaStoreManager =
284281
metaStoreManagerMap.get(realmContext.getRealmIdentifier());
282+
BasePersistence metaStore = sessionSupplierMap.get(realmContext.getRealmIdentifier()).get();
285283
PolarisCallContext polarisContext =
286-
new PolarisCallContext(
287-
realmContext,
288-
sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(),
289-
diagServices);
284+
new PolarisCallContext(realmContext, metaStore, diagServices);
290285
if (CallContext.getCurrentContext() == null) {
291286
CallContext.setCurrentContext(polarisContext);
292287
}

polaris-core/src/main/java/org/apache/polaris/core/persistence/LocalPolarisMetaStoreManagerFactory.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ public synchronized Map<String, PrincipalSecretsResult> bootstrapRealms(
114114
if (!metaStoreManagerMap.containsKey(realm)) {
115115
initializeForRealm(realmContext, rootCredentialsSet);
116116
PrincipalSecretsResult secretsResult =
117-
bootstrapServiceAndCreatePolarisPrincipalForRealm(
118-
realmContext, metaStoreManagerMap.get(realm));
117+
bootstrapServiceAndCreatePolarisPrincipalForRealm(realmContext);
119118
results.put(realm, secretsResult);
120119
}
121120
}
@@ -178,18 +177,17 @@ public synchronized EntityCache getOrCreateEntityCache(
178177

179178
/**
180179
* This method bootstraps service for a given realm: i.e. creates all the needed entities in the
181-
* metastore and creates a root service principal. After that we rotate the root principal
182-
* credentials and print them to stdout
180+
* metastore and creates a root service principal.
183181
*/
184182
private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm(
185-
RealmContext realmContext, PolarisMetaStoreManager metaStoreManager) {
183+
RealmContext realmContext) {
186184
// While bootstrapping we need to act as a fake privileged context since the real
187185
// CallContext may not have been resolved yet.
188-
var polarisContext =
189-
new PolarisCallContext(
190-
realmContext,
191-
sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(),
192-
diagServices);
186+
PolarisMetaStoreManager metaStoreManager =
187+
metaStoreManagerMap.get(realmContext.getRealmIdentifier());
188+
BasePersistence metaStore = sessionSupplierMap.get(realmContext.getRealmIdentifier()).get();
189+
PolarisCallContext polarisContext =
190+
new PolarisCallContext(realmContext, metaStore, diagServices);
193191
if (CallContext.getCurrentContext() == null) {
194192
CallContext.setCurrentContext(polarisContext);
195193
}
@@ -235,11 +233,9 @@ private PrincipalSecretsResult bootstrapServiceAndCreatePolarisPrincipalForRealm
235233
private void checkPolarisServiceBootstrappedForRealm(RealmContext realmContext) {
236234
PolarisMetaStoreManager metaStoreManager =
237235
metaStoreManagerMap.get(realmContext.getRealmIdentifier());
236+
BasePersistence metaStore = sessionSupplierMap.get(realmContext.getRealmIdentifier()).get();
238237
PolarisCallContext polarisContext =
239-
new PolarisCallContext(
240-
realmContext,
241-
sessionSupplierMap.get(realmContext.getRealmIdentifier()).get(),
242-
diagServices);
238+
new PolarisCallContext(realmContext, metaStore, diagServices);
243239
if (CallContext.getCurrentContext() == null) {
244240
CallContext.setCurrentContext(polarisContext);
245241
}

0 commit comments

Comments
 (0)