Search in sources :

Example 21 with BucketEntity

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

the class RegistryService method createFlow.

// ---------------------- VersionedFlow methods ---------------------------------------------
public VersionedFlow createFlow(final String bucketIdentifier, final VersionedFlow versionedFlow) {
    if (StringUtils.isBlank(bucketIdentifier)) {
        throw new IllegalArgumentException("Bucket identifier cannot be null or blank");
    }
    if (versionedFlow == null) {
        throw new IllegalArgumentException("Versioned flow cannot be null");
    }
    if (versionedFlow.getBucketIdentifier() != null && !bucketIdentifier.equals(versionedFlow.getBucketIdentifier())) {
        throw new IllegalArgumentException("Bucket identifiers must match");
    }
    if (versionedFlow.getBucketIdentifier() == null) {
        versionedFlow.setBucketIdentifier(bucketIdentifier);
    }
    versionedFlow.setIdentifier(UUID.randomUUID().toString());
    final long timestamp = System.currentTimeMillis();
    versionedFlow.setCreatedTimestamp(timestamp);
    versionedFlow.setModifiedTimestamp(timestamp);
    validate(versionedFlow, "Cannot create versioned flow");
    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 another flow with the same name doesn't exist
        final List<FlowEntity> flowsWithSameName = metadataService.getFlowsByName(existingBucket.getId(), versionedFlow.getName());
        if (flowsWithSameName != null && flowsWithSameName.size() > 0) {
            throw new IllegalStateException("A versioned flow with the same name already exists in the selected bucket");
        }
        // convert from dto to entity and set the bucket relationship
        final FlowEntity flowEntity = DataModelMapper.map(versionedFlow);
        flowEntity.setBucketId(existingBucket.getId());
        // persist the flow and return the created entity
        final FlowEntity createdFlow = metadataService.createFlow(flowEntity);
        return DataModelMapper.map(existingBucket, createdFlow);
    } 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)

Example 22 with BucketEntity

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

the class TestDatabaseMetadataService method testGetBucketDoesNotExist.

@Test
public void testGetBucketDoesNotExist() {
    final BucketEntity bucket = metadataService.getBucketById("does-not-exist");
    assertNull(bucket);
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) Test(org.junit.Test)

Example 23 with BucketEntity

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

the class TestDatabaseMetadataService method testDeleteBucketNoChildren.

@Test
public void testDeleteBucketNoChildren() {
    final BucketEntity bucket = metadataService.getBucketById("6");
    assertNotNull(bucket);
    metadataService.deleteBucket(bucket);
    final BucketEntity deletedBucket = metadataService.getBucketById("6");
    assertNull(deletedBucket);
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) Test(org.junit.Test)

Example 24 with BucketEntity

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

the class TestDatabaseMetadataService method testGetFlowsByBucket.

@Test
public void testGetFlowsByBucket() {
    final BucketEntity bucketEntity = metadataService.getBucketById("1");
    final List<FlowEntity> flows = metadataService.getFlowsByBucket(bucketEntity.getId());
    assertEquals(2, flows.size());
    final FlowEntity flowEntity = flows.stream().filter(f -> f.getId().equals("1")).findFirst().orElse(null);
    assertNotNull(flowEntity);
    assertEquals(3, flowEntity.getSnapshotCount());
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) Test(org.junit.Test)

Example 25 with BucketEntity

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

the class DataModelMapper method map.

// --- Map buckets
public static BucketEntity map(final Bucket bucket) {
    final BucketEntity bucketEntity = new BucketEntity();
    bucketEntity.setId(bucket.getIdentifier());
    bucketEntity.setName(bucket.getName());
    bucketEntity.setDescription(bucket.getDescription());
    bucketEntity.setCreated(new Date(bucket.getCreatedTimestamp()));
    return bucketEntity;
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) Date(java.util.Date)

Aggregations

BucketEntity (org.apache.nifi.registry.db.entity.BucketEntity)49 Test (org.junit.Test)32 FlowEntity (org.apache.nifi.registry.db.entity.FlowEntity)31 Date (java.util.Date)26 FlowSnapshotEntity (org.apache.nifi.registry.db.entity.FlowSnapshotEntity)16 ResourceNotFoundException (org.apache.nifi.registry.exception.ResourceNotFoundException)14 VersionedFlow (org.apache.nifi.registry.flow.VersionedFlow)11 Bucket (org.apache.nifi.registry.bucket.Bucket)10 VersionedFlowSnapshotMetadata (org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata)9 VersionedFlowSnapshot (org.apache.nifi.registry.flow.VersionedFlowSnapshot)8 ArrayList (java.util.ArrayList)5 InputStream (java.io.InputStream)3 TreeSet (java.util.TreeSet)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 BucketItem (org.apache.nifi.registry.bucket.BucketItem)2 BucketItemEntity (org.apache.nifi.registry.db.entity.BucketItemEntity)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