use of org.projectnessie.versioned.ReferenceConflictException in project nessie by projectnessie.
the class TreeApiImpl method assignReference.
protected void assignReference(NamedRef ref, String oldHash, Reference assignTo) throws NessieNotFoundException, NessieConflictException {
try {
ReferenceInfo<CommitMeta> resolved = getStore().getNamedRef(ref.getName(), GetNamedRefsParams.DEFAULT);
getStore().assign(resolved.getNamedRef(), toHash(oldHash, true), toHash(assignTo.getName(), assignTo.getHash()));
} catch (ReferenceNotFoundException e) {
throw new NessieReferenceNotFoundException(e.getMessage(), e);
} catch (ReferenceConflictException e) {
throw new NessieReferenceConflictException(e.getMessage(), e);
}
}
use of org.projectnessie.versioned.ReferenceConflictException in project nessie by projectnessie.
the class TreeApiImpl method commitMultipleOperations.
@Override
public Branch commitMultipleOperations(String branch, String hash, Operations operations) throws NessieNotFoundException, NessieConflictException {
List<org.projectnessie.versioned.Operation<Content>> ops = operations.getOperations().stream().map(TreeApiImpl::toOp).collect(ImmutableList.toImmutableList());
CommitMeta commitMeta = operations.getCommitMeta();
if (commitMeta.getCommitter() != null) {
throw new IllegalArgumentException("Cannot set the committer on the client side. It is set by the server.");
}
try {
Hash newHash = getStore().commit(BranchName.of(Optional.ofNullable(branch).orElse(getConfig().getDefaultBranch())), Optional.ofNullable(hash).map(Hash::of), commitMetaUpdate().apply(commitMeta), ops);
return Branch.of(branch, newHash.asString());
} catch (ReferenceNotFoundException e) {
throw new NessieReferenceNotFoundException(e.getMessage(), e);
} catch (ReferenceConflictException e) {
throw new NessieReferenceConflictException(e.getMessage(), e);
}
}
use of org.projectnessie.versioned.ReferenceConflictException 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.versioned.ReferenceConflictException 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.versioned.ReferenceConflictException in project nessie by projectnessie.
the class AbstractAssign method assignReferenceToFreshMain.
/**
* Assigning a branch/tag to a fresh main without any commits didn't work in 0.9.2
*/
@Test
public void assignReferenceToFreshMain() throws ReferenceNotFoundException, ReferenceAlreadyExistsException, ReferenceConflictException {
ReferenceInfo<CommitMessage> main = store.getNamedRef("main", GetNamedRefsParams.DEFAULT);
try (Stream<Commit<CommitMessage, BaseContent>> commits = store().getCommits(main.getHash(), false)) {
assertThat(commits).isEmpty();
}
try (Stream<ReferenceInfo<CommitMessage>> refs = store().getNamedRefs(GetNamedRefsParams.DEFAULT)) {
assertThat(refs).extracting(r -> r.getNamedRef().getName()).containsExactly(main.getNamedRef().getName());
}
BranchName testBranch = BranchName.of("testBranch");
Hash testBranchHash = store.create(testBranch, Optional.empty());
store.assign(testBranch, Optional.of(testBranchHash), main.getHash());
assertThat(store.getNamedRef(testBranch.getName(), GetNamedRefsParams.DEFAULT).getHash()).isEqualTo(main.getHash());
TagName testTag = TagName.of("testTag");
Hash testTagHash = store.create(testTag, Optional.empty());
store.assign(testTag, Optional.of(testTagHash), main.getHash());
assertThat(store.getNamedRef(testTag.getName(), GetNamedRefsParams.DEFAULT).getHash()).isEqualTo(main.getHash());
}
Aggregations