Search in sources :

Example 1 with BulletinBoardDTO

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

the class StandardNiFiServiceFacade method getBulletinBoard.

@Override
public BulletinBoardDTO getBulletinBoard(final BulletinQueryDTO query) {
    // build the query
    final BulletinQuery.Builder queryBuilder = new BulletinQuery.Builder().groupIdMatches(query.getGroupId()).sourceIdMatches(query.getSourceId()).nameMatches(query.getName()).messageMatches(query.getMessage()).after(query.getAfter()).limit(query.getLimit());
    // perform the query
    final List<Bulletin> results = bulletinRepository.findBulletins(queryBuilder.build());
    // perform the query and generate the results - iterating in reverse order since we are
    // getting the most recent results by ordering by timestamp desc above. this gets the
    // exact results we want but in reverse order
    final List<BulletinEntity> bulletinEntities = new ArrayList<>();
    for (final ListIterator<Bulletin> bulletinIter = results.listIterator(results.size()); bulletinIter.hasPrevious(); ) {
        final Bulletin bulletin = bulletinIter.previous();
        bulletinEntities.add(entityFactory.createBulletinEntity(dtoFactory.createBulletinDto(bulletin), authorizeBulletin(bulletin)));
    }
    // create the bulletin board
    final BulletinBoardDTO bulletinBoard = new BulletinBoardDTO();
    bulletinBoard.setBulletins(bulletinEntities);
    bulletinBoard.setGenerated(new Date());
    return bulletinBoard;
}
Also used : Bulletin(org.apache.nifi.reporting.Bulletin) BulletinBoardDTO(org.apache.nifi.web.api.dto.BulletinBoardDTO) BulletinQuery(org.apache.nifi.reporting.BulletinQuery) ArrayList(java.util.ArrayList) BulletinEntity(org.apache.nifi.web.api.entity.BulletinEntity) Date(java.util.Date)

Example 2 with BulletinBoardDTO

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

the class FlowResource method getBulletinBoard.

// --------------
// bulletin board
// --------------
/**
 * Retrieves all the of bulletins in this NiFi.
 *
 * @param after      Supporting querying for bulletins after a particular
 *                   bulletin id.
 * @param limit      The max number of bulletins to return.
 * @param sourceName Source name filter. Supports a regular expression.
 * @param message    Message filter. Supports a regular expression.
 * @param sourceId   Source id filter. Supports a regular expression.
 * @param groupId    Group id filter. Supports a regular expression.
 * @return A bulletinBoardEntity.
 * @throws InterruptedException if interrupted
 */
@GET
@Consumes(MediaType.WILDCARD)
@Produces(MediaType.APPLICATION_JSON)
@Path("bulletin-board")
@ApiOperation(value = "Gets current bulletins", response = BulletinBoardEntity.class, authorizations = { @Authorization(value = "Read - /flow"), @Authorization(value = "Read - /{component-type}/{uuid} - For component specific bulletins") })
@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 getBulletinBoard(@ApiParam(value = "Includes bulletins with an id after this value.", required = false) @QueryParam("after") LongParameter after, @ApiParam(value = "Includes bulletins originating from this sources whose name match this regular expression.", required = false) @QueryParam("sourceName") BulletinBoardPatternParameter sourceName, @ApiParam(value = "Includes bulletins whose message that match this regular expression.", required = false) @QueryParam("message") BulletinBoardPatternParameter message, @ApiParam(value = "Includes bulletins originating from this sources whose id match this regular expression.", required = false) @QueryParam("sourceId") BulletinBoardPatternParameter sourceId, @ApiParam(value = "Includes bulletins originating from this sources whose group id match this regular expression.", required = false) @QueryParam("groupId") BulletinBoardPatternParameter groupId, @ApiParam(value = "The number of bulletins to limit the response to.", required = false) @QueryParam("limit") IntegerParameter limit) throws InterruptedException {
    authorizeFlow();
    // replicate if cluster manager
    if (isReplicateRequest()) {
        return replicate(HttpMethod.GET);
    }
    // build the bulletin query
    final BulletinQueryDTO query = new BulletinQueryDTO();
    if (sourceId != null) {
        query.setSourceId(sourceId.getRawPattern());
    }
    if (groupId != null) {
        query.setGroupId(groupId.getRawPattern());
    }
    if (sourceName != null) {
        query.setName(sourceName.getRawPattern());
    }
    if (message != null) {
        query.setMessage(message.getRawPattern());
    }
    if (after != null) {
        query.setAfter(after.getLong());
    }
    if (limit != null) {
        query.setLimit(limit.getInteger());
    }
    // get the bulletin board
    final BulletinBoardDTO bulletinBoard = serviceFacade.getBulletinBoard(query);
    // create the response entity
    BulletinBoardEntity entity = new BulletinBoardEntity();
    entity.setBulletinBoard(bulletinBoard);
    // generate the response
    return generateOkResponse(entity).build();
}
Also used : BulletinBoardEntity(org.apache.nifi.web.api.entity.BulletinBoardEntity) BulletinBoardDTO(org.apache.nifi.web.api.dto.BulletinBoardDTO) BulletinQueryDTO(org.apache.nifi.web.api.dto.BulletinQueryDTO) 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 3 with BulletinBoardDTO

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

the class BulletinBoardEndpointMerger method mergeResponses.

@Override
protected void mergeResponses(BulletinBoardDTO clientDto, Map<NodeIdentifier, BulletinBoardDTO> dtoMap, Set<NodeResponse> successfulResponses, Set<NodeResponse> problematicResponses) {
    final Map<NodeIdentifier, List<BulletinEntity>> bulletinEntities = new HashMap<>();
    for (final Map.Entry<NodeIdentifier, BulletinBoardDTO> entry : dtoMap.entrySet()) {
        final NodeIdentifier nodeIdentifier = entry.getKey();
        final BulletinBoardDTO boardDto = entry.getValue();
        boardDto.getBulletins().forEach(bulletin -> {
            bulletinEntities.computeIfAbsent(nodeIdentifier, nodeId -> new ArrayList<>()).add(bulletin);
        });
    }
    clientDto.setBulletins(BulletinMerger.mergeBulletins(bulletinEntities, dtoMap.size()));
}
Also used : NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Set(java.util.Set) BulletinBoardDTO(org.apache.nifi.web.api.dto.BulletinBoardDTO) HashMap(java.util.HashMap) BulletinBoardEntity(org.apache.nifi.web.api.entity.BulletinBoardEntity) ArrayList(java.util.ArrayList) List(java.util.List) BulletinMerger(org.apache.nifi.cluster.manager.BulletinMerger) BulletinEntity(org.apache.nifi.web.api.entity.BulletinEntity) Map(java.util.Map) URI(java.net.URI) Pattern(java.util.regex.Pattern) NodeResponse(org.apache.nifi.cluster.manager.NodeResponse) HashMap(java.util.HashMap) BulletinBoardDTO(org.apache.nifi.web.api.dto.BulletinBoardDTO) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

BulletinBoardDTO (org.apache.nifi.web.api.dto.BulletinBoardDTO)3 ArrayList (java.util.ArrayList)2 BulletinBoardEntity (org.apache.nifi.web.api.entity.BulletinBoardEntity)2 BulletinEntity (org.apache.nifi.web.api.entity.BulletinEntity)2 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 URI (java.net.URI)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Pattern (java.util.regex.Pattern)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 BulletinMerger (org.apache.nifi.cluster.manager.BulletinMerger)1 NodeResponse (org.apache.nifi.cluster.manager.NodeResponse)1 NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)1