Search in sources :

Example 1 with FlowEntity

use of org.apache.nifi.registry.db.entity.FlowEntity in project nifi-registry by apache.

the class DatabaseMetadataService method getItemsWithCounts.

private List<BucketItemEntity> getItemsWithCounts(final Iterable<BucketItemEntity> items) {
    final Map<String, Long> snapshotCounts = getFlowSnapshotCounts();
    final List<BucketItemEntity> itemWithCounts = new ArrayList<>();
    for (final BucketItemEntity item : items) {
        if (item.getType() == BucketItemEntityType.FLOW) {
            final Long snapshotCount = snapshotCounts.get(item.getId());
            if (snapshotCount != null) {
                final FlowEntity flowEntity = (FlowEntity) item;
                flowEntity.setSnapshotCount(snapshotCount);
            }
        }
        itemWithCounts.add(item);
    }
    return itemWithCounts;
}
Also used : BucketItemEntity(org.apache.nifi.registry.db.entity.BucketItemEntity) ArrayList(java.util.ArrayList) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity)

Example 2 with FlowEntity

use of org.apache.nifi.registry.db.entity.FlowEntity in project nifi-registry by apache.

the class DatabaseMetadataService method getFlowsByBucket.

@Override
public List<FlowEntity> getFlowsByBucket(final String bucketIdentifier) {
    final String sql = "SELECT * FROM flow f, bucket_item item WHERE item.bucket_id = ? AND item.id = f.id";
    final List<FlowEntity> flows = jdbcTemplate.query(sql, new Object[] { bucketIdentifier }, new FlowEntityRowMapper());
    final Map<String, Long> snapshotCounts = getFlowSnapshotCounts();
    for (final FlowEntity flowEntity : flows) {
        final Long snapshotCount = snapshotCounts.get(flowEntity.getId());
        if (snapshotCount != null) {
            flowEntity.setSnapshotCount(snapshotCount);
        }
    }
    return flows;
}
Also used : FlowEntityRowMapper(org.apache.nifi.registry.db.mapper.FlowEntityRowMapper) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity)

Example 3 with FlowEntity

use of org.apache.nifi.registry.db.entity.FlowEntity in project nifi-registry by apache.

the class BucketItemEntityRowMapper method mapRow.

@Nullable
@Override
public BucketItemEntity mapRow(ResultSet rs, int rowNum) throws SQLException {
    final BucketItemEntityType type = BucketItemEntityType.valueOf(rs.getString("ITEM_TYPE"));
    // Create the appropriate type of sub-class, eventually populate specific data for each type
    final BucketItemEntity item;
    switch(type) {
        case FLOW:
            item = new FlowEntity();
            break;
        default:
            // should never happen
            item = new BucketItemEntity();
            break;
    }
    // populate fields common to all bucket items
    item.setId(rs.getString("ID"));
    item.setName(rs.getString("NAME"));
    item.setDescription(rs.getString("DESCRIPTION"));
    item.setCreated(rs.getTimestamp("CREATED"));
    item.setModified(rs.getTimestamp("MODIFIED"));
    item.setBucketId(rs.getString("BUCKET_ID"));
    item.setBucketName(rs.getString("BUCKET_NAME"));
    item.setType(type);
    return item;
}
Also used : BucketItemEntityType(org.apache.nifi.registry.db.entity.BucketItemEntityType) BucketItemEntity(org.apache.nifi.registry.db.entity.BucketItemEntity) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) Nullable(org.springframework.lang.Nullable)

Example 4 with FlowEntity

use of org.apache.nifi.registry.db.entity.FlowEntity in project nifi-registry by apache.

the class FlowEntityRowMapper method mapRow.

@Nullable
@Override
public FlowEntity mapRow(ResultSet rs, int rowNum) throws SQLException {
    final FlowEntity flowEntity = new FlowEntity();
    flowEntity.setId(rs.getString("ID"));
    flowEntity.setName(rs.getString("NAME"));
    flowEntity.setDescription(rs.getString("DESCRIPTION"));
    flowEntity.setCreated(rs.getTimestamp("CREATED"));
    flowEntity.setModified(rs.getTimestamp("MODIFIED"));
    flowEntity.setBucketId(rs.getString("BUCKET_ID"));
    flowEntity.setType(BucketItemEntityType.FLOW);
    return flowEntity;
}
Also used : FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) Nullable(org.springframework.lang.Nullable)

Example 5 with FlowEntity

use of org.apache.nifi.registry.db.entity.FlowEntity in project nifi-registry by apache.

the class TestRegistryService method testGetSnapshotDoesNotExistInPersistenceProvider.

@Test(expected = IllegalStateException.class)
public void testGetSnapshotDoesNotExistInPersistenceProvider() {
    final BucketEntity existingBucket = createBucketEntity("b1");
    final FlowEntity existingFlow = createFlowEntity(existingBucket.getId());
    final FlowSnapshotEntity existingSnapshot = createFlowSnapshotEntity(existingFlow.getId());
    existingFlow.setSnapshotCount(10);
    when(metadataService.getBucketById(existingBucket.getId())).thenReturn(existingBucket);
    when(metadataService.getFlowByIdWithSnapshotCounts(existingFlow.getId())).thenReturn(existingFlow);
    when(metadataService.getFlowSnapshot(existingFlow.getId(), existingSnapshot.getVersion())).thenReturn(existingSnapshot);
    when(flowPersistenceProvider.getFlowContent(existingBucket.getId(), existingSnapshot.getFlowId(), existingSnapshot.getVersion())).thenReturn(null);
    registryService.getFlowSnapshot(existingBucket.getId(), existingSnapshot.getFlowId(), existingSnapshot.getVersion());
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) FlowSnapshotEntity(org.apache.nifi.registry.db.entity.FlowSnapshotEntity) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) Test(org.junit.Test)

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