Search in sources :

Example 1 with ListingRequestDTO

use of org.apache.nifi.web.api.dto.ListingRequestDTO in project nifi by apache.

the class StandardNiFiServiceFacade method getFlowFileListingRequest.

@Override
public ListingRequestDTO getFlowFileListingRequest(final String connectionId, final String listingRequestId) {
    final Connection connection = connectionDAO.getConnection(connectionId);
    final ListingRequestDTO listRequest = dtoFactory.createListingRequestDTO(connectionDAO.getFlowFileListingRequest(connectionId, listingRequestId));
    // include whether the source and destination are running
    if (connection.getSource() != null) {
        listRequest.setSourceRunning(connection.getSource().isRunning());
    }
    if (connection.getDestination() != null) {
        listRequest.setDestinationRunning(connection.getDestination().isRunning());
    }
    return listRequest;
}
Also used : ListingRequestDTO(org.apache.nifi.web.api.dto.ListingRequestDTO) Connection(org.apache.nifi.connectable.Connection) VersionedConnection(org.apache.nifi.registry.flow.VersionedConnection)

Example 2 with ListingRequestDTO

use of org.apache.nifi.web.api.dto.ListingRequestDTO in project nifi by apache.

the class FlowFileQueueResource method deleteListingRequest.

/**
 * Deletes the specified listing request.
 *
 * @param httpServletRequest request
 * @param connectionId       The connection id
 * @param listingRequestId   The drop request id
 * @return A dropRequestEntity
 */
@DELETE
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/listing-requests/{listing-request-id}")
@ApiOperation(value = "Cancels and/or removes a request to list the contents of this connection.", response = ListingRequestEntity.class, authorizations = { @Authorization(value = "Read Source Data - /data/{component-type}/{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 deleteListingRequest(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The connection id.", required = true) @PathParam("id") final String connectionId, @ApiParam(value = "The listing request id.", required = true) @PathParam("listing-request-id") final String listingRequestId) {
    if (isReplicateRequest()) {
        return replicate(HttpMethod.DELETE);
    }
    return withWriteLock(serviceFacade, new ListingEntity(connectionId, listingRequestId), lookup -> {
        final ConnectionAuthorizable connAuth = lookup.getConnection(connectionId);
        final Authorizable dataAuthorizable = connAuth.getSourceData();
        dataAuthorizable.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
    }, null, (listingEntity) -> {
        // delete the listing request
        final ListingRequestDTO listingRequest = serviceFacade.deleteFlowFileListingRequest(listingEntity.getConnectionId(), listingEntity.getListingRequestId());
        // prune the results as they were already received when the listing completed
        listingRequest.setFlowFileSummaries(null);
        // populate remaining content
        populateRemainingFlowFileListingContent(listingEntity.getConnectionId(), listingRequest);
        // create the response entity
        final ListingRequestEntity entity = new ListingRequestEntity();
        entity.setListingRequest(listingRequest);
        return generateOkResponse(entity).build();
    });
}
Also used : ListingRequestDTO(org.apache.nifi.web.api.dto.ListingRequestDTO) Authorizable(org.apache.nifi.authorization.resource.Authorizable) ConnectionAuthorizable(org.apache.nifi.authorization.ConnectionAuthorizable) ConnectionAuthorizable(org.apache.nifi.authorization.ConnectionAuthorizable) ListingRequestEntity(org.apache.nifi.web.api.entity.ListingRequestEntity) 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)

Example 3 with ListingRequestDTO

use of org.apache.nifi.web.api.dto.ListingRequestDTO in project nifi by apache.

the class FlowFileQueueResource method createFlowFileListing.

/**
 * Creates a request to list the flowfiles in the queue of the specified connection.
 *
 * @param httpServletRequest request
 * @param id                 The id of the connection
 * @return A listRequestEntity
 */
@POST
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}/listing-requests")
@ApiOperation(value = "Lists the contents of the queue in this connection.", response = ListingRequestEntity.class, authorizations = { @Authorization(value = "Read Source Data - /data/{component-type}/{uuid}") })
@ApiResponses(value = { @ApiResponse(code = 202, message = "The request has been accepted. A HTTP response header will contain the URI where the response can be polled."), @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 createFlowFileListing(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The connection id.", required = true) @PathParam("id") final String id) {
    if (isReplicateRequest()) {
        return replicate(HttpMethod.POST);
    }
    final ConnectionEntity requestConnectionEntity = new ConnectionEntity();
    requestConnectionEntity.setId(id);
    return withWriteLock(serviceFacade, requestConnectionEntity, lookup -> {
        final ConnectionAuthorizable connAuth = lookup.getConnection(id);
        final Authorizable dataAuthorizable = connAuth.getSourceData();
        dataAuthorizable.authorize(authorizer, RequestAction.READ, NiFiUserUtils.getNiFiUser());
    }, () -> serviceFacade.verifyListQueue(id), (connectionEntity) -> {
        // ensure the id is the same across the cluster
        final String listingRequestId = generateUuid();
        // submit the listing request
        final ListingRequestDTO listingRequest = serviceFacade.createFlowFileListingRequest(connectionEntity.getId(), listingRequestId);
        populateRemainingFlowFileListingContent(connectionEntity.getId(), listingRequest);
        // create the response entity
        final ListingRequestEntity entity = new ListingRequestEntity();
        entity.setListingRequest(listingRequest);
        // generate the URI where the response will be
        final URI location = URI.create(listingRequest.getUri());
        return Response.status(Status.ACCEPTED).location(location).entity(entity).build();
    });
}
Also used : ListingRequestDTO(org.apache.nifi.web.api.dto.ListingRequestDTO) Authorizable(org.apache.nifi.authorization.resource.Authorizable) ConnectionAuthorizable(org.apache.nifi.authorization.ConnectionAuthorizable) ConnectionAuthorizable(org.apache.nifi.authorization.ConnectionAuthorizable) ListingRequestEntity(org.apache.nifi.web.api.entity.ListingRequestEntity) ConnectionEntity(org.apache.nifi.web.api.entity.ConnectionEntity) URI(java.net.URI) 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 ListingRequestDTO

use of org.apache.nifi.web.api.dto.ListingRequestDTO in project nifi by apache.

the class ListFlowFilesEndpointMerger method mergeResponses.

@Override
protected void mergeResponses(ListingRequestDTO clientDto, Map<NodeIdentifier, ListingRequestDTO> dtoMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) {
    final Comparator<FlowFileSummaryDTO> comparator = new Comparator<FlowFileSummaryDTO>() {

        @Override
        public int compare(final FlowFileSummaryDTO dto1, final FlowFileSummaryDTO dto2) {
            int positionCompare = dto1.getPosition().compareTo(dto2.getPosition());
            if (positionCompare != 0) {
                return positionCompare;
            }
            final String address1 = dto1.getClusterNodeAddress();
            final String address2 = dto2.getClusterNodeAddress();
            if (address1 == null && address2 == null) {
                return 0;
            }
            if (address1 == null) {
                return 1;
            }
            if (address2 == null) {
                return -1;
            }
            return address1.compareTo(address2);
        }
    };
    final NavigableSet<FlowFileSummaryDTO> flowFileSummaries = new TreeSet<>(comparator);
    ListFlowFileState state = null;
    int numStepsCompleted = 0;
    int numStepsTotal = 0;
    int objectCount = 0;
    long byteCount = 0;
    boolean finished = true;
    for (final Map.Entry<NodeIdentifier, ListingRequestDTO> entry : dtoMap.entrySet()) {
        final NodeIdentifier nodeIdentifier = entry.getKey();
        final String nodeAddress = nodeIdentifier.getApiAddress() + ":" + nodeIdentifier.getApiPort();
        final ListingRequestDTO nodeRequest = entry.getValue();
        numStepsTotal++;
        if (Boolean.TRUE.equals(nodeRequest.getFinished())) {
            numStepsCompleted++;
        }
        final QueueSizeDTO nodeQueueSize = nodeRequest.getQueueSize();
        objectCount += nodeQueueSize.getObjectCount();
        byteCount += nodeQueueSize.getByteCount();
        if (!nodeRequest.getFinished()) {
            finished = false;
        }
        if (nodeRequest.getLastUpdated().after(clientDto.getLastUpdated())) {
            clientDto.setLastUpdated(nodeRequest.getLastUpdated());
        }
        // Keep the state with the lowest ordinal value (the "least completed").
        final ListFlowFileState nodeState = ListFlowFileState.valueOfDescription(nodeRequest.getState());
        if (state == null || state.compareTo(nodeState) > 0) {
            state = nodeState;
        }
        if (nodeRequest.getFlowFileSummaries() != null) {
            for (final FlowFileSummaryDTO summaryDTO : nodeRequest.getFlowFileSummaries()) {
                if (summaryDTO.getClusterNodeId() == null || summaryDTO.getClusterNodeAddress() == null) {
                    summaryDTO.setClusterNodeId(nodeIdentifier.getId());
                    summaryDTO.setClusterNodeAddress(nodeAddress);
                }
                flowFileSummaries.add(summaryDTO);
                // Keep the set from growing beyond our max
                if (flowFileSummaries.size() > clientDto.getMaxResults()) {
                    flowFileSummaries.pollLast();
                }
            }
        }
        if (nodeRequest.getFailureReason() != null) {
            clientDto.setFailureReason(nodeRequest.getFailureReason());
        }
    }
    final List<FlowFileSummaryDTO> summaryDTOs = new ArrayList<>(flowFileSummaries);
    clientDto.setFlowFileSummaries(summaryDTOs);
    // depends on invariant if numStepsTotal is 0, so is numStepsCompleted, all steps being completed
    // would be 1
    final int percentCompleted = (numStepsTotal == 0) ? 1 : numStepsCompleted / numStepsTotal;
    clientDto.setPercentCompleted(percentCompleted);
    clientDto.setFinished(finished);
    clientDto.getQueueSize().setByteCount(byteCount);
    clientDto.getQueueSize().setObjectCount(objectCount);
}
Also used : ListingRequestDTO(org.apache.nifi.web.api.dto.ListingRequestDTO) QueueSizeDTO(org.apache.nifi.web.api.dto.QueueSizeDTO) ArrayList(java.util.ArrayList) Comparator(java.util.Comparator) ListFlowFileState(org.apache.nifi.controller.queue.ListFlowFileState) TreeSet(java.util.TreeSet) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Map(java.util.Map) FlowFileSummaryDTO(org.apache.nifi.web.api.dto.FlowFileSummaryDTO)

Example 5 with ListingRequestDTO

use of org.apache.nifi.web.api.dto.ListingRequestDTO in project nifi by apache.

the class StandardNiFiServiceFacade method createFlowFileListingRequest.

@Override
public ListingRequestDTO createFlowFileListingRequest(final String connectionId, final String listingRequestId) {
    final Connection connection = connectionDAO.getConnection(connectionId);
    final ListingRequestDTO listRequest = dtoFactory.createListingRequestDTO(connectionDAO.createFlowFileListingRequest(connectionId, listingRequestId));
    // include whether the source and destination are running
    if (connection.getSource() != null) {
        listRequest.setSourceRunning(connection.getSource().isRunning());
    }
    if (connection.getDestination() != null) {
        listRequest.setDestinationRunning(connection.getDestination().isRunning());
    }
    return listRequest;
}
Also used : ListingRequestDTO(org.apache.nifi.web.api.dto.ListingRequestDTO) Connection(org.apache.nifi.connectable.Connection) VersionedConnection(org.apache.nifi.registry.flow.VersionedConnection)

Aggregations

ListingRequestDTO (org.apache.nifi.web.api.dto.ListingRequestDTO)7 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 Consumes (javax.ws.rs.Consumes)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 ConnectionAuthorizable (org.apache.nifi.authorization.ConnectionAuthorizable)3 Authorizable (org.apache.nifi.authorization.resource.Authorizable)3 Connection (org.apache.nifi.connectable.Connection)3 VersionedConnection (org.apache.nifi.registry.flow.VersionedConnection)3 ListingRequestEntity (org.apache.nifi.web.api.entity.ListingRequestEntity)3 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)1