Search in sources :

Example 1 with ProvenanceEntity

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

the class ProvenanceResource method getProvenance.

/**
 * Gets the provenance with the specified id.
 *
 * @param id            The id of the provenance
 * @param clusterNodeId The id of node in the cluster to search. This is optional and only relevant when clustered. If clustered and it is not specified the entire cluster is searched.
 * @return A provenanceEntity
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(value = "Gets a provenance query", response = ProvenanceEntity.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 getProvenance(@ApiParam(value = "The id of the node where this query exists if clustered.", required = false) @QueryParam("clusterNodeId") final String clusterNodeId, @ApiParam(value = "Whether or not incremental results are returned. If false, provenance events" + " are only returned once the query completes. This property is true by default.", required = false) @QueryParam("summarize") @DefaultValue(value = "false") final Boolean summarize, @ApiParam(value = "Whether or not to summarize provenance events returned. This property is false by default.", required = false) @QueryParam("incrementalResults") @DefaultValue(value = "true") final Boolean incrementalResults, @ApiParam(value = "The id of the provenance query.", required = true) @PathParam("id") final String id) {
    authorizeProvenanceRequest();
    // replicate if cluster manager
    if (isReplicateRequest()) {
        // determine where this request should be sent
        if (clusterNodeId == null) {
            // replicate to all nodes
            return replicate(HttpMethod.GET);
        } else {
            return replicate(HttpMethod.GET, clusterNodeId);
        }
    }
    // get the provenance
    final ProvenanceDTO dto = serviceFacade.getProvenance(id, summarize, incrementalResults);
    dto.getRequest().setClusterNodeId(clusterNodeId);
    populateRemainingProvenanceContent(dto);
    // create the response entity
    final ProvenanceEntity entity = new ProvenanceEntity();
    entity.setProvenance(dto);
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : ProvenanceEntity(org.apache.nifi.web.api.entity.ProvenanceEntity) ProvenanceDTO(org.apache.nifi.web.api.dto.provenance.ProvenanceDTO) 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)

Example 2 with ProvenanceEntity

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

the class ProvenanceResource method deleteProvenance.

/**
 * Deletes the provenance with the specified id.
 *
 * @param httpServletRequest request
 * @param id                 The id of the provenance
 * @param clusterNodeId      The id of node in the cluster to search. This is optional and only relevant when clustered. If clustered and it is not specified the entire cluster is searched.
 * @return A provenanceEntity
 */
@DELETE
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("{id}")
@ApiOperation(value = "Deletes a provenance query", response = ProvenanceEntity.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 deleteProvenance(@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 provenance query.", required = true) @PathParam("id") final String id) {
    // replicate if cluster manager
    if (isReplicateRequest()) {
        // determine where this request should be sent
        if (clusterNodeId == null) {
            // replicate to all nodes
            return replicate(HttpMethod.DELETE);
        } else {
            return replicate(HttpMethod.DELETE, clusterNodeId);
        }
    }
    final ComponentEntity requestEntity = new ComponentEntity();
    requestEntity.setId(id);
    return withWriteLock(serviceFacade, requestEntity, lookup -> authorizeProvenanceRequest(), null, (entity) -> {
        // delete the provenance
        serviceFacade.deleteProvenance(entity.getId());
        // generate the response
        return generateOkResponse(new ProvenanceEntity()).build();
    });
}
Also used : ComponentEntity(org.apache.nifi.web.api.entity.ComponentEntity) ProvenanceEntity(org.apache.nifi.web.api.entity.ProvenanceEntity) 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 ProvenanceEntity

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

the class ProvenanceQueryEndpointMerger method merge.

@Override
public NodeResponse merge(URI uri, String method, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses, NodeResponse clientResponse) {
    if (!canHandle(uri, method)) {
        throw new IllegalArgumentException("Cannot use Endpoint Mapper of type " + getClass().getSimpleName() + " to map responses for URI " + uri + ", HTTP Method " + method);
    }
    final ProvenanceEntity responseEntity = clientResponse.getClientResponse().readEntity(ProvenanceEntity.class);
    final ProvenanceDTO dto = responseEntity.getProvenance();
    final Map<NodeIdentifier, ProvenanceDTO> dtoMap = new HashMap<>();
    for (final NodeResponse nodeResponse : successfulResponses) {
        final ProvenanceEntity nodeResponseEntity = nodeResponse == clientResponse ? responseEntity : nodeResponse.getClientResponse().readEntity(ProvenanceEntity.class);
        final ProvenanceDTO nodeDto = nodeResponseEntity.getProvenance();
        dtoMap.put(nodeResponse.getNodeId(), nodeDto);
    }
    mergeResponses(dto, dtoMap, successfulResponses, problematicResponses);
    return new NodeResponse(clientResponse, responseEntity);
}
Also used : HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) ProvenanceEntity(org.apache.nifi.web.api.entity.ProvenanceEntity) ProvenanceDTO(org.apache.nifi.web.api.dto.provenance.ProvenanceDTO)

Example 4 with ProvenanceEntity

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

the class ProvenanceResource method submitProvenanceRequest.

/**
 * Creates provenance using the specified query criteria.
 *
 * @param httpServletRequest request
 * @param requestProvenanceEntity   A provenanceEntity
 * @return A provenanceEntity
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
// necessary due to bug in swagger
@Path("")
@ApiOperation(value = "Submits a provenance query", notes = "Provenance 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 provenance request " + "should be deleted by the client who originally submitted it.", response = ProvenanceEntity.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 = 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 submitProvenanceRequest(@Context final HttpServletRequest httpServletRequest, @ApiParam(value = "The provenance query details.", required = true) ProvenanceEntity requestProvenanceEntity) {
    // check the request
    if (requestProvenanceEntity == null) {
        requestProvenanceEntity = new ProvenanceEntity();
    }
    // get the provenance
    final ProvenanceDTO requestProvenanceDto;
    if (requestProvenanceEntity.getProvenance() != null) {
        requestProvenanceDto = requestProvenanceEntity.getProvenance();
    } else {
        requestProvenanceDto = new ProvenanceDTO();
        requestProvenanceEntity.setProvenance(requestProvenanceDto);
    }
    // replicate if cluster manager
    if (isReplicateRequest()) {
        // change content type to JSON for serializing entity
        final Map<String, String> headersToOverride = new HashMap<>();
        headersToOverride.put("content-type", MediaType.APPLICATION_JSON);
        // determine where this request should be sent
        if (requestProvenanceDto.getRequest() == null || requestProvenanceDto.getRequest().getClusterNodeId() == null) {
            // replicate to all nodes
            return replicate(HttpMethod.POST, requestProvenanceEntity, headersToOverride);
        } else {
            return replicate(HttpMethod.POST, requestProvenanceEntity, requestProvenanceDto.getRequest().getClusterNodeId(), headersToOverride);
        }
    }
    return withWriteLock(serviceFacade, requestProvenanceEntity, lookup -> authorizeProvenanceRequest(), null, (provenanceEntity) -> {
        final ProvenanceDTO provenanceDTO = provenanceEntity.getProvenance();
        // ensure the id is the same across the cluster
        final String provenanceId = generateUuid();
        // set the provenance id accordingly
        provenanceDTO.setId(provenanceId);
        // submit the provenance request
        final ProvenanceDTO dto = serviceFacade.submitProvenance(provenanceDTO);
        populateRemainingProvenanceContent(dto);
        // set the cluster id if necessary
        if (provenanceDTO.getRequest() != null && provenanceDTO.getRequest().getClusterNodeId() != null) {
            dto.getRequest().setClusterNodeId(provenanceDTO.getRequest().getClusterNodeId());
        }
        // create the response entity
        final ProvenanceEntity entity = new ProvenanceEntity();
        entity.setProvenance(dto);
        // generate the response
        return generateCreatedResponse(URI.create(dto.getUri()), entity).build();
    });
}
Also used : HashMap(java.util.HashMap) ProvenanceEntity(org.apache.nifi.web.api.entity.ProvenanceEntity) ProvenanceDTO(org.apache.nifi.web.api.dto.provenance.ProvenanceDTO) 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)

Aggregations

ProvenanceEntity (org.apache.nifi.web.api.entity.ProvenanceEntity)4 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 ProvenanceDTO (org.apache.nifi.web.api.dto.provenance.ProvenanceDTO)3 HashMap (java.util.HashMap)2 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 NodeResponse (org.apache.nifi.cluster.manager.NodeResponse)1 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)1 ComponentEntity (org.apache.nifi.web.api.entity.ComponentEntity)1