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