World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#12685] fix(core): Fix built-in policy supportedObjectTypes validation and error message (#12686)
Tanay Paulcbadfbf9e98f
diff --git a/core/src/main/java/org/apache/gravitino/policy/PolicyManager.java b/core/src/main/java/org/apache/gravitino/policy/PolicyManager.javaindex ce91fe393e..e4dc65746c 100644--- a/core/src/main/java/org/apache/gravitino/policy/PolicyManager.java+++ b/core/src/main/java/org/apache/gravitino/policy/PolicyManager.java@@ -527,11 +527,13 @@ public class PolicyManager implements PolicyDispatcher {if (policyType != Policy.BuiltInType.CUSTOM) {// cannot change the supported object types for built-in policiesPreconditions.checkArgument(- Sets.difference(+ Sets.symmetricDifference(policyEntity.content().supportedObjectTypes(),updateContent.getContent().supportedObjectTypes()).isEmpty(),- "Policy content type mismatch: expected %s but got %s");+ "Policy content type mismatch: expected %s but got %s",+ policyEntity.content().supportedObjectTypes(),+ updateContent.getContent().supportedObjectTypes());}newContent = updateContent.getContent();diff --git a/core/src/test/java/org/apache/gravitino/policy/TestPolicyManager.java b/core/src/test/java/org/apache/gravitino/policy/TestPolicyManager.javaindex 5b80249042..5f69606220 100644--- a/core/src/test/java/org/apache/gravitino/policy/TestPolicyManager.java+++ b/core/src/test/java/org/apache/gravitino/policy/TestPolicyManager.java@@ -354,6 +354,61 @@ public class TestPolicyManager {Assertions.assertTrue(enabledPolicy.enabled());}+ @Test+ public void testAlterBuiltInPolicyContent() {+ String policyName = "policy_" + UUID.randomUUID().toString().replace("-", "");+ policyManager.createPolicy(+ METALAKE,+ policyName,+ Policy.BuiltInType.ICEBERG_COMPACTION,+ null,+ true,+ PolicyContents.icebergDataCompaction());++ // Adding a type not in the original set must be rejected.+ Set<MetadataObject.Type> withExtra =+ ImmutableSet.of(+ MetadataObject.Type.CATALOG,+ MetadataObject.Type.SCHEMA,+ MetadataObject.Type.TABLE,+ MetadataObject.Type.FILESET);+ PolicyContent addedType = PolicyContents.custom(ImmutableMap.of(), withExtra, null);+ IllegalArgumentException addEx =+ Assertions.assertThrows(+ IllegalArgumentException.class,+ () ->+ policyManager.alterPolicy(+ METALAKE,+ policyName,+ PolicyChange.updateContent("system_iceberg_compaction", addedType)));+ Assertions.assertTrue(+ addEx.getMessage().contains("Policy content type mismatch"),+ "expected mismatch message, got: " + addEx.getMessage());+ // Format arguments must be substituted — neither placeholder should survive literally.+ Assertions.assertFalse(+ addEx.getMessage().contains("%s"),+ "format args were not substituted: " + addEx.getMessage());++ // Removing a type must equally be rejected.+ Set<MetadataObject.Type> withFewer =+ ImmutableSet.of(MetadataObject.Type.CATALOG, MetadataObject.Type.SCHEMA);+ PolicyContent removedType = PolicyContents.custom(ImmutableMap.of(), withFewer, null);+ IllegalArgumentException removeEx =+ Assertions.assertThrows(+ IllegalArgumentException.class,+ () ->+ policyManager.alterPolicy(+ METALAKE,+ policyName,+ PolicyChange.updateContent("system_iceberg_compaction", removedType)));+ Assertions.assertTrue(+ removeEx.getMessage().contains("Policy content type mismatch"),+ "expected mismatch message, got: " + removeEx.getMessage());+ Assertions.assertFalse(+ removeEx.getMessage().contains("%s"),+ "format args were not substituted: " + removeEx.getMessage());+ }+@Testpublic void testDeletePolicy() {String policyName = "policy1" + UUID.randomUUID().toString().replace("-", "");