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));
}
}
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);
}
}
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);
}
}
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);
}
}
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();
}
Aggregations