org.apache.nifi.reporting.BulletinQuery Java Examples

The following examples show how to use org.apache.nifi.reporting.BulletinQuery. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StandardNiFiServiceFacade.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #2
Source File: StatusRequestParser.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
static ReportingTaskStatus parseReportingTaskStatusRequest(String id, ReportingTaskNode reportingTaskNode, String statusTypes, FlowController flowController, Logger logger) {
    ReportingTaskStatus reportingTaskStatus = new ReportingTaskStatus();
    reportingTaskStatus.setName(id);

    String[] statusSplits = statusTypes.split(",");
    List<Bulletin> bulletinList = flowController.getBulletinRepository().findBulletins(
            new BulletinQuery.Builder()
                    .sourceIdMatches(id)
                    .build());
    for (String statusType : statusSplits) {
        switch (statusType.toLowerCase().trim()) {
            case "health":
                ReportingTaskHealth reportingTaskHealth = new ReportingTaskHealth();

                reportingTaskHealth.setScheduledState(reportingTaskNode.getScheduledState().name());
                reportingTaskHealth.setActiveThreads(reportingTaskNode.getActiveThreadCount());
                reportingTaskHealth.setHasBulletins(!bulletinList.isEmpty());

                Collection<ValidationResult> validationResults = reportingTaskNode.getValidationErrors();
                reportingTaskHealth.setValidationErrorList(transformValidationResults(validationResults));

                reportingTaskStatus.setReportingTaskHealth(reportingTaskHealth);
                break;
            case "bulletins":
                reportingTaskStatus.setBulletinList(transformBulletins(bulletinList));
                break;
        }
    }
    return reportingTaskStatus;
}
 
Example #3
Source File: StatusRequestParser.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
static ControllerServiceStatus parseControllerServiceStatusRequest(ControllerServiceNode controllerServiceNode, String statusTypes, FlowController flowController, Logger logger) {
    ControllerServiceStatus controllerServiceStatus = new ControllerServiceStatus();
    String id = controllerServiceNode.getIdentifier();
    controllerServiceStatus.setName(id);

    String[] statusSplits = statusTypes.split(",");
    List<Bulletin> bulletinList = flowController.getBulletinRepository().findBulletins(
            new BulletinQuery.Builder()
                    .sourceIdMatches(id)
                    .build());
    for (String statusType : statusSplits) {
        switch (statusType.toLowerCase().trim()) {
            case "health":
                ControllerServiceHealth controllerServiceHealth = new ControllerServiceHealth();

                controllerServiceHealth.setState(controllerServiceNode.getState().name());
                controllerServiceHealth.setHasBulletins(!bulletinList.isEmpty());

                Collection<ValidationResult> validationResults = controllerServiceNode.getValidationErrors();
                controllerServiceHealth.setValidationErrorList(transformValidationResults(validationResults));

                controllerServiceStatus.setControllerServiceHealth(controllerServiceHealth);
                break;
            case "bulletins":
                controllerServiceStatus.setBulletinList(transformBulletins(bulletinList));
                break;
        }
    }
    return controllerServiceStatus;
}
 
Example #4
Source File: StatusConfigReporterTest.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
    BulletinQuery bulletinQuery = (BulletinQuery) invocationOnMock.getArguments()[0];
    if (idToMatch.equals(bulletinQuery.getSourceIdPattern().toString())) {
        return bulletinList;
    }
    return Collections.emptyList();
}
 
Example #5
Source File: BulletinEnumerator.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void reset() {
    BulletinRepository bulletinRepo = context.getBulletinRepository();
    List<Bulletin> fullBulletinList = new ArrayList<>(bulletinRepo.findBulletinsForController());
    fullBulletinList.addAll(bulletinRepo.findBulletins((new BulletinQuery.Builder()).sourceType(ComponentType.PROCESSOR).build()));
    fullBulletinList.addAll(bulletinRepo.findBulletins((new BulletinQuery.Builder()).sourceType(ComponentType.INPUT_PORT).build()));
    fullBulletinList.addAll(bulletinRepo.findBulletins((new BulletinQuery.Builder()).sourceType(ComponentType.OUTPUT_PORT).build()));
    fullBulletinList.addAll(bulletinRepo.findBulletins((new BulletinQuery.Builder()).sourceType(ComponentType.REMOTE_PROCESS_GROUP).build()));
    fullBulletinList.addAll(bulletinRepo.findBulletins((new BulletinQuery.Builder()).sourceType(ComponentType.REPORTING_TASK).build()));
    fullBulletinList.addAll(bulletinRepo.findBulletins((new BulletinQuery.Builder()).sourceType(ComponentType.CONTROLLER_SERVICE).build()));

    bulletinIterator = fullBulletinList.iterator();
}
 
Example #6
Source File: MockBulletinRepository.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Override
public List<Bulletin> findBulletins(BulletinQuery bulletinQuery) {
    // TODO: Implement
    return null;
}
 
Example #7
Source File: VolatileBulletinRepository.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Override
public List<Bulletin> findBulletins(final BulletinQuery bulletinQuery) {
    final Filter<Bulletin> filter = new Filter<Bulletin>() {
        @Override
        public boolean select(final Bulletin bulletin) {
            final long fiveMinutesAgo = System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(5);
            if (bulletin.getTimestamp().getTime() < fiveMinutesAgo) {
                return false;
            }

            // only include bulletins after the specified id
            if (bulletinQuery.getAfter() != null && bulletin.getId() <= bulletinQuery.getAfter()) {
                return false;
            }

            // if group pattern was specified see if it should be excluded
            if (bulletinQuery.getGroupIdPattern() != null) {
                // exclude if this bulletin doesnt have a group or if it doesnt match
                if (bulletin.getGroupId() == null || !bulletinQuery.getGroupIdPattern().matcher(bulletin.getGroupId()).find()) {
                    return false;
                }
            }

            // if a message pattern was specified see if it should be excluded
            if (bulletinQuery.getMessagePattern() != null) {
                // exclude if this bulletin doesnt have a message or if it doesnt match
                if (bulletin.getMessage() == null || !bulletinQuery.getMessagePattern().matcher(bulletin.getMessage()).find()) {
                    return false;
                }
            }

            // if a name pattern was specified see if it should be excluded
            if (bulletinQuery.getNamePattern() != null) {
                // exclude if this bulletin doesnt have a source name or if it doesnt match
                if (bulletin.getSourceName() == null || !bulletinQuery.getNamePattern().matcher(bulletin.getSourceName()).find()) {
                    return false;
                }
            }

            // if a source id was specified see if it should be excluded
            if (bulletinQuery.getSourceIdPattern() != null) {
                // exclude if this bulletin doesn't have a source id or if it doesn't match
                if (bulletin.getSourceId() == null || !bulletinQuery.getSourceIdPattern().matcher(bulletin.getSourceId()).find()) {
                    return false;
                }
            }

            // if a source component type was specified see if it should be excluded
            if (bulletinQuery.getSourceType() != null) {
                // exclude if this bulletin source type doesn't match
                if (bulletin.getSourceType() == null || !bulletinQuery.getSourceType().equals(bulletin.getSourceType())) {
                    return false;
                }
            }

            return true;
        }
    };

    final List<Bulletin> selected = new ArrayList<>();
    int max = bulletinQuery.getLimit() == null ? Integer.MAX_VALUE : bulletinQuery.getLimit();

    for (final ConcurrentMap<String, RingBuffer<Bulletin>> componentMap : bulletinStoreMap.values()) {
        for (final RingBuffer<Bulletin> ringBuffer : componentMap.values()) {
            final List<Bulletin> bulletinsForComponent = ringBuffer.getSelectedElements(filter, max);
            selected.addAll(bulletinsForComponent);
            max -= bulletinsForComponent.size();
            if (max <= 0) {
                break;
            }
        }
    }

    // sort by descending ID
    Collections.sort(selected);

    return selected;
}
 
Example #8
Source File: VolatileBulletinRepository.java    From localization_nifi with Apache License 2.0 4 votes vote down vote up
@Override
public List<Bulletin> findBulletinsForSource(String sourceId) {
    return findBulletins(new BulletinQuery.Builder().sourceIdMatches(sourceId).limit(COMPONENT_BUFFER_SIZE).build());
}
 
Example #9
Source File: StatusRequestParser.java    From nifi-minifi with Apache License 2.0 4 votes vote down vote up
static ProcessorStatusBean parseProcessorStatusRequest(ProcessorStatus inputProcessorStatus, String statusTypes, FlowController flowController, Collection<ValidationResult> validationResults) {
    ProcessorStatusBean processorStatusBean = new ProcessorStatusBean();
    processorStatusBean.setId(inputProcessorStatus.getId());
    processorStatusBean.setName(inputProcessorStatus.getName());

    String[] statusSplits = statusTypes.split(",");
    List<Bulletin> bulletinList = flowController.getBulletinRepository().findBulletins(
            new BulletinQuery.Builder()
                    .sourceIdMatches(inputProcessorStatus.getId())
                    .build());

    for (String statusType : statusSplits) {
        switch (statusType.toLowerCase().trim()) {
            case "health":
                ProcessorHealth processorHealth = new ProcessorHealth();

                processorHealth.setRunStatus(inputProcessorStatus.getRunStatus().name());
                processorHealth.setHasBulletins(!bulletinList.isEmpty());
                processorHealth.setValidationErrorList(transformValidationResults(validationResults));

                processorStatusBean.setProcessorHealth(processorHealth);
                break;
            case "bulletins":
                processorStatusBean.setBulletinList(transformBulletins(bulletinList));
                break;
            case "stats":
                ProcessorStats processorStats = new ProcessorStats();

                processorStats.setActiveThreads(inputProcessorStatus.getActiveThreadCount());
                processorStats.setFlowfilesReceived(inputProcessorStatus.getFlowFilesReceived());
                processorStats.setBytesRead(inputProcessorStatus.getBytesRead());
                processorStats.setBytesWritten(inputProcessorStatus.getBytesWritten());
                processorStats.setFlowfilesSent(inputProcessorStatus.getFlowFilesSent());
                processorStats.setInvocations(inputProcessorStatus.getInvocations());
                processorStats.setProcessingNanos(inputProcessorStatus.getProcessingNanos());

                processorStatusBean.setProcessorStats(processorStats);
                break;
        }
    }
    return processorStatusBean;
}
 
Example #10
Source File: StatusRequestParser.java    From nifi-minifi with Apache License 2.0 4 votes vote down vote up
static RemoteProcessGroupStatusBean parseRemoteProcessGroupStatusRequest(RemoteProcessGroupStatus inputRemoteProcessGroupStatus, String statusTypes, FlowController flowController) {
    RemoteProcessGroupStatusBean remoteProcessGroupStatusBean = new RemoteProcessGroupStatusBean();
    remoteProcessGroupStatusBean.setName(inputRemoteProcessGroupStatus.getName());

    String rootGroupId = flowController.getRootGroupId();
    String[] statusSplits = statusTypes.split(",");

    List<Bulletin> bulletinList = flowController.getBulletinRepository().findBulletins(
            new BulletinQuery.Builder()
                    .sourceIdMatches(inputRemoteProcessGroupStatus.getId())
                    .build());

    for (String statusType : statusSplits) {
        switch (statusType.toLowerCase().trim()) {
            case "health":
                RemoteProcessGroupHealth remoteProcessGroupHealth = new RemoteProcessGroupHealth();

                remoteProcessGroupHealth.setTransmissionStatus(inputRemoteProcessGroupStatus.getTransmissionStatus().name());
                remoteProcessGroupHealth.setActivePortCount(inputRemoteProcessGroupStatus.getActiveRemotePortCount());
                remoteProcessGroupHealth.setInactivePortCount(inputRemoteProcessGroupStatus.getInactiveRemotePortCount());
                remoteProcessGroupHealth.setHasBulletins(!bulletinList.isEmpty());

                remoteProcessGroupStatusBean.setRemoteProcessGroupHealth(remoteProcessGroupHealth);
                break;
            case "bulletins":
                remoteProcessGroupStatusBean.setBulletinList(transformBulletins(bulletinList));
                break;
            case "inputports":
                remoteProcessGroupStatusBean.setInputPortStatusList(getPortStatusList(inputRemoteProcessGroupStatus, flowController, rootGroupId, RemoteProcessGroup::getInputPorts));
                break;
            case "outputports":
                remoteProcessGroupStatusBean.setOutputPortStatusList(getPortStatusList(inputRemoteProcessGroupStatus, flowController, rootGroupId, RemoteProcessGroup::getOutputPorts));
                break;
            case "stats":
                RemoteProcessGroupStats remoteProcessGroupStats = new RemoteProcessGroupStats();

                remoteProcessGroupStats.setActiveThreads(inputRemoteProcessGroupStatus.getActiveThreadCount());
                remoteProcessGroupStats.setSentContentSize(inputRemoteProcessGroupStatus.getSentContentSize());
                remoteProcessGroupStats.setSentCount(inputRemoteProcessGroupStatus.getSentCount());

                remoteProcessGroupStatusBean.setRemoteProcessGroupStats(remoteProcessGroupStats);
                break;
        }
    }
    return remoteProcessGroupStatusBean;
}
 
Example #11
Source File: MockBulletinRepository.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public List<Bulletin> findBulletins(BulletinQuery bulletinQuery) {
    // TODO: Implement
    return null;
}
 
Example #12
Source File: VolatileBulletinRepository.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public List<Bulletin> findBulletins(final BulletinQuery bulletinQuery) {
    final Filter<Bulletin> filter = new Filter<Bulletin>() {
        @Override
        public boolean select(final Bulletin bulletin) {
            final long fiveMinutesAgo = System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(5);
            if (bulletin.getTimestamp().getTime() < fiveMinutesAgo) {
                return false;
            }

            // only include bulletins after the specified id
            if (bulletinQuery.getAfter() != null && bulletin.getId() <= bulletinQuery.getAfter()) {
                return false;
            }

            // if group pattern was specified see if it should be excluded
            if (bulletinQuery.getGroupIdPattern() != null) {
                // exclude if this bulletin doesnt have a group or if it doesnt match
                if (bulletin.getGroupId() == null || !bulletinQuery.getGroupIdPattern().matcher(bulletin.getGroupId()).find()) {
                    return false;
                }
            }

            // if a message pattern was specified see if it should be excluded
            if (bulletinQuery.getMessagePattern() != null) {
                // exclude if this bulletin doesnt have a message or if it doesnt match
                if (bulletin.getMessage() == null || !bulletinQuery.getMessagePattern().matcher(bulletin.getMessage()).find()) {
                    return false;
                }
            }

            // if a name pattern was specified see if it should be excluded
            if (bulletinQuery.getNamePattern() != null) {
                // exclude if this bulletin doesnt have a source name or if it doesnt match
                if (bulletin.getSourceName() == null || !bulletinQuery.getNamePattern().matcher(bulletin.getSourceName()).find()) {
                    return false;
                }
            }

            // if a source id was specified see if it should be excluded
            if (bulletinQuery.getSourceIdPattern() != null) {
                // exclude if this bulletin doesn't have a source id or if it doesn't match
                if (bulletin.getSourceId() == null || !bulletinQuery.getSourceIdPattern().matcher(bulletin.getSourceId()).find()) {
                    return false;
                }
            }

            // if a source component type was specified see if it should be excluded
            if (bulletinQuery.getSourceType() != null) {
                // exclude if this bulletin source type doesn't match
                if (bulletin.getSourceType() == null || !bulletinQuery.getSourceType().equals(bulletin.getSourceType())) {
                    return false;
                }
            }

            return true;
        }
    };

    final Set<Bulletin> selected = new TreeSet<>();
    int max = bulletinQuery.getLimit() == null ? Integer.MAX_VALUE : bulletinQuery.getLimit();

    for (final ConcurrentMap<String, RingBuffer<Bulletin>> componentMap : bulletinStoreMap.values()) {
        for (final RingBuffer<Bulletin> ringBuffer : componentMap.values()) {
            final List<Bulletin> bulletinsForComponent = ringBuffer.getSelectedElements(filter, max);
            selected.addAll(bulletinsForComponent);
            max -= bulletinsForComponent.size();
            if (max <= 0) {
                break;
            }
        }
    }

    return new ArrayList<>(selected);
}
 
Example #13
Source File: VolatileBulletinRepository.java    From nifi with Apache License 2.0 4 votes vote down vote up
@Override
public List<Bulletin> findBulletinsForSource(String sourceId) {
    return findBulletins(new BulletinQuery.Builder().sourceIdMatches(sourceId).limit(COMPONENT_BUFFER_SIZE).build());
}