org.apache.nifi.reporting.Bulletin Java Examples

The following examples show how to use org.apache.nifi.reporting.Bulletin. 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: ScriptedActionHandlerTest.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testPropertyContextActionHandler() throws InitializationException {
    actionHandler = initTask("src/test/resources/groovy/test_propertycontext_action_handler.groovy");
    mockScriptedBulletinRepository = new MockScriptedBulletinRepository();
    reportingContext = mock(ReportingContext.class);
    when(reportingContext.getBulletinRepository()).thenReturn(mockScriptedBulletinRepository);
    when(reportingContext.createBulletin(anyString(), Mockito.any(Severity.class), anyString()))
            .thenAnswer(invocation -> BulletinFactory.createBulletin(invocation.getArgument(0), invocation.getArgument(1).toString(), invocation.getArgument(2)));
    actionHandler.onEnabled(context);
    List<Action> actions = Arrays.asList(new Action("LOG", attrs), new Action("ALERT", attrs));
    actions.forEach(action -> actionHandler.execute(reportingContext, action, facts));

    // Verify instead of a bulletin being added, a fact was added (not the intended operation of ActionHandler, but testable)
    List<Bulletin> bulletinList = mockScriptedBulletinRepository.bulletinList;
    assertEquals(2, bulletinList.size());
}
 
Example #2
Source File: BulletinEnumerator.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public boolean moveNext() {
    currentRow = null;

    if (!bulletinIterator.hasNext()) {
        // If we are out of data, close the InputStream. We do this because
        // Calcite does not necessarily call our close() method.
        close();
        try {
            onFinish();
        } catch (final Exception e) {
            logger.error("Failed to perform tasks when enumerator was finished", e);
        }

        return false;
    }

    final Bulletin bulletin = bulletinIterator.next();
    currentRow = filterColumns(bulletin);

    recordsRead++;
    return true;
}
 
Example #3
Source File: BulletinAdapter.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public AdaptedBulletin marshal(final Bulletin b) throws Exception {
    if (b == null) {
        return null;
    }
    final AdaptedBulletin aBulletin = new AdaptedBulletin();
    aBulletin.setId(b.getId());
    aBulletin.setTimestamp(b.getTimestamp());
    aBulletin.setGroupId(b.getGroupId());
    aBulletin.setGroupName(b.getGroupName());
    aBulletin.setSourceId(b.getSourceId());
    aBulletin.setSourceType(b.getSourceType());
    aBulletin.setSourceName(b.getSourceName());
    aBulletin.setCategory(b.getCategory());
    aBulletin.setLevel(b.getLevel());
    aBulletin.setMessage(b.getMessage());
    return aBulletin;
}
 
Example #4
Source File: BulletinAdapter.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Override
public AdaptedBulletin marshal(final Bulletin b) throws Exception {
    if (b == null) {
        return null;
    }
    final AdaptedBulletin aBulletin = new AdaptedBulletin();
    aBulletin.setId(b.getId());
    aBulletin.setTimestamp(b.getTimestamp());
    aBulletin.setGroupId(b.getGroupId());
    aBulletin.setSourceId(b.getSourceId());
    aBulletin.setSourceType(b.getSourceType());
    aBulletin.setSourceName(b.getSourceName());
    aBulletin.setCategory(b.getCategory());
    aBulletin.setLevel(b.getLevel());
    aBulletin.setMessage(b.getMessage());
    return aBulletin;
}
 
Example #5
Source File: BulletinFactory.java    From nifi with Apache License 2.0 6 votes vote down vote up
public static Bulletin createBulletin(final Connectable connectable, final String category, final String severity, final String message) {
    final ComponentType type;
    switch (connectable.getConnectableType()) {
        case REMOTE_INPUT_PORT:
        case REMOTE_OUTPUT_PORT:
            type = ComponentType.REMOTE_PROCESS_GROUP;
            break;
        case INPUT_PORT:
            type = ComponentType.INPUT_PORT;
            break;
        case OUTPUT_PORT:
            type = ComponentType.OUTPUT_PORT;
            break;
        case PROCESSOR:
        default:
            type = ComponentType.PROCESSOR;
            break;
    }

    final ProcessGroup group = connectable.getProcessGroup();
    final String groupId = connectable.getProcessGroupIdentifier();
    final String groupName = group == null ? null : group.getName();
    final String groupPath = buildGroupPath(group);
    return BulletinFactory.createBulletin(groupId, groupName, connectable.getIdentifier(), type, connectable.getName(), category, severity, message, groupPath);
}
 
Example #6
Source File: VolatileBulletinRepository.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Override
public List<Bulletin> findBulletinsForGroupBySource(final String groupId, final int maxPerComponent) {
    final long fiveMinutesAgo = System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(5);

    final ConcurrentMap<String, RingBuffer<Bulletin>> componentMap = bulletinStoreMap.get(groupId);
    if (componentMap == null) {
        return Collections.<Bulletin>emptyList();
    }

    final List<Bulletin> allComponentBulletins = new ArrayList<>();
    for (final RingBuffer<Bulletin> ringBuffer : componentMap.values()) {
        allComponentBulletins.addAll(ringBuffer.getSelectedElements(new Filter<Bulletin>() {
            @Override
            public boolean select(final Bulletin bulletin) {
                return bulletin.getTimestamp().getTime() >= fiveMinutesAgo;
            }
        }, maxPerComponent));
    }

    return allComponentBulletins;
}
 
Example #7
Source File: BulletinFactory.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
public static Bulletin createBulletin(final Connectable connectable, final String category, final String severity, final String message) {
    final ComponentType type;
    switch (connectable.getConnectableType()) {
        case REMOTE_INPUT_PORT:
        case REMOTE_OUTPUT_PORT:
            type = ComponentType.REMOTE_PROCESS_GROUP;
            break;
        case INPUT_PORT:
            type = ComponentType.INPUT_PORT;
            break;
        case OUTPUT_PORT:
            type = ComponentType.OUTPUT_PORT;
            break;
        case PROCESSOR:
        default:
            type = ComponentType.PROCESSOR;
            break;
    }

    final ProcessGroup group = connectable.getProcessGroup();
    final String groupId = group == null ? null : group.getIdentifier();
    return BulletinFactory.createBulletin(groupId, connectable.getIdentifier(), type, connectable.getName(), category, severity, message);
}
 
Example #8
Source File: TestAlertHandler.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testAlertWithBulletinLevel() {

    final Map<String, String> attributes = new HashMap<>();
    final Map<String, Object> metrics = new HashMap<>();

    final String category = "Rules Alert";
    final String message = "This should be sent as an alert!";
    final String severity =  "INFO";
    attributes.put("category", category);
    attributes.put("message", message);
    attributes.put("severity", severity);
    metrics.put("jvmHeap", "1000000");
    metrics.put("cpu", "90");

    final String expectedOutput = "This should be sent as an alert!\n" +
            "Alert Facts:\n" +
            "Field: cpu, Value: 90\n" +
            "Field: jvmHeap, Value: 1000000\n";

    final Action action = new Action();
    action.setType("ALERT");
    action.setAttributes(attributes);
    alertHandler.execute(reportingContext, action, metrics);
    BulletinRepository bulletinRepository = reportingContext.getBulletinRepository();
    List<Bulletin> bulletins = bulletinRepository.findBulletinsForController();
    assertFalse(bulletins.isEmpty());
    Bulletin bulletin = bulletins.get(0);
    assertEquals(bulletin.getCategory(), category);
    assertEquals(bulletin.getMessage(), expectedOutput);
    assertEquals(bulletin.getLevel(), severity);
}
 
Example #9
Source File: StandardReportingContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Bulletin createBulletin(final String componentId, final String category, final Severity severity, final String message) {
    final Connectable connectable = flowController.getFlowManager().findConnectable(componentId);
    if (connectable == null) {
        throw new IllegalStateException("Cannot create Component-Level Bulletin because no component can be found with ID " + componentId);
    }
    return BulletinFactory.createBulletin(connectable, category, severity.name(), message);
}
 
Example #10
Source File: ScriptedActionHandlerTest.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testAlertWithBulletinLevel() throws Exception {
    setupTestRunner();
    final Map<String, String> attributes = new HashMap<>();
    final Map<String, Object> metrics = new HashMap<>();

    final String category = "Rules Alert";
    final String message = "This should be sent as an alert!";
    final String severity = "INFO";
    attributes.put("category", category);
    attributes.put("message", message);
    attributes.put("severity", severity);
    metrics.put("jvmHeap", "1000000");
    metrics.put("cpu", "90");

    final String expectedOutput = "This should be sent as an alert!\n" +
            "Alert Facts:\n" +
            "Field: cpu, Value: 90\n" +
            "Field: jvmHeap, Value: 1000000\n";

    final Action action = new Action();
    action.setType("ALERT");
    action.setAttributes(attributes);
    actionHandler.execute(reportingContext, action, metrics);
    BulletinRepository bulletinRepository = reportingContext.getBulletinRepository();
    List<Bulletin> bulletins = bulletinRepository.findBulletinsForController();
    assertFalse(bulletins.isEmpty());
    Bulletin bulletin = bulletins.get(0);
    assertEquals(bulletin.getCategory(), category);
    assertEquals(bulletin.getMessage(), expectedOutput);
    assertEquals(bulletin.getLevel(), severity);
}
 
Example #11
Source File: VolatileBulletinRepository.java    From nifi with Apache License 2.0 5 votes vote down vote up
private boolean isControllerBulletin(final Bulletin bulletin) {
    switch (bulletin.getSourceType()) {
        case FLOW_CONTROLLER:
        case CONTROLLER_SERVICE:
        case REPORTING_TASK:
            return true;
        default:
            return false;
    }
}
 
Example #12
Source File: VolatileBulletinRepository.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private boolean isControllerBulletin(final Bulletin bulletin) {
    switch (bulletin.getSourceType()) {
        case FLOW_CONTROLLER:
        case CONTROLLER_SERVICE:
        case REPORTING_TASK:
            return true;
        default:
            return false;
    }
}
 
Example #13
Source File: TestAlertHandler.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testAlertWithDefaultValues() {

    final Map<String, String> attributes = new HashMap<>();
    final Map<String, Object> metrics = new HashMap<>();

    final String category = "Rules Triggered Alert";
    final String message = "An alert was triggered by a rules based action.";
    final String severity =  "INFO";
    metrics.put("jvmHeap", "1000000");
    metrics.put("cpu", "90");

    final String expectedOutput = "An alert was triggered by a rules-based action.\n" +
            "Alert Facts:\n" +
            "Field: cpu, Value: 90\n" +
            "Field: jvmHeap, Value: 1000000\n";

    final Action action = new Action();
    action.setType("ALERT");
    action.setAttributes(attributes);
    alertHandler.execute(reportingContext, action, metrics);
    BulletinRepository bulletinRepository = reportingContext.getBulletinRepository();
    List<Bulletin> bulletins = bulletinRepository.findBulletinsForController();
    assertFalse(bulletins.isEmpty());
    Bulletin bulletin = bulletins.get(0);
    assertEquals(bulletin.getCategory(), category);
    assertEquals(bulletin.getMessage(), expectedOutput);
    assertEquals(bulletin.getLevel(), severity);
}
 
Example #14
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 #15
Source File: ControllerServiceLogObserver.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void onLogMessage(final LogMessage message) {
    // Map LogLevel.WARN to Severity.WARNING so that we are consistent with the Severity enumeration. Else, just use whatever
    // the LogLevel is (INFO and ERROR map directly and all others we will just accept as they are).
    final String bulletinLevel = message.getLevel() == LogLevel.WARN ? Severity.WARNING.name() : message.getLevel().toString();

    final ProcessGroup pg = serviceNode.getProcessGroup();
    final String groupId = pg == null ? null : pg.getIdentifier();
    final String groupName = pg == null ? null : pg.getName();

    final Bulletin bulletin = BulletinFactory.createBulletin(groupId, groupName, serviceNode.getIdentifier(), ComponentType.CONTROLLER_SERVICE,
            serviceNode.getName(), "Log Message", bulletinLevel, message.getMessage());
    bulletinRepository.addBulletin(bulletin);
}
 
Example #16
Source File: FlowController.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
public void setPrimary(final boolean primary) {
    final PrimaryNodeState nodeState = primary ? PrimaryNodeState.ELECTED_PRIMARY_NODE : PrimaryNodeState.PRIMARY_NODE_REVOKED;
    final ProcessGroup rootGroup = getGroup(getRootGroupId());
    for (final ProcessorNode procNode : rootGroup.findAllProcessors()) {
        try (final NarCloseable narCloseable = NarCloseable.withComponentNarLoader(procNode.getProcessor().getClass(), procNode.getIdentifier())) {
            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnPrimaryNodeStateChange.class, procNode.getProcessor(), nodeState);
        }
    }
    for (final ControllerServiceNode serviceNode : getAllControllerServices()) {
        try (final NarCloseable narCloseable = NarCloseable.withComponentNarLoader(serviceNode.getControllerServiceImplementation().getClass(), serviceNode.getIdentifier())) {
            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnPrimaryNodeStateChange.class, serviceNode.getControllerServiceImplementation(), nodeState);
        }
    }
    for (final ReportingTaskNode reportingTaskNode : getAllReportingTasks()) {
        try (final NarCloseable narCloseable = NarCloseable.withComponentNarLoader(reportingTaskNode.getReportingTask().getClass(), reportingTaskNode.getIdentifier())) {
            ReflectionUtils.quietlyInvokeMethodsWithAnnotation(OnPrimaryNodeStateChange.class, reportingTaskNode.getReportingTask(), nodeState);
        }
    }

    // update primary
    eventDrivenWorkerQueue.setPrimary(primary);

    // update the heartbeat bean
    final HeartbeatBean oldBean = this.heartbeatBeanRef.getAndSet(new HeartbeatBean(rootGroup, primary));

    // Emit a bulletin detailing the fact that the primary node state has changed
    if (oldBean == null || oldBean.isPrimary() != primary) {
        final String message = primary ? "This node has been elected Primary Node" : "This node is no longer Primary Node";
        final Bulletin bulletin = BulletinFactory.createBulletin("Primary Node", Severity.INFO.name(), message);
        bulletinRepository.addBulletin(bulletin);
        LOG.info(message);
    }
}
 
Example #17
Source File: BulletinFactory.java    From nifi with Apache License 2.0 5 votes vote down vote up
public static Bulletin createBulletin(final String groupId, final String sourceId, final ComponentType sourceType, final String sourceName,
    final String category, final String severity, final String message) {
    final Bulletin bulletin = new ComponentBulletin(currentId.getAndIncrement());
    bulletin.setGroupId(groupId);
    bulletin.setSourceId(sourceId);
    bulletin.setSourceType(sourceType);
    bulletin.setSourceName(sourceName);
    bulletin.setCategory(category);
    bulletin.setLevel(severity);
    bulletin.setMessage(message);
    return bulletin;
}
 
Example #18
Source File: StandardNiFiServiceFacade.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private List<BulletinEntity> getProcessGroupBulletins(final ProcessGroup group) {
    final List<Bulletin> bulletins = new ArrayList<>(bulletinRepository.findBulletinsForGroupBySource(group.getIdentifier()));

    for (final ProcessGroup descendantGroup : group.findAllProcessGroups()) {
        bulletins.addAll(bulletinRepository.findBulletinsForGroupBySource(descendantGroup.getIdentifier()));
    }

    List<BulletinEntity> bulletinEntities = new ArrayList<>();
    for (final Bulletin bulletin : bulletins) {
        bulletinEntities.add(entityFactory.createBulletinEntity(dtoFactory.createBulletinDto(bulletin), authorizeBulletin(bulletin)));
    }

    return pruneAndSortBulletins(bulletinEntities, BulletinRepository.MAX_BULLETINS_PER_COMPONENT);
}
 
Example #19
Source File: VolatileBulletinRepository.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public List<Bulletin> findBulletinsForController(final int max) {
    final long fiveMinutesAgo = System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(5);

    final Filter<Bulletin> filter = new Filter<Bulletin>() {
        @Override
        public boolean select(final Bulletin bulletin) {
            return bulletin.getTimestamp().getTime() >= fiveMinutesAgo;
        }
    };

    final List<Bulletin> controllerBulletins = new ArrayList<>();

    final ConcurrentMap<String, RingBuffer<Bulletin>> controllerBulletinMap = bulletinStoreMap.get(CONTROLLER_BULLETIN_STORE_KEY);
    if (controllerBulletinMap != null) {
        final RingBuffer<Bulletin> buffer = controllerBulletinMap.get(CONTROLLER_BULLETIN_STORE_KEY);
        if (buffer != null) {
            controllerBulletins.addAll(buffer.getSelectedElements(filter, max));
        }
    }

    // We only want the newest bulletin, so we sort based on time and take the top 'max' entries
    Collections.sort(controllerBulletins);
    if (controllerBulletins.size() > max) {
        return controllerBulletins.subList(0, max);
    }

    return controllerBulletins;
}
 
Example #20
Source File: VolatileBulletinRepository.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private String getBulletinStoreKey(final Bulletin bulletin) {
    switch (bulletin.getSourceType()) {
        case FLOW_CONTROLLER:
            return CONTROLLER_BULLETIN_STORE_KEY;
        case CONTROLLER_SERVICE:
            return SERVICE_BULLETIN_STORE_KEY;
        case REPORTING_TASK:
            return REPORTING_TASK_BULLETIN_STORE_KEY;
        default:
            return bulletin.getGroupId();
    }
}
 
Example #21
Source File: BulletinAdapter.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Bulletin unmarshal(final AdaptedBulletin b) throws Exception {
    if (b == null) {
        return null;
    }
    // TODO - timestamp is overridden here with a new timestamp... address?
    if (b.getSourceId() == null) {
        return BulletinFactory.createBulletin(b.getCategory(), b.getLevel(), b.getMessage());
    } else {
        return BulletinFactory.createBulletin(b.getGroupId(), b.getSourceId(), b.getSourceType(), b.getSourceName(), b.getCategory(), b.getLevel(), b.getMessage());
    }
}
 
Example #22
Source File: FlowController.java    From nifi with Apache License 2.0 5 votes vote down vote up
public EventReporter createEventReporter() {
    return new EventReporter() {
        private static final long serialVersionUID = 1L;

        @Override
        public void reportEvent(final Severity severity, final String category, final String message) {
            final Bulletin bulletin = BulletinFactory.createBulletin(category, severity.name(), message);
            bulletinRepository.addBulletin(bulletin);
        }
    };
}
 
Example #23
Source File: VolatileBulletinRepository.java    From nifi with Apache License 2.0 5 votes vote down vote up
private String getBulletinStoreKey(final Bulletin bulletin) {
    switch (bulletin.getSourceType()) {
        case FLOW_CONTROLLER:
            return CONTROLLER_BULLETIN_STORE_KEY;
        case CONTROLLER_SERVICE:
            return SERVICE_BULLETIN_STORE_KEY;
        case REPORTING_TASK:
            return REPORTING_TASK_BULLETIN_STORE_KEY;
        default:
            return bulletin.getGroupId();
    }
}
 
Example #24
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 #25
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 #26
Source File: StatusRequestParser.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
static InstanceStatus parseInstanceRequest(String statusTypes, FlowController flowController, ProcessGroupStatus rootGroupStatus) {
    InstanceStatus instanceStatus = new InstanceStatus();

    flowController.getAllControllerServices();
    List<Bulletin> bulletinList = flowController.getBulletinRepository().findBulletinsForController();
    String[] statusSplits = statusTypes.split(",");

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

                instanceHealth.setQueuedCount(rootGroupStatus.getQueuedCount());
                instanceHealth.setQueuedContentSize(rootGroupStatus.getQueuedContentSize());
                instanceHealth.setHasBulletins(!bulletinList.isEmpty());
                instanceHealth.setActiveThreads(rootGroupStatus.getActiveThreadCount());

                instanceStatus.setInstanceHealth(instanceHealth);
                break;
            case "bulletins":
                instanceStatus.setBulletinList(transformBulletins(flowController.getBulletinRepository().findBulletinsForController()));
                break;
            case "stats":
                InstanceStats instanceStats = new InstanceStats();

                instanceStats.setBytesRead(rootGroupStatus.getBytesRead());
                instanceStats.setBytesWritten(rootGroupStatus.getBytesWritten());
                instanceStats.setBytesSent(rootGroupStatus.getBytesSent());
                instanceStats.setFlowfilesSent(rootGroupStatus.getFlowFilesSent());
                instanceStats.setBytesTransferred(rootGroupStatus.getBytesTransferred());
                instanceStats.setFlowfilesTransferred(rootGroupStatus.getFlowFilesTransferred());
                instanceStats.setBytesReceived(rootGroupStatus.getBytesReceived());
                instanceStats.setFlowfilesReceived(rootGroupStatus.getFlowFilesReceived());

                instanceStatus.setInstanceStats(instanceStats);
                break;
        }
    }
    return instanceStatus;
}
 
Example #27
Source File: StatusRequestParser.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
private static List<BulletinStatus> transformBulletins(List<Bulletin> bulletinList) {
    List<BulletinStatus> bulletinStatusList = new LinkedList<>();
    if (!bulletinList.isEmpty()) {
        for (Bulletin bulletin : bulletinList) {
            BulletinStatus bulletinStatus = new BulletinStatus();
            bulletinStatus.setMessage(bulletin.getMessage());
            bulletinStatus.setTimestamp(bulletin.getTimestamp());
            bulletinStatusList.add(bulletinStatus);
        }
    }
    return bulletinStatusList;
}
 
Example #28
Source File: StatusConfigReporterTest.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
/***************************
 * Populator methods
 *************************/

private void addBulletinsToInstance() {
    Bulletin bulletin = mock(Bulletin.class);
    when(bulletin.getTimestamp()).thenReturn(new Date(1464019245000L));
    when(bulletin.getMessage()).thenReturn("Bulletin message");

    List<Bulletin> bulletinList = new ArrayList<>();
    bulletinList.add(bulletin);

    when(bulletinRepo.findBulletinsForController()).thenReturn(bulletinList);
}
 
Example #29
Source File: StatusConfigReporterTest.java    From nifi-minifi with Apache License 2.0 5 votes vote down vote up
private void addBulletins(String message, String sourceId) {
    Bulletin bulletin = mock(Bulletin.class);
    when(bulletin.getTimestamp()).thenReturn(new Date(1464019245000L));
    when(bulletin.getMessage()).thenReturn(message);

    List<Bulletin> bulletinList = new ArrayList<>();
    bulletinList.add(bulletin);

    BulletinQueryAnswer bulletinQueryAnswer = new BulletinQueryAnswer(sourceId, bulletinList);
    when(bulletinRepo.findBulletins(anyObject())).then(bulletinQueryAnswer);
}
 
Example #30
Source File: MockReportingContext.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public Bulletin createBulletin(final String componentId, final String category, final Severity severity, final String message) {
    final Bulletin bulletin = BulletinFactory.createBulletin(null, null, componentId, "test processor", category, severity.name(), message);
    List<Bulletin> bulletins = componentBulletinsCreated.get(componentId);
    if (bulletins == null) {
        bulletins = new ArrayList<>();
        componentBulletinsCreated.put(componentId, bulletins);
    }
    bulletins.add(bulletin);
    return bulletin;
}