Search in sources :

Example 1 with LineageRequestDTO

use of org.apache.nifi.web.api.dto.provenance.lineage.LineageRequestDTO in project nifi by apache.

the class ProvenanceResource method submitLineageRequest.

/**
 * Submits a lineage request based on an event or a flowfile uuid.
 * <p>
 * When querying for the lineage of an event you must specify the eventId and the eventDirection. The eventDirection must be 'parents' or 'children' and specifies whether we are going up or down
 * the flowfile ancestry. The uuid cannot be specified in these cases.
 * <p>
 * When querying for the lineage of a flowfile you must specify the uuid. The eventId and eventDirection cannot be specified in this case.
 *
 * @param httpServletRequest request
 * @param requestLineageEntity      A lineageEntity
 * @return A lineageEntity
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Path("lineage")
@ApiOperation(value = "Submits a lineage query", notes = "Lineage queries may be long running so this endpoint submits a request. The response will include the " + "current state of the query. If the request is not completed the URI in the response can be used at a " + "later time to get the updated state of the query. Once the query has completed the lineage request " + "should be deleted by the client who originally submitted it.", response = LineageEntity.class, authorizations = { @Authorization(value = "Read - /provenance"), @Authorization(value = "Read - /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 submitLineageRequest(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The lineage query details.", required = true) final LineageEntity requestLineageEntity) {
    if (requestLineageEntity == null || requestLineageEntity.getLineage() == null || requestLineageEntity.getLineage().getRequest() == null) {
        throw new IllegalArgumentException("Lineage request must be specified.");
    }
    // ensure the request is well formed
    final LineageDTO requestLineageDto = requestLineageEntity.getLineage();
    final LineageRequestDTO requestDto = requestLineageDto.getRequest();
    // ensure the type has been specified
    if (requestDto.getLineageRequestType() == null) {
        throw new IllegalArgumentException("The type of lineage request must be specified.");
    }
    // validate the remainder of the request
    switch(requestDto.getLineageRequestType()) {
        case CHILDREN:
        case PARENTS:
            // ensure the event has been specified
            if (requestDto.getEventId() == null) {
                throw new IllegalArgumentException("The event id must be specified when the event type is PARENTS or CHILDREN.");
            }
            break;
        case FLOWFILE:
            // ensure the uuid or event id has been specified
            if (requestDto.getUuid() == null && requestDto.getEventId() == null) {
                throw new IllegalArgumentException("The flowfile uuid or event id must be specified when the event type is FLOWFILE.");
            }
            break;
    }
    // replicate if cluster manager
    if (isReplicateRequest()) {
        if (requestDto.getClusterNodeId() == null) {
            throw new IllegalArgumentException("The cluster node identifier must be specified.");
        }
        // change content type to JSON for serializing entity
        final Map<String, String> headersToOverride = new HashMap<>();
        headersToOverride.put("content-type", MediaType.APPLICATION_JSON);
        return replicate(HttpMethod.POST, requestLineageEntity, requestDto.getClusterNodeId(), headersToOverride);
    }
    return withWriteLock(serviceFacade, requestLineageEntity, lookup -> authorizeProvenanceRequest(), null, (lineageEntity) -> {
        final LineageDTO lineageDTO = lineageEntity.getLineage();
        // get the provenance event
        final LineageDTO dto = serviceFacade.submitLineage(lineageDTO);
        populateRemainingLineageContent(dto, lineageDTO.getRequest().getClusterNodeId());
        // create a response entity
        final LineageEntity entity = new LineageEntity();
        entity.setLineage(dto);
        // generate the response
        return generateCreatedResponse(URI.create(dto.getUri()), entity).build();
    });
}
Also used : LineageRequestDTO(org.apache.nifi.web.api.dto.provenance.lineage.LineageRequestDTO) LineageDTO(org.apache.nifi.web.api.dto.provenance.lineage.LineageDTO) HashMap(java.util.HashMap) LineageEntity(org.apache.nifi.web.api.entity.LineageEntity) 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 2 with LineageRequestDTO

use of org.apache.nifi.web.api.dto.provenance.lineage.LineageRequestDTO in project nifi by apache.

the class DtoFactory method createLineageDto.

/**
 * Creates a LineageDTO for the specified Lineage.
 *
 * @param computeLineageSubmission submission
 * @return dto
 */
public LineageDTO createLineageDto(final ComputeLineageSubmission computeLineageSubmission) {
    // build the lineage dto
    final LineageDTO dto = new LineageDTO();
    final LineageRequestDTO requestDto = new LineageRequestDTO();
    final LineageResultsDTO resultsDto = new LineageResultsDTO();
    // include the original request and results
    dto.setRequest(requestDto);
    dto.setResults(resultsDto);
    // rebuild the request from the submission object
    switch(computeLineageSubmission.getLineageComputationType()) {
        case EXPAND_CHILDREN:
            requestDto.setEventId(computeLineageSubmission.getExpandedEventId());
            requestDto.setLineageRequestType(LineageRequestType.CHILDREN);
            break;
        case EXPAND_PARENTS:
            requestDto.setEventId(computeLineageSubmission.getExpandedEventId());
            requestDto.setLineageRequestType(LineageRequestType.PARENTS);
            break;
        case FLOWFILE_LINEAGE:
            final Collection<String> uuids = computeLineageSubmission.getLineageFlowFileUuids();
            if (uuids.size() == 1) {
                requestDto.setUuid(uuids.iterator().next());
            }
            requestDto.setEventId(computeLineageSubmission.getExpandedEventId());
            requestDto.setLineageRequestType(LineageRequestType.FLOWFILE);
            break;
    }
    // include lineage details
    dto.setId(computeLineageSubmission.getLineageIdentifier());
    dto.setSubmissionTime(computeLineageSubmission.getSubmissionTime());
    // create the results dto
    final ComputeLineageResult results = computeLineageSubmission.getResult();
    dto.setFinished(results.isFinished());
    dto.setPercentCompleted(results.getPercentComplete());
    dto.setExpiration(results.getExpiration());
    final List<LineageNode> nodes = results.getNodes();
    final List<LineageEdge> edges = results.getEdges();
    final List<ProvenanceNodeDTO> nodeDtos = new ArrayList<>();
    if (results.isFinished()) {
        // create the node dto's
        for (final LineageNode node : nodes) {
            switch(node.getNodeType()) {
                case FLOWFILE_NODE:
                    nodeDtos.add(createFlowFileNodeDTO(node));
                    break;
                case PROVENANCE_EVENT_NODE:
                    nodeDtos.add(createProvenanceEventNodeDTO((ProvenanceEventLineageNode) node));
                    break;
            }
        }
    }
    resultsDto.setNodes(nodeDtos);
    // include any errors
    if (results.getError() != null) {
        final Set<String> errors = new HashSet<>();
        errors.add(results.getError());
        resultsDto.setErrors(errors);
    }
    // create the link dto's
    final List<ProvenanceLinkDTO> linkDtos = new ArrayList<>();
    for (final LineageEdge edge : edges) {
        linkDtos.add(createProvenanceLinkDTO(edge));
    }
    resultsDto.setLinks(linkDtos);
    return dto;
}
Also used : ComputeLineageResult(org.apache.nifi.provenance.lineage.ComputeLineageResult) LineageDTO(org.apache.nifi.web.api.dto.provenance.lineage.LineageDTO) ArrayList(java.util.ArrayList) ProvenanceNodeDTO(org.apache.nifi.web.api.dto.provenance.lineage.ProvenanceNodeDTO) LineageRequestDTO(org.apache.nifi.web.api.dto.provenance.lineage.LineageRequestDTO) ProvenanceEventLineageNode(org.apache.nifi.provenance.lineage.ProvenanceEventLineageNode) LineageResultsDTO(org.apache.nifi.web.api.dto.provenance.lineage.LineageResultsDTO) LineageEdge(org.apache.nifi.provenance.lineage.LineageEdge) ProvenanceEventLineageNode(org.apache.nifi.provenance.lineage.ProvenanceEventLineageNode) LineageNode(org.apache.nifi.provenance.lineage.LineageNode) ProvenanceLinkDTO(org.apache.nifi.web.api.dto.provenance.lineage.ProvenanceLinkDTO) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 3 with LineageRequestDTO

use of org.apache.nifi.web.api.dto.provenance.lineage.LineageRequestDTO in project nifi by apache.

the class ControllerFacade method submitLineage.

/**
 * Submits the specified lineage request.
 *
 * @param lineageDto dto
 * @return updated lineage
 */
public LineageDTO submitLineage(LineageDTO lineageDto) {
    final LineageRequestDTO requestDto = lineageDto.getRequest();
    // get the provenance repo
    final ProvenanceRepository provenanceRepository = flowController.getProvenanceRepository();
    final ComputeLineageSubmission result;
    if (LineageRequestType.FLOWFILE.equals(requestDto.getLineageRequestType())) {
        if (requestDto.getUuid() != null) {
            // submit uuid if it is specified
            result = provenanceRepository.submitLineageComputation(requestDto.getUuid(), NiFiUserUtils.getNiFiUser());
        } else {
            // submit the event if the flowfile uuid needs to be looked up
            result = provenanceRepository.submitLineageComputation(requestDto.getEventId(), NiFiUserUtils.getNiFiUser());
        }
    } else {
        // submit event... (parents or children)
        if (LineageRequestType.PARENTS.equals(requestDto.getLineageRequestType())) {
            result = provenanceRepository.submitExpandParents(requestDto.getEventId(), NiFiUserUtils.getNiFiUser());
        } else {
            result = provenanceRepository.submitExpandChildren(requestDto.getEventId(), NiFiUserUtils.getNiFiUser());
        }
    }
    return getLineage(result.getLineageIdentifier());
}
Also used : LineageRequestDTO(org.apache.nifi.web.api.dto.provenance.lineage.LineageRequestDTO) ComputeLineageSubmission(org.apache.nifi.provenance.lineage.ComputeLineageSubmission) ProvenanceRepository(org.apache.nifi.provenance.ProvenanceRepository)

Aggregations

LineageRequestDTO (org.apache.nifi.web.api.dto.provenance.lineage.LineageRequestDTO)3 LineageDTO (org.apache.nifi.web.api.dto.provenance.lineage.LineageDTO)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 ProvenanceRepository (org.apache.nifi.provenance.ProvenanceRepository)1 ComputeLineageResult (org.apache.nifi.provenance.lineage.ComputeLineageResult)1 ComputeLineageSubmission (org.apache.nifi.provenance.lineage.ComputeLineageSubmission)1 LineageEdge (org.apache.nifi.provenance.lineage.LineageEdge)1 LineageNode (org.apache.nifi.provenance.lineage.LineageNode)1 ProvenanceEventLineageNode (org.apache.nifi.provenance.lineage.ProvenanceEventLineageNode)1 LineageResultsDTO (org.apache.nifi.web.api.dto.provenance.lineage.LineageResultsDTO)1 ProvenanceLinkDTO (org.apache.nifi.web.api.dto.provenance.lineage.ProvenanceLinkDTO)1