Search in sources :

Example 11 with PortEntity

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

the class ProcessGroupResource method getOutputPorts.

/**
 * Retrieves all the of output ports in this NiFi.
 *
 * @return A outputPortsEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/output-ports")
@ApiOperation(value = "Gets all output ports", response = OutputPortsEntity.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 getOutputPorts(@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 output ports
    final Set<PortEntity> outputPorts = serviceFacade.getOutputPorts(groupId);
    // create the response entity
    final OutputPortsEntity entity = new OutputPortsEntity();
    entity.setOutputPorts(outputPortResource.populateRemainingOutputPortEntitiesContent(outputPorts));
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : OutputPortsEntity(org.apache.nifi.web.api.entity.OutputPortsEntity) 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) PortEntity(org.apache.nifi.web.api.entity.PortEntity) 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 12 with PortEntity

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

the class ProcessGroupResource method createInputPort.

// -----------
// input ports
// -----------
/**
 * Creates a new input port.
 *
 * @param httpServletRequest request
 * @param groupId            The group id
 * @param requestPortEntity         A inputPortEntity.
 * @return A inputPortEntity.
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/input-ports")
@ApiOperation(value = "Creates an input port", response = PortEntity.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 createInputPort(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The process group id.", required = true) @PathParam("id") final String groupId, @ApiParam(value = "The input port configuration details.", required = true) final PortEntity requestPortEntity) {
    if (requestPortEntity == null || requestPortEntity.getComponent() == null) {
        throw new IllegalArgumentException("Port details must be specified.");
    }
    if (requestPortEntity.getRevision() == null || (requestPortEntity.getRevision().getVersion() == null || requestPortEntity.getRevision().getVersion() != 0)) {
        throw new IllegalArgumentException("A revision of 0 must be specified when creating a new Input port.");
    }
    if (requestPortEntity.getComponent().getId() != null) {
        throw new IllegalArgumentException("Input port ID cannot be specified.");
    }
    final PositionDTO proposedPosition = requestPortEntity.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 (requestPortEntity.getComponent().getParentGroupId() != null && !groupId.equals(requestPortEntity.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", requestPortEntity.getComponent().getParentGroupId(), groupId));
    }
    requestPortEntity.getComponent().setParentGroupId(groupId);
    if (isReplicateRequest()) {
        return replicate(HttpMethod.POST, requestPortEntity);
    }
    return withWriteLock(serviceFacade, requestPortEntity, lookup -> {
        final Authorizable processGroup = lookup.getProcessGroup(groupId).getAuthorizable();
        processGroup.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser());
    }, null, portEntity -> {
        // set the processor id as appropriate
        portEntity.getComponent().setId(generateUuid());
        // create the input port and generate the json
        final Revision revision = getRevision(portEntity, portEntity.getComponent().getId());
        final PortEntity entity = serviceFacade.createInputPort(revision, groupId, portEntity.getComponent());
        inputPortResource.populateRemainingInputPortEntityContent(entity);
        // build the response
        return generateCreatedResponse(URI.create(entity.getUri()), entity).build();
    });
}
Also used : 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) PortEntity(org.apache.nifi.web.api.entity.PortEntity) 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 13 with PortEntity

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

the class EntityFactory method createPortEntity.

public PortEntity createPortEntity(final PortDTO dto, final RevisionDTO revision, final PermissionsDTO permissions, final PortStatusDTO status, final List<BulletinEntity> bulletins) {
    final PortEntity entity = new PortEntity();
    entity.setRevision(revision);
    if (dto != null) {
        entity.setPermissions(permissions);
        entity.setStatus(status);
        entity.setId(dto.getId());
        entity.setPosition(dto.getPosition());
        entity.setPortType(dto.getType());
        if (permissions != null && permissions.getCanRead()) {
            entity.setComponent(dto);
            entity.setBulletins(bulletins);
        }
    }
    return entity;
}
Also used : RemoteProcessGroupPortEntity(org.apache.nifi.web.api.entity.RemoteProcessGroupPortEntity) PortEntity(org.apache.nifi.web.api.entity.PortEntity)

Example 14 with PortEntity

use of org.apache.nifi.web.api.entity.PortEntity 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 15 with PortEntity

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

the class ITInputPortAccessControl method verifyDelete.

private void verifyDelete(final NiFiTestUser user, final String clientId, final int responseCode) throws Exception {
    final PortEntity entity = createInputPort("Copy");
    // create the entity body
    final Map<String, String> queryParams = new HashMap<>();
    queryParams.put("version", String.valueOf(entity.getRevision().getVersion()));
    queryParams.put("clientId", clientId);
    // perform the request
    Response response = user.testDelete(entity.getUri(), queryParams);
    // ensure the request is failed with a forbidden status code
    assertEquals(responseCode, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) HashMap(java.util.HashMap) PortEntity(org.apache.nifi.web.api.entity.PortEntity)

Aggregations

PortEntity (org.apache.nifi.web.api.entity.PortEntity)52 Response (javax.ws.rs.core.Response)23 Test (org.junit.Test)18 RevisionDTO (org.apache.nifi.web.api.dto.RevisionDTO)17 Authorizable (org.apache.nifi.authorization.resource.Authorizable)16 PortDTO (org.apache.nifi.web.api.dto.PortDTO)16 HashMap (java.util.HashMap)13 ApiOperation (io.swagger.annotations.ApiOperation)10 ApiResponses (io.swagger.annotations.ApiResponses)10 Map (java.util.Map)10 Consumes (javax.ws.rs.Consumes)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)10 FlowDTO (org.apache.nifi.web.api.dto.flow.FlowDTO)9 ProcessGroupFlowEntity (org.apache.nifi.web.api.entity.ProcessGroupFlowEntity)9 ConnectionEntity (org.apache.nifi.web.api.entity.ConnectionEntity)8 FunnelEntity (org.apache.nifi.web.api.entity.FunnelEntity)8 LabelEntity (org.apache.nifi.web.api.entity.LabelEntity)8 ProcessGroupEntity (org.apache.nifi.web.api.entity.ProcessGroupEntity)8