Search in sources :

Example 1 with EntriesResponse

use of org.projectnessie.model.EntriesResponse 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 2 with EntriesResponse

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

the class AbstractRestReferences method referenceNames.

@ParameterizedTest
@ValueSource(strings = { "normal", "with-no_space", "slash/thing" })
public void referenceNames(String refNamePart) throws BaseNessieClientServerException {
    String tagName = "tag" + refNamePart;
    String branchName = "branch" + refNamePart;
    String branchName2 = "branch2" + refNamePart;
    String root = "ref_name_" + refNamePart.replaceAll("[^a-z]", "");
    Branch main = createBranch(root);
    IcebergTable meta = IcebergTable.of("meep", 42, 42, 42, 42);
    main = getApi().commitMultipleOperations().branchName(main.getName()).hash(main.getHash()).commitMeta(CommitMeta.builder().message("common-merge-ancestor").properties(ImmutableMap.of("prop1", "val1", "prop2", "val2")).build()).operation(Operation.Put.of(ContentKey.of("meep"), meta)).commit();
    String someHash = main.getHash();
    Reference createdTag = getApi().createReference().sourceRefName(main.getName()).reference(Tag.of(tagName, someHash)).create();
    assertEquals(Tag.of(tagName, someHash), createdTag);
    Reference createdBranch1 = getApi().createReference().sourceRefName(main.getName()).reference(Branch.of(branchName, someHash)).create();
    assertEquals(Branch.of(branchName, someHash), createdBranch1);
    Reference createdBranch2 = getApi().createReference().sourceRefName(main.getName()).reference(Branch.of(branchName2, someHash)).create();
    assertEquals(Branch.of(branchName2, someHash), createdBranch2);
    Map<String, Reference> references = getApi().getAllReferences().get().getReferences().stream().filter(r -> root.equals(r.getName()) || r.getName().endsWith(refNamePart)).collect(Collectors.toMap(Reference::getName, Function.identity()));
    assertThat(references).containsAllEntriesOf(ImmutableMap.of(main.getName(), main, createdTag.getName(), createdTag, createdBranch1.getName(), createdBranch1, createdBranch2.getName(), createdBranch2));
    assertThat(references.get(main.getName())).isInstanceOf(Branch.class);
    assertThat(references.get(createdTag.getName())).isInstanceOf(Tag.class);
    assertThat(references.get(createdBranch1.getName())).isInstanceOf(Branch.class);
    assertThat(references.get(createdBranch2.getName())).isInstanceOf(Branch.class);
    Reference tagRef = references.get(tagName);
    Reference branchRef = references.get(branchName);
    Reference branchRef2 = references.get(branchName2);
    String tagHash = tagRef.getHash();
    String branchHash = branchRef.getHash();
    String branchHash2 = branchRef2.getHash();
    assertThat(getApi().getReference().refName(tagName).get()).isEqualTo(tagRef);
    assertThat(getApi().getReference().refName(branchName).get()).isEqualTo(branchRef);
    EntriesResponse entries = getApi().getEntries().refName(tagName).get();
    assertThat(entries).isNotNull();
    entries = getApi().getEntries().refName(branchName).get();
    assertThat(entries).isNotNull();
    LogResponse log = getApi().getCommitLog().refName(tagName).get();
    assertThat(log).isNotNull();
    log = getApi().getCommitLog().refName(branchName).get();
    assertThat(log).isNotNull();
    // Need to have at least one op, otherwise all following operations (assignTag/Branch, merge,
    // delete) will fail
    meta = IcebergTable.of("foo", 42, 42, 42, 42);
    getApi().commitMultipleOperations().branchName(branchName).hash(branchHash).operation(Put.of(ContentKey.of("some-key"), meta)).commitMeta(CommitMeta.fromMessage("One dummy op")).commit();
    log = getApi().getCommitLog().refName(branchName).get();
    String newHash = log.getLogEntries().get(0).getCommitMeta().getHash();
    getApi().assignTag().tagName(tagName).hash(tagHash).assignTo(Branch.of(branchName, newHash)).assign();
    getApi().assignBranch().branchName(branchName).hash(newHash).assignTo(Branch.of(branchName, newHash)).assign();
    getApi().mergeRefIntoBranch().branchName(branchName2).hash(branchHash2).fromRefName(branchName).fromHash(newHash).merge();
}
Also used : ReferenceMetadata(org.projectnessie.model.ReferenceMetadata) NessieBadRequestException(org.projectnessie.error.NessieBadRequestException) LogResponse(org.projectnessie.model.LogResponse) Put(org.projectnessie.model.Operation.Put) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) Function(java.util.function.Function) Reference(org.projectnessie.model.Reference) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Map(java.util.Map) Assertions.assertAll(org.junit.jupiter.api.Assertions.assertAll) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CommitMeta(org.projectnessie.model.CommitMeta) ValueSource(org.junit.jupiter.params.provider.ValueSource) Operation(org.projectnessie.model.Operation) ImmutableMap(com.google.common.collect.ImmutableMap) Validation(org.projectnessie.model.Validation) ReferencesResponse(org.projectnessie.model.ReferencesResponse) Branch(org.projectnessie.model.Branch) LogEntry(org.projectnessie.model.LogResponse.LogEntry) EntriesResponse(org.projectnessie.model.EntriesResponse) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) FetchOption(org.projectnessie.api.params.FetchOption) Stream(java.util.stream.Stream) IcebergView(org.projectnessie.model.IcebergView) IcebergTable(org.projectnessie.model.IcebergTable) Optional(java.util.Optional) Tag(org.projectnessie.model.Tag) BaseNessieClientServerException(org.projectnessie.error.BaseNessieClientServerException) ContentKey(org.projectnessie.model.ContentKey) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) EntriesResponse(org.projectnessie.model.EntriesResponse) LogResponse(org.projectnessie.model.LogResponse) Branch(org.projectnessie.model.Branch) Reference(org.projectnessie.model.Reference) IcebergTable(org.projectnessie.model.IcebergTable) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with EntriesResponse

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

the class TreeApiImpl method getEntries.

@Override
public EntriesResponse getEntries(String namedRef, EntriesParams params) throws NessieNotFoundException {
    Preconditions.checkArgument(params.pageToken() == null, "Paging not supported");
    WithHash<NamedRef> refWithHash = namedRefWithHashOrThrow(namedRef, params.hashOnRef());
    // all existing VersionStore implementations have to read all keys anyways so we don't get much
    try {
        List<EntriesResponse.Entry> entries;
        try (Stream<EntriesResponse.Entry> entryStream = getStore().getKeys(refWithHash.getHash()).map(key -> EntriesResponse.Entry.builder().name(fromKey(key.getValue())).type((Type) key.getType()).build())) {
            Stream<EntriesResponse.Entry> entriesStream = filterEntries(entryStream, params.filter());
            if (params.namespaceDepth() != null && params.namespaceDepth() > 0) {
                entriesStream = entriesStream.filter(e -> e.getName().getElements().size() >= params.namespaceDepth()).map(e -> truncate(e, params.namespaceDepth())).distinct();
            }
            entries = entriesStream.collect(ImmutableList.toImmutableList());
        }
        return EntriesResponse.builder().addAllEntries(entries).build();
    } catch (ReferenceNotFoundException e) {
        throw new NessieReferenceNotFoundException(e.getMessage(), e);
    }
}
Also used : Detached(org.projectnessie.model.Detached) TreeApi(org.projectnessie.api.TreeApi) ServerConfig(org.projectnessie.services.config.ServerConfig) VAR_REF_TYPE(org.projectnessie.services.cel.CELUtil.VAR_REF_TYPE) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) NessieConflictException(org.projectnessie.error.NessieConflictException) GetNamedRefsParams(org.projectnessie.versioned.GetNamedRefsParams) VAR_REF(org.projectnessie.services.cel.CELUtil.VAR_REF) VersionStore(org.projectnessie.versioned.VersionStore) Delete(org.projectnessie.versioned.Delete) Type(org.projectnessie.model.Content.Type) Map(java.util.Map) Content(org.projectnessie.model.Content) Ref(org.projectnessie.versioned.Ref) NamedRef(org.projectnessie.versioned.NamedRef) VAR_CONTENT_TYPE(org.projectnessie.services.cel.CELUtil.VAR_CONTENT_TYPE) ScriptException(org.projectnessie.cel.tools.ScriptException) ImmutableMap(com.google.common.collect.ImmutableMap) Validation(org.projectnessie.model.Validation) ReferencesResponse(org.projectnessie.model.ReferencesResponse) REFERENCES_DECLARATIONS(org.projectnessie.services.cel.CELUtil.REFERENCES_DECLARATIONS) Branch(org.projectnessie.model.Branch) LogEntry(org.projectnessie.model.LogResponse.LogEntry) ReferenceAlreadyExistsException(org.projectnessie.versioned.ReferenceAlreadyExistsException) EntriesResponse(org.projectnessie.model.EntriesResponse) COMMIT_LOG_TYPES(org.projectnessie.services.cel.CELUtil.COMMIT_LOG_TYPES) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) BranchName(org.projectnessie.versioned.BranchName) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) List(java.util.List) Principal(java.security.Principal) Stream(java.util.stream.Stream) ENTRIES_DECLARATIONS(org.projectnessie.services.cel.CELUtil.ENTRIES_DECLARATIONS) Transplant(org.projectnessie.model.Transplant) ImmutableReferencesResponse(org.projectnessie.model.ImmutableReferencesResponse) Optional(java.util.Optional) ContentKey(org.projectnessie.model.ContentKey) CELUtil(org.projectnessie.services.cel.CELUtil) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) Put(org.projectnessie.versioned.Put) ReferenceMetadata(org.projectnessie.model.ReferenceMetadata) LogResponse(org.projectnessie.model.LogResponse) NessieReferenceAlreadyExistsException(org.projectnessie.error.NessieReferenceAlreadyExistsException) Authorizer(org.projectnessie.services.authz.Authorizer) VAR_ENTRY(org.projectnessie.services.cel.CELUtil.VAR_ENTRY) TagName(org.projectnessie.versioned.TagName) Reference(org.projectnessie.model.Reference) Strings(com.google.common.base.Strings) Script(org.projectnessie.cel.tools.Script) COMMIT_LOG_DECLARATIONS(org.projectnessie.services.cel.CELUtil.COMMIT_LOG_DECLARATIONS) ImmutableLogResponse(org.projectnessie.model.ImmutableLogResponse) ImmutableList(com.google.common.collect.ImmutableList) GetReferenceParams(org.projectnessie.api.params.GetReferenceParams) ReferencesParams(org.projectnessie.api.params.ReferencesParams) Merge(org.projectnessie.model.Merge) NessieReferenceConflictException(org.projectnessie.error.NessieReferenceConflictException) StreamSupport(java.util.stream.StreamSupport) CommitMeta(org.projectnessie.model.CommitMeta) ImmutableLogEntry(org.projectnessie.model.ImmutableLogEntry) Nullable(javax.annotation.Nullable) VAR_COMMIT(org.projectnessie.services.cel.CELUtil.VAR_COMMIT) WithHash(org.projectnessie.versioned.WithHash) Operation(org.projectnessie.model.Operation) REFERENCES_TYPES(org.projectnessie.services.cel.CELUtil.REFERENCES_TYPES) CommitLogParams(org.projectnessie.api.params.CommitLogParams) Hash(org.projectnessie.versioned.Hash) ImmutableTag(org.projectnessie.model.ImmutableTag) ImmutableBranch(org.projectnessie.model.ImmutableBranch) SCRIPT_HOST(org.projectnessie.services.cel.CELUtil.SCRIPT_HOST) Commit(org.projectnessie.versioned.Commit) ImmutableReferenceMetadata(org.projectnessie.model.ImmutableReferenceMetadata) CONTAINER(org.projectnessie.services.cel.CELUtil.CONTAINER) VAR_NAMESPACE(org.projectnessie.services.cel.CELUtil.VAR_NAMESPACE) Key(org.projectnessie.versioned.Key) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) VAR_REF_META(org.projectnessie.services.cel.CELUtil.VAR_REF_META) RetrieveOptions(org.projectnessie.versioned.GetNamedRefsParams.RetrieveOptions) EntriesParams(org.projectnessie.api.params.EntriesParams) FetchOption(org.projectnessie.api.params.FetchOption) Operations(org.projectnessie.model.Operations) ReferenceInfo(org.projectnessie.versioned.ReferenceInfo) Preconditions(com.google.common.base.Preconditions) RefUtil.toNamedRef(org.projectnessie.services.impl.RefUtil.toNamedRef) Collections(java.util.Collections) VAR_OPERATIONS(org.projectnessie.services.cel.CELUtil.VAR_OPERATIONS) Unchanged(org.projectnessie.versioned.Unchanged) LogEntry(org.projectnessie.model.LogResponse.LogEntry) ImmutableLogEntry(org.projectnessie.model.ImmutableLogEntry) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) NamedRef(org.projectnessie.versioned.NamedRef) RefUtil.toNamedRef(org.projectnessie.services.impl.RefUtil.toNamedRef)

Aggregations

Branch (org.projectnessie.model.Branch)3 ContentKey (org.projectnessie.model.ContentKey)3 EntriesResponse (org.projectnessie.model.EntriesResponse)3 LogResponse (org.projectnessie.model.LogResponse)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 Test (org.junit.jupiter.api.Test)2 FetchOption (org.projectnessie.api.params.FetchOption)2 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)2 NessieReferenceNotFoundException (org.projectnessie.error.NessieReferenceNotFoundException)2 CommitMeta (org.projectnessie.model.CommitMeta)2 LogEntry (org.projectnessie.model.LogResponse.LogEntry)2 Operation (org.projectnessie.model.Operation)2 Reference (org.projectnessie.model.Reference)2 ReferenceMetadata (org.projectnessie.model.ReferenceMetadata)2 ReferencesResponse (org.projectnessie.model.ReferencesResponse)2