Search in sources :

Example 11 with ReferenceConflictException

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);
    }
}
Also used : NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) NessieReferenceConflictException(org.projectnessie.error.NessieReferenceConflictException) NessieReferenceConflictException(org.projectnessie.error.NessieReferenceConflictException) CommitMeta(org.projectnessie.model.CommitMeta)

Example 12 with ReferenceConflictException

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);
    }
}
Also used : NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) NessieReferenceConflictException(org.projectnessie.error.NessieReferenceConflictException) NessieReferenceConflictException(org.projectnessie.error.NessieReferenceConflictException) Operation(org.projectnessie.model.Operation) CommitMeta(org.projectnessie.model.CommitMeta) WithHash(org.projectnessie.versioned.WithHash) Hash(org.projectnessie.versioned.Hash)

Example 13 with ReferenceConflictException

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);
    }
}
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 ReferenceConflictException

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);
    }
}
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 15 with ReferenceConflictException

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());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Hash(org.projectnessie.versioned.Hash) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CommitMessage(org.projectnessie.versioned.testworker.CommitMessage) Commit(org.projectnessie.versioned.Commit) TagName(org.projectnessie.versioned.TagName) ReferenceAlreadyExistsException(org.projectnessie.versioned.ReferenceAlreadyExistsException) VersionStoreException(org.projectnessie.versioned.VersionStoreException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) GetNamedRefsParams(org.projectnessie.versioned.GetNamedRefsParams) Test(org.junit.jupiter.api.Test) BranchName(org.projectnessie.versioned.BranchName) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) Stream(java.util.stream.Stream) BaseContent(org.projectnessie.versioned.testworker.BaseContent) VersionStore(org.projectnessie.versioned.VersionStore) ReferenceInfo(org.projectnessie.versioned.ReferenceInfo) Optional(java.util.Optional) Commit(org.projectnessie.versioned.Commit) CommitMessage(org.projectnessie.versioned.testworker.CommitMessage) TagName(org.projectnessie.versioned.TagName) BranchName(org.projectnessie.versioned.BranchName) Hash(org.projectnessie.versioned.Hash) ReferenceInfo(org.projectnessie.versioned.ReferenceInfo) Test(org.junit.jupiter.api.Test)

Aggregations

ReferenceConflictException (org.projectnessie.versioned.ReferenceConflictException)27 ReferenceNotFoundException (org.projectnessie.versioned.ReferenceNotFoundException)22 Hash (org.projectnessie.versioned.Hash)21 DatabaseAdapterUtil.randomHash (org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.randomHash)16 RefLogNotFoundException (org.projectnessie.versioned.RefLogNotFoundException)15 ReferenceAlreadyExistsException (org.projectnessie.versioned.ReferenceAlreadyExistsException)12 VersionStoreException (org.projectnessie.versioned.VersionStoreException)12 DatabaseAdapterUtil.verifyExpectedHash (org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.verifyExpectedHash)11 ArrayList (java.util.ArrayList)8 BranchName (org.projectnessie.versioned.BranchName)8 Key (org.projectnessie.versioned.Key)7 CommitLogEntry (org.projectnessie.versioned.persist.adapter.CommitLogEntry)7 GlobalStateLogEntry (org.projectnessie.versioned.persist.serialize.AdapterTypes.GlobalStateLogEntry)7 ByteString (com.google.protobuf.ByteString)6 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)6 Optional (java.util.Optional)6 TagName (org.projectnessie.versioned.TagName)6 RefLogEntry (org.projectnessie.versioned.persist.serialize.AdapterTypes.RefLogEntry)6 Collections (java.util.Collections)5 HashMap (java.util.HashMap)5