use of org.apache.nifi.registry.db.entity.BucketEntity in project nifi-registry by apache.
the class TestRegistryService method testCreateSnapshotFlowDoesNotExist.
@Test(expected = ResourceNotFoundException.class)
public void testCreateSnapshotFlowDoesNotExist() {
final VersionedFlowSnapshot snapshot = createSnapshot();
final BucketEntity existingBucket = new BucketEntity();
existingBucket.setId("b1");
existingBucket.setName("My Bucket");
existingBucket.setDescription("This is my bucket");
existingBucket.setCreated(new Date());
when(metadataService.getBucketById(existingBucket.getId())).thenReturn(existingBucket);
when(metadataService.getFlowById(snapshot.getSnapshotMetadata().getFlowIdentifier())).thenReturn(null);
registryService.createFlowSnapshot(snapshot);
}
use of org.apache.nifi.registry.db.entity.BucketEntity in project nifi-registry by apache.
the class TestRegistryService method testUpdateFlow.
@Test
public void testUpdateFlow() throws InterruptedException {
final BucketEntity existingBucket = new BucketEntity();
existingBucket.setId("b1");
existingBucket.setName("My Bucket");
existingBucket.setDescription("This is my bucket");
existingBucket.setCreated(new Date());
final FlowEntity flowToUpdate = new FlowEntity();
flowToUpdate.setId("flow1");
flowToUpdate.setName("My Flow");
flowToUpdate.setDescription("This is my flow.");
flowToUpdate.setCreated(new Date());
flowToUpdate.setModified(new Date());
flowToUpdate.setBucketId(existingBucket.getId());
when(metadataService.getBucketById(existingBucket.getId())).thenReturn(existingBucket);
when(metadataService.getFlowByIdWithSnapshotCounts(flowToUpdate.getId())).thenReturn(flowToUpdate);
when(metadataService.getFlowsByName(flowToUpdate.getName())).thenReturn(Collections.singletonList(flowToUpdate));
doAnswer(updateFlowAnswer()).when(metadataService).updateFlow(any(FlowEntity.class));
final VersionedFlow versionedFlow = new VersionedFlow();
versionedFlow.setBucketIdentifier(flowToUpdate.getBucketId());
versionedFlow.setIdentifier(flowToUpdate.getId());
versionedFlow.setName("New Flow Name");
versionedFlow.setDescription("This is a new description");
Thread.sleep(10);
final VersionedFlow updatedFlow = registryService.updateFlow(versionedFlow);
assertNotNull(updatedFlow);
assertEquals(versionedFlow.getIdentifier(), updatedFlow.getIdentifier());
// name and description should be updated
assertEquals(versionedFlow.getName(), updatedFlow.getName());
assertEquals(versionedFlow.getDescription(), updatedFlow.getDescription());
// other fields should not be updated
assertEquals(flowToUpdate.getBucketId(), updatedFlow.getBucketIdentifier());
assertEquals(flowToUpdate.getCreated().getTime(), updatedFlow.getCreatedTimestamp());
}
use of org.apache.nifi.registry.db.entity.BucketEntity in project nifi-registry by apache.
the class RegistryService method deleteBucket.
public Bucket deleteBucket(final String bucketIdentifier) {
if (bucketIdentifier == null) {
throw new IllegalArgumentException("Bucket identifier cannot be null");
}
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.");
}
// for each flow in the bucket, delete all snapshots from the flow persistence provider
for (final FlowEntity flowEntity : metadataService.getFlowsByBucket(existingBucket.getId())) {
flowPersistenceProvider.deleteAllFlowContent(bucketIdentifier, flowEntity.getId());
}
// now delete the bucket from the metadata provider, which deletes all flows referencing it
metadataService.deleteBucket(existingBucket);
return DataModelMapper.map(existingBucket);
} finally {
writeLock.unlock();
}
}
use of org.apache.nifi.registry.db.entity.BucketEntity in project nifi-registry by apache.
the class RegistryService method getFlowSnapshots.
/**
* Returns all versions of a flow, sorted newest to oldest.
*
* @param bucketIdentifier the id of the bucket to search for the flowIdentifier
* @param flowIdentifier the id of the flow to retrieve from the specified bucket
* @return all versions of the specified flow, sorted newest to oldest
*/
public SortedSet<VersionedFlowSnapshotMetadata> getFlowSnapshots(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");
}
// convert the set of FlowSnapshotEntity to set of VersionedFlowSnapshotMetadata, ordered by version descending
final SortedSet<VersionedFlowSnapshotMetadata> sortedSnapshots = new TreeSet<>(Collections.reverseOrder());
final List<FlowSnapshotEntity> existingFlowSnapshots = metadataService.getSnapshots(existingFlow.getId());
if (existingFlowSnapshots != null) {
existingFlowSnapshots.stream().forEach(s -> sortedSnapshots.add(DataModelMapper.map(existingBucket, s)));
}
return sortedSnapshots;
} finally {
readLock.unlock();
}
}
use of org.apache.nifi.registry.db.entity.BucketEntity in project nifi-registry by apache.
the class RegistryService method getBucketItems.
// ---------------------- BucketItem methods ---------------------------------------------
public List<BucketItem> getBucketItems(final String bucketIdentifier) {
if (bucketIdentifier == null) {
throw new IllegalArgumentException("Bucket identifier cannot be null");
}
readLock.lock();
try {
final BucketEntity bucket = metadataService.getBucketById(bucketIdentifier);
if (bucket == 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 List<BucketItem> bucketItems = new ArrayList<>();
metadataService.getBucketItems(bucket.getId()).stream().forEach(b -> addBucketItem(bucketItems, b));
return bucketItems;
} finally {
readLock.unlock();
}
}
Aggregations