-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
### What changes were proposed in this pull request? - Support pass header when using the Java Gravitino Client. ### Why are the changes needed? - For now, we can't pass the useful header on the Java Gravitino Client. We want to pass on more information such as some audit messages. The base header may not be used for now, but it is useful for users to integrate with their platform. Fix: #2976 ### Does this PR introduce _any_ user-facing change? - yes 1. Change in user-facing APIs. - add `withHeaders` in GravitinoClientBuilder. ``` GravitinoClient.builder("uri") .withMetalake("metalake") .withHeaders(Map) // add header .builder(); GravitinoAdminClient.builder("uri") .withHeaders(Map) // add header .builder(); ``` 2. Addition or removal of property keys. - add withHeaders() method ### How was this patch tested? - original Uts
- Loading branch information
Showing
4 changed files
with
113 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...client-java/src/test/java/com/datastrato/gravitino/client/TestGravitinoClientBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2024 Datastrato Pvt Ltd. | ||
* This software is licensed under the Apache License version 2. | ||
*/ | ||
package com.datastrato.gravitino.client; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class TestGravitinoClientBuilder { | ||
@Test | ||
public void testGravitinoClientHeaders() { | ||
Map<String, String> headers = ImmutableMap.of("k1", "v1"); | ||
try (MockGravitinoClient client = | ||
MockGravitinoClient.builder("http://127.0.0.1").withHeaders(headers).build()) { | ||
Assertions.assertEquals(headers, client.getHeaders()); | ||
} | ||
|
||
try (MockGravitinoClient client1 = MockGravitinoClient.builder("http://127.0.0.1").build()) { | ||
Assertions.assertEquals(ImmutableMap.of(), client1.getHeaders()); | ||
} | ||
|
||
try (MockGravitinoClient client1 = | ||
MockGravitinoClient.builder("http://127.0.0.1").withHeaders(null).build()) { | ||
Assertions.assertEquals(ImmutableMap.of(), client1.getHeaders()); | ||
} | ||
} | ||
} | ||
|
||
class MockGravitinoClient extends GravitinoClientBase { | ||
|
||
private Map<String, String> headers; | ||
|
||
/** | ||
* Constructs a new GravitinoClient with the given URI, authenticator and AuthDataProvider. | ||
* | ||
* @param uri The base URI for the Gravitino API. | ||
* @param authDataProvider The provider of the data which is used for authentication. | ||
* @param headers The base header of the Gravitino API. | ||
*/ | ||
private MockGravitinoClient( | ||
String uri, AuthDataProvider authDataProvider, Map<String, String> headers) { | ||
super(uri, authDataProvider, headers); | ||
this.headers = headers; | ||
} | ||
|
||
Map<String, String> getHeaders() { | ||
return headers; | ||
} | ||
|
||
/** | ||
* Creates a new builder for constructing a GravitinoClient. | ||
* | ||
* @param uri The base URI for the Gravitino API. | ||
* @return A new instance of the Builder class for constructing a GravitinoClient. | ||
*/ | ||
static MockGravitinoClientBuilder builder(String uri) { | ||
return new MockGravitinoClientBuilder(uri); | ||
} | ||
|
||
static class MockGravitinoClientBuilder extends GravitinoClientBase.Builder<MockGravitinoClient> { | ||
|
||
/** | ||
* The constructor for the Builder class. | ||
* | ||
* @param uri The base URI for the Gravitino API. | ||
*/ | ||
protected MockGravitinoClientBuilder(String uri) { | ||
super(uri); | ||
} | ||
|
||
@Override | ||
public MockGravitinoClient build() { | ||
return new MockGravitinoClient(uri, authDataProvider, headers); | ||
} | ||
} | ||
} |