Skip to content

Commit 5fe9fd9

Browse files
authored
Replace getConfiguration usage with PolarisCallContext to use RealmContext (PART 1) (#1780)
1 parent 8f906a6 commit 5fe9fd9

File tree

18 files changed

+88
-79
lines changed

18 files changed

+88
-79
lines changed

polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ public void authorizeOrThrow(
584584
@Nullable List<PolarisResolvedPathWrapper> secondaries) {
585585
boolean enforceCredentialRotationRequiredState =
586586
featureConfig.getConfiguration(
587-
callContext.getPolarisCallContext(),
587+
callContext.getRealmContext(),
588588
FeatureConfiguration.ENFORCE_PRINCIPAL_CREDENTIAL_ROTATION_REQUIRED_CHECKING);
589589
if (enforceCredentialRotationRequiredState
590590
&& authenticatedPrincipal

polaris-core/src/main/java/org/apache/polaris/core/config/FeatureConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public static void enforceFeatureEnabledOrThrow(
5252
callContext
5353
.getPolarisCallContext()
5454
.getConfigurationStore()
55-
.getConfiguration(callContext.getPolarisCallContext(), featureConfig);
55+
.getConfiguration(callContext.getRealmContext(), featureConfig);
5656
if (!enabled) {
5757
throw new UnsupportedOperationException("Feature not enabled: " + featureConfig.key);
5858
}

polaris-core/src/main/java/org/apache/polaris/core/config/PolarisConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ public static <T> T loadConfig(PolarisConfiguration<T> configuration) {
226226
return callContext
227227
.getPolarisCallContext()
228228
.getConfigurationStore()
229-
.getConfiguration(callContext.getPolarisCallContext(), configuration);
229+
.getConfiguration(callContext.getRealmContext(), configuration);
230230
}
231231

232232
public static <T> Builder<T> builder() {

polaris-core/src/main/java/org/apache/polaris/core/config/PolarisConfigurationStore.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -133,32 +133,31 @@ public interface PolarisConfigurationStore {
133133
}
134134

135135
/**
136-
* Retrieve the current value for a configuration. TODO: update the function to take RealmContext
137-
* instead of PolarisCallContext. Github issue https://github.com/apache/polaris/issues/1775
136+
* Retrieve the current value for a configuration.
138137
*
139-
* @param ctx the current call context
138+
* @param realmContext the current realm context
140139
* @param config the configuration to load
141140
* @return the current value set for the configuration key or null if not set
142141
* @param <T> the type of the configuration value
143142
*/
144-
default <T> @Nonnull T getConfiguration(PolarisCallContext ctx, PolarisConfiguration<T> config) {
145-
T result = getConfiguration(ctx, config.key, config.defaultValue);
143+
default <T> @Nonnull T getConfiguration(
144+
RealmContext realmContext, PolarisConfiguration<T> config) {
145+
T result = getConfiguration(realmContext, config.key, config.defaultValue);
146146
return tryCast(config, result);
147147
}
148148

149149
/**
150150
* Retrieve the current value for a configuration, overriding with a catalog config if it is
151-
* present. TODO: update the function to take RealmContext instead of PolarisCallContext Github
152-
* issue https://github.com/apache/polaris/issues/1775
151+
* present.
153152
*
154-
* @param ctx the current call context
153+
* @param realmContext the current realm context
155154
* @param catalogEntity the catalog to check for an override
156155
* @param config the configuration to load
157156
* @return the current value set for the configuration key or null if not set
158157
* @param <T> the type of the configuration value
159158
*/
160159
default <T> @Nonnull T getConfiguration(
161-
PolarisCallContext ctx,
160+
RealmContext realmContext,
162161
@Nonnull CatalogEntity catalogEntity,
163162
PolarisConfiguration<T> config) {
164163
if (config.hasCatalogConfig() || config.hasCatalogConfigUnsafe()) {
@@ -182,6 +181,6 @@ public interface PolarisConfigurationStore {
182181
return tryCast(config, propertyValue);
183182
}
184183
}
185-
return getConfiguration(ctx, config);
184+
return getConfiguration(realmContext, config);
186185
}
187186
}

polaris-core/src/main/java/org/apache/polaris/core/rest/PolarisEndpoints.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public static Set<Endpoint> getSupportedGenericTableEndpoints(CallContext callCo
8484
.getPolarisCallContext()
8585
.getConfigurationStore()
8686
.getConfiguration(
87-
callContext.getPolarisCallContext(), FeatureConfiguration.ENABLE_GENERIC_TABLES);
87+
callContext.getRealmContext(), FeatureConfiguration.ENABLE_GENERIC_TABLES);
8888

8989
return genericTableEnabled ? GENERIC_TABLE_ENDPOINTS : ImmutableSet.of();
9090
}
@@ -99,7 +99,7 @@ public static Set<Endpoint> getSupportedPolicyEndpoints(CallContext callContext)
9999
.getPolarisCallContext()
100100
.getConfigurationStore()
101101
.getConfiguration(
102-
callContext.getPolarisCallContext(), FeatureConfiguration.ENABLE_POLICY_STORE);
102+
callContext.getRealmContext(), FeatureConfiguration.ENABLE_POLICY_STORE);
103103
return policyStoreEnabled ? POLICY_STORE_ENDPOINTS : ImmutableSet.of();
104104
}
105105
}

polaris-core/src/main/java/org/apache/polaris/core/storage/InMemoryStorageIntegration.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ public InMemoryStorageIntegration(String identifierOrId) {
7878

7979
boolean allowWildcardLocation =
8080
Optional.ofNullable(CallContext.getCurrentContext())
81-
.flatMap(c -> Optional.ofNullable(c.getPolarisCallContext()))
8281
.map(
83-
pc ->
84-
pc.getConfigurationStore()
85-
.getConfiguration(pc, "ALLOW_WILDCARD_LOCATION", false))
82+
ctx ->
83+
ctx.getPolarisCallContext()
84+
.getConfigurationStore()
85+
.getConfiguration(ctx.getRealmContext(), "ALLOW_WILDCARD_LOCATION", false))
8686
.orElse(false);
8787

8888
if (allowWildcardLocation && allowedLocationStrings.contains("*")) {

polaris-core/src/main/java/org/apache/polaris/core/storage/PolarisStorageConfigurationInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public static Optional<PolarisStorageConfigurationInfo> forEntityPath(
166166
.getPolarisCallContext()
167167
.getConfigurationStore()
168168
.getConfiguration(
169-
CallContext.getCurrentContext().getPolarisCallContext(),
169+
CallContext.getCurrentContext().getRealmContext(),
170170
catalog,
171171
FeatureConfiguration.ALLOW_UNSTRUCTURED_TABLE_LOCATION);
172172
if (!allowEscape

polaris-core/src/test/java/org/apache/polaris/core/storage/InMemoryStorageIntegrationTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.apache.polaris.core.PolarisDiagnostics;
3131
import org.apache.polaris.core.config.PolarisConfigurationStore;
3232
import org.apache.polaris.core.context.CallContext;
33+
import org.apache.polaris.core.context.RealmContext;
3334
import org.apache.polaris.core.storage.aws.AwsStorageConfigurationInfo;
3435
import org.assertj.core.api.Assertions;
3536
import org.junit.jupiter.api.Test;
@@ -100,7 +101,7 @@ public void testValidateAccessToLocationsWithWildcard() {
100101
new PolarisConfigurationStore() {
101102
@SuppressWarnings("unchecked")
102103
@Override
103-
public <T> @Nullable T getConfiguration(PolarisCallContext ctx, String configName) {
104+
public <T> @Nullable T getConfiguration(RealmContext ctx, String configName) {
104105
return (T) config.get(configName);
105106
}
106107
},

polaris-core/src/test/java/org/apache/polaris/service/storage/PolarisConfigurationStoreTest.java

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,19 @@
2323
import java.util.Map;
2424
import java.util.function.Function;
2525
import java.util.function.Supplier;
26-
import org.apache.polaris.core.PolarisCallContext;
2726
import org.apache.polaris.core.config.BehaviorChangeConfiguration;
2827
import org.apache.polaris.core.config.FeatureConfiguration;
2928
import org.apache.polaris.core.config.PolarisConfiguration;
3029
import org.apache.polaris.core.config.PolarisConfigurationStore;
30+
import org.apache.polaris.core.context.RealmContext;
3131
import org.apache.polaris.core.entity.CatalogEntity;
3232
import org.junit.jupiter.api.Assertions;
3333
import org.junit.jupiter.api.Test;
34-
import org.mockito.Mockito;
3534

3635
/** Unit test for the default behaviors of the PolarisConfigurationStore interface. */
3736
public class PolarisConfigurationStoreTest {
37+
private final RealmContext testRealmContext = () -> "testRealm";
38+
3839
@Test
3940
public void testConfigsCanBeCastedFromString() {
4041
List<PolarisConfiguration<?>> configs =
@@ -52,7 +53,7 @@ public void testConfigsCanBeCastedFromString() {
5253
*/
5354
@SuppressWarnings("unchecked")
5455
@Override
55-
public <T> @Nullable T getConfiguration(PolarisCallContext ctx, String configName) {
56+
public <T> @Nullable T getConfiguration(RealmContext ctx, String configName) {
5657
for (PolarisConfiguration<?> c : configs) {
5758
if (c.key.equals(configName)) {
5859
return (T) String.valueOf(c.defaultValue);
@@ -68,9 +69,8 @@ public void testConfigsCanBeCastedFromString() {
6869

6970
// Ensure that we can fetch all the configs and that the value is what we expect, which
7071
// is the config's default value based on how we've implemented PolarisConfigurationStore above.
71-
PolarisCallContext polarisCallContext = Mockito.mock(PolarisCallContext.class);
7272
for (PolarisConfiguration<?> c : configs) {
73-
Assertions.assertEquals(c.defaultValue, store.getConfiguration(polarisCallContext, c));
73+
Assertions.assertEquals(c.defaultValue, store.getConfiguration(testRealmContext, c));
7474
}
7575
}
7676

@@ -84,15 +84,14 @@ public void testInvalidCastThrowsException() {
8484
new PolarisConfigurationStore() {
8585
@SuppressWarnings("unchecked")
8686
@Override
87-
public <T> T getConfiguration(PolarisCallContext ctx, String configName) {
87+
public <T> T getConfiguration(RealmContext ctx, String configName) {
8888
return (T) "abc123";
8989
}
9090
};
9191

92-
PolarisCallContext polarisCallContext = Mockito.mock(PolarisCallContext.class);
9392
for (PolarisConfiguration<?> c : configs) {
9493
Assertions.assertThrows(
95-
NumberFormatException.class, () -> store.getConfiguration(polarisCallContext, c));
94+
NumberFormatException.class, () -> store.getConfiguration(testRealmContext, c));
9695
}
9796
}
9897

@@ -106,18 +105,18 @@ private static <T> PolarisConfiguration<T> buildConfig(String key, T defaultValu
106105

107106
private static class PolarisConfigurationConsumer {
108107

109-
private final PolarisCallContext polarisCallContext;
108+
private final RealmContext realmContext;
110109
private final PolarisConfigurationStore configurationStore;
111110

112111
public PolarisConfigurationConsumer(
113-
PolarisCallContext polarisCallContext, PolarisConfigurationStore configurationStore) {
114-
this.polarisCallContext = polarisCallContext;
112+
RealmContext realmContext, PolarisConfigurationStore configurationStore) {
113+
this.realmContext = realmContext;
115114
this.configurationStore = configurationStore;
116115
}
117116

118117
public <T> T consumeConfiguration(
119118
PolarisConfiguration<Boolean> config, Supplier<T> code, T defaultVal) {
120-
if (configurationStore.getConfiguration(polarisCallContext, config)) {
119+
if (configurationStore.getConfiguration(realmContext, config)) {
121120
return code.get();
122121
}
123122
return defaultVal;
@@ -127,7 +126,7 @@ public <T> T consumeConfiguration(
127126
@Test
128127
public void testBehaviorAndFeatureConfigs() {
129128
PolarisConfigurationConsumer consumer =
130-
new PolarisConfigurationConsumer(null, new PolarisConfigurationStore() {});
129+
new PolarisConfigurationConsumer(testRealmContext, new PolarisConfigurationStore() {});
131130

132131
FeatureConfiguration<Boolean> featureConfig =
133132
PolarisConfiguration.<Boolean>builder()
@@ -164,22 +163,25 @@ public void testEntityOverrides() {
164163
PolarisConfigurationStore store =
165164
new PolarisConfigurationStore() {
166165
@Override
167-
public <T> @Nullable T getConfiguration(PolarisCallContext ctx, String configName) {
166+
public <T> @Nullable T getConfiguration(RealmContext realmContext, String configName) {
168167
//noinspection unchecked
169168
return (T) Map.of("key2", "config-value2").get(configName);
170169
}
171170
};
172171

173-
PolarisCallContext ctx = null;
174172
CatalogEntity entity =
175173
new CatalogEntity.Builder()
176174
.addProperty("polaris.config.catalog-key3", "entity-new3")
177175
.addProperty("legacy-key4", "entity-legacy4")
178176
.build();
179177

180-
Assertions.assertEquals("test-default1", store.getConfiguration(ctx, entity, cfg.apply(1)));
181-
Assertions.assertEquals("config-value2", store.getConfiguration(ctx, entity, cfg.apply(2)));
182-
Assertions.assertEquals("entity-new3", store.getConfiguration(ctx, entity, cfg.apply(3)));
183-
Assertions.assertEquals("entity-legacy4", store.getConfiguration(ctx, entity, cfg.apply(4)));
178+
Assertions.assertEquals(
179+
"test-default1", store.getConfiguration(testRealmContext, entity, cfg.apply(1)));
180+
Assertions.assertEquals(
181+
"config-value2", store.getConfiguration(testRealmContext, entity, cfg.apply(2)));
182+
Assertions.assertEquals(
183+
"entity-new3", store.getConfiguration(testRealmContext, entity, cfg.apply(3)));
184+
Assertions.assertEquals(
185+
"entity-legacy4", store.getConfiguration(testRealmContext, entity, cfg.apply(4)));
184186
}
185187
}

quarkus/service/src/test/java/org/apache/polaris/service/quarkus/catalog/IcebergCatalogTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,8 @@ public void testUpdateNotificationCreateTableWithLocalFilePrefix() {
10321032
PolarisCallContext polarisCallContext = callContext.getPolarisCallContext();
10331033
if (!polarisCallContext
10341034
.getConfigurationStore()
1035-
.getConfiguration(polarisCallContext, FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES)
1035+
.getConfiguration(
1036+
callContext.getRealmContext(), FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES)
10361037
.contains("FILE")) {
10371038
Assertions.assertThatThrownBy(() -> catalog.sendNotification(table, request))
10381039
.isInstanceOf(ForbiddenException.class)
@@ -1100,7 +1101,8 @@ public void testUpdateNotificationCreateTableWithHttpPrefix() {
11001101
PolarisCallContext polarisCallContext = callContext.getPolarisCallContext();
11011102
if (!polarisCallContext
11021103
.getConfigurationStore()
1103-
.getConfiguration(polarisCallContext, FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES)
1104+
.getConfiguration(
1105+
callContext.getRealmContext(), FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES)
11041106
.contains("FILE")) {
11051107
Assertions.assertThatThrownBy(() -> catalog.sendNotification(table, request))
11061108
.isInstanceOf(ForbiddenException.class)
@@ -1121,7 +1123,8 @@ public void testUpdateNotificationCreateTableWithHttpPrefix() {
11211123

11221124
if (!polarisCallContext
11231125
.getConfigurationStore()
1124-
.getConfiguration(polarisCallContext, FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES)
1126+
.getConfiguration(
1127+
callContext.getRealmContext(), FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES)
11251128
.contains("FILE")) {
11261129
Assertions.assertThatThrownBy(() -> catalog.sendNotification(table, newRequest))
11271130
.isInstanceOf(ForbiddenException.class)

quarkus/service/src/test/java/org/apache/polaris/service/quarkus/config/DefaultConfigurationStoreTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,13 @@ public void testRegisterAndUseFeatureConfigurations() {
238238

239239
CatalogEntity catalog = new CatalogEntity.Builder().build();
240240

241-
Assertions.assertThat(configurationStore.getConfiguration(polarisContext, catalog, safeConfig))
241+
Assertions.assertThat(configurationStore.getConfiguration(realmContext, catalog, safeConfig))
242242
.isTrue();
243243

244-
Assertions.assertThat(
245-
configurationStore.getConfiguration(polarisContext, catalog, unsafeConfig))
244+
Assertions.assertThat(configurationStore.getConfiguration(realmContext, catalog, unsafeConfig))
246245
.isTrue();
247246

248-
Assertions.assertThat(configurationStore.getConfiguration(polarisContext, catalog, bothConfig))
247+
Assertions.assertThat(configurationStore.getConfiguration(realmContext, catalog, bothConfig))
249248
.isTrue();
250249
}
251250
}

service/common/src/main/java/org/apache/polaris/service/admin/PolarisAdminService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ private boolean catalogOverlapsWithExistingCatalog(CatalogEntity catalogEntity)
606606
getCurrentPolarisContext()
607607
.getConfigurationStore()
608608
.getConfiguration(
609-
getCurrentPolarisContext(), FeatureConfiguration.ALLOW_OVERLAPPING_CATALOG_URLS);
609+
callContext.getRealmContext(), FeatureConfiguration.ALLOW_OVERLAPPING_CATALOG_URLS);
610610

611611
if (allowOverlappingCatalogUrls) {
612612
return false;
@@ -778,7 +778,8 @@ public void deleteCatalog(String name) {
778778
boolean cleanup =
779779
polarisCallContext
780780
.getConfigurationStore()
781-
.getConfiguration(polarisCallContext, FeatureConfiguration.CLEANUP_ON_CATALOG_DROP);
781+
.getConfiguration(
782+
callContext.getRealmContext(), FeatureConfiguration.CLEANUP_ON_CATALOG_DROP);
782783
DropEntityResult dropEntityResult =
783784
metaStoreManager.dropEntityIfExists(
784785
getCurrentPolarisContext(), null, entity, Map.of(), cleanup);

service/common/src/main/java/org/apache/polaris/service/admin/PolarisServiceImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ private void validateStorageConfig(StorageConfigInfo storageConfigInfo) {
157157
polarisCallContext
158158
.getConfigurationStore()
159159
.getConfiguration(
160-
polarisCallContext, FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES);
160+
callContext.getRealmContext(),
161+
FeatureConfiguration.SUPPORTED_CATALOG_STORAGE_TYPES);
161162
if (!allowedStorageTypes.contains(storageConfigInfo.getStorageType().name())) {
162163
LOGGER
163164
.atWarn()
@@ -179,7 +180,7 @@ private void validateConnectionConfigInfo(Catalog catalog) {
179180
.getPolarisCallContext()
180181
.getConfigurationStore()
181182
.getConfiguration(
182-
callContext.getPolarisCallContext(),
183+
callContext.getRealmContext(),
183184
FeatureConfiguration.SUPPORTED_CATALOG_CONNECTION_TYPES)
184185
.stream()
185186
.map(s -> s.toUpperCase(Locale.ROOT))

service/common/src/main/java/org/apache/polaris/service/catalog/iceberg/CatalogHandlerUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@
8282
import org.apache.iceberg.view.ViewMetadata;
8383
import org.apache.iceberg.view.ViewOperations;
8484
import org.apache.iceberg.view.ViewRepresentation;
85-
import org.apache.polaris.core.PolarisCallContext;
8685
import org.apache.polaris.core.config.FeatureConfiguration;
8786
import org.apache.polaris.core.config.PolarisConfigurationStore;
87+
import org.apache.polaris.core.context.RealmContext;
8888

8989
/**
9090
* CODE_COPIED_TO_POLARIS Copied from CatalogHandler in Iceberg 1.8.0 Contains a collection of
@@ -95,13 +95,13 @@ public class CatalogHandlerUtils {
9595
private static final Schema EMPTY_SCHEMA = new Schema();
9696
private static final String INITIAL_PAGE_TOKEN = "";
9797

98-
private final PolarisCallContext polarisCallContext;
98+
private final RealmContext realmContext;
9999
private final PolarisConfigurationStore configurationStore;
100100

101101
@Inject
102102
public CatalogHandlerUtils(
103-
PolarisCallContext polarisCallContext, PolarisConfigurationStore configurationStore) {
104-
this.polarisCallContext = polarisCallContext;
103+
RealmContext realmContext, PolarisConfigurationStore configurationStore) {
104+
this.realmContext = realmContext;
105105
this.configurationStore = configurationStore;
106106
}
107107

@@ -609,6 +609,6 @@ protected ViewMetadata commit(ViewOperations ops, UpdateTableRequest request) {
609609

610610
private int maxCommitRetries() {
611611
return configurationStore.getConfiguration(
612-
polarisCallContext, FeatureConfiguration.ICEBERG_COMMIT_MAX_RETRIES);
612+
realmContext, FeatureConfiguration.ICEBERG_COMMIT_MAX_RETRIES);
613613
}
614614
}

0 commit comments

Comments
 (0)