Skip to content

Commit 81b34b6

Browse files
authored
Cleanup nessie-client (#7516)
Cleanup the packages and especially the public facing client API and enhance the ability to configure a Nessie client instance. `NessieClientBuilder` related changes: * Use Java system properties, process environment, a (new) Nessie client config file and a dot-env file as configuration sources. Can later be extended to allow encrypted configuration values (think: bearer tokens, passwords, etc) and expressions by using SmallRye Config. * Refactor `NessieClientBuilder` to use the Java services API, so it's easier to pull in custom implementations. * Make `NessieClientBuilder` a "pure interface", add abstract base class(es) for implementations. * Remove the generic type arg from `NessieClientBuilder`, because it's irrelevant for integrations, added a generic `asInstanceOf()` for special cases. * Move configuration via string key-value pairs (`fromConfig()` functions) to the introduced abstract base classes. Nessie API implementation related changes: * Move REST/API-v1 code to the new `org.projectnessie.client.rest.v1` package. * Move REST/API-v2 code to the new `org.projectnessie.client.rest.v2` package. * Let the `org.projectnessie.client.http` itself only contain types for HTTP, except the legacy `HttpClientBuilder`, which is now deprecated for removal. * Remove old, Java streams related baggage (restricts compatibility tests to 0.31.0 or newer). * Move "common" client-side namsepace handling out of the REST-v2 implementation. * Fix an oversight in the REST-v2 implementation for tag deletion. Content-generator tool change: * Add option for Nessie client name * Add option for Nessie client builder properties GC tool change: * Add option for Nessie client name Test support change: * add `NessieClientNameResolver` interface for test classes
1 parent 91ca867 commit 81b34b6

File tree

104 files changed

+2220
-1089
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+2220
-1089
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ jobs:
692692
ICEBERG_MAIN_REPOSITORY: apache/iceberg
693693
ICEBERG_MAIN_BRANCH: master
694694
ICEBERG_PATCH_REPOSITORY: snazy/iceberg
695-
ICEBERG_PATCH_BRANCH: iceberg-nesqueit
695+
ICEBERG_PATCH_BRANCH: iceberg-nesqueit-next
696696
SPARK_LOCAL_IP: localhost
697697
steps:
698698
- name: Prepare Git

api/client-testextension/src/main/java/org/projectnessie/client/ext/NessieApiVersion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public URI resolve(URI base) {
4141
return base.resolve(getPathElement());
4242
}
4343

44-
public NessieApiV1 build(NessieClientBuilder<?> builder) {
44+
public NessieApiV1 build(NessieClientBuilder builder) {
4545
return builder.build(clientApiClass);
4646
}
4747
}

api/client-testextension/src/main/java/org/projectnessie/client/ext/NessieClientCustomizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@
2626
@FunctionalInterface
2727
public interface NessieClientCustomizer {
2828

29-
NessieClientBuilder<?> configure(NessieClientBuilder<?> builder, NessieApiVersion apiVersion);
29+
NessieClientBuilder configure(NessieClientBuilder builder, NessieApiVersion apiVersion);
3030
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (C) 2023 Dremio
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.projectnessie.client.ext;
17+
18+
import java.util.HashMap;
19+
import java.util.Map;
20+
import org.projectnessie.client.NessieClientBuilder;
21+
import org.projectnessie.client.NessieConfigConstants;
22+
23+
/**
24+
* Test classes that implement this interface can specify a different Nessie client by {@linkplain
25+
* NessieClientBuilder#name() its name} and optionally a set of configuration options.
26+
*/
27+
@FunctionalInterface
28+
public interface NessieClientNameResolver {
29+
String nessieClientName();
30+
31+
/**
32+
* When overriding this function, make sure to use the map of this implementation to include the
33+
* {@link #nessieClientName()}.
34+
*/
35+
default Map<String, String> mainNessieClientConfigMap() {
36+
Map<String, String> mainConfig = new HashMap<>();
37+
mainConfig.put(NessieConfigConstants.CONF_NESSIE_CLIENT_NAME, nessieClientName());
38+
return mainConfig;
39+
}
40+
}

api/client-testextension/src/main/java/org/projectnessie/client/ext/NessieClientResolver.java

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.projectnessie.client.ext;
1717

18+
import static org.projectnessie.client.NessieClientBuilder.createClientBuilderFromSystemSettings;
1819
import static org.projectnessie.client.ext.MultiVersionApiTest.apiVersion;
1920

2021
import java.io.Serializable;
@@ -30,8 +31,10 @@
3031
import org.junit.platform.commons.util.AnnotationUtils;
3132
import org.projectnessie.client.NessieClientBuilder;
3233
import org.projectnessie.client.api.NessieApiV1;
33-
import org.projectnessie.client.http.HttpClientBuilder;
34+
import org.projectnessie.client.config.NessieClientConfigSource;
35+
import org.projectnessie.client.config.NessieClientConfigSources;
3436
import org.projectnessie.client.http.HttpResponseFactory;
37+
import org.projectnessie.client.http.NessieHttpClientBuilder;
3538

3639
/**
3740
* A base class for extensions that manage a Nessie test execution environment. This class injects
@@ -89,6 +92,15 @@ public Object resolveParameter(
8992
}
9093

9194
private NessieClientFactory clientFactoryForContext(ExtensionContext extensionContext) {
95+
NessieClientConfigSource mainConfigSource =
96+
extensionContext
97+
.getTestInstance()
98+
.filter(t -> t instanceof NessieClientNameResolver)
99+
.map(NessieClientNameResolver.class::cast)
100+
.map(NessieClientNameResolver::mainNessieClientConfigMap)
101+
.map(NessieClientConfigSources::mapConfigSource)
102+
.orElseGet(NessieClientConfigSources::emptyConfigSource);
103+
92104
NessieApiVersion apiVersion = apiVersion(extensionContext);
93105
URI uri = resolvedNessieUri(extensionContext);
94106
List<NessieClientCustomizer> customizers =
@@ -118,7 +130,7 @@ private NessieClientFactory clientFactoryForContext(ExtensionContext extensionCo
118130
return builder;
119131
};
120132

121-
return new ClientFactory(uri, apiVersion, responseFactoryClass) {
133+
return new ClientFactory(uri, mainConfigSource, apiVersion, responseFactoryClass) {
122134
@Nonnull
123135
@jakarta.annotation.Nonnull
124136
@Override // Note: this object is not serializable
@@ -132,19 +144,23 @@ public NessieApiV1 make(NessieClientCustomizer customizer) {
132144

133145
// We use a serializable impl. here as a workaround for @QuarkusTest instances, whose parameters
134146
// are deep-cloned by the Quarkus test extension.
135-
return new ClientFactory(uri, apiVersion, responseFactoryClass);
147+
return new ClientFactory(uri, mainConfigSource, apiVersion, responseFactoryClass);
136148
}
137149

138150
private static class ClientFactory implements NessieClientFactory, Serializable {
151+
139152
private final URI resolvedUri;
153+
private final NessieClientConfigSource mainConfigSource;
140154
private final NessieApiVersion apiVersion;
141155
private final Class<? extends HttpResponseFactory> responseFactoryClass;
142156

143157
private ClientFactory(
144158
URI nessieUri,
159+
NessieClientConfigSource mainConfigSource,
145160
NessieApiVersion apiVersion,
146161
Class<? extends HttpResponseFactory> responseFactoryClass) {
147162
this.resolvedUri = nessieUri;
163+
this.mainConfigSource = mainConfigSource;
148164
this.apiVersion = apiVersion;
149165
this.responseFactoryClass = responseFactoryClass;
150166
}
@@ -158,17 +174,19 @@ public NessieApiVersion apiVersion() {
158174
@jakarta.annotation.Nonnull
159175
@Override
160176
public NessieApiV1 make(NessieClientCustomizer customizer) {
161-
HttpClientBuilder clientBuilder = HttpClientBuilder.builder().withUri(resolvedUri);
177+
NessieClientBuilder clientBuilder =
178+
createClientBuilderFromSystemSettings(mainConfigSource).withUri(resolvedUri);
162179
if (responseFactoryClass != null) {
163180
try {
164181
clientBuilder =
165-
clientBuilder.withResponseFactory(
166-
responseFactoryClass.getDeclaredConstructor().newInstance());
182+
clientBuilder
183+
.asInstanceOf(NessieHttpClientBuilder.class)
184+
.withResponseFactory(responseFactoryClass.getDeclaredConstructor().newInstance());
167185
} catch (Exception e) {
168186
throw new RuntimeException(e);
169187
}
170188
}
171-
NessieClientBuilder<?> builder = customizer.configure(clientBuilder, apiVersion);
189+
NessieClientBuilder builder = customizer.configure(clientBuilder, apiVersion);
172190
return apiVersion.build(builder);
173191
}
174192
}

0 commit comments

Comments
 (0)