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