Search in sources :

Example 11 with ResourceNotFoundException

use of org.apache.nifi.registry.exception.ResourceNotFoundException in project nifi-registry by apache.

the class RegistryService method getFlow.

public VersionedFlow getFlow(final String bucketIdentifier, final String flowIdentifier) {
    if (StringUtils.isBlank(bucketIdentifier)) {
        throw new IllegalArgumentException("Bucket identifier cannot be null or blank");
    }
    if (StringUtils.isBlank(flowIdentifier)) {
        throw new IllegalArgumentException("Versioned flow identifier cannot be null or blank");
    }
    readLock.lock();
    try {
        // ensure the bucket exists
        final BucketEntity existingBucket = metadataService.getBucketById(bucketIdentifier);
        if (existingBucket == null) {
            LOGGER.warn("The specified bucket id [{}] does not exist.", bucketIdentifier);
            throw new ResourceNotFoundException("The specified bucket ID does not exist in this registry.");
        }
        final FlowEntity existingFlow = metadataService.getFlowByIdWithSnapshotCounts(flowIdentifier);
        if (existingFlow == null) {
            LOGGER.warn("The specified flow id [{}] does not exist.", flowIdentifier);
            throw new ResourceNotFoundException("The specified flow ID does not exist in this bucket.");
        }
        if (!existingBucket.getId().equals(existingFlow.getBucketId())) {
            throw new IllegalStateException("The requested flow is not located in the given bucket");
        }
        return DataModelMapper.map(existingBucket, existingFlow);
    } finally {
        readLock.unlock();
    }
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) ResourceNotFoundException(org.apache.nifi.registry.exception.ResourceNotFoundException) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity)

Example 12 with ResourceNotFoundException

use of org.apache.nifi.registry.exception.ResourceNotFoundException in project nifi-registry by apache.

the class RegistryService method updateFlow.

public VersionedFlow updateFlow(final VersionedFlow versionedFlow) {
    if (versionedFlow == null) {
        throw new IllegalArgumentException("Versioned flow cannot be null");
    }
    if (StringUtils.isBlank(versionedFlow.getIdentifier())) {
        throw new IllegalArgumentException("Versioned flow identifier cannot be null or blank");
    }
    if (StringUtils.isBlank(versionedFlow.getBucketIdentifier())) {
        throw new IllegalArgumentException("Versioned flow bucket identifier cannot be null or blank");
    }
    if (versionedFlow.getName() != null && StringUtils.isBlank(versionedFlow.getName())) {
        throw new IllegalArgumentException("Versioned flow name cannot be blank");
    }
    writeLock.lock();
    try {
        // ensure the bucket exists
        final BucketEntity existingBucket = metadataService.getBucketById(versionedFlow.getBucketIdentifier());
        if (existingBucket == null) {
            LOGGER.warn("The specified bucket id [{}] does not exist.", versionedFlow.getBucketIdentifier());
            throw new ResourceNotFoundException("The specified bucket ID does not exist in this registry.");
        }
        final FlowEntity existingFlow = metadataService.getFlowByIdWithSnapshotCounts(versionedFlow.getIdentifier());
        if (existingFlow == null) {
            LOGGER.warn("The specified flow id [{}] does not exist.", versionedFlow.getIdentifier());
            throw new ResourceNotFoundException("The specified flow ID does not exist in this bucket.");
        }
        if (!existingBucket.getId().equals(existingFlow.getBucketId())) {
            throw new IllegalStateException("The requested flow is not located in the given bucket");
        }
        // since we're allowing partial updates here, only check this if a non-null name is provided
        if (StringUtils.isNotBlank(versionedFlow.getName())) {
            final List<FlowEntity> flowsWithSameName = metadataService.getFlowsByName(existingBucket.getId(), versionedFlow.getName());
            if (flowsWithSameName != null) {
                for (final FlowEntity flowWithSameName : flowsWithSameName) {
                    if (!flowWithSameName.getId().equals(existingFlow.getId())) {
                        throw new IllegalStateException("A versioned flow with the same name already exists in the selected bucket");
                    }
                }
            }
        }
        // transfer over the new values to the existing flow
        if (StringUtils.isNotBlank(versionedFlow.getName())) {
            existingFlow.setName(versionedFlow.getName());
        }
        if (versionedFlow.getDescription() != null) {
            existingFlow.setDescription(versionedFlow.getDescription());
        }
        // perform the actual update
        final FlowEntity updatedFlow = metadataService.updateFlow(existingFlow);
        return DataModelMapper.map(existingBucket, updatedFlow);
    } finally {
        writeLock.unlock();
    }
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) ResourceNotFoundException(org.apache.nifi.registry.exception.ResourceNotFoundException) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity)

Example 13 with ResourceNotFoundException

use of org.apache.nifi.registry.exception.ResourceNotFoundException in project nifi-registry by apache.

the class RegistryService method updateBucket.

public Bucket updateBucket(final Bucket bucket) {
    if (bucket == null) {
        throw new IllegalArgumentException("Bucket cannot be null");
    }
    if (bucket.getIdentifier() == null) {
        throw new IllegalArgumentException("Bucket identifier cannot be null");
    }
    if (bucket.getName() != null && StringUtils.isBlank(bucket.getName())) {
        throw new IllegalArgumentException("Bucket name cannot be blank");
    }
    writeLock.lock();
    try {
        // ensure a bucket with the given id exists
        final BucketEntity existingBucketById = metadataService.getBucketById(bucket.getIdentifier());
        if (existingBucketById == null) {
            LOGGER.warn("The specified bucket id [{}] does not exist.", bucket.getIdentifier());
            throw new ResourceNotFoundException("The specified bucket ID does not exist in this registry.");
        }
        // since we're allowing partial updates here, only check this if a non-null name is provided
        if (StringUtils.isNotBlank(bucket.getName())) {
            final List<BucketEntity> bucketsWithSameName = metadataService.getBucketsByName(bucket.getName());
            if (bucketsWithSameName != null) {
                for (final BucketEntity bucketWithSameName : bucketsWithSameName) {
                    if (!bucketWithSameName.getId().equals(existingBucketById.getId())) {
                        throw new IllegalStateException("A bucket with the same name already exists - " + bucket.getName());
                    }
                }
            }
        }
        // transfer over the new values to the existing bucket
        if (StringUtils.isNotBlank(bucket.getName())) {
            existingBucketById.setName(bucket.getName());
        }
        if (bucket.getDescription() != null) {
            existingBucketById.setDescription(bucket.getDescription());
        }
        // perform the actual update
        final BucketEntity updatedBucket = metadataService.updateBucket(existingBucketById);
        return DataModelMapper.map(updatedBucket);
    } finally {
        writeLock.unlock();
    }
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) ResourceNotFoundException(org.apache.nifi.registry.exception.ResourceNotFoundException)

Example 14 with ResourceNotFoundException

use of org.apache.nifi.registry.exception.ResourceNotFoundException in project nifi-registry by apache.

the class RegistryService method deleteFlow.

public VersionedFlow deleteFlow(final String bucketIdentifier, final String flowIdentifier) {
    if (StringUtils.isBlank(bucketIdentifier)) {
        throw new IllegalArgumentException("Bucket identifier cannot be null or blank");
    }
    if (StringUtils.isBlank(flowIdentifier)) {
        throw new IllegalArgumentException("Flow identifier cannot be null or blank");
    }
    writeLock.lock();
    try {
        // ensure the bucket exists
        final BucketEntity existingBucket = metadataService.getBucketById(bucketIdentifier);
        if (existingBucket == null) {
            LOGGER.warn("The specified bucket id [{}] does not exist.", bucketIdentifier);
            throw new ResourceNotFoundException("The specified bucket ID does not exist in this registry.");
        }
        // ensure the flow exists
        final FlowEntity existingFlow = metadataService.getFlowById(flowIdentifier);
        if (existingFlow == null) {
            LOGGER.warn("The specified flow id [{}] does not exist.", flowIdentifier);
            throw new ResourceNotFoundException("The specified flow ID does not exist in this bucket.");
        }
        if (!existingBucket.getId().equals(existingFlow.getBucketId())) {
            throw new IllegalStateException("The requested flow is not located in the given bucket");
        }
        // delete all snapshots from the flow persistence provider
        flowPersistenceProvider.deleteAllFlowContent(existingFlow.getBucketId(), existingFlow.getId());
        // now delete the flow from the metadata provider
        metadataService.deleteFlow(existingFlow);
        return DataModelMapper.map(existingBucket, existingFlow);
    } finally {
        writeLock.unlock();
    }
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) ResourceNotFoundException(org.apache.nifi.registry.exception.ResourceNotFoundException) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity)

Example 15 with ResourceNotFoundException

use of org.apache.nifi.registry.exception.ResourceNotFoundException in project nifi-registry by apache.

the class RegistryService method getFlows.

public List<VersionedFlow> getFlows(final String bucketId) {
    if (StringUtils.isBlank(bucketId)) {
        throw new IllegalArgumentException("Bucket identifier cannot be null");
    }
    readLock.lock();
    try {
        final BucketEntity existingBucket = metadataService.getBucketById(bucketId);
        if (existingBucket == null) {
            LOGGER.warn("The specified bucket id [{}] does not exist.", bucketId);
            throw new ResourceNotFoundException("The specified bucket ID does not exist in this registry.");
        }
        // return non-verbose set of flows for the given bucket
        final List<FlowEntity> flows = metadataService.getFlowsByBucket(existingBucket.getId());
        return flows.stream().map(f -> DataModelMapper.map(existingBucket, f)).collect(Collectors.toList());
    } finally {
        readLock.unlock();
    }
}
Also used : SortedSet(java.util.SortedSet) FlowComparison(org.apache.nifi.registry.flow.diff.FlowComparison) LoggerFactory(org.slf4j.LoggerFactory) StandardFlowComparator(org.apache.nifi.registry.flow.diff.StandardFlowComparator) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) VersionedFlowSnapshotMetadata(org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata) ByteArrayInputStream(java.io.ByteArrayInputStream) VersionedProcessGroup(org.apache.nifi.registry.flow.VersionedProcessGroup) Map(java.util.Map) VersionedComponent(org.apache.nifi.registry.flow.VersionedComponent) ConstraintViolation(javax.validation.ConstraintViolation) FlowSnapshotEntity(org.apache.nifi.registry.db.entity.FlowSnapshotEntity) Validator(javax.validation.Validator) Set(java.util.Set) FlowSnapshotContext(org.apache.nifi.registry.flow.FlowSnapshotContext) UUID(java.util.UUID) Serializer(org.apache.nifi.registry.serialization.Serializer) Collectors(java.util.stream.Collectors) BucketItem(org.apache.nifi.registry.bucket.BucketItem) BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) List(java.util.List) VersionedFlowDifference(org.apache.nifi.registry.diff.VersionedFlowDifference) FlowComparator(org.apache.nifi.registry.flow.diff.FlowComparator) Bucket(org.apache.nifi.registry.bucket.Bucket) StandardComparableDataFlow(org.apache.nifi.registry.flow.diff.StandardComparableDataFlow) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HashMap(java.util.HashMap) ConciseEvolvingDifferenceDescriptor(org.apache.nifi.registry.flow.diff.ConciseEvolvingDifferenceDescriptor) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) BucketItemEntity(org.apache.nifi.registry.db.entity.BucketItemEntity) ObjectUtils(org.apache.commons.lang3.ObjectUtils) ComparableDataFlow(org.apache.nifi.registry.flow.diff.ComparableDataFlow) Service(org.springframework.stereotype.Service) ResourceNotFoundException(org.apache.nifi.registry.exception.ResourceNotFoundException) ComponentDifferenceGroup(org.apache.nifi.registry.diff.ComponentDifferenceGroup) Logger(org.slf4j.Logger) StandardFlowSnapshotContext(org.apache.nifi.registry.provider.flow.StandardFlowSnapshotContext) FlowPersistenceProvider(org.apache.nifi.registry.flow.FlowPersistenceProvider) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) FlowDifference(org.apache.nifi.registry.flow.diff.FlowDifference) Lock(java.util.concurrent.locks.Lock) Validate(org.apache.commons.lang3.Validate) ConstraintViolationException(javax.validation.ConstraintViolationException) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) InputStream(java.io.InputStream) BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) ResourceNotFoundException(org.apache.nifi.registry.exception.ResourceNotFoundException) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity)

Aggregations

ResourceNotFoundException (org.apache.nifi.registry.exception.ResourceNotFoundException)23 BucketEntity (org.apache.nifi.registry.db.entity.BucketEntity)14 FlowEntity (org.apache.nifi.registry.db.entity.FlowEntity)12 ApiOperation (io.swagger.annotations.ApiOperation)9 ApiResponses (io.swagger.annotations.ApiResponses)9 Consumes (javax.ws.rs.Consumes)9 Path (javax.ws.rs.Path)9 Produces (javax.ws.rs.Produces)9 FlowSnapshotEntity (org.apache.nifi.registry.db.entity.FlowSnapshotEntity)7 GET (javax.ws.rs.GET)4 VersionedFlowSnapshotMetadata (org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata)4 TreeSet (java.util.TreeSet)3 DELETE (javax.ws.rs.DELETE)3 User (org.apache.nifi.registry.authorization.User)3 Bucket (org.apache.nifi.registry.bucket.Bucket)3 VersionedFlow (org.apache.nifi.registry.flow.VersionedFlow)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2