Search in sources :

Example 11 with ReferenceNotFoundException

use of org.projectnessie.versioned.ReferenceNotFoundException 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 ReferenceNotFoundException

use of org.projectnessie.versioned.ReferenceNotFoundException 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 ReferenceNotFoundException

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

the class ContentApiImpl method getMultipleContents.

@Override
public GetMultipleContentsResponse getMultipleContents(String namedRef, String hashOnRef, GetMultipleContentsRequest request) throws NessieNotFoundException {
    try {
        WithHash<NamedRef> ref = namedRefWithHashOrThrow(namedRef, hashOnRef);
        List<ContentKey> externalKeys = request.getRequestedKeys();
        List<Key> internalKeys = externalKeys.stream().map(ContentApiImpl::toKey).collect(Collectors.toList());
        Map<Key, Content> values = getStore().getValues(ref.getHash(), internalKeys);
        List<ContentWithKey> output = values.entrySet().stream().map(e -> ContentWithKey.of(toContentKey(e.getKey()), e.getValue())).collect(Collectors.toList());
        return ImmutableGetMultipleContentsResponse.builder().contents(output).build();
    } catch (ReferenceNotFoundException ex) {
        throw new NessieReferenceNotFoundException(ex.getMessage(), ex);
    }
}
Also used : NamedRef(org.projectnessie.versioned.NamedRef) NessieContentNotFoundException(org.projectnessie.error.NessieContentNotFoundException) GetMultipleContentsResponse(org.projectnessie.model.GetMultipleContentsResponse) ServerConfig(org.projectnessie.services.config.ServerConfig) ContentWithKey(org.projectnessie.model.GetMultipleContentsResponse.ContentWithKey) ContentApi(org.projectnessie.api.ContentApi) GetMultipleContentsRequest(org.projectnessie.model.GetMultipleContentsRequest) Authorizer(org.projectnessie.services.authz.Authorizer) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) Key(org.projectnessie.versioned.Key) Collectors(java.util.stream.Collectors) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) List(java.util.List) Principal(java.security.Principal) VersionStore(org.projectnessie.versioned.VersionStore) Map(java.util.Map) Content(org.projectnessie.model.Content) ContentKey(org.projectnessie.model.ContentKey) ImmutableGetMultipleContentsResponse(org.projectnessie.model.ImmutableGetMultipleContentsResponse) CommitMeta(org.projectnessie.model.CommitMeta) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) WithHash(org.projectnessie.versioned.WithHash) NamedRef(org.projectnessie.versioned.NamedRef) ContentKey(org.projectnessie.model.ContentKey) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) Content(org.projectnessie.model.Content) ContentWithKey(org.projectnessie.model.GetMultipleContentsResponse.ContentWithKey) ContentWithKey(org.projectnessie.model.GetMultipleContentsResponse.ContentWithKey) Key(org.projectnessie.versioned.Key) ContentKey(org.projectnessie.model.ContentKey)

Example 14 with ReferenceNotFoundException

use of org.projectnessie.versioned.ReferenceNotFoundException 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 15 with ReferenceNotFoundException

use of org.projectnessie.versioned.ReferenceNotFoundException 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)

Aggregations

ReferenceNotFoundException (org.projectnessie.versioned.ReferenceNotFoundException)33 ReferenceConflictException (org.projectnessie.versioned.ReferenceConflictException)25 Hash (org.projectnessie.versioned.Hash)24 RefLogNotFoundException (org.projectnessie.versioned.RefLogNotFoundException)17 DatabaseAdapterUtil.randomHash (org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.randomHash)17 ReferenceAlreadyExistsException (org.projectnessie.versioned.ReferenceAlreadyExistsException)16 VersionStoreException (org.projectnessie.versioned.VersionStoreException)14 DatabaseAdapterUtil.verifyExpectedHash (org.projectnessie.versioned.persist.adapter.spi.DatabaseAdapterUtil.verifyExpectedHash)13 NessieReferenceNotFoundException (org.projectnessie.error.NessieReferenceNotFoundException)12 BranchName (org.projectnessie.versioned.BranchName)11 Key (org.projectnessie.versioned.Key)10 NamedRef (org.projectnessie.versioned.NamedRef)9 TagName (org.projectnessie.versioned.TagName)9 List (java.util.List)8 Map (java.util.Map)8 Optional (java.util.Optional)8 Collectors (java.util.stream.Collectors)8 Stream (java.util.stream.Stream)8 CommitLogEntry (org.projectnessie.versioned.persist.adapter.CommitLogEntry)8 ByteString (com.google.protobuf.ByteString)7