Search in sources :

Example 1 with FunnelEntity

use of org.apache.nifi.web.api.entity.FunnelEntity in project kylo by Teradata.

the class NiFiProcessGroupsRestClientV1 method toFlowSnippet.

/**
 * Converts the specified flow to a flow snippet.
 *
 * @param flow the flow
 * @return the flow snippet
 */
@Nonnull
private FlowSnippetDTO toFlowSnippet(@Nonnull final FlowDTO flow, boolean recursive) {
    final FlowSnippetDTO snippet = new FlowSnippetDTO();
    snippet.setConnections(flow.getConnections().stream().map(ConnectionEntity::getComponent).collect(Collectors.toSet()));
    snippet.setControllerServices(Collections.emptySet());
    snippet.setFunnels(flow.getFunnels().stream().map(FunnelEntity::getComponent).collect(Collectors.toSet()));
    snippet.setInputPorts(flow.getInputPorts().stream().map(PortEntity::getComponent).collect(Collectors.toSet()));
    snippet.setLabels(flow.getLabels().stream().map(LabelEntity::getComponent).collect(Collectors.toSet()));
    snippet.setOutputPorts(flow.getOutputPorts().stream().map(PortEntity::getComponent).collect(Collectors.toSet()));
    snippet.setProcessGroups(flow.getProcessGroups().stream().map(ProcessGroupEntity::getComponent).collect(Collectors.toSet()));
    snippet.setProcessors(flow.getProcessors().stream().map(ProcessorEntity::getComponent).collect(Collectors.toSet()));
    snippet.setRemoteProcessGroups(flow.getRemoteProcessGroups().stream().map(RemoteProcessGroupEntity::getComponent).collect(Collectors.toSet()));
    // Add flow for child process groups
    if (recursive) {
        for (final ProcessGroupDTO processGroup : snippet.getProcessGroups()) {
            processGroup.setContents(getFlowSnippet(processGroup.getId(), true));
        }
    }
    return snippet;
}
Also used : FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) RemoteProcessGroupEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupEntity) ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) FlowSnippetDTO(org.apache.nifi.web.api.dto.FlowSnippetDTO) LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) ConnectionEntity(org.apache.nifi.web.api.entity.ConnectionEntity) RemoteProcessGroupEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupEntity) PortEntity(org.apache.nifi.web.api.entity.PortEntity) Nonnull(javax.annotation.Nonnull)

Example 2 with FunnelEntity

use of org.apache.nifi.web.api.entity.FunnelEntity in project nifi by apache.

the class ProcessGroupResource method getFunnels.

/**
 * Retrieves all the of funnels in this NiFi.
 *
 * @return A funnelsEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/funnels")
@ApiOperation(value = "Gets all funnels", response = FunnelsEntity.class, authorizations = { @Authorization(value = "Read - /process-groups/{uuid}") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 404, message = "The specified resource could not be found."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response getFunnels(@ApiParam(value = "The process group id.", required = true) @PathParam("id") final String groupId) {
    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }
    // authorize access
    serviceFacade.authorizeAccess(lookup -> {
        final Authorizable processGroup = lookup.getProcessGroup(groupId).getAuthorizable();
        processGroup.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
    });
    // get all the funnels
    final Set<FunnelEntity> funnels = serviceFacade.getFunnels(groupId);
    // create the response entity
    final FunnelsEntity entity = new FunnelsEntity();
    entity.setFunnels(funnelResource.populateRemainingFunnelEntitiesContent(funnels));
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) FunnelsEntity(org.apache.nifi.web.api.entity.FunnelsEntity) ComponentAuthorizable(org.apache.nifi.authorization.ComponentAuthorizable) Authorizable(org.apache.nifi.authorization.resource.Authorizable) SnippetAuthorizable(org.apache.nifi.authorization.SnippetAuthorizable) TemplateContentsAuthorizable(org.apache.nifi.authorization.TemplateContentsAuthorizable) ProcessGroupAuthorizable(org.apache.nifi.authorization.ProcessGroupAuthorizable) 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 3 with FunnelEntity

use of org.apache.nifi.web.api.entity.FunnelEntity in project nifi by apache.

the class ProcessGroupResource method createFunnel.

// -------
// funnels
// -------
/**
 * Creates a new Funnel.
 *
 * @param httpServletRequest request
 * @param groupId            The group id
 * @param requestFunnelEntity       A funnelEntity.
 * @return A funnelEntity.
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/funnels")
@ApiOperation(value = "Creates a funnel", response = FunnelEntity.class, authorizations = { @Authorization(value = "Write - /process-groups/{uuid}") })
@ApiResponses(value = { @ApiResponse(code = 400, message = "NiFi was unable to complete the request because it was invalid. The request should not be retried without modification."), @ApiResponse(code = 401, message = "Client could not be authenticated."), @ApiResponse(code = 403, message = "Client is not authorized to make this request."), @ApiResponse(code = 404, message = "The specified resource could not be found."), @ApiResponse(code = 409, message = "The request was valid but NiFi was not in the appropriate state to process it. Retrying the same request later may be successful.") })
public Response createFunnel(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The process group id.", required = true) @PathParam("id") final String groupId, @ApiParam(value = "The funnel configuration details.", required = true) final FunnelEntity requestFunnelEntity) {
    if (requestFunnelEntity == null || requestFunnelEntity.getComponent() == null) {
        throw new IllegalArgumentException("Funnel details must be specified.");
    }
    if (requestFunnelEntity.getRevision() == null || (requestFunnelEntity.getRevision().getVersion() == null || requestFunnelEntity.getRevision().getVersion() != 0)) {
        throw new IllegalArgumentException("A revision of 0 must be specified when creating a new Funnel.");
    }
    if (requestFunnelEntity.getComponent().getId() != null) {
        throw new IllegalArgumentException("Funnel ID cannot be specified.");
    }
    final PositionDTO proposedPosition = requestFunnelEntity.getComponent().getPosition();
    if (proposedPosition != null) {
        if (proposedPosition.getX() == null || proposedPosition.getY() == null) {
            throw new IllegalArgumentException("The x and y coordinate of the proposed position must be specified.");
        }
    }
    if (requestFunnelEntity.getComponent().getParentGroupId() != null && !groupId.equals(requestFunnelEntity.getComponent().getParentGroupId())) {
        throw new IllegalArgumentException(String.format("If specified, the parent process group id %s must be the same as specified in the URI %s", requestFunnelEntity.getComponent().getParentGroupId(), groupId));
    }
    requestFunnelEntity.getComponent().setParentGroupId(groupId);
    if (isReplicateRequest()) {
        return replicate(HttpMethod.POST, requestFunnelEntity);
    }
    return withWriteLock(serviceFacade, requestFunnelEntity, lookup -> {
        final Authorizable processGroup = lookup.getProcessGroup(groupId).getAuthorizable();
        processGroup.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
    }, null, funnelEntity -> {
        // set the processor id as appropriate
        funnelEntity.getComponent().setId(generateUuid());
        // create the funnel and generate the json
        final Revision revision = getRevision(funnelEntity, funnelEntity.getComponent().getId());
        final FunnelEntity entity = serviceFacade.createFunnel(revision, groupId, funnelEntity.getComponent());
        funnelResource.populateRemainingFunnelEntityContent(entity);
        // build the response
        return generateCreatedResponse(URI.create(entity.getUri()), entity).build();
    });
}
Also used : FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) Revision(org.apache.nifi.web.Revision) ComponentAuthorizable(org.apache.nifi.authorization.ComponentAuthorizable) Authorizable(org.apache.nifi.authorization.resource.Authorizable) SnippetAuthorizable(org.apache.nifi.authorization.SnippetAuthorizable) TemplateContentsAuthorizable(org.apache.nifi.authorization.TemplateContentsAuthorizable) ProcessGroupAuthorizable(org.apache.nifi.authorization.ProcessGroupAuthorizable) PositionDTO(org.apache.nifi.web.api.dto.PositionDTO) 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 4 with FunnelEntity

use of org.apache.nifi.web.api.entity.FunnelEntity in project nifi by apache.

the class NiFiWebApiTest method populateFlow.

public static void populateFlow(Client client, String baseUrl, NiFiTestUser user, String clientId) throws Exception {
    // -----------------------------------------------
    // Create a source processor
    // -----------------------------------------------
    // create the local selection processor
    ProcessorDTO processorDTO = new ProcessorDTO();
    processorDTO.setName("Pick up");
    processorDTO.setType(SourceTestProcessor.class.getName());
    // create the revision
    final RevisionDTO revision = new RevisionDTO();
    revision.setClientId(clientId);
    revision.setVersion(0l);
    // create the local selection processor entity
    ProcessorEntity processorEntity = new ProcessorEntity();
    processorEntity.setRevision(revision);
    processorEntity.setComponent(processorDTO);
    // add the processor
    Response response = user.testPost(baseUrl + "/process-groups/root/processors", processorEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
    // get the processors id
    processorEntity = response.readEntity(ProcessorEntity.class);
    processorDTO = processorEntity.getComponent();
    String localSelectionId = processorDTO.getId();
    String localSelectionGroupId = processorDTO.getParentGroupId();
    // -----------------------------------------------
    // Create a termination processor
    // -----------------------------------------------
    // create the termination processor
    processorDTO = new ProcessorDTO();
    processorDTO.setName("End");
    processorDTO.setType(TerminationTestProcessor.class.getName());
    // create the termination processor entity
    processorEntity = new ProcessorEntity();
    processorEntity.setRevision(revision);
    processorEntity.setComponent(processorDTO);
    // add the processor
    response = user.testPost(baseUrl + "/process-groups/root/processors", processorEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
    // get the processors id
    processorEntity = response.readEntity(ProcessorEntity.class);
    processorDTO = processorEntity.getComponent();
    String terminationId = processorDTO.getId();
    String terminationGroupId = processorDTO.getParentGroupId();
    // -----------------------------------------------
    // Connect the two processors
    // -----------------------------------------------
    ConnectableDTO source = new ConnectableDTO();
    source.setId(localSelectionId);
    source.setGroupId(localSelectionGroupId);
    source.setType(ConnectableType.PROCESSOR.name());
    ConnectableDTO target = new ConnectableDTO();
    target.setId(terminationId);
    target.setGroupId(terminationGroupId);
    target.setType(ConnectableType.PROCESSOR.name());
    // create the relationships
    Set<String> relationships = new HashSet<>();
    relationships.add("success");
    // create the connection
    ConnectionDTO connectionDTO = new ConnectionDTO();
    connectionDTO.setSource(source);
    connectionDTO.setDestination(target);
    connectionDTO.setSelectedRelationships(relationships);
    // create the connection entity
    ConnectionEntity connectionEntity = new ConnectionEntity();
    connectionEntity.setRevision(revision);
    connectionEntity.setComponent(connectionDTO);
    // add the processor
    response = user.testPost(baseUrl + "/process-groups/root/connections", connectionEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
    // -----------------------------------------------
    // Create a label
    // -----------------------------------------------
    // create the label
    LabelDTO labelDTO = new LabelDTO();
    labelDTO.setLabel("Test label");
    // create the label entity
    LabelEntity labelEntity = new LabelEntity();
    labelEntity.setRevision(revision);
    labelEntity.setComponent(labelDTO);
    // add the label
    response = user.testPost(baseUrl + "/process-groups/root/labels", labelEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
    // -----------------------------------------------
    // Create a funnel
    // -----------------------------------------------
    // create the funnel
    FunnelDTO funnelDTO = new FunnelDTO();
    // create the funnel entity
    FunnelEntity funnelEntity = new FunnelEntity();
    funnelEntity.setRevision(revision);
    funnelEntity.setComponent(funnelDTO);
    // add the funnel
    response = user.testPost(baseUrl + "/process-groups/root/funnels", funnelEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
    // -----------------------------------------------
    // Create a process group
    // -----------------------------------------------
    // create the process group
    ProcessGroupDTO processGroup = new ProcessGroupDTO();
    processGroup.setName("group name");
    // create the process group entity
    ProcessGroupEntity processGroupEntity = new ProcessGroupEntity();
    processGroupEntity.setRevision(revision);
    processGroupEntity.setComponent(processGroup);
    // add the process group
    response = user.testPost(baseUrl + "/process-groups/root/process-groups", processGroupEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
    // -----------------------------------------------
    // Create an input port
    // -----------------------------------------------
    // create the input port
    PortDTO inputPort = new PortDTO();
    inputPort.setName("input");
    // create the input port entity
    PortEntity inputPortEntity = new PortEntity();
    inputPortEntity.setRevision(revision);
    inputPortEntity.setComponent(inputPort);
    // add the input port
    response = user.testPost(baseUrl + "/process-groups/root/input-ports", inputPortEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
    // -----------------------------------------------
    // Create a output ports
    // -----------------------------------------------
    // create the process group
    PortDTO outputPort = new PortDTO();
    outputPort.setName("output");
    // create the process group entity
    PortEntity outputPortEntity = new PortEntity();
    outputPortEntity.setRevision(revision);
    outputPortEntity.setComponent(outputPort);
    // add the output port
    response = user.testPost(baseUrl + "/process-groups/root/output-ports", outputPortEntity);
    // ensure a successful response
    if (Response.Status.CREATED.getStatusCode() != response.getStatusInfo().getStatusCode()) {
        // since it was unable to create the component attempt to extract an
        // error message from the response body
        final String responseEntity = response.readEntity(String.class);
        throw new Exception("Unable to populate initial flow: " + responseEntity);
    }
}
Also used : ProcessGroupEntity(org.apache.nifi.web.api.entity.ProcessGroupEntity) ConnectionDTO(org.apache.nifi.web.api.dto.ConnectionDTO) PortDTO(org.apache.nifi.web.api.dto.PortDTO) FunnelDTO(org.apache.nifi.web.api.dto.FunnelDTO) ProcessorEntity(org.apache.nifi.web.api.entity.ProcessorEntity) RevisionDTO(org.apache.nifi.web.api.dto.RevisionDTO) Response(javax.ws.rs.core.Response) FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) LabelEntity(org.apache.nifi.web.api.entity.LabelEntity) ProcessorDTO(org.apache.nifi.web.api.dto.ProcessorDTO) TerminationTestProcessor(org.apache.nifi.integration.util.TerminationTestProcessor) LabelDTO(org.apache.nifi.web.api.dto.LabelDTO) ProcessGroupDTO(org.apache.nifi.web.api.dto.ProcessGroupDTO) SourceTestProcessor(org.apache.nifi.integration.util.SourceTestProcessor) ConnectableDTO(org.apache.nifi.web.api.dto.ConnectableDTO) ConnectionEntity(org.apache.nifi.web.api.entity.ConnectionEntity) HashSet(java.util.HashSet) PortEntity(org.apache.nifi.web.api.entity.PortEntity)

Example 5 with FunnelEntity

use of org.apache.nifi.web.api.entity.FunnelEntity in project nifi by apache.

the class ITFunnelAccessControl method testNoneUserGetFunnel.

/**
 * Ensures the NONE user can get a funnel.
 *
 * @throws Exception ex
 */
@Test
public void testNoneUserGetFunnel() throws Exception {
    final FunnelEntity entity = getRandomFunnel(helper.getNoneUser());
    assertFalse(entity.getPermissions().getCanRead());
    assertFalse(entity.getPermissions().getCanWrite());
    assertNull(entity.getComponent());
}
Also used : FunnelEntity(org.apache.nifi.web.api.entity.FunnelEntity) Test(org.junit.Test)

Aggregations

FunnelEntity (org.apache.nifi.web.api.entity.FunnelEntity)21 Response (javax.ws.rs.core.Response)8 Test (org.junit.Test)8 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 Consumes (javax.ws.rs.Consumes)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 Authorizable (org.apache.nifi.authorization.resource.Authorizable)5 FunnelDTO (org.apache.nifi.web.api.dto.FunnelDTO)5 PositionDTO (org.apache.nifi.web.api.dto.PositionDTO)5 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)4 HashMap (java.util.HashMap)3 ConnectionEntity (org.apache.nifi.web.api.entity.ConnectionEntity)3 LabelEntity (org.apache.nifi.web.api.entity.LabelEntity)3 PortEntity (org.apache.nifi.web.api.entity.PortEntity)3 ProcessGroupEntity (org.apache.nifi.web.api.entity.ProcessGroupEntity)3 ProcessorEntity (org.apache.nifi.web.api.entity.ProcessorEntity)3 Map (java.util.Map)2 GET (javax.ws.rs.GET)2