Search in sources :

Example 6 with Namespace

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

the class AbstractRestEntries method checkNamespaces.

private void checkNamespaces(Reference reference, List<String> knownNamespaces, List<ContentKey> knownContentKeys) throws NessieReferenceNotFoundException, NessieNamespaceNotFoundException {
    assertThat(getApi().getMultipleNamespaces().reference(reference).namespace("a").get().getNamespaces()).hasSize(4);
    for (String namespace : knownNamespaces) {
        Namespace ns = Namespace.parse(namespace);
        assertThat(getApi().getNamespace().reference(reference).namespace(ns).get()).isNotNull();
        assertThatThrownBy(() -> getApi().createNamespace().reference(reference).namespace(ns).create()).isInstanceOf(NessieNamespaceAlreadyExistsException.class).hasMessage(String.format("Namespace '%s' already exists", namespace));
        assertThatThrownBy(() -> getApi().deleteNamespace().reference(reference).namespace(ns).delete()).isInstanceOf(NessieNamespaceNotEmptyException.class).hasMessage(String.format("Namespace '%s' is not empty", namespace));
    }
    // unknown in the sense that these are actual tables and not namespaces
    List<String> unknownNamespaces = knownContentKeys.stream().map(ContentKey::toString).collect(Collectors.toList());
    for (String namespace : unknownNamespaces) {
        assertThatThrownBy(() -> getApi().getNamespace().reference(reference).namespace(Namespace.parse(namespace)).get()).isInstanceOf(NessieNamespaceNotFoundException.class).hasMessage(String.format("Namespace '%s' does not exist", namespace));
    }
}
Also used : NessieNamespaceNotEmptyException(org.projectnessie.error.NessieNamespaceNotEmptyException) NessieNamespaceAlreadyExistsException(org.projectnessie.error.NessieNamespaceAlreadyExistsException) NessieNamespaceNotFoundException(org.projectnessie.error.NessieNamespaceNotFoundException) Namespace(org.projectnessie.model.Namespace)

Example 7 with Namespace

use of org.projectnessie.model.Namespace 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 8 with Namespace

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

the class NamespaceApiImpl method getNamespaces.

@Override
public GetNamespacesResponse getNamespaces(MultipleNamespacesParams params) throws NessieReferenceNotFoundException {
    BranchName branch = branchFromRefName(params.getRefName());
    try {
        Set<Namespace> allNamespaces = Sets.newHashSet(getExplicitlyCreatedNamespaces(params, branch));
        List<Namespace> implicitlyCreatedNamespaces = getImplicitlyCreatedNamespaces(params, branch);
        allNamespaces.addAll(implicitlyCreatedNamespaces);
        return ImmutableGetNamespacesResponse.builder().addAllNamespaces(allNamespaces).build();
    } catch (ReferenceNotFoundException e) {
        throw refNotFoundException(e);
    }
}
Also used : NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) BranchName(org.projectnessie.versioned.BranchName) Namespace(org.projectnessie.model.Namespace)

Example 9 with Namespace

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

the class NamespaceApiImpl method createNamespace.

@Override
public Namespace createNamespace(NamespaceParams params) throws NessieNamespaceAlreadyExistsException, NessieReferenceNotFoundException {
    try {
        BranchName branch = branchFromRefName(params.getRefName());
        Callable<Void> validator = () -> {
            if (getExplicitlyCreatedNamespace(params, branch).isPresent()) {
                throw namespaceAlreadyExistsException(params);
            }
            if (getImplicitlyCreatedNamespace(params, branch).isPresent()) {
                throw namespaceAlreadyExistsException(params);
            }
            return null;
        };
        Namespace namespace = params.getNamespace();
        Put put = Put.of(ContentKey.of(namespace.getElements()), namespace);
        commit(branch, "create namespace " + namespace.name(), TreeApiImpl.toOp(put), validator);
        return namespace;
    } catch (ReferenceNotFoundException | ReferenceConflictException e) {
        throw new NessieReferenceNotFoundException(e.getMessage(), e);
    }
}
Also used : NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) BranchName(org.projectnessie.versioned.BranchName) Namespace(org.projectnessie.model.Namespace) Put(org.projectnessie.model.Operation.Put)

Example 10 with Namespace

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

the class AbstractRestMergeTransplant method mergeWithNamespaces.

@ParameterizedTest
@EnumSource(value = ReferenceMode.class, mode = Mode.EXCLUDE, // merge requires the hash
names = "NAME_ONLY")
public void mergeWithNamespaces(ReferenceMode refMode) throws BaseNessieClientServerException {
    Branch base = createBranch("merge-base");
    Branch branch = createBranch("merge-branch");
    Namespace ns = Namespace.parse("a.b.c");
    // create the same namespace on both branches
    getApi().createNamespace().namespace(ns).refName(branch.getName()).create();
    getApi().createNamespace().namespace(ns).refName(base.getName()).create();
    IcebergTable table1 = IcebergTable.of("merge-table1", 42, 42, 42, 42);
    IcebergTable table2 = IcebergTable.of("merge-table2", 43, 43, 43, 43);
    ContentKey key1 = ContentKey.of(ns, "key1");
    ContentKey key2 = ContentKey.of(ns, "key2");
    Branch committed1 = getApi().commitMultipleOperations().branchName(branch.getName()).hash(branch.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-branch1")).operation(Put.of(key1, table1)).commit();
    assertThat(committed1.getHash()).isNotNull();
    Branch committed2 = getApi().commitMultipleOperations().branchName(branch.getName()).hash(committed1.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-branch2")).operation(Put.of(key1, table1, table1)).commit();
    assertThat(committed2.getHash()).isNotNull();
    getApi().commitMultipleOperations().branchName(base.getName()).hash(base.getHash()).commitMeta(CommitMeta.fromMessage("test-merge-main")).operation(Put.of(key2, table2)).commit();
    getApi().mergeRefIntoBranch().branch(base).fromRef(refMode.transform(committed2)).merge();
    LogResponse log = getApi().getCommitLog().refName(base.getName()).untilHash(base.getHash()).get();
    assertThat(log.getLogEntries().stream().map(LogEntry::getCommitMeta).map(CommitMeta::getMessage)).containsExactly("test-merge-branch2", "test-merge-branch1", "create namespace a.b.c", "test-merge-main", "create namespace a.b.c");
    assertThat(getApi().getEntries().refName(base.getName()).get().getEntries().stream().map(Entry::getName)).containsExactlyInAnyOrder(key1, key2, ContentKey.of(ns.getElements()));
    assertThat(getApi().getNamespace().refName(base.getName()).namespace(ns).get()).isNotNull();
}
Also used : ContentKey(org.projectnessie.model.ContentKey) LogResponse(org.projectnessie.model.LogResponse) LogEntry(org.projectnessie.model.LogResponse.LogEntry) Entry(org.projectnessie.model.EntriesResponse.Entry) Branch(org.projectnessie.model.Branch) IcebergTable(org.projectnessie.model.IcebergTable) CommitMeta(org.projectnessie.model.CommitMeta) Namespace(org.projectnessie.model.Namespace) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Namespace (org.projectnessie.model.Namespace)12 Test (org.junit.jupiter.api.Test)6 Branch (org.projectnessie.model.Branch)6 CommitMeta (org.projectnessie.model.CommitMeta)5 NessieNamespaceAlreadyExistsException (org.projectnessie.error.NessieNamespaceAlreadyExistsException)4 NessieNamespaceNotFoundException (org.projectnessie.error.NessieNamespaceNotFoundException)4 Entry (org.projectnessie.model.EntriesResponse.Entry)4 IcebergTable (org.projectnessie.model.IcebergTable)4 LogResponse (org.projectnessie.model.LogResponse)4 LogEntry (org.projectnessie.model.LogResponse.LogEntry)4 NessieNamespaceNotEmptyException (org.projectnessie.error.NessieNamespaceNotEmptyException)3 NessieReferenceNotFoundException (org.projectnessie.error.NessieReferenceNotFoundException)3 ContentKey (org.projectnessie.model.ContentKey)3 Put (org.projectnessie.model.Operation.Put)3 BranchName (org.projectnessie.versioned.BranchName)3 ReferenceNotFoundException (org.projectnessie.versioned.ReferenceNotFoundException)3 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 NessieReferenceConflictException (org.projectnessie.error.NessieReferenceConflictException)2