use of org.apache.nifi.registry.flow.VersionedFlowSnapshot in project nifi-registry by apache.
the class BucketFlowResource method getFlowVersion.
@GET
@Path("{flowId}/versions/{versionNumber: \\d+}")
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets the given version of a flow", response = VersionedFlowSnapshot.class, extensions = { @Extension(name = "access-policy", properties = { @ExtensionProperty(name = "action", value = "read"), @ExtensionProperty(name = "resource", value = "/buckets/{bucketId}") }) })
@ApiResponses({ @ApiResponse(code = 400, message = HttpStatusMessages.MESSAGE_400), @ApiResponse(code = 401, message = HttpStatusMessages.MESSAGE_401), @ApiResponse(code = 403, message = HttpStatusMessages.MESSAGE_403), @ApiResponse(code = 404, message = HttpStatusMessages.MESSAGE_404), @ApiResponse(code = 409, message = HttpStatusMessages.MESSAGE_409) })
public Response getFlowVersion(@PathParam("bucketId") @ApiParam("The bucket identifier") final String bucketId, @PathParam("flowId") @ApiParam("The flow identifier") final String flowId, @PathParam("versionNumber") @ApiParam("The version number") final Integer versionNumber) {
authorizeBucketAccess(RequestAction.READ, bucketId);
final VersionedFlowSnapshot snapshot = registryService.getFlowSnapshot(bucketId, flowId, versionNumber);
populateLinksAndPermissions(snapshot);
return Response.status(Response.Status.OK).entity(snapshot).build();
}
use of org.apache.nifi.registry.flow.VersionedFlowSnapshot in project nifi-registry by apache.
the class BucketFlowResource method createFlowVersion.
@POST
@Path("{flowId}/versions")
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Creates the next version of a flow", notes = "The version number of the object being created must be the next available version integer. " + "Flow versions are immutable after they are created.", response = VersionedFlowSnapshot.class, extensions = { @Extension(name = "access-policy", properties = { @ExtensionProperty(name = "action", value = "write"), @ExtensionProperty(name = "resource", value = "/buckets/{bucketId}") }) })
@ApiResponses({ @ApiResponse(code = 400, message = HttpStatusMessages.MESSAGE_400), @ApiResponse(code = 401, message = HttpStatusMessages.MESSAGE_401), @ApiResponse(code = 403, message = HttpStatusMessages.MESSAGE_403), @ApiResponse(code = 404, message = HttpStatusMessages.MESSAGE_404), @ApiResponse(code = 409, message = HttpStatusMessages.MESSAGE_409) })
public Response createFlowVersion(@PathParam("bucketId") @ApiParam("The bucket identifier") final String bucketId, @PathParam("flowId") @ApiParam(value = "The flow identifier") final String flowId, @ApiParam(value = "The new versioned flow snapshot.", required = true) final VersionedFlowSnapshot snapshot) {
verifyPathParamsMatchBody(bucketId, flowId, snapshot);
authorizeBucketAccess(RequestAction.WRITE, bucketId);
// bucketId and flowId fields are optional in the body parameter, but required before calling the service layer
setSnaphotMetadataIfMissing(bucketId, flowId, snapshot);
final String userIdentity = NiFiUserUtils.getNiFiUserIdentity();
snapshot.getSnapshotMetadata().setAuthor(userIdentity);
final VersionedFlowSnapshot createdSnapshot = registryService.createFlowSnapshot(snapshot);
if (createdSnapshot.getSnapshotMetadata() != null) {
linkService.populateSnapshotLinks(createdSnapshot.getSnapshotMetadata());
}
if (createdSnapshot.getBucket() != null) {
permissionsService.populateBucketPermissions(createdSnapshot.getBucket());
linkService.populateBucketLinks(createdSnapshot.getBucket());
}
return Response.status(Response.Status.OK).entity(createdSnapshot).build();
}
use of org.apache.nifi.registry.flow.VersionedFlowSnapshot in project nifi-registry by apache.
the class TestRegistryService method testCreateSnapshotVersionNotNextVersion.
@Test(expected = IllegalStateException.class)
public void testCreateSnapshotVersionNotNextVersion() {
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());
// make a snapshot that has the same version as the one being created
final FlowSnapshotEntity existingSnapshot = new FlowSnapshotEntity();
existingSnapshot.setFlowId(snapshot.getSnapshotMetadata().getFlowIdentifier());
existingSnapshot.setVersion(snapshot.getSnapshotMetadata().getVersion());
existingSnapshot.setComments("This is an existing snapshot");
existingSnapshot.setCreated(new Date());
existingSnapshot.setCreatedBy("test-user");
when(metadataService.getFlowById(existingFlow.getId())).thenReturn(existingFlow);
// set the version to something that is not the next one-up version
snapshot.getSnapshotMetadata().setVersion(100);
registryService.createFlowSnapshot(snapshot);
}
Aggregations