Skip to content

Commit 15032f2

Browse files
authored
Bootstrap all configured realms on startup for in-memory metastore (#802)
1 parent d2f2ff3 commit 15032f2

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

quarkus/service/src/testFixtures/java/org/apache/polaris/service/quarkus/it/QuarkusServerManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public URI baseUri() {
4747
@Override
4848
public ClientPrincipal adminCredentials() {
4949
// These credentials are injected via env. variables from build scripts.
50-
// Cf. POLARIS_BOOTSTRAP_POLARIS_ROOT_CLIENT_ID
50+
// Cf. POLARIS_BOOTSTRAP_CREDENTIALS in build.gradle.kts
5151
return new ClientPrincipal("root", new ClientCredentials("test-admin", "test-secret"));
5252
}
5353

service/common/src/main/java/org/apache/polaris/service/persistence/InMemoryPolarisMetaStoreManagerFactory.java

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import jakarta.enterprise.context.ApplicationScoped;
2525
import jakarta.inject.Inject;
2626
import java.time.Clock;
27-
import java.util.Collections;
27+
import java.util.List;
2828
import java.util.Map;
2929
import java.util.Set;
3030
import java.util.concurrent.CopyOnWriteArraySet;
@@ -65,7 +65,7 @@ public InMemoryPolarisMetaStoreManagerFactory(
6565
}
6666

6767
public void onStartup(RealmContextConfiguration realmContextConfiguration) {
68-
bootstrapRealmAndPrintCredentials(realmContextConfiguration.defaultRealm());
68+
bootstrapRealmsAndPrintCredentials(realmContextConfiguration.realms());
6969
}
7070

7171
@Override
@@ -86,7 +86,7 @@ protected PolarisMetaStoreSession createMetaStoreSession(
8686
@Override
8787
public synchronized PolarisMetaStoreManager getOrCreateMetaStoreManager(RealmId realmId) {
8888
if (!bootstrappedRealms.contains(realmId.id())) {
89-
bootstrapRealmAndPrintCredentials(realmId.id());
89+
bootstrapRealmsAndPrintCredentials(List.of(realmId.id()));
9090
}
9191
return super.getOrCreateMetaStoreManager(realmId);
9292
}
@@ -95,25 +95,28 @@ public synchronized PolarisMetaStoreManager getOrCreateMetaStoreManager(RealmId
9595
public synchronized Supplier<PolarisMetaStoreSession> getOrCreateSessionSupplier(
9696
RealmId realmId) {
9797
if (!bootstrappedRealms.contains(realmId.id())) {
98-
bootstrapRealmAndPrintCredentials(realmId.id());
98+
bootstrapRealmsAndPrintCredentials(List.of(realmId.id()));
9999
}
100100
return super.getOrCreateSessionSupplier(realmId);
101101
}
102102

103-
private void bootstrapRealmAndPrintCredentials(String realmId) {
103+
private void bootstrapRealmsAndPrintCredentials(List<String> realms) {
104+
PolarisCredentialsBootstrap credentialsBootstrap =
105+
PolarisCredentialsBootstrap.fromEnvironment();
104106
Map<String, PrincipalSecretsResult> results =
105-
this.bootstrapRealms(
106-
Collections.singletonList(realmId), PolarisCredentialsBootstrap.fromEnvironment());
107-
bootstrappedRealms.add(realmId);
107+
this.bootstrapRealms(realms, credentialsBootstrap);
108+
bootstrappedRealms.addAll(realms);
108109

109-
PrincipalSecretsResult principalSecrets = results.get(realmId);
110+
for (String realmId : realms) {
111+
PrincipalSecretsResult principalSecrets = results.get(realmId);
110112

111-
String msg =
112-
String.format(
113-
"realm: %1s root principal credentials: %2s:%3s",
114-
realmId,
115-
principalSecrets.getPrincipalSecrets().getPrincipalClientId(),
116-
principalSecrets.getPrincipalSecrets().getMainSecret());
117-
System.out.println(msg);
113+
String msg =
114+
String.format(
115+
"realm: %1s root principal credentials: %2s:%3s",
116+
realmId,
117+
principalSecrets.getPrincipalSecrets().getPrincipalClientId(),
118+
principalSecrets.getPrincipalSecrets().getMainSecret());
119+
System.out.println(msg);
120+
}
118121
}
119122
}

0 commit comments

Comments
 (0)