use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.
the class GCUtil method getApi.
/**
* Builds the client builder; default({@link HttpClientBuilder}) or custom, based on the
* configuration provided.
*
* @param configuration map of client builder configurations.
* @return {@link NessieApiV1} object.
*/
static NessieApiV1 getApi(Map<String, String> configuration) {
String clientBuilderClassName = configuration.get(NessieConfigConstants.CONF_NESSIE_CLIENT_BUILDER_IMPL);
NessieClientBuilder builder;
if (clientBuilderClassName == null) {
// Use the default HttpClientBuilder
builder = HttpClientBuilder.builder();
} else {
// Use the custom client builder
try {
builder = (NessieClientBuilder) Class.forName(clientBuilderClassName).getDeclaredConstructor().newInstance();
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException(String.format("No custom client builder class found for '%s' ", clientBuilderClassName));
} catch (InvocationTargetException | InstantiationException | IllegalAccessException | NoSuchMethodException e) {
throw new IllegalArgumentException(String.format("Could not initialize '%s': ", clientBuilderClassName), e);
}
}
return (NessieApiV1) builder.fromConfig(configuration::get).build(NessieApiV1.class);
}
use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.
the class IdentifyContentsPerExecutor method computeLiveContents.
private Map<String, ContentBloomFilter> computeLiveContents(Instant cutOffTimestamp, String reference, Instant droppedRefTime, long bloomFilterSize) {
try (NessieApiV1 api = GCUtil.getApi(gcParams.getNessieClientConfigs())) {
boolean isRefDroppedAfterCutoffTimeStamp = droppedRefTime == null || droppedRefTime.compareTo(cutOffTimestamp) >= 0;
if (!isRefDroppedAfterCutoffTimeStamp) {
// All the contents for all the keys are expired.
return new HashMap<>();
}
Predicate<CommitMeta> liveCommitPredicate = commitMeta -> commitMeta.getCommitTime().compareTo(cutOffTimestamp) >= 0;
ImmutableGCStateParamsPerTask gcStateParamsPerTask = ImmutableGCStateParamsPerTask.builder().api(api).reference(GCUtil.deserializeReference(reference)).liveCommitPredicate(liveCommitPredicate).bloomFilterSize(bloomFilterSize).build();
return walkLiveCommitsInReference(gcStateParamsPerTask);
}
}
use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.
the class TestNessieApiHolder method currentVersionServer.
@Test
void currentVersionServer() throws Throwable {
ExtensionValuesStore valuesStore = new ExtensionValuesStore(null);
try {
Store store = new NamespaceAwareStore(valuesStore, Util.NAMESPACE);
ExtensionContext ctx = mock(ExtensionContext.class);
when(ctx.getRoot()).thenReturn(ctx);
when(ctx.getStore(any(Namespace.class))).thenReturn(store);
CurrentNessieApiHolder apiHolder = new CurrentNessieApiHolder(new ClientKey(Version.CURRENT, "org.projectnessie.client.http.HttpClientBuilder", NessieApiV1.class, Collections.singletonMap("nessie.uri", "http://127.42.42.42:19120")));
try {
assertThat(apiHolder).extracting(AbstractNessieApiHolder::getApiInstance).extracting(Object::getClass).extracting(Class::getClassLoader).isSameAs(Thread.currentThread().getContextClassLoader());
} finally {
apiHolder.close();
}
} finally {
valuesStore.closeAllStoredCloseableValues();
}
}
use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.
the class AbstractRest method init.
protected void init(URI uri) {
NessieApiV1 api = HttpClientBuilder.builder().withUri(uri).build(NessieApiV1.class);
ObjectMapper mapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT).disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
HttpClient.Builder httpClient = HttpClient.builder().setBaseUri(uri).setObjectMapper(mapper);
httpClient.addResponseFilter(new NessieHttpResponseFilter(mapper));
init(api, httpClient, uri);
}
use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.
the class TestJerseyRestNaiveClientInMemory method init.
@Override
protected void init(NessieApiV1 api, @Nullable HttpClient.Builder httpClient, URI uri) {
assumeThat(httpClient).isNotNull();
// Intentionally remove the `Accept` header from requests.
// Service endpoints should declare the content type for their return values,
// which should allow the Web Container to properly format output even in the absence
// of `Accept` HTTP headers.
RequestFilter noAcceptFilter = context -> context.removeHeader(HEADER_ACCEPT);
httpClient.addRequestFilter(noAcceptFilter);
api = HttpClientBuilder.builder().withAuthentication((HttpAuthentication) client -> client.addRequestFilter(noAcceptFilter)).withUri(httpClient.getBaseUri()).build(NessieApiV1.class);
super.init(api, httpClient, uri);
}
Aggregations