Search in sources :

Example 11 with Content

use of org.projectnessie.model.Content in project nessie by projectnessie.

the class AbstractRestInvalidRefs method testValidHashesOnValidNamedRefs.

@Test
public void testValidHashesOnValidNamedRefs() throws BaseNessieClientServerException {
    Branch branch = createBranch("testValidHashesOnValidNamedRefs");
    int commits = 10;
    String currentHash = branch.getHash();
    createCommits(branch, 1, commits, currentHash);
    LogResponse entireLog = getApi().getCommitLog().refName(branch.getName()).get();
    assertThat(entireLog).isNotNull();
    assertThat(entireLog.getLogEntries()).hasSize(commits);
    EntriesResponse allEntries = getApi().getEntries().refName(branch.getName()).get();
    assertThat(allEntries).isNotNull();
    assertThat(allEntries.getEntries()).hasSize(commits);
    List<ContentKey> keys = new ArrayList<>();
    IntStream.range(0, commits).forEach(i -> keys.add(ContentKey.of("table" + i)));
    // TODO: check where hashOnRef is set
    Map<ContentKey, Content> allContent = getApi().getContent().keys(keys).refName(branch.getName()).get();
    for (int i = 0; i < commits; i++) {
        String hash = entireLog.getLogEntries().get(i).getCommitMeta().getHash();
        LogResponse log = getApi().getCommitLog().refName(branch.getName()).hashOnRef(hash).get();
        assertThat(log).isNotNull();
        assertThat(log.getLogEntries()).hasSize(commits - i);
        assertThat(ImmutableList.copyOf(entireLog.getLogEntries()).subList(i, commits)).containsExactlyElementsOf(log.getLogEntries());
        EntriesResponse entries = getApi().getEntries().refName(branch.getName()).hashOnRef(hash).get();
        assertThat(entries).isNotNull();
        assertThat(entries.getEntries()).hasSize(commits - i);
        int idx = commits - 1 - i;
        ContentKey key = ContentKey.of("table" + idx);
        Content c = getApi().getContent().key(key).refName(branch.getName()).hashOnRef(hash).get().get(key);
        assertThat(c).isNotNull().isEqualTo(allContent.get(key));
    }
}
Also used : EntriesResponse(org.projectnessie.model.EntriesResponse) ContentKey(org.projectnessie.model.ContentKey) LogResponse(org.projectnessie.model.LogResponse) Branch(org.projectnessie.model.Branch) Content(org.projectnessie.model.Content) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 12 with Content

use of org.projectnessie.model.Content in project nessie by projectnessie.

the class AbstractResteasyTest method testGetContent.

@Test
public void testGetContent() {
    Branch branch = makeBranch("content-test");
    IcebergTable table = IcebergTable.of("content-table1", 42, 42, 42, 42);
    branch = commit(table.getId(), branch, "key1", table.getMetadataLocation());
    Content content = rest().queryParam("ref", branch.getName()).queryParam("hashOnRef", branch.getHash()).get(String.format("contents/%s", "key1")).then().statusCode(200).extract().as(Content.class);
    assertThat(content).isEqualTo(table);
}
Also used : ImmutableBranch(org.projectnessie.model.ImmutableBranch) Branch(org.projectnessie.model.Branch) Content(org.projectnessie.model.Content) IcebergTable(org.projectnessie.model.IcebergTable) Test(org.junit.jupiter.api.Test)

Example 13 with Content

use of org.projectnessie.model.Content in project nessie by projectnessie.

the class ContentApiImpl method getMultipleContents.

@Override
public GetMultipleContentsResponse getMultipleContents(String namedRef, String hashOnRef, GetMultipleContentsRequest request) throws NessieNotFoundException {
    try {
        WithHash<NamedRef> ref = namedRefWithHashOrThrow(namedRef, hashOnRef);
        List<ContentKey> externalKeys = request.getRequestedKeys();
        List<Key> internalKeys = externalKeys.stream().map(ContentApiImpl::toKey).collect(Collectors.toList());
        Map<Key, Content> values = getStore().getValues(ref.getHash(), internalKeys);
        List<ContentWithKey> output = values.entrySet().stream().map(e -> ContentWithKey.of(toContentKey(e.getKey()), e.getValue())).collect(Collectors.toList());
        return ImmutableGetMultipleContentsResponse.builder().contents(output).build();
    } catch (ReferenceNotFoundException ex) {
        throw new NessieReferenceNotFoundException(ex.getMessage(), ex);
    }
}
Also used : NamedRef(org.projectnessie.versioned.NamedRef) NessieContentNotFoundException(org.projectnessie.error.NessieContentNotFoundException) GetMultipleContentsResponse(org.projectnessie.model.GetMultipleContentsResponse) ServerConfig(org.projectnessie.services.config.ServerConfig) ContentWithKey(org.projectnessie.model.GetMultipleContentsResponse.ContentWithKey) ContentApi(org.projectnessie.api.ContentApi) GetMultipleContentsRequest(org.projectnessie.model.GetMultipleContentsRequest) Authorizer(org.projectnessie.services.authz.Authorizer) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) Key(org.projectnessie.versioned.Key) Collectors(java.util.stream.Collectors) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) List(java.util.List) Principal(java.security.Principal) VersionStore(org.projectnessie.versioned.VersionStore) Map(java.util.Map) Content(org.projectnessie.model.Content) ContentKey(org.projectnessie.model.ContentKey) ImmutableGetMultipleContentsResponse(org.projectnessie.model.ImmutableGetMultipleContentsResponse) CommitMeta(org.projectnessie.model.CommitMeta) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) WithHash(org.projectnessie.versioned.WithHash) NamedRef(org.projectnessie.versioned.NamedRef) ContentKey(org.projectnessie.model.ContentKey) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) Content(org.projectnessie.model.Content) ContentWithKey(org.projectnessie.model.GetMultipleContentsResponse.ContentWithKey) ContentWithKey(org.projectnessie.model.GetMultipleContentsResponse.ContentWithKey) Key(org.projectnessie.versioned.Key) ContentKey(org.projectnessie.model.ContentKey)

Example 14 with Content

use of org.projectnessie.model.Content in project iceberg by apache.

the class NessieCatalog method table.

private IcebergTable table(TableIdentifier tableIdentifier) {
    try {
        ContentKey key = NessieUtil.toKey(tableIdentifier);
        Content table = api.getContent().key(key).reference(reference.getReference()).get().get(key);
        return table != null ? table.unwrap(IcebergTable.class).orElse(null) : null;
    } catch (NessieNotFoundException e) {
        return null;
    }
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Content(org.projectnessie.model.Content) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException)

Example 15 with Content

use of org.projectnessie.model.Content in project iceberg by apache.

the class NessieTableOperations method doRefresh.

@Override
protected void doRefresh() {
    try {
        reference.refresh(api);
    } catch (NessieNotFoundException e) {
        throw new RuntimeException("Failed to refresh as ref is no longer valid.", e);
    }
    String metadataLocation = null;
    try {
        Content content = api.getContent().key(key).reference(reference.getReference()).get().get(key);
        LOG.debug("Content '{}' at '{}': {}", key, reference.getReference(), content);
        if (content == null) {
            if (currentMetadataLocation() != null) {
                throw new NoSuchTableException("No such table %s in %s", key, reference.getReference());
            }
        } else {
            this.table = content.unwrap(IcebergTable.class).orElseThrow(() -> new IllegalStateException("Cannot refresh iceberg table: " + String.format("Nessie points to a non-Iceberg object for path: %s.", key)));
            metadataLocation = table.getMetadataLocation();
        }
    } catch (NessieNotFoundException ex) {
        if (currentMetadataLocation() != null) {
            throw new NoSuchTableException(ex, "No such table %s", key);
        }
    }
    refreshFromMetadataLocation(metadataLocation, 2);
}
Also used : Content(org.projectnessie.model.Content) NoSuchTableException(org.apache.iceberg.exceptions.NoSuchTableException) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException)

Aggregations

Content (org.projectnessie.model.Content)32 ContentKey (org.projectnessie.model.ContentKey)16 CommitMeta (org.projectnessie.model.CommitMeta)11 IcebergTable (org.projectnessie.model.IcebergTable)11 Test (org.junit.jupiter.api.Test)9 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)9 Branch (org.projectnessie.model.Branch)8 Map (java.util.Map)7 ByteString (com.google.protobuf.ByteString)6 IcebergView (org.projectnessie.model.IcebergView)6 HashMap (java.util.HashMap)5 List (java.util.List)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 NessieApiV1 (org.projectnessie.client.api.NessieApiV1)5 Reference (org.projectnessie.model.Reference)5 Instant (java.time.Instant)4 ArrayList (java.util.ArrayList)4 LogResponse (org.projectnessie.model.LogResponse)4 Put (org.projectnessie.model.Operation.Put)4 HashSet (java.util.HashSet)3