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();
});
}
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;
}
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());
}
Aggregations