Skip to content

Commit d962c64

Browse files
Update CatalogEntity::Builder to set default CatalogType as INTERNAL (#1998)
Encountered the issue while adding additional validations to `ExternalCatalog`. The `CatalogEntity::Builder` checks if the `Catalog::type` is set to `INTERNAL`, if not it defaults to `EXTERNAL`. However this is the opposite of the behavior defined in polaris-management-service.yml where the default is set to `INTERNAL`. This change only affects tests because in other cases the catalog entity is generated from the REST request. Testing: Updated CatalogEntityTest to ensure that the default is set to `INTERNAL`.
1 parent 1ce77e9 commit d962c64

File tree

2 files changed

+74
-6
lines changed

2 files changed

+74
-6
lines changed

polaris-core/src/main/java/org/apache/polaris/core/entity/CatalogEntity.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,25 +106,25 @@ public Catalog asCatalog() {
106106
CatalogProperties.builder(propertiesMap.get(DEFAULT_BASE_LOCATION_KEY))
107107
.putAll(propertiesMap)
108108
.build();
109-
return catalogType == Catalog.TypeEnum.INTERNAL
110-
? PolarisCatalog.builder()
111-
.setType(Catalog.TypeEnum.INTERNAL)
109+
return catalogType == Catalog.TypeEnum.EXTERNAL
110+
? ExternalCatalog.builder()
111+
.setType(Catalog.TypeEnum.EXTERNAL)
112112
.setName(getName())
113113
.setProperties(catalogProps)
114114
.setCreateTimestamp(getCreateTimestamp())
115115
.setLastUpdateTimestamp(getLastUpdateTimestamp())
116116
.setEntityVersion(getEntityVersion())
117117
.setStorageConfigInfo(getStorageInfo(internalProperties))
118+
.setConnectionConfigInfo(getConnectionInfo(internalProperties))
118119
.build()
119-
: ExternalCatalog.builder()
120-
.setType(Catalog.TypeEnum.EXTERNAL)
120+
: PolarisCatalog.builder()
121+
.setType(Catalog.TypeEnum.INTERNAL)
121122
.setName(getName())
122123
.setProperties(catalogProps)
123124
.setCreateTimestamp(getCreateTimestamp())
124125
.setLastUpdateTimestamp(getLastUpdateTimestamp())
125126
.setEntityVersion(getEntityVersion())
126127
.setStorageConfigInfo(getStorageInfo(internalProperties))
127-
.setConnectionConfigInfo(getConnectionInfo(internalProperties))
128128
.build();
129129
}
130130

runtime/service/src/test/java/org/apache/polaris/service/quarkus/entity/CatalogEntityTest.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,72 @@ public void testInvalidArn(String roleArn) {
266266
.isInstanceOf(IllegalArgumentException.class)
267267
.hasMessage(expectedMessage);
268268
}
269+
270+
@Test
271+
public void testCatalogTypeDefaultsToInternal() {
272+
String baseLocation = "s3://test-bucket/path";
273+
AwsStorageConfigInfo storageConfigModel =
274+
AwsStorageConfigInfo.builder()
275+
.setRoleArn("arn:aws:iam::012345678901:role/test-role")
276+
.setExternalId("externalId")
277+
.setUserArn("aws::a:user:arn")
278+
.setStorageType(StorageConfigInfo.StorageTypeEnum.S3)
279+
.setAllowedLocations(List.of(baseLocation))
280+
.build();
281+
CatalogEntity catalogEntity =
282+
new CatalogEntity.Builder()
283+
.setName("test-catalog")
284+
.setDefaultBaseLocation(baseLocation)
285+
.setStorageConfigurationInfo(callContext, storageConfigModel, baseLocation)
286+
.build();
287+
288+
Catalog catalog = catalogEntity.asCatalog();
289+
Assertions.assertThat(catalog.getType()).isEqualTo(Catalog.TypeEnum.INTERNAL);
290+
}
291+
292+
@Test
293+
public void testCatalogTypeExternalPreserved() {
294+
String baseLocation = "s3://test-bucket/path";
295+
AwsStorageConfigInfo storageConfigModel =
296+
AwsStorageConfigInfo.builder()
297+
.setRoleArn("arn:aws:iam::012345678901:role/test-role")
298+
.setExternalId("externalId")
299+
.setUserArn("aws::a:user:arn")
300+
.setStorageType(StorageConfigInfo.StorageTypeEnum.S3)
301+
.setAllowedLocations(List.of(baseLocation))
302+
.build();
303+
CatalogEntity catalogEntity =
304+
new CatalogEntity.Builder()
305+
.setName("test-external-catalog")
306+
.setDefaultBaseLocation(baseLocation)
307+
.setCatalogType(Catalog.TypeEnum.EXTERNAL.name())
308+
.setStorageConfigurationInfo(callContext, storageConfigModel, baseLocation)
309+
.build();
310+
311+
Catalog catalog = catalogEntity.asCatalog();
312+
Assertions.assertThat(catalog.getType()).isEqualTo(Catalog.TypeEnum.EXTERNAL);
313+
}
314+
315+
@Test
316+
public void testCatalogTypeInternalExplicitlySet() {
317+
String baseLocation = "s3://test-bucket/path";
318+
AwsStorageConfigInfo storageConfigModel =
319+
AwsStorageConfigInfo.builder()
320+
.setRoleArn("arn:aws:iam::012345678901:role/test-role")
321+
.setExternalId("externalId")
322+
.setUserArn("aws::a:user:arn")
323+
.setStorageType(StorageConfigInfo.StorageTypeEnum.S3)
324+
.setAllowedLocations(List.of(baseLocation))
325+
.build();
326+
CatalogEntity catalogEntity =
327+
new CatalogEntity.Builder()
328+
.setName("test-internal-catalog")
329+
.setDefaultBaseLocation(baseLocation)
330+
.setCatalogType(Catalog.TypeEnum.INTERNAL.name())
331+
.setStorageConfigurationInfo(callContext, storageConfigModel, baseLocation)
332+
.build();
333+
334+
Catalog catalog = catalogEntity.asCatalog();
335+
Assertions.assertThat(catalog.getType()).isEqualTo(Catalog.TypeEnum.INTERNAL);
336+
}
269337
}

0 commit comments

Comments
 (0)