Search in sources :

Example 1 with ProvenanceLinkDTO

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

the class DtoFactory method createProvenanceLinkDTO.

/**
 * Creates a ProvenanceLinkDTO for the specified LineageEdge.
 *
 * @param edge edge
 * @return dto
 */
public ProvenanceLinkDTO createProvenanceLinkDTO(final LineageEdge edge) {
    final LineageNode source = edge.getSource();
    final LineageNode target = edge.getDestination();
    final ProvenanceLinkDTO dto = new ProvenanceLinkDTO();
    dto.setTimestamp(new Date(target.getTimestamp()));
    dto.setMillis(target.getTimestamp());
    dto.setFlowFileUuid(edge.getUuid());
    dto.setSourceId(source.getIdentifier());
    dto.setTargetId(target.getIdentifier());
    return dto;
}
Also used : ProvenanceEventLineageNode(org.apache.nifi.provenance.lineage.ProvenanceEventLineageNode) LineageNode(org.apache.nifi.provenance.lineage.LineageNode) ProvenanceLinkDTO(org.apache.nifi.web.api.dto.provenance.lineage.ProvenanceLinkDTO) Date(java.util.Date)

Example 2 with ProvenanceLinkDTO

use of org.apache.nifi.web.api.dto.provenance.lineage.ProvenanceLinkDTO 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)

Aggregations

LineageNode (org.apache.nifi.provenance.lineage.LineageNode)2 ProvenanceEventLineageNode (org.apache.nifi.provenance.lineage.ProvenanceEventLineageNode)2 ProvenanceLinkDTO (org.apache.nifi.web.api.dto.provenance.lineage.ProvenanceLinkDTO)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 ComputeLineageResult (org.apache.nifi.provenance.lineage.ComputeLineageResult)1 LineageEdge (org.apache.nifi.provenance.lineage.LineageEdge)1 LineageDTO (org.apache.nifi.web.api.dto.provenance.lineage.LineageDTO)1 LineageRequestDTO (org.apache.nifi.web.api.dto.provenance.lineage.LineageRequestDTO)1 LineageResultsDTO (org.apache.nifi.web.api.dto.provenance.lineage.LineageResultsDTO)1 ProvenanceNodeDTO (org.apache.nifi.web.api.dto.provenance.lineage.ProvenanceNodeDTO)1