Search in sources :

Example 1 with ComponentHistoryEntity

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

the class FlowResource method getComponentHistory.

/**
 * Gets the actions for the specified component.
 *
 * @param componentId The id of the component.
 * @return An processorHistoryEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("history/components/{componentId}")
@ApiOperation(value = "Gets configuration history for a component", notes = NON_GUARANTEED_ENDPOINT, response = ComponentHistoryEntity.class, authorizations = { @Authorization(value = "Read - /flow"), @Authorization(value = "Read underlying component - /{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 getComponentHistory(@ApiParam(value = "The component id.", required = true) @PathParam("componentId") final String componentId) {
    serviceFacade.authorizeAccess(lookup -> {
        final NiFiUser user = NiFiUserUtils.getNiFiUser();
        // authorize the flow
        authorizeFlow();
        try {
            final Authorizable authorizable = lookup.getProcessor(componentId).getAuthorizable();
            authorizable.authorize(authorizer, RequestAction.READ, user);
            return;
        } catch (final ResourceNotFoundException e) {
        // ignore as the component may not be a processor
        }
        try {
            final Authorizable authorizable = lookup.getControllerService(componentId).getAuthorizable();
            authorizable.authorize(authorizer, RequestAction.READ, user);
            return;
        } catch (final ResourceNotFoundException e) {
        // ignore as the component may not be a controller service
        }
        try {
            final Authorizable authorizable = lookup.getReportingTask(componentId).getAuthorizable();
            authorizable.authorize(authorizer, RequestAction.READ, user);
            return;
        } catch (final ResourceNotFoundException e) {
        // ignore as the component may not be a reporting task
        }
        // a component for the specified id could not be found, attempt to authorize based on read to the controller
        final Authorizable controller = lookup.getController();
        controller.authorize(authorizer, RequestAction.READ, user);
    });
    // Note: History requests are not replicated throughout the cluster and are instead handled by the nodes independently
    // create the response entity
    final ComponentHistoryEntity entity = new ComponentHistoryEntity();
    entity.setComponentHistory(serviceFacade.getComponentHistory(componentId));
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : ComponentHistoryEntity(org.apache.nifi.web.api.entity.ComponentHistoryEntity) NiFiUser(org.apache.nifi.authorization.user.NiFiUser) Authorizable(org.apache.nifi.authorization.resource.Authorizable) ResourceNotFoundException(org.apache.nifi.web.ResourceNotFoundException) 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)1 ApiResponses (io.swagger.annotations.ApiResponses)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Authorizable (org.apache.nifi.authorization.resource.Authorizable)1 NiFiUser (org.apache.nifi.authorization.user.NiFiUser)1 ResourceNotFoundException (org.apache.nifi.web.ResourceNotFoundException)1 ComponentHistoryEntity (org.apache.nifi.web.api.entity.ComponentHistoryEntity)1