Search in sources :

Example 11 with FlowEntity

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));
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) FlowSnapshotEntity(org.apache.nifi.registry.db.entity.FlowSnapshotEntity) OutputStream(java.io.OutputStream) VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) Date(java.util.Date) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) Test(org.junit.Test)

Example 12 with FlowEntity

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());
    }
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) FlowSnapshotEntity(org.apache.nifi.registry.db.entity.FlowSnapshotEntity) ResourceNotFoundException(org.apache.nifi.registry.exception.ResourceNotFoundException) Date(java.util.Date) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) Test(org.junit.Test)

Example 13 with FlowEntity

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());
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) Date(java.util.Date) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) Test(org.junit.Test)

Example 14 with FlowEntity

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());
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) Date(java.util.Date) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) Test(org.junit.Test)

Example 15 with FlowEntity

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

Aggregations

FlowEntity (org.apache.nifi.registry.db.entity.FlowEntity)46 BucketEntity (org.apache.nifi.registry.db.entity.BucketEntity)30 Test (org.junit.Test)27 Date (java.util.Date)20 FlowSnapshotEntity (org.apache.nifi.registry.db.entity.FlowSnapshotEntity)16 ResourceNotFoundException (org.apache.nifi.registry.exception.ResourceNotFoundException)12 VersionedFlow (org.apache.nifi.registry.flow.VersionedFlow)10 VersionedFlowSnapshotMetadata (org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata)9 VersionedFlowSnapshot (org.apache.nifi.registry.flow.VersionedFlowSnapshot)7 ArrayList (java.util.ArrayList)5 Bucket (org.apache.nifi.registry.bucket.Bucket)5 BucketItemEntity (org.apache.nifi.registry.db.entity.BucketItemEntity)5 InputStream (java.io.InputStream)3 TreeSet (java.util.TreeSet)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FlowSnapshotContext (org.apache.nifi.registry.flow.FlowSnapshotContext)2 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)2 StandardFlowSnapshotContext (org.apache.nifi.registry.provider.flow.StandardFlowSnapshotContext)2 Nullable (org.springframework.lang.Nullable)2