Skip to content

Commit

Permalink
[apache#5210] fix(core): Fix the audit info of metalake (apache#5211)
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?

 Fix the audit info of metalake.

### Why are the changes needed?

Fix: apache#5210

### Does this PR introduce _any_ user-facing change?
Audit info changed.

### How was this patch tested?

Add a UT.
  • Loading branch information
jerqi authored Oct 22, 2024
1 parent d35ab31 commit 31b4e9d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ public BaseMetalake alterMetalake(NameIdentifier ident, MetalakeChange... change
EntityType.METALAKE,
metalake -> {
BaseMetalake.Builder builder = newMetalakeBuilder(metalake);

Map<String, String> newProps =
metalake.properties() == null
? Maps.newHashMap()
Expand Down Expand Up @@ -335,7 +334,7 @@ private BaseMetalake.Builder newMetalakeBuilder(BaseMetalake metalake) {
AuditInfo.builder()
.withCreator(metalake.auditInfo().creator())
.withCreateTime(metalake.auditInfo().createTime())
.withLastModifier(metalake.auditInfo().creator()) /*TODO: Use real user later on. */
.withLastModifier(PrincipalUtils.getCurrentUserName())
.withLastModifiedTime(Instant.now())
.build();
return builder.withAuditInfo(newInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@
import org.apache.gravitino.MetalakeChange;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.StringIdentifier;
import org.apache.gravitino.UserPrincipal;
import org.apache.gravitino.auth.AuthConstants;
import org.apache.gravitino.exceptions.MetalakeAlreadyExistsException;
import org.apache.gravitino.exceptions.NoSuchMetalakeException;
import org.apache.gravitino.meta.BaseMetalake;
import org.apache.gravitino.storage.RandomIdGenerator;
import org.apache.gravitino.storage.memory.TestMemoryEntityStore;
import org.apache.gravitino.utils.PrincipalUtils;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -119,7 +122,7 @@ public void testLoadMetalake() {
}

@Test
public void testAlterMetalake() {
public void testAlterMetalake() throws Exception {
NameIdentifier ident = NameIdentifier.of("test31");
Map<String, String> props = ImmutableMap.of("key1", "value1");

Expand Down Expand Up @@ -161,6 +164,14 @@ public void testAlterMetalake() {
Assertions.assertThrows(
NoSuchMetalakeException.class, () -> metalakeManager.alterMetalake(id, change));
Assertions.assertTrue(exception.getMessage().contains("Metalake test3 does not exist"));

// Test the audit info
UserPrincipal userPrincipal = new UserPrincipal("test");
MetalakeChange change5 = MetalakeChange.setProperty("key5", "value5");
alteredMetalake =
PrincipalUtils.doAs(userPrincipal, () -> metalakeManager.alterMetalake(ident1, change5));
Assertions.assertEquals(userPrincipal.getName(), alteredMetalake.auditInfo().lastModifier());
Assertions.assertEquals(AuthConstants.ANONYMOUS_USER, alteredMetalake.auditInfo().creator());
}

@Test
Expand Down

0 comments on commit 31b4e9d

Please sign in to comment.