Search in sources :

Example 11 with ContentKey

use of org.projectnessie.model.ContentKey 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 ContentKey

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

the class AbstractRestAccessCheckDetached method detachedRefAccessChecks.

@Test
public void detachedRefAccessChecks(@NessieAccessChecker Consumer<Function<AccessContext, BatchAccessChecker>> accessCheckerConsumer) throws Exception {
    accessCheckerConsumer.accept(x -> newAccessChecker());
    Branch main = createBranch("committerAndAuthor");
    Branch merge = createBranch("committerAndAuthorMerge");
    Branch transplant = createBranch("committerAndAuthorTransplant");
    IcebergTable meta1 = IcebergTable.of("meep", 42, 42, 42, 42);
    ContentKey key = ContentKey.of("meep");
    Branch mainCommit = getApi().commitMultipleOperations().branchName(main.getName()).hash(main.getHash()).commitMeta(CommitMeta.builder().message("no security context").build()).operation(Put.of(key, meta1)).commit();
    Branch detachedAsBranch = Branch.of(Detached.REF_NAME, mainCommit.getHash());
    Tag detachedAsTag = Tag.of(Detached.REF_NAME, mainCommit.getHash());
    Detached detached = Detached.of(mainCommit.getHash());
    assertThat(Stream.of(detached, detachedAsBranch, detachedAsTag)).allSatisfy(ref -> assertAll(() -> assertThatThrownBy(() -> getApi().getCommitLog().reference(ref).get()).describedAs("ref='%s', getCommitLog", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(COMMITS_MSG), () -> assertThatThrownBy(() -> getApi().mergeRefIntoBranch().fromRef(ref).branch(merge).merge()).describedAs("ref='%s', mergeRefIntoBranch", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(VIEW_MSG), () -> assertThatThrownBy(() -> getApi().transplantCommitsIntoBranch().fromRefName(ref.getName()).hashesToTransplant(singletonList(ref.getHash())).branch(transplant).transplant()).describedAs("ref='%s', transplantCommitsIntoBranch", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(VIEW_MSG), () -> assertThatThrownBy(() -> getApi().getEntries().reference(ref).get()).describedAs("ref='%s', getEntries", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(READ_MSG), () -> assertThatThrownBy(() -> getApi().getContent().reference(ref).key(key).get()).describedAs("ref='%s', getContent", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(ENTITIES_MSG), () -> assertThatThrownBy(() -> getApi().getDiff().fromRef(ref).toRef(main).get()).describedAs("ref='%s', getDiff1", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(VIEW_MSG), () -> assertThatThrownBy(() -> getApi().getDiff().fromRef(main).toRef(ref).get()).describedAs("ref='%s', getDiff2", ref).isInstanceOf(NessieForbiddenException.class).hasMessageContaining(VIEW_MSG)));
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Branch(org.projectnessie.model.Branch) IcebergTable(org.projectnessie.model.IcebergTable) Tag(org.projectnessie.model.Tag) NessieForbiddenException(org.projectnessie.error.NessieForbiddenException) Detached(org.projectnessie.model.Detached) Test(org.junit.jupiter.api.Test)

Example 13 with ContentKey

use of org.projectnessie.model.ContentKey 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 ContentKey

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

the class ITNativeNessieError method testNullParamViolation.

@Test
void testNullParamViolation() {
    ContentKey k = ContentKey.of("a");
    IcebergTable t = IcebergTable.of("path1", 42, 42, 42, 42);
    assertEquals("Bad Request (HTTP/400): commitMultipleOperations.hash: must not be null", assertThrows(NessieBadRequestException.class, () -> api.commitMultipleOperations().branchName("branchName").operation(Put.of(k, t)).commitMeta(CommitMeta.fromMessage("message")).commit()).getMessage());
}
Also used : ContentKey(org.projectnessie.model.ContentKey) IcebergTable(org.projectnessie.model.IcebergTable) Test(org.junit.jupiter.api.Test) NativeImageTest(io.quarkus.test.junit.NativeImageTest)

Example 15 with ContentKey

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

the class AbstractTestBasicOperations method testAdmin.

@Test
@TestSecurity(user = "admin_user", roles = { "admin", "user" })
void testAdmin() throws BaseNessieClientServerException {
    getCatalog("testx");
    Branch branch = (Branch) api.getReference().refName("testx").get();
    List<Entry> tables = api.getEntries().refName("testx").get().getEntries();
    Assertions.assertTrue(tables.isEmpty());
    ContentKey key = ContentKey.of("x", "x");
    tryEndpointPass(() -> api.commitMultipleOperations().branch(branch).operation(Put.of(key, IcebergTable.of("foo", 42, 42, 42, 42, "cid-foo"))).commitMeta(CommitMeta.fromMessage("empty message")).commit());
    Assertions.assertTrue(api.getContent().refName("testx").key(key).get().get(key).unwrap(IcebergTable.class).isPresent());
    Branch master = (Branch) api.getReference().refName("testx").get();
    Branch test = Branch.of("testy", master.getHash());
    tryEndpointPass(() -> api.createReference().sourceRefName(master.getName()).reference(test).create());
    Branch test2 = (Branch) api.getReference().refName("testy").get();
    tryEndpointPass(() -> api.deleteBranch().branch(test2).delete());
    tryEndpointPass(() -> api.commitMultipleOperations().branch(master).operation(Delete.of(key)).commitMeta(CommitMeta.fromMessage("")).commit());
    assertThat(api.getContent().refName("testx").key(key).get()).isEmpty();
    tryEndpointPass(() -> {
        Branch b = (Branch) api.getReference().refName(branch.getName()).get();
        // Note: the initial version-store implementations just committed this operation, but it
        // should actually fail, because the operations of the 1st commit above and this commit
        // have conflicts.
        api.commitMultipleOperations().branch(b).operation(Put.of(key, IcebergTable.of("bar", 42, 42, 42, 42, "cid-bar"))).commitMeta(CommitMeta.fromMessage("")).commit();
    });
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Entry(org.projectnessie.model.EntriesResponse.Entry) Branch(org.projectnessie.model.Branch) TestSecurity(io.quarkus.test.security.TestSecurity) Test(org.junit.jupiter.api.Test)

Aggregations

ContentKey (org.projectnessie.model.ContentKey)35 Branch (org.projectnessie.model.Branch)20 Test (org.junit.jupiter.api.Test)15 Content (org.projectnessie.model.Content)15 IcebergTable (org.projectnessie.model.IcebergTable)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 CommitMeta (org.projectnessie.model.CommitMeta)10 Put (org.projectnessie.model.Operation.Put)7 Map (java.util.Map)6 Entry (org.projectnessie.model.EntriesResponse.Entry)6 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 NessieApiV1 (org.projectnessie.client.api.NessieApiV1)5 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)5 LogResponse (org.projectnessie.model.LogResponse)5 Reference (org.projectnessie.model.Reference)5 HashMap (java.util.HashMap)4 EnumSource (org.junit.jupiter.params.provider.EnumSource)4 NessieReferenceNotFoundException (org.projectnessie.error.NessieReferenceNotFoundException)4 LogEntry (org.projectnessie.model.LogResponse.LogEntry)4