mchades commented on code in PR #7625:
URL: https://github.com/apache/gravitino/pull/7625#discussion_r2242357429


##########
core/src/main/java/org/apache/gravitino/policy/PolicyManager.java:
##########
@@ -127,4 +251,100 @@ public Policy getPolicyForMetadataObject(
       String metalake, MetadataObject metadataObject, String policyName) {
     throw new UnsupportedOperationException("Not implemented yet");
   }
+
+  private void changePolicyEnabledState(
+      String metalake, String policyName, boolean expectedEnabledState) {
+    NameIdentifier metalakeIdent = NameIdentifierUtil.ofMetalake(metalake);
+    checkMetalake(metalakeIdent, entityStore);
+    TreeLockUtils.doWithTreeLock(
+        NameIdentifierUtil.ofPolicy(metalake, policyName),
+        LockType.WRITE,
+        () -> {
+          if (policyEnabled(metalake, policyName) == expectedEnabledState) {
+            return null;
+          }
+
+          try {
+            entityStore.update(
+                NameIdentifierUtil.ofPolicy(metalake, policyName),
+                PolicyEntity.class,
+                Entity.EntityType.POLICY,
+                policyEntity -> {
+                  PolicyEntity.Builder builder = 
newPolicyBuilder(policyEntity);
+                  builder.withEnabled(expectedEnabledState);
+                  return builder.build();
+                });
+            return null;
+          } catch (IOException ioe) {
+            LOG.error(
+                "Failed to change policy {} enabled state under metalake {}",
+                policyName,
+                metalake,
+                ioe);
+            throw new RuntimeException(ioe);
+          }
+        });
+  }
+
+  private PolicyEntity.Builder newPolicyBuilder(PolicyEntity policyEntity) {

Review Comment:
   I would prefer to keep it as is, since this is not a common operation for 
PolicyEntity and is only used in this class.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to