Search in sources :

Example 1 with LineageEntity

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

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

the class ProvenanceResource method deleteLineage.

/**
 * Deletes the lineage with the specified id.
 *
 * @param httpServletRequest request
 * @param clusterNodeId      The id of node in the cluster that the event/flowfile originated from. This is only required when clustered.
 * @param id                 The id of the lineage
 * @return A lineageEntity
 */
@DELETE
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("lineage/{id}")
@ApiOperation(value = "Deletes a lineage query", response = LineageEntity.class, authorizations = { @Authorization(value = "Read - /provenance") })
@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 deleteLineage(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The id of the node where this query exists if clustered.", required = false) @QueryParam("clusterNodeId") final String clusterNodeId, @ApiParam(value = "The id of the lineage query.", required = true) @PathParam("id") final String id) {
    // replicate if cluster manager
    if (isReplicateRequest()) {
        return replicate(HttpMethod.DELETE, clusterNodeId);
    }
    final ComponentEntity requestEntity = new ComponentEntity();
    requestEntity.setId(id);
    return withWriteLock(serviceFacade, requestEntity, lookup -> authorizeProvenanceRequest(), null, (entity) -> {
        // delete the lineage
        serviceFacade.deleteLineage(entity.getId());
        // generate the response
        return generateOkResponse(new LineageEntity()).build();
    });
}
Also used : ComponentEntity(org.apache.nifi.web.api.entity.ComponentEntity) LineageEntity(org.apache.nifi.web.api.entity.LineageEntity) 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 LineageEntity

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

the class ProvenanceResource method getLineage.

/**
 * Gets the lineage with the specified id.
 *
 * @param clusterNodeId The id of node in the cluster that the event/flowfile originated from. This is only required when clustered.
 * @param id            The id of the lineage
 * @return A lineageEntity
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("lineage/{id}")
@ApiOperation(value = "Gets a lineage query", 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 getLineage(@ApiParam(value = "The id of the node where this query exists if clustered.", required = false) @QueryParam("clusterNodeId") final String clusterNodeId, @ApiParam(value = "The id of the lineage query.", required = true) @PathParam("id") final String id) {
    authorizeProvenanceRequest();
    // replicate if cluster manager
    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET, clusterNodeId);
    }
    // get the lineage
    final LineageDTO dto = serviceFacade.getLineage(id);
    populateRemainingLineageContent(dto, clusterNodeId);
    // create the response entity
    final LineageEntity entity = new LineageEntity();
    entity.setLineage(dto);
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : LineageDTO(org.apache.nifi.web.api.dto.provenance.lineage.LineageDTO) LineageEntity(org.apache.nifi.web.api.entity.LineageEntity) 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)

Aggregations

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 LineageEntity (org.apache.nifi.web.api.entity.LineageEntity)3 LineageDTO (org.apache.nifi.web.api.dto.provenance.lineage.LineageDTO)2 HashMap (java.util.HashMap)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 LineageRequestDTO (org.apache.nifi.web.api.dto.provenance.lineage.LineageRequestDTO)1 ComponentEntity (org.apache.nifi.web.api.entity.ComponentEntity)1