use of org.apache.nifi.registry.db.entity.FlowEntity in project nifi-registry by apache.
the class TestRegistryService method testCreateFirstSnapshot.
@Test
public void testCreateFirstSnapshot() {
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);
// return a flow with the existing snapshot when getFlowById is called
final FlowEntity existingFlow = new FlowEntity();
existingFlow.setId("flow1");
existingFlow.setName("My Flow");
existingFlow.setDescription("This is my flow.");
existingFlow.setCreated(new Date());
existingFlow.setModified(new Date());
existingFlow.setBucketId(existingBucket.getId());
when(metadataService.getFlowById(existingFlow.getId())).thenReturn(existingFlow);
when(metadataService.getFlowByIdWithSnapshotCounts(existingFlow.getId())).thenReturn(existingFlow);
final VersionedFlowSnapshot createdSnapshot = registryService.createFlowSnapshot(snapshot);
assertNotNull(createdSnapshot);
assertNotNull(createdSnapshot.getSnapshotMetadata());
assertNotNull(createdSnapshot.getFlow());
assertNotNull(createdSnapshot.getBucket());
verify(snapshotSerializer, times(1)).serialize(eq(snapshot.getFlowContents()), any(OutputStream.class));
verify(flowPersistenceProvider, times(1)).saveFlowContent(any(), any());
verify(metadataService, times(1)).createFlowSnapshot(any(FlowSnapshotEntity.class));
}
use of org.apache.nifi.registry.db.entity.FlowEntity in project nifi-registry by apache.
the class TestRegistryService method testGetLatestSnapshotMetadataWhenNoVersionsExist.
@Test
public void testGetLatestSnapshotMetadataWhenNoVersionsExist() {
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);
// return a flow with the existing snapshot when getFlowById is called
final FlowEntity existingFlow = new FlowEntity();
existingFlow.setId("flow1");
existingFlow.setName("My Flow");
existingFlow.setDescription("This is my flow.");
existingFlow.setCreated(new Date());
existingFlow.setModified(new Date());
existingFlow.setBucketId(existingBucket.getId());
when(metadataService.getFlowById(existingFlow.getId())).thenReturn(existingFlow);
final FlowSnapshotEntity existingSnapshot1 = new FlowSnapshotEntity();
existingSnapshot1.setVersion(1);
existingSnapshot1.setFlowId(existingFlow.getId());
existingSnapshot1.setCreatedBy("user1");
existingSnapshot1.setCreated(new Date());
existingSnapshot1.setComments("This is snapshot 1");
when(metadataService.getLatestSnapshot(existingFlow.getId())).thenReturn(null);
try {
registryService.getLatestFlowSnapshotMetadata(existingBucket.getId(), existingFlow.getId());
Assert.fail("Should have thrown exception");
} catch (ResourceNotFoundException e) {
assertEquals("The specified flow ID has no versions", e.getMessage());
}
}
use of org.apache.nifi.registry.db.entity.FlowEntity in project nifi-registry by apache.
the class TestRegistryService method testGetFlowExists.
@Test
public void testGetFlowExists() {
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);
final FlowEntity flowEntity = new FlowEntity();
flowEntity.setId("flow1");
flowEntity.setName("My Flow");
flowEntity.setDescription("This is my flow.");
flowEntity.setCreated(new Date());
flowEntity.setModified(new Date());
flowEntity.setBucketId(existingBucket.getId());
when(metadataService.getFlowByIdWithSnapshotCounts(flowEntity.getId())).thenReturn(flowEntity);
final VersionedFlow versionedFlow = registryService.getFlow(existingBucket.getId(), flowEntity.getId());
assertNotNull(versionedFlow);
assertEquals(flowEntity.getId(), versionedFlow.getIdentifier());
assertEquals(flowEntity.getName(), versionedFlow.getName());
assertEquals(flowEntity.getDescription(), versionedFlow.getDescription());
assertEquals(flowEntity.getBucketId(), versionedFlow.getBucketIdentifier());
assertEquals(existingBucket.getName(), versionedFlow.getBucketName());
assertEquals(flowEntity.getCreated().getTime(), versionedFlow.getCreatedTimestamp());
assertEquals(flowEntity.getModified().getTime(), versionedFlow.getModifiedTimestamp());
}
use of org.apache.nifi.registry.db.entity.FlowEntity 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.FlowEntity 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();
}
}
Aggregations