Search in sources :

Example 1 with HistoryQueryDTO

use of org.apache.nifi.web.api.dto.action.HistoryQueryDTO in project nifi by apache.

the class FlowResource method queryHistory.

// -------
// history
// -------
/**
 * Queries the history of this Controller.
 *
 * @param offset       The offset into the data. This parameter is required and is
 *                     used in conjunction with count.
 * @param count        The number of rows that should be returned. This parameter
 *                     is required and is used in conjunction with page.
 * @param sortColumn   The column to sort on. This parameter is optional. If
 *                     not specified the results will be returned with the most recent first.
 * @param sortOrder    The sort order.
 * @param startDate    The start date/time for the query. The start date/time
 *                     must be formatted as 'MM/dd/yyyy HH:mm:ss'. This parameter is optional
 *                     and must be specified in the timezone of the server. The server's
 *                     timezone can be determined by inspecting the result of a status or
 *                     history request.
 * @param endDate      The end date/time for the query. The end date/time must be
 *                     formatted as 'MM/dd/yyyy HH:mm:ss'. This parameter is optional and must
 *                     be specified in the timezone of the server. The server's timezone can be
 *                     determined by inspecting the result of a status or history request.
 * @param userIdentity The user name of the user who's actions are being
 *                     queried. This parameter is optional.
 * @param sourceId     The id of the source being queried (usually a processor
 *                     id). This parameter is optional.
 * @return A historyEntity.
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("history")
@ApiOperation(value = "Gets configuration history", notes = NON_GUARANTEED_ENDPOINT, response = HistoryEntity.class, authorizations = { @Authorization(value = "Read - /flow") })
@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 queryHistory(@ApiParam(value = "The offset into the result set.", required = true) @QueryParam("offset") IntegerParameter offset, @ApiParam(value = "The number of actions to return.", required = true) @QueryParam("count") IntegerParameter count, @ApiParam(value = "The field to sort on.", required = false) @QueryParam("sortColumn") String sortColumn, @ApiParam(value = "The direction to sort.", required = false) @QueryParam("sortOrder") String sortOrder, @ApiParam(value = "Include actions after this date.", required = false) @QueryParam("startDate") DateTimeParameter startDate, @ApiParam(value = "Include actions before this date.", required = false) @QueryParam("endDate") DateTimeParameter endDate, @ApiParam(value = "Include actions performed by this user.", required = false) @QueryParam("userIdentity") String userIdentity, @ApiParam(value = "Include actions on this component.", required = false) @QueryParam("sourceId") String sourceId) {
    authorizeFlow();
    // ensure the page is specified
    if (offset == null) {
        throw new IllegalArgumentException("The desired offset must be specified.");
    } else if (offset.getInteger() < 0) {
        throw new IllegalArgumentException("The desired offset must be an integer value greater than or equal to 0.");
    }
    // ensure the row count is specified
    if (count == null) {
        throw new IllegalArgumentException("The desired row count must be specified.");
    } else if (count.getInteger() < 1) {
        throw new IllegalArgumentException("The desired row count must be an integer value greater than 0.");
    }
    // normalize the sort order
    if (sortOrder != null) {
        if (!sortOrder.equalsIgnoreCase("asc") && !sortOrder.equalsIgnoreCase("desc")) {
            throw new IllegalArgumentException("The sort order must be 'asc' or 'desc'.");
        }
    }
    // ensure the start and end dates are specified
    if (endDate != null && startDate != null) {
        if (endDate.getDateTime().before(startDate.getDateTime())) {
            throw new IllegalArgumentException("The start date/time must come before the end date/time.");
        }
    }
    // Note: History requests are not replicated throughout the cluster and are instead handled by the nodes independently
    // create a history query
    final HistoryQueryDTO query = new HistoryQueryDTO();
    query.setSortColumn(sortColumn);
    query.setSortOrder(sortOrder);
    query.setOffset(offset.getInteger());
    query.setCount(count.getInteger());
    // optionally set the start date
    if (startDate != null) {
        query.setStartDate(startDate.getDateTime());
    }
    // optionally set the end date
    if (endDate != null) {
        query.setEndDate(endDate.getDateTime());
    }
    // optionally set the user id
    if (userIdentity != null) {
        query.setUserIdentity(userIdentity);
    }
    // optionally set the processor id
    if (sourceId != null) {
        query.setSourceId(sourceId);
    }
    // perform the query
    final HistoryDTO history = serviceFacade.getActions(query);
    // create the response entity
    final HistoryEntity entity = new HistoryEntity();
    entity.setHistory(history);
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : HistoryDTO(org.apache.nifi.web.api.dto.action.HistoryDTO) HistoryQueryDTO(org.apache.nifi.web.api.dto.action.HistoryQueryDTO) StatusHistoryEntity(org.apache.nifi.web.api.entity.StatusHistoryEntity) HistoryEntity(org.apache.nifi.web.api.entity.HistoryEntity) ComponentHistoryEntity(org.apache.nifi.web.api.entity.ComponentHistoryEntity) 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 HistoryQueryDTO

use of org.apache.nifi.web.api.dto.action.HistoryQueryDTO in project nifi by apache.

the class StandardNiFiServiceFacadeTest method testGetActionsForUser2.

@Test
public void testGetActionsForUser2() throws Exception {
    // set the user
    final Authentication authentication = new NiFiAuthenticationToken(new NiFiUserDetails(new Builder().identity(USER_2).build()));
    SecurityContextHolder.getContext().setAuthentication(authentication);
    final HistoryDTO dto = serviceFacade.getActions(new HistoryQueryDTO());
    // verify user 2 only has access to actions for processor 2
    dto.getActions().forEach(action -> {
        if (PROCESSOR_ID_1.equals(action.getSourceId())) {
            assertFalse(action.getCanRead());
            assertNull(action.getAction());
        } else if (PROCESSOR_ID_2.equals(action.getSourceId())) {
            assertTrue(action.getCanRead());
        }
    });
}
Also used : HistoryDTO(org.apache.nifi.web.api.dto.action.HistoryDTO) HistoryQueryDTO(org.apache.nifi.web.api.dto.action.HistoryQueryDTO) Authentication(org.springframework.security.core.Authentication) Builder(org.apache.nifi.authorization.user.StandardNiFiUser.Builder) NiFiUserDetails(org.apache.nifi.authorization.user.NiFiUserDetails) NiFiAuthenticationToken(org.apache.nifi.web.security.token.NiFiAuthenticationToken) Test(org.junit.Test)

Example 3 with HistoryQueryDTO

use of org.apache.nifi.web.api.dto.action.HistoryQueryDTO in project nifi by apache.

the class StandardNiFiServiceFacadeTest method testGetActionsForUser1.

@Test
public void testGetActionsForUser1() throws Exception {
    // set the user
    final Authentication authentication = new NiFiAuthenticationToken(new NiFiUserDetails(new Builder().identity(USER_1).build()));
    SecurityContextHolder.getContext().setAuthentication(authentication);
    final HistoryDTO dto = serviceFacade.getActions(new HistoryQueryDTO());
    // verify user 1 only has access to actions for processor 1
    dto.getActions().forEach(action -> {
        if (PROCESSOR_ID_1.equals(action.getSourceId())) {
            assertTrue(action.getCanRead());
        } else if (PROCESSOR_ID_2.equals(action.getSourceId())) {
            assertFalse(action.getCanRead());
            assertNull(action.getAction());
        }
    });
}
Also used : HistoryDTO(org.apache.nifi.web.api.dto.action.HistoryDTO) HistoryQueryDTO(org.apache.nifi.web.api.dto.action.HistoryQueryDTO) Authentication(org.springframework.security.core.Authentication) Builder(org.apache.nifi.authorization.user.StandardNiFiUser.Builder) NiFiUserDetails(org.apache.nifi.authorization.user.NiFiUserDetails) NiFiAuthenticationToken(org.apache.nifi.web.security.token.NiFiAuthenticationToken) Test(org.junit.Test)

Aggregations

HistoryDTO (org.apache.nifi.web.api.dto.action.HistoryDTO)3 HistoryQueryDTO (org.apache.nifi.web.api.dto.action.HistoryQueryDTO)3 NiFiUserDetails (org.apache.nifi.authorization.user.NiFiUserDetails)2 Builder (org.apache.nifi.authorization.user.StandardNiFiUser.Builder)2 NiFiAuthenticationToken (org.apache.nifi.web.security.token.NiFiAuthenticationToken)2 Test (org.junit.Test)2 Authentication (org.springframework.security.core.Authentication)2 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 ComponentHistoryEntity (org.apache.nifi.web.api.entity.ComponentHistoryEntity)1 HistoryEntity (org.apache.nifi.web.api.entity.HistoryEntity)1 StatusHistoryEntity (org.apache.nifi.web.api.entity.StatusHistoryEntity)1