Search in sources :

Example 41 with VersionedFlow

use of org.apache.nifi.registry.flow.VersionedFlow in project nifi-registry by apache.

the class TestRegistryService method testCreateFlowWithSameName.

@Test(expected = IllegalStateException.class)
public void testCreateFlowWithSameName() {
    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);
    // setup a flow with the same name that already exists
    final FlowEntity flowWithSameName = new FlowEntity();
    flowWithSameName.setId("flow1");
    flowWithSameName.setName("Flow 1");
    flowWithSameName.setDescription("This is flow 1");
    flowWithSameName.setCreated(new Date());
    flowWithSameName.setModified(new Date());
    when(metadataService.getFlowsByName(existingBucket.getId(), flowWithSameName.getName())).thenReturn(Collections.singletonList(flowWithSameName));
    final VersionedFlow versionedFlow = new VersionedFlow();
    versionedFlow.setName(flowWithSameName.getName());
    versionedFlow.setBucketIdentifier("b1");
    registryService.createFlow(versionedFlow.getBucketIdentifier(), versionedFlow);
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) Date(java.util.Date) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) Test(org.junit.Test)

Example 42 with VersionedFlow

use of org.apache.nifi.registry.flow.VersionedFlow in project nifi-registry by apache.

the class TestRegistryService method testDeleteFlowWithSnapshots.

@Test
public void testDeleteFlowWithSnapshots() {
    final BucketEntity existingBucket = new BucketEntity();
    existingBucket.setId("b1");
    existingBucket.setName("My Bucket");
    existingBucket.setDescription("This is my bucket");
    existingBucket.setCreated(new Date());
    final FlowEntity flowToDelete = new FlowEntity();
    flowToDelete.setId("flow1");
    flowToDelete.setName("My Flow");
    flowToDelete.setDescription("This is my flow.");
    flowToDelete.setCreated(new Date());
    flowToDelete.setModified(new Date());
    flowToDelete.setBucketId(existingBucket.getId());
    when(metadataService.getBucketById(existingBucket.getId())).thenReturn(existingBucket);
    when(metadataService.getFlowById(flowToDelete.getId())).thenReturn(flowToDelete);
    when(metadataService.getFlowsByName(flowToDelete.getName())).thenReturn(Collections.singletonList(flowToDelete));
    final VersionedFlow deletedFlow = registryService.deleteFlow(existingBucket.getId(), flowToDelete.getId());
    assertNotNull(deletedFlow);
    assertEquals(flowToDelete.getId(), deletedFlow.getIdentifier());
    verify(flowPersistenceProvider, times(1)).deleteAllFlowContent(flowToDelete.getBucketId(), flowToDelete.getId());
    verify(metadataService, times(1)).deleteFlow(flowToDelete);
}
Also used : BucketEntity(org.apache.nifi.registry.db.entity.BucketEntity) VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) Date(java.util.Date) FlowEntity(org.apache.nifi.registry.db.entity.FlowEntity) Test(org.junit.Test)

Example 43 with VersionedFlow

use of org.apache.nifi.registry.flow.VersionedFlow in project nifi-registry by apache.

the class BucketFlowResource method getFlow.

@GET
@Path("{flowId}")
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets a flow", response = VersionedFlow.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 getFlow(@PathParam("bucketId") @ApiParam("The bucket identifier") final String bucketId, @PathParam("flowId") @ApiParam("The flow identifier") final String flowId) {
    authorizeBucketAccess(RequestAction.READ, bucketId);
    final VersionedFlow flow = registryService.getFlow(bucketId, flowId);
    permissionsService.populateItemPermissions(flow);
    linkService.populateFlowLinks(flow);
    return Response.status(Response.Status.OK).entity(flow).build();
}
Also used : VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) 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 44 with VersionedFlow

use of org.apache.nifi.registry.flow.VersionedFlow in project nifi-registry by apache.

the class BucketFlowResource method createFlow.

@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Creates a flow", notes = "The flow id is created by the server and populated in the returned entity.", response = VersionedFlow.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 createFlow(@PathParam("bucketId") @ApiParam("The bucket identifier") final String bucketId, @ApiParam(value = "The details of the flow to create.", required = true) final VersionedFlow flow) {
    authorizeBucketAccess(RequestAction.WRITE, bucketId);
    verifyPathParamsMatchBody(bucketId, flow);
    final VersionedFlow createdFlow = registryService.createFlow(bucketId, flow);
    permissionsService.populateItemPermissions(createdFlow);
    linkService.populateFlowLinks(createdFlow);
    return Response.status(Response.Status.OK).entity(createdFlow).build();
}
Also used : VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) 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 45 with VersionedFlow

use of org.apache.nifi.registry.flow.VersionedFlow in project nifi-registry by apache.

the class BucketFlowResource method deleteFlow.

@DELETE
@Path("{flowId}")
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Deletes a flow, including all saved versions of that flow.", response = VersionedFlow.class, extensions = { @Extension(name = "access-policy", properties = { @ExtensionProperty(name = "action", value = "delete"), @ExtensionProperty(name = "resource", value = "/buckets/{bucketId}") }) })
@ApiResponses({ @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 deleteFlow(@PathParam("bucketId") @ApiParam("The bucket identifier") final String bucketId, @PathParam("flowId") @ApiParam("The flow identifier") final String flowId) {
    authorizeBucketAccess(RequestAction.DELETE, bucketId);
    final VersionedFlow deletedFlow = registryService.deleteFlow(bucketId, flowId);
    return Response.status(Response.Status.OK).entity(deletedFlow).build();
}
Also used : VersionedFlow(org.apache.nifi.registry.flow.VersionedFlow) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

VersionedFlow (org.apache.nifi.registry.flow.VersionedFlow)46 Test (org.junit.Test)19 Bucket (org.apache.nifi.registry.bucket.Bucket)12 BucketEntity (org.apache.nifi.registry.db.entity.BucketEntity)11 FlowEntity (org.apache.nifi.registry.db.entity.FlowEntity)11 VersionedFlowSnapshot (org.apache.nifi.registry.flow.VersionedFlowSnapshot)11 VersionedFlowSnapshotMetadata (org.apache.nifi.registry.flow.VersionedFlowSnapshotMetadata)10 Date (java.util.Date)9 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)8 ApiOperation (io.swagger.annotations.ApiOperation)7 ApiResponses (io.swagger.annotations.ApiResponses)7 Consumes (javax.ws.rs.Consumes)7 Produces (javax.ws.rs.Produces)7 ArrayList (java.util.ArrayList)6 Path (javax.ws.rs.Path)6 IOException (java.io.IOException)5 FlowClient (org.apache.nifi.registry.client.FlowClient)5 NiFiRegistryException (org.apache.nifi.registry.client.NiFiRegistryException)5 TreeSet (java.util.TreeSet)3 Response (javax.ws.rs.core.Response)3