Search in sources :

Example 11 with Key

use of org.projectnessie.versioned.Key in project nessie by projectnessie.

the class CommitBench method initialOperations.

static List<Operation<BaseContent>> initialOperations(BenchmarkParam bp, List<Key> keys, Map<Key, String> contentIds) {
    List<Operation<BaseContent>> operations = new ArrayList<>(bp.tablesPerCommit);
    for (Key key : keys) {
        String contentId = contentIds.get(key);
        operations.add(Put.of(key, withGlobal("0", "initial commit content", contentId)));
    }
    return operations;
}
Also used : ArrayList(java.util.ArrayList) Operation(org.projectnessie.versioned.Operation) Key(org.projectnessie.versioned.Key)

Example 12 with Key

use of org.projectnessie.versioned.Key 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 13 with Key

use of org.projectnessie.versioned.Key in project nessie by projectnessie.

the class NamespaceApiImpl method deleteNamespace.

@Override
public void deleteNamespace(NamespaceParams params) throws NessieReferenceNotFoundException, NessieNamespaceNotEmptyException, NessieNamespaceNotFoundException {
    BranchName branch = branchFromRefName(params.getRefName());
    try {
        Namespace namespace = getNamespace(params, branch);
        Delete delete = Delete.of(ContentKey.of(namespace.getElements()));
        Callable<Void> validator = () -> {
            try (Stream<WithType<Key, Type>> keys = getStore().getKeys(branch)) {
                if (keys.anyMatch(k -> Namespace.of(k.getValue().getElements()).name().startsWith(params.getNamespace().name()) && k.getType() != Type.NAMESPACE)) {
                    throw namespaceNotEmptyException(params);
                }
            }
            return null;
        };
        commit(branch, "delete namespace " + namespace.name(), TreeApiImpl.toOp(delete), validator);
    } catch (ReferenceNotFoundException | ReferenceConflictException e) {
        throw new NessieReferenceNotFoundException(e.getMessage(), e);
    }
}
Also used : Delete(org.projectnessie.model.Operation.Delete) NessieNamespaceNotEmptyException(org.projectnessie.error.NessieNamespaceNotEmptyException) ImmutableGetNamespacesResponse(org.projectnessie.model.ImmutableGetNamespacesResponse) Put(org.projectnessie.model.Operation.Put) ServerConfig(org.projectnessie.services.config.ServerConfig) NessieNamespaceAlreadyExistsException(org.projectnessie.error.NessieNamespaceAlreadyExistsException) Authorizer(org.projectnessie.services.authz.Authorizer) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) NamespaceApi(org.projectnessie.api.NamespaceApi) Callable(java.util.concurrent.Callable) GetNamespacesResponse(org.projectnessie.model.GetNamespacesResponse) MultipleNamespacesParams(org.projectnessie.api.params.MultipleNamespacesParams) WithType(org.projectnessie.versioned.WithType) VersionStore(org.projectnessie.versioned.VersionStore) Type(org.projectnessie.model.Content.Type) Map(java.util.Map) Content(org.projectnessie.model.Content) CommitMeta(org.projectnessie.model.CommitMeta) NessieNamespaceNotFoundException(org.projectnessie.error.NessieNamespaceNotFoundException) Nullable(javax.annotation.Nullable) NamespaceParams(org.projectnessie.api.params.NamespaceParams) Set(java.util.Set) Operation(org.projectnessie.versioned.Operation) Key(org.projectnessie.versioned.Key) Collectors(java.util.stream.Collectors) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) Sets(com.google.common.collect.Sets) BranchName(org.projectnessie.versioned.BranchName) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) List(java.util.List) Principal(java.security.Principal) Stream(java.util.stream.Stream) Delete(org.projectnessie.model.Operation.Delete) Namespace(org.projectnessie.model.Namespace) Optional(java.util.Optional) ContentKey(org.projectnessie.model.ContentKey) Collections(java.util.Collections) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) Namespace(org.projectnessie.model.Namespace) WithType(org.projectnessie.versioned.WithType) Type(org.projectnessie.model.Content.Type) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) Stream(java.util.stream.Stream) BranchName(org.projectnessie.versioned.BranchName) Key(org.projectnessie.versioned.Key) ContentKey(org.projectnessie.model.ContentKey)

Example 14 with Key

use of org.projectnessie.versioned.Key in project nessie by projectnessie.

the class AbstractCommitLog method commitLogExtendedNoGlobalState.

@Test
public void commitLogExtendedNoGlobalState() throws Exception {
    BranchName branch = BranchName.of("commitLogExtended");
    Hash firstParent = store().create(branch, Optional.empty());
    int numCommits = 10;
    List<Hash> hashes = IntStream.rangeClosed(1, numCommits).mapToObj(i -> {
        try {
            return commit("Commit #" + i).put("k" + i, onRef("v" + i, "c" + i)).put("key" + i, onRef("value" + i, "cid" + i)).delete("delete" + i).toBranch(branch);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }).collect(Collectors.toList());
    List<Hash> parentHashes = Stream.concat(Stream.of(firstParent), hashes.subList(0, 9).stream()).collect(Collectors.toList());
    assertThat(Lists.reverse(commitsList(branch, false))).allSatisfy(c -> {
        assertThat(c.getOperations()).isNull();
        assertThat(c.getParentHash()).isNull();
    }).extracting(Commit::getHash).containsExactlyElementsOf(hashes);
    List<Commit<CommitMessage, BaseContent>> commits = Lists.reverse(commitsList(branch, true));
    assertThat(IntStream.rangeClosed(1, numCommits)).allSatisfy(i -> {
        Commit<CommitMessage, BaseContent> c = commits.get(i - 1);
        assertThat(c).extracting(Commit::getCommitMeta, Commit::getHash, Commit::getParentHash, Commit::getOperations).containsExactly(commitMessage("Commit #" + i), hashes.get(i - 1), parentHashes.get(i - 1), Arrays.asList(Delete.of(Key.of("delete" + i)), Put.of(Key.of("k" + i), onRef("v" + i, "c" + i)), Put.of(Key.of("key" + i), onRef("value" + i, "cid" + i))));
    });
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CommitMessage(org.projectnessie.versioned.testworker.CommitMessage) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) BaseContent(org.projectnessie.versioned.testworker.BaseContent) ImmutableList(com.google.common.collect.ImmutableList) VersionStore(org.projectnessie.versioned.VersionStore) Delete(org.projectnessie.versioned.Delete) OnRefOnly.onRef(org.projectnessie.versioned.testworker.OnRefOnly.onRef) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CommitMessage.commitMessage(org.projectnessie.versioned.testworker.CommitMessage.commitMessage) Hash(org.projectnessie.versioned.Hash) Commit(org.projectnessie.versioned.Commit) Key(org.projectnessie.versioned.Key) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) BranchName(org.projectnessie.versioned.BranchName) List(java.util.List) Stream(java.util.stream.Stream) OnRefOnly.newOnRef(org.projectnessie.versioned.testworker.OnRefOnly.newOnRef) Optional(java.util.Optional) Put(org.projectnessie.versioned.Put) Collections(java.util.Collections) Commit(org.projectnessie.versioned.Commit) CommitMessage(org.projectnessie.versioned.testworker.CommitMessage) BaseContent(org.projectnessie.versioned.testworker.BaseContent) BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) Test(org.junit.jupiter.api.Test)

Example 15 with Key

use of org.projectnessie.versioned.Key in project nessie by projectnessie.

the class AbstractCommits method commitWithValidation.

@Test
void commitWithValidation() throws Exception {
    BranchName branch = BranchName.of("main");
    Key key = Key.of("my", "table0");
    Hash branchHead = store().getNamedRef(branch.getName(), GetNamedRefsParams.DEFAULT).getHash();
    String cid = "cid-0";
    RuntimeException exception = new ArithmeticException("Whatever");
    assertThatThrownBy(() -> doCommitWithValidation(branch, cid, key, () -> {
        // do some operations here
        try {
            assertThat(store().getValue(branch, key)).isNull();
            store().getKeys(branch).close();
        } catch (ReferenceNotFoundException e) {
            throw new RuntimeException(e);
        }
        // let the custom commit-validation fail
        throw exception;
    })).isSameAs(exception);
    assertThat(store().getNamedRef(branch.getName(), GetNamedRefsParams.DEFAULT).getHash()).isEqualTo(branchHead);
    assertThat(store().getValue(branch, key)).isNull();
}
Also used : ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) Key(org.projectnessie.versioned.Key) Test(org.junit.jupiter.api.Test)

Aggregations

Key (org.projectnessie.versioned.Key)29 BranchName (org.projectnessie.versioned.BranchName)21 Hash (org.projectnessie.versioned.Hash)21 ByteString (com.google.protobuf.ByteString)14 List (java.util.List)12 Collectors (java.util.stream.Collectors)12 Stream (java.util.stream.Stream)12 ReferenceConflictException (org.projectnessie.versioned.ReferenceConflictException)12 ArrayList (java.util.ArrayList)11 Map (java.util.Map)11 Optional (java.util.Optional)11 ReferenceNotFoundException (org.projectnessie.versioned.ReferenceNotFoundException)11 Test (org.junit.jupiter.api.Test)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)10 ContentId (org.projectnessie.versioned.persist.adapter.ContentId)10 IntStream (java.util.stream.IntStream)9 KeyWithBytes (org.projectnessie.versioned.persist.adapter.KeyWithBytes)9 Collections (java.util.Collections)8 ContentAndState (org.projectnessie.versioned.persist.adapter.ContentAndState)8 DatabaseAdapter (org.projectnessie.versioned.persist.adapter.DatabaseAdapter)8