mchades commented on code in PR #7625: URL: https://github.com/apache/gravitino/pull/7625#discussion_r2238146714
########## core/src/main/java/org/apache/gravitino/policy/PolicyManager.java: ########## @@ -74,28 +125,106 @@ public Policy createPolicy( boolean exclusive, boolean inheritable, Set<MetadataObject.Type> supportedObjectTypes, - PolicyContent content) { - throw new UnsupportedOperationException("Not implemented yet"); + PolicyContent content) + throws PolicyAlreadyExistsException { + NameIdentifier metalakeIdent = NameIdentifierUtil.ofMetalake(metalake); + return TreeLockUtils.doWithTreeLock( + NameIdentifier.of(NamespaceUtil.ofPolicy(metalake).levels()), + LockType.WRITE, + () -> { + checkMetalake(metalakeIdent, entityStore); + + PolicyEntity policyEntity = + PolicyEntity.builder() + .withId(idGenerator.nextId()) + .withName(policyName) + .withNamespace(NamespaceUtil.ofPolicy(metalake)) + .withComment(comment) + .withPolicyType(type) + .withEnabled(enabled) + .withExclusive(exclusive) + .withInheritable(inheritable) + .withSupportedObjectTypes(supportedObjectTypes) + .withContent(content) + .withAuditInfo( + AuditInfo.builder() + .withCreator(PrincipalUtils.getCurrentPrincipal().getName()) + .withCreateTime(Instant.now()) + .build()) + .build(); + + try { + entityStore.put(policyEntity, false /* overwritten */); + return policyEntity; + } catch (EntityAlreadyExistsException e) { + throw new PolicyAlreadyExistsException( + "Policy with name %s under metalake %s already exists", policyName, metalake); + } catch (IOException ioe) { + LOG.error("Failed to create policy {} under metalake {}", policyName, metalake, ioe); + throw new RuntimeException(ioe); + } + }); } @Override public Policy alterPolicy(String metalake, String policyName, PolicyChange... changes) { - throw new UnsupportedOperationException("Not implemented yet"); + NameIdentifier metalakeIdent = NameIdentifierUtil.ofMetalake(metalake); + return TreeLockUtils.doWithTreeLock( + NameIdentifier.of(NamespaceUtil.ofPolicy(metalake).levels()), + LockType.WRITE, Review Comment: fixed -- 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: commits-unsubscr...@gravitino.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org