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