Search in sources :

Example 36 with VersionedFlowSnapshot

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();
}
Also used : VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 37 with VersionedFlowSnapshot

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();
}
Also used : VersionedFlowSnapshot(org.apache.nifi.registry.flow.VersionedFlowSnapshot) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 38 with VersionedFlowSnapshot

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

Aggregations

VersionedFlowSnapshot (org.apache.nifi.registry.flow.VersionedFlowSnapshot)38 VersionedFlowSnapshotMetadata (org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata)18 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)16 VersionedFlow (org.apache.nifi.registry.flow.VersionedFlow)15 Bucket (org.apache.nifi.registry.bucket.Bucket)12 IOException (java.io.IOException)11 Date (java.util.Date)11 Test (org.junit.Test)11 ApiOperation (io.swagger.annotations.ApiOperation)8 ApiResponses (io.swagger.annotations.ApiResponses)8 Consumes (javax.ws.rs.Consumes)8 Path (javax.ws.rs.Path)8 Produces (javax.ws.rs.Produces)8 Authorizable (org.apache.nifi.authorization.resource.Authorizable)8 VersionedFlowState (org.apache.nifi.registry.flow.VersionedFlowState)8 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)8 VersionControlInformationDTO (org.apache.nifi.web.api.dto.VersionControlInformationDTO)8 HashMap (java.util.HashMap)7 NiFiRegistryException (org.apache.nifi.registry.client.NiFiRegistryException)7 Collections (java.util.Collections)6