Search in sources :

Example 16 with NessieApiV1

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);
}
Also used : NessieClientBuilder(org.projectnessie.client.NessieClientBuilder) InvocationTargetException(java.lang.reflect.InvocationTargetException) NessieApiV1(org.projectnessie.client.api.NessieApiV1)

Example 17 with NessieApiV1

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);
    }
}
Also used : Operation(org.projectnessie.model.Operation) Detached(org.projectnessie.model.Detached) LogResponse(org.projectnessie.model.LogResponse) Predicate(java.util.function.Predicate) Set(java.util.Set) HashMap(java.util.HashMap) Instant(java.time.Instant) OptionalInt(java.util.OptionalInt) Reference(org.projectnessie.model.Reference) Serializable(java.io.Serializable) NessieApiV1(org.projectnessie.client.api.NessieApiV1) HashSet(java.util.HashSet) Consumer(java.util.function.Consumer) FetchOption(org.projectnessie.api.params.FetchOption) Stream(java.util.stream.Stream) StreamingUtil(org.projectnessie.client.StreamingUtil) Map(java.util.Map) Content(org.projectnessie.model.Content) ContentKey(org.projectnessie.model.ContentKey) Function(org.apache.spark.api.java.function.Function) CommitMeta(org.projectnessie.model.CommitMeta) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) SparkSession(org.apache.spark.sql.SparkSession) HashMap(java.util.HashMap) CommitMeta(org.projectnessie.model.CommitMeta) NessieApiV1(org.projectnessie.client.api.NessieApiV1)

Example 18 with NessieApiV1

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();
    }
}
Also used : ExtensionValuesStore(org.junit.jupiter.engine.execution.ExtensionValuesStore) NamespaceAwareStore(org.junit.jupiter.engine.execution.NamespaceAwareStore) Store(org.junit.jupiter.api.extension.ExtensionContext.Store) NamespaceAwareStore(org.junit.jupiter.engine.execution.NamespaceAwareStore) ExtensionValuesStore(org.junit.jupiter.engine.execution.ExtensionValuesStore) ExtensionContext(org.junit.jupiter.api.extension.ExtensionContext) Namespace(org.junit.jupiter.api.extension.ExtensionContext.Namespace) NessieApiV1(org.projectnessie.client.api.NessieApiV1) Test(org.junit.jupiter.api.Test)

Example 19 with NessieApiV1

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);
}
Also used : NessieHttpResponseFilter(org.projectnessie.client.rest.NessieHttpResponseFilter) HttpClient(org.projectnessie.client.http.HttpClient) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) NessieApiV1(org.projectnessie.client.api.NessieApiV1)

Example 20 with NessieApiV1

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);
}
Also used : HttpClientBuilder(org.projectnessie.client.http.HttpClientBuilder) Assumptions.assumeThat(org.assertj.core.api.Assumptions.assumeThat) HttpAuthentication(org.projectnessie.client.http.HttpAuthentication) InmemoryDatabaseAdapterFactory(org.projectnessie.versioned.persist.inmem.InmemoryDatabaseAdapterFactory) NessieDbAdapterName(org.projectnessie.versioned.persist.tests.extension.NessieDbAdapterName) InmemoryTestConnectionProviderSource(org.projectnessie.versioned.persist.inmem.InmemoryTestConnectionProviderSource) NessieExternalDatabase(org.projectnessie.versioned.persist.tests.extension.NessieExternalDatabase) NessieApiV1(org.projectnessie.client.api.NessieApiV1) RequestFilter(org.projectnessie.client.http.RequestFilter) HEADER_ACCEPT(org.projectnessie.client.http.HttpUtils.HEADER_ACCEPT) URI(java.net.URI) Nullable(javax.annotation.Nullable) HttpClient(org.projectnessie.client.http.HttpClient) HttpAuthentication(org.projectnessie.client.http.HttpAuthentication) RequestFilter(org.projectnessie.client.http.RequestFilter) NessieApiV1(org.projectnessie.client.api.NessieApiV1)

Aggregations

NessieApiV1 (org.projectnessie.client.api.NessieApiV1)25 Test (org.junit.jupiter.api.Test)11 TestServer (org.projectnessie.client.util.TestServer)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 Instant (java.time.Instant)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Stream (java.util.stream.Stream)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 InstanceOfAssertFactories (org.assertj.core.api.InstanceOfAssertFactories)2 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)2 BeforeAll (org.junit.jupiter.api.BeforeAll)2 Arguments (org.junit.jupiter.params.provider.Arguments)2 ValueSource (org.junit.jupiter.params.provider.ValueSource)2 FetchOption (org.projectnessie.api.params.FetchOption)2 HttpClient (org.projectnessie.client.http.HttpClient)2 HttpApiV1 (org.projectnessie.client.http.v1api.HttpApiV1)2 NessieInternalServerException (org.projectnessie.client.rest.NessieInternalServerException)2