Search in sources :

Example 11 with NessieApiV1

use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.

the class BaseClientAuthTest method api.

protected NessieApiV1 api() {
    if (api != null) {
        return api;
    }
    HttpClientBuilder builder = HttpClientBuilder.builder().withUri("http://localhost:19121/api/v1");
    if (customizer != null) {
        customizer.accept(builder);
    }
    api = builder.build(NessieApiV1.class);
    return api;
}
Also used : HttpClientBuilder(org.projectnessie.client.http.HttpClientBuilder) NessieApiV1(org.projectnessie.client.api.NessieApiV1)

Example 12 with NessieApiV1

use of org.projectnessie.client.api.NessieApiV1 in project iceberg by apache.

the class BaseTestIceberg method beforeEach.

@BeforeEach
public void beforeEach(@NessieUri URI nessieUri) throws IOException {
    this.uri = nessieUri.toString();
    this.api = HttpClientBuilder.builder().withUri(this.uri).build(NessieApiV1.class);
    resetData();
    try {
        api.createReference().reference(Branch.of(branch, null)).create();
    } catch (Exception e) {
    // ignore, already created. Can't run this in BeforeAll as quarkus hasn't disabled auth
    }
    hadoopConfig = new Configuration();
    catalog = initCatalog(branch);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) NessieConflictException(org.projectnessie.error.NessieConflictException) IOException(java.io.IOException) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) NessieApiV1(org.projectnessie.client.api.NessieApiV1) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 13 with NessieApiV1

use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.

the class TestTranslatingVersionNessieApi method serialization.

@ParameterizedTest
@MethodSource("serialization")
void serialization(Class<?> modelClass, Object modelObj, String modelJson) throws Exception {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try (TranslatingVersionNessieApi translating = new TranslatingVersionNessieApi(createOldVersionNessieAPi(), NessieApiV1.class, oldVersionClassLoader)) {
        Object translatedObject = translating.translateObject(modelObj, oldVersionClassLoader, contextClassLoader);
        assertThat(translating.serializeWith(contextClassLoader, modelObj)).isEqualTo(translating.serializeWith(oldVersionClassLoader, translatedObject)).isEqualTo(modelJson);
        assertThat(translating.deserializeWith(contextClassLoader, modelJson, modelClass.getName())).isEqualTo(modelObj);
        assertThat(translating.deserializeWith(oldVersionClassLoader, modelJson, modelClass.getName())).isEqualTo(translatedObject);
        assertThat(translating.reserialize(modelObj)).isEqualTo(translatedObject).extracting(b -> b.getClass().getClassLoader()).isSameAs(oldVersionClassLoader);
        assertThat(translating.reserialize(translatedObject)).isEqualTo(modelObj).extracting(b -> b.getClass().getClassLoader()).isSameAs(contextClassLoader);
    }
}
Also used : NessieRuntimeException(org.projectnessie.error.NessieRuntimeException) NessieContentNotFoundException(org.projectnessie.error.NessieContentNotFoundException) NessieBadRequestException(org.projectnessie.error.NessieBadRequestException) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) NessieReferenceAlreadyExistsException(org.projectnessie.error.NessieReferenceAlreadyExistsException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) NessieForbiddenException(org.projectnessie.error.NessieForbiddenException) ErrorCode(org.projectnessie.error.ErrorCode) ArrayList(java.util.ArrayList) ErrorCodeAware(org.projectnessie.error.ErrorCodeAware) BeforeAll(org.junit.jupiter.api.BeforeAll) NessieReferenceConflictException(org.projectnessie.error.NessieReferenceConflictException) HttpApiV1(org.projectnessie.client.http.v1api.HttpApiV1) MethodSource(org.junit.jupiter.params.provider.MethodSource) ValueSource(org.junit.jupiter.params.provider.ValueSource) NessieBackendThrottledException(org.projectnessie.error.NessieBackendThrottledException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ImmutableBranch(org.projectnessie.model.ImmutableBranch) Branch(org.projectnessie.model.Branch) Arguments(org.junit.jupiter.params.provider.Arguments) NessieRefLogNotFoundException(org.projectnessie.error.NessieRefLogNotFoundException) NessieApiV1(org.projectnessie.client.api.NessieApiV1) Test(org.junit.jupiter.api.Test) ImmutableNessieError(org.projectnessie.error.ImmutableNessieError) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ImmutableIcebergTable(org.projectnessie.model.ImmutableIcebergTable) Stream(java.util.stream.Stream) IcebergTable(org.projectnessie.model.IcebergTable) Util.withClassLoader(org.projectnessie.tools.compatibility.internal.Util.withClassLoader) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) Collections(java.util.Collections) NessieInternalServerException(org.projectnessie.client.rest.NessieInternalServerException) Version(org.projectnessie.tools.compatibility.api.Version) Util.withClassLoader(org.projectnessie.tools.compatibility.internal.Util.withClassLoader) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 14 with NessieApiV1

use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.

the class TestTranslatingVersionNessieApi method translate.

@ParameterizedTest
@MethodSource("translate")
void translate(String expectedClassName, Object modelObj) throws Exception {
    ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
    try (TranslatingVersionNessieApi translating = new TranslatingVersionNessieApi(createOldVersionNessieAPi(), NessieApiV1.class, oldVersionClassLoader)) {
        assertThat(translating.translateObject(null, oldVersionClassLoader, contextClassLoader)).isNull();
        assertThat(translating.translateArgs(null, oldVersionClassLoader, contextClassLoader)).isNull();
        assertThat(translating.translateArgs(new Object[] { null, null }, oldVersionClassLoader, contextClassLoader)).containsExactly(null, null);
        Object translatedObject = translating.translateObject(modelObj, oldVersionClassLoader, contextClassLoader);
        assertThat(translatedObject).extracting(Object::getClass).matches(c -> c.getName().equals(expectedClassName)).matches(c -> c.getClassLoader() == oldVersionClassLoader);
        Object[] translatedArgs = translating.translateArgs(new Object[] { null, modelObj, Collections.singletonList(modelObj), Collections.singleton(modelObj), Collections.singletonMap("key", modelObj) }, oldVersionClassLoader, contextClassLoader);
        assertThat(translatedArgs).hasSize(5);
        assertThat(translatedArgs[0]).isNull();
        assertThat(translatedArgs[1]).extracting(Object::getClass).matches(c -> c.getName().equals(expectedClassName)).matches(c -> c.getClassLoader() == oldVersionClassLoader);
        assertThat(translatedArgs[2]).asInstanceOf(InstanceOfAssertFactories.list(Object.class)).hasSize(1).allMatch(o -> o.getClass().getClassLoader() == oldVersionClassLoader);
        assertThat(translatedArgs[3]).asInstanceOf(InstanceOfAssertFactories.collection(Object.class)).hasSize(1).allMatch(o -> o.getClass().getClassLoader() == oldVersionClassLoader);
        assertThat(translatedArgs[4]).asInstanceOf(InstanceOfAssertFactories.map(String.class, Object.class)).hasSize(1).containsKey("key").extractingByKey("key").matches(o -> o.getClass().getClassLoader() == oldVersionClassLoader);
    }
}
Also used : NessieRuntimeException(org.projectnessie.error.NessieRuntimeException) NessieContentNotFoundException(org.projectnessie.error.NessieContentNotFoundException) NessieBadRequestException(org.projectnessie.error.NessieBadRequestException) InstanceOfAssertFactories(org.assertj.core.api.InstanceOfAssertFactories) NessieReferenceAlreadyExistsException(org.projectnessie.error.NessieReferenceAlreadyExistsException) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) NessieForbiddenException(org.projectnessie.error.NessieForbiddenException) ErrorCode(org.projectnessie.error.ErrorCode) ArrayList(java.util.ArrayList) ErrorCodeAware(org.projectnessie.error.ErrorCodeAware) BeforeAll(org.junit.jupiter.api.BeforeAll) NessieReferenceConflictException(org.projectnessie.error.NessieReferenceConflictException) HttpApiV1(org.projectnessie.client.http.v1api.HttpApiV1) MethodSource(org.junit.jupiter.params.provider.MethodSource) ValueSource(org.junit.jupiter.params.provider.ValueSource) NessieBackendThrottledException(org.projectnessie.error.NessieBackendThrottledException) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ImmutableBranch(org.projectnessie.model.ImmutableBranch) Branch(org.projectnessie.model.Branch) Arguments(org.junit.jupiter.params.provider.Arguments) NessieRefLogNotFoundException(org.projectnessie.error.NessieRefLogNotFoundException) NessieApiV1(org.projectnessie.client.api.NessieApiV1) Test(org.junit.jupiter.api.Test) ImmutableNessieError(org.projectnessie.error.ImmutableNessieError) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ImmutableIcebergTable(org.projectnessie.model.ImmutableIcebergTable) Stream(java.util.stream.Stream) IcebergTable(org.projectnessie.model.IcebergTable) Util.withClassLoader(org.projectnessie.tools.compatibility.internal.Util.withClassLoader) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) Collections(java.util.Collections) NessieInternalServerException(org.projectnessie.client.rest.NessieInternalServerException) Version(org.projectnessie.tools.compatibility.api.Version) Util.withClassLoader(org.projectnessie.tools.compatibility.internal.Util.withClassLoader) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 15 with NessieApiV1

use of org.projectnessie.client.api.NessieApiV1 in project nessie by projectnessie.

the class GCImpl method identifyExpiredContents.

/**
 * Identify the expired contents using a two-step traversal algorithm.
 *
 * <h2>Algorithm for identifying the live contents and return the bloom filter per content-id</h2>
 *
 * <p>Walk through each reference(both live and dead) distributively (one spark task for each
 * reference).
 *
 * <p>While traversing from the head commit in a reference(use DETACHED reference to fetch commits
 * from dead reference), for each live commit (commit that is not expired based on cutoff time)
 * add the contents of put operation to bloom filter.
 *
 * <p>Collect the live content keys for this reference just before cutoff time (at first expired
 * commit head). Which is used to identify the commit head for each live content key at the time
 * of cutoff time to support the time travel.
 *
 * <p>While traversing the expired commits (commit that is expired based on cutoff time), if it is
 * a head commit content for its key, add it to bloom filter. Else move to next expired commit.
 *
 * <p>Stop traversing the expired commits if each live content key has processed one live commit
 * for it. This is an optimization to avoid traversing all the commits.
 *
 * <p>Collect bloom filter per content id from each task and merge them.
 *
 * <h2>Algorithm for identifying the expired contents and return the list of globally expired
 * contents per content id per reference </h2>
 *
 * <p>Walk through each reference(both live and dead) distributively (one spark task for each
 * reference).
 *
 * <p>For each commit in the reference (use DETACHED reference to fetch commits from dead
 * reference) check it against bloom filter to decide whether its contents in put operation are
 * globally expired or not. If globally expired, Add the contents to the expired output for this
 * content id for this reference.
 *
 * <p>Overall the contents after or equal to cutoff time and the contents that are mapped to
 * commit head of live keys at the time of cutoff timestamp will be retained.
 *
 * @param session spark session for distributed computation
 * @return {@link IdentifiedResult} object having expired contents per content id.
 */
public IdentifiedResult identifyExpiredContents(SparkSession session) {
    try (NessieApiV1 api = GCUtil.getApi(gcParams.getNessieClientConfigs())) {
        DistributedIdentifyContents distributedIdentifyContents = new DistributedIdentifyContents(session, gcParams);
        List<Reference> liveReferences = api.getAllReferences().get().getReferences();
        Map<String, Instant> droppedReferenceTimeMap = collectDeadReferences(api);
        // As this list of references is passed from Spark driver to executor,
        // using available Immutables JSON serialization instead of adding java serialization to the
        // classes.
        List<String> allRefs = liveReferences.stream().map(GCUtil::serializeReference).collect(Collectors.toList());
        if (droppedReferenceTimeMap.size() > 0) {
            allRefs.addAll(droppedReferenceTimeMap.keySet());
        }
        long bloomFilterSize = gcParams.getBloomFilterExpectedEntries() == null ? getTotalCommitsInDefaultReference(api) : gcParams.getBloomFilterExpectedEntries();
        // Identify the live contents and return the bloom filter per content-id
        Map<String, ContentBloomFilter> liveContentsBloomFilterMap = distributedIdentifyContents.getLiveContentsBloomFilters(allRefs, bloomFilterSize, droppedReferenceTimeMap);
        // Identify the expired contents
        return distributedIdentifyContents.getIdentifiedResults(liveContentsBloomFilterMap, allRefs);
    }
}
Also used : Reference(org.projectnessie.model.Reference) Instant(java.time.Instant) 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