use of org.apache.nifi.registry.db.entity.BucketEntity 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();
}
}
use of org.apache.nifi.registry.db.entity.BucketEntity in project nifi-registry by apache.
the class RegistryService method getFlowSnapshot.
public VersionedFlowSnapshot getFlowSnapshot(final String bucketIdentifier, final String flowIdentifier, final Integer version) {
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");
}
if (version == null) {
throw new IllegalArgumentException("Version cannot be null or blank");
}
readLock.lock();
try {
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.");
}
// we need to populate the version count here so we have to do this retrieval instead of snapshotEntity.getFlow()
final FlowEntity flowEntityWithCount = metadataService.getFlowByIdWithSnapshotCounts(flowIdentifier);
if (flowEntityWithCount == 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(flowEntityWithCount.getBucketId())) {
throw new IllegalStateException("The requested flow is not located in the given bucket");
}
// ensure the snapshot exists
final FlowSnapshotEntity snapshotEntity = metadataService.getFlowSnapshot(flowIdentifier, version);
if (snapshotEntity == null) {
LOGGER.warn("The specified flow snapshot id [{}] does not exist for version [{}].", flowIdentifier, version);
throw new ResourceNotFoundException("The specified versioned flow snapshot does not exist for this flow.");
}
// get the serialized bytes of the snapshot
final byte[] serializedSnapshot = flowPersistenceProvider.getFlowContent(bucketIdentifier, flowIdentifier, version);
if (serializedSnapshot == null || serializedSnapshot.length == 0) {
throw new IllegalStateException("No serialized content found for snapshot with flow identifier " + flowIdentifier + " and version " + version);
}
// deserialize the contents
final InputStream input = new ByteArrayInputStream(serializedSnapshot);
final VersionedProcessGroup flowContents = processGroupSerializer.deserialize(input);
// map entities to data model
final Bucket bucket = DataModelMapper.map(existingBucket);
final VersionedFlow versionedFlow = DataModelMapper.map(existingBucket, flowEntityWithCount);
final VersionedFlowSnapshotMetadata snapshotMetadata = DataModelMapper.map(existingBucket, snapshotEntity);
// create the snapshot to return
final VersionedFlowSnapshot snapshot = new VersionedFlowSnapshot();
snapshot.setFlowContents(flowContents);
snapshot.setSnapshotMetadata(snapshotMetadata);
snapshot.setFlow(versionedFlow);
snapshot.setBucket(bucket);
return snapshot;
} finally {
readLock.unlock();
}
}
use of org.apache.nifi.registry.db.entity.BucketEntity in project nifi-registry by apache.
the class RegistryService method getLatestFlowSnapshotMetadata.
public VersionedFlowSnapshotMetadata getLatestFlowSnapshotMetadata(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");
}
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.");
}
// 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");
}
// get latest snapshot for the flow
final FlowSnapshotEntity latestSnapshot = metadataService.getLatestSnapshot(existingFlow.getId());
if (latestSnapshot == null) {
throw new ResourceNotFoundException("The specified flow ID has no versions");
}
return DataModelMapper.map(existingBucket, latestSnapshot);
} finally {
readLock.unlock();
}
}
use of org.apache.nifi.registry.db.entity.BucketEntity in project nifi-registry by apache.
the class RegistryService method deleteFlowSnapshot.
public VersionedFlowSnapshotMetadata deleteFlowSnapshot(final String bucketIdentifier, final String flowIdentifier, final Integer version) {
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");
}
if (version == null) {
throw new IllegalArgumentException("Version 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");
}
// ensure the snapshot exists
final FlowSnapshotEntity snapshotEntity = metadataService.getFlowSnapshot(flowIdentifier, version);
if (snapshotEntity == null) {
throw new ResourceNotFoundException("Versioned flow snapshot does not exist for flow " + flowIdentifier + " and version " + version);
}
// delete the content of the snapshot
flowPersistenceProvider.deleteFlowContent(bucketIdentifier, flowIdentifier, version);
// delete the snapshot itself
metadataService.deleteFlowSnapshot(snapshotEntity);
return DataModelMapper.map(existingBucket, snapshotEntity);
} finally {
writeLock.unlock();
}
}
use of org.apache.nifi.registry.db.entity.BucketEntity in project nifi-registry by apache.
the class RegistryService method createBucket.
// ---------------------- Bucket methods ---------------------------------------------
public Bucket createBucket(final Bucket bucket) {
if (bucket == null) {
throw new IllegalArgumentException("Bucket cannot be null");
}
// set an id, the created time, and clear out the flows since its read-only
bucket.setIdentifier(UUID.randomUUID().toString());
bucket.setCreatedTimestamp(System.currentTimeMillis());
validate(bucket, "Cannot create Bucket");
writeLock.lock();
try {
final List<BucketEntity> bucketsWithSameName = metadataService.getBucketsByName(bucket.getName());
if (bucketsWithSameName.size() > 0) {
throw new IllegalStateException("A bucket with the same name already exists");
}
final BucketEntity createdBucket = metadataService.createBucket(DataModelMapper.map(bucket));
return DataModelMapper.map(createdBucket);
} finally {
writeLock.unlock();
}
}
Aggregations