Search in sources :

Example 1 with WithType

use of org.projectnessie.versioned.WithType 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 2 with WithType

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

the class AbstractCommits method commitNonConflictingOperations.

/*
   * Test:
   * - Create a new branch
   * - Add a commit for 3 keys
   * - Add a commit based on initial commit for first key
   * - Add a commit based on initial commit for second key
   * - Add a commit based on initial commit for third  key
   * - Check commit metadata
   * - Check keys for each commit hash
   * - Check values for each commit hash
   */
@Test
public void commitNonConflictingOperations() throws Exception {
    final BranchName branch = BranchName.of("foo");
    store().create(branch, Optional.empty());
    final Hash initialCommit = commit("Initial Commit").put("t1", V_1_1).put("t2", V_2_1).put("t3", V_3_1).toBranch(branch);
    final Hash t1Commit = commit("T1 Commit").fromReference(initialCommit).put("t1", V_1_2).toBranch(branch);
    final Hash t2Commit = commit("T2 Commit").fromReference(initialCommit).delete("t2").toBranch(branch);
    final Hash t3Commit = commit("T3 Commit").fromReference(initialCommit).unchanged("t3").toBranch(branch);
    final Hash extraCommit = commit("Extra Commit").fromReference(t1Commit).put("t1", V_1_3).put("t3", V_3_2).toBranch(branch);
    final Hash newT2Commit = commit("New T2 Commit").fromReference(t2Commit).put("t2", NEW_v2_1).toBranch(branch);
    assertThat(commitsList(branch, false)).contains(commit(newT2Commit, "New T2 Commit"), commit(extraCommit, "Extra Commit"), commit(t3Commit, "T3 Commit"), commit(t2Commit, "T2 Commit"), commit(t1Commit, "T1 Commit"), commit(initialCommit, "Initial Commit"));
    try (Stream<Key> keys = store().getKeys(branch).map(WithType::getValue)) {
        assertThat(keys).containsExactlyInAnyOrder(Key.of("t1"), Key.of("t2"), Key.of("t3"));
    }
    assertThat(store().getValues(branch, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3")))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(Key.of("t1"), V_1_3, Key.of("t2"), NEW_v2_1, Key.of("t3"), V_3_2));
    assertThat(store().getValues(newT2Commit, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3")))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(Key.of("t1"), V_1_3, Key.of("t2"), NEW_v2_1, Key.of("t3"), V_3_2));
    assertThat(store().getValues(extraCommit, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3")))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(Key.of("t1"), V_1_3, Key.of("t3"), V_3_2));
    assertThat(store().getValues(t3Commit, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3")))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(Key.of("t1"), V_1_2, Key.of("t3"), V_3_1));
    assertThat(store().getValues(t2Commit, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3")))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(Key.of("t1"), V_1_2, Key.of("t3"), V_3_1));
    assertThat(store().getValues(t1Commit, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3")))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(Key.of("t1"), V_1_2, Key.of("t2"), V_2_1, Key.of("t3"), V_3_1));
}
Also used : WithType(org.projectnessie.versioned.WithType) BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) Key(org.projectnessie.versioned.Key) Test(org.junit.jupiter.api.Test)

Example 3 with WithType

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

the class AbstractCommits method commitSomeOperations.

/*
   * Test:
   * - Create a new branch
   * - Add 3 commits in succession with no conflicts to it with put and delete operations
   * - Check commit metadata
   * - Check keys for each commit hash
   * - Check values for each commit hash
   */
@Test
public void commitSomeOperations() throws Exception {
    final BranchName branch = BranchName.of("foo");
    store().create(branch, Optional.empty());
    final Hash initialCommit = commit("Initial Commit").put("t1", V_1_1).put("t2", V_2_1).put("t3", V_3_1).toBranch(branch);
    final Hash secondCommit = commit("Second Commit").put("t1", V_1_2).delete("t2").delete("t3").put("t4", V_4_1).toBranch(branch);
    final Hash thirdCommit = commit("Third Commit").put("t2", V_2_2).unchanged("t4").toBranch(branch);
    assertThat(commitsList(branch, false)).contains(commit(thirdCommit, "Third Commit"), commit(secondCommit, "Second Commit"), commit(initialCommit, "Initial Commit"));
    try (Stream<Key> keys = store().getKeys(branch).map(WithType::getValue)) {
        assertThat(keys).containsExactlyInAnyOrder(Key.of("t1"), Key.of("t2"), Key.of("t4"));
    }
    try (Stream<Key> keys = store().getKeys(secondCommit).map(WithType::getValue)) {
        assertThat(keys).containsExactlyInAnyOrder(Key.of("t1"), Key.of("t4"));
    }
    try (Stream<Key> keys = store().getKeys(initialCommit).map(WithType::getValue)) {
        assertThat(keys).containsExactlyInAnyOrder(Key.of("t1"), Key.of("t2"), Key.of("t3"));
    }
    assertThat(store().getValues(secondCommit, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3"), Key.of("t4")))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(Key.of("t1"), V_1_2, Key.of("t4"), V_4_1));
    assertThat(store().getValues(initialCommit, Arrays.asList(Key.of("t1"), Key.of("t2"), Key.of("t3"), Key.of("t4")))).containsExactlyInAnyOrderEntriesOf(ImmutableMap.of(Key.of("t1"), V_1_1, Key.of("t2"), V_2_1, Key.of("t3"), V_3_1));
    assertThat(store().getValue(branch, Key.of("t1"))).isEqualTo(V_1_2);
    assertThat(store().getValue(branch, Key.of("t2"))).isEqualTo(V_2_2);
    assertThat(store().getValue(branch, Key.of("t3"))).isNull();
    assertThat(store().getValue(branch, Key.of("t4"))).isEqualTo(V_4_1);
    assertThat(store().getValue(secondCommit, Key.of("t1"))).isEqualTo(V_1_2);
    assertThat(store().getValue(secondCommit, Key.of("t2"))).isNull();
    assertThat(store().getValue(secondCommit, Key.of("t3"))).isNull();
    assertThat(store().getValue(secondCommit, Key.of("t4"))).isEqualTo(V_4_1);
    assertThat(store().getValue(initialCommit, Key.of("t1"))).isEqualTo(V_1_1);
    assertThat(store().getValue(initialCommit, Key.of("t2"))).isEqualTo(V_2_1);
    assertThat(store().getValue(initialCommit, Key.of("t3"))).isEqualTo(V_3_1);
    assertThat(store().getValue(initialCommit, Key.of("t4"))).isNull();
}
Also used : WithType(org.projectnessie.versioned.WithType) BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) Key(org.projectnessie.versioned.Key) Test(org.junit.jupiter.api.Test)

Aggregations

BranchName (org.projectnessie.versioned.BranchName)3 Key (org.projectnessie.versioned.Key)3 WithType (org.projectnessie.versioned.WithType)3 Test (org.junit.jupiter.api.Test)2 Hash (org.projectnessie.versioned.Hash)2 Sets (com.google.common.collect.Sets)1 Principal (java.security.Principal)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Callable (java.util.concurrent.Callable)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Nullable (javax.annotation.Nullable)1 NamespaceApi (org.projectnessie.api.NamespaceApi)1 MultipleNamespacesParams (org.projectnessie.api.params.MultipleNamespacesParams)1 NamespaceParams (org.projectnessie.api.params.NamespaceParams)1 NessieNamespaceAlreadyExistsException (org.projectnessie.error.NessieNamespaceAlreadyExistsException)1