Search in sources :

Example 16 with ProcessorStatus

use of org.apache.nifi.controller.status.ProcessorStatus in project nifi-minifi by apache.

the class StatusConfigReporter method getStatus.

public static FlowStatusReport getStatus(FlowController flowController, String statusRequest, Logger logger) throws StatusRequestException {
    if (statusRequest == null) {
        logger.error("Received a status request which was null");
        throw new StatusRequestException("Cannot complete status request because the statusRequest is null");
    }
    if (flowController == null) {
        logger.error("Received a status but the Flow Controller is null");
        throw new StatusRequestException("Cannot complete status request because the Flow Controller is null");
    }
    FlowStatusReport flowStatusReport = new FlowStatusReport();
    List<String> errorsGeneratingReport = new LinkedList<>();
    flowStatusReport.setErrorsGeneratingReport(errorsGeneratingReport);
    String[] itemsToReport = statusRequest.split(";");
    ProcessGroupStatus rootGroupStatus = flowController.getControllerStatus();
    Map<String, ProcessorStatus> processorStatusMap = null;
    Map<String, ConnectionStatus> connectionStatusMap = null;
    Map<String, RemoteProcessGroupStatus> remoteProcessGroupStatusMap = null;
    for (String item : itemsToReport) {
        String[] sections = item.split(":");
        try {
            switch(sections[0].toLowerCase().trim()) {
                case "systemdiagnostics":
                    SystemDiagnosticsStatus systemDiagnosticsStatus = parseSystemDiagnosticsRequest(flowController.getSystemDiagnostics(), sections[1]);
                    flowStatusReport.setSystemDiagnosticsStatus(systemDiagnosticsStatus);
                    break;
                case "instance":
                    InstanceStatus instanceStatus = parseInstanceRequest(sections[1], flowController, rootGroupStatus);
                    flowStatusReport.setInstanceStatus(instanceStatus);
                    break;
                case "remoteprocessgroup":
                    if (flowStatusReport.getRemoteProcessGroupStatusList() == null) {
                        List<RemoteProcessGroupStatusBean> remoteProcessGroupStatusList = new LinkedList<>();
                        flowStatusReport.setRemoteProcessGroupStatusList(remoteProcessGroupStatusList);
                    }
                    handleRemoteProcessGroupRequest(sections, rootGroupStatus, flowController, flowStatusReport.getRemoteProcessGroupStatusList(), remoteProcessGroupStatusMap, logger);
                    break;
                case "processor":
                    if (flowStatusReport.getProcessorStatusList() == null) {
                        List<ProcessorStatusBean> processorStatusList = new LinkedList<>();
                        flowStatusReport.setProcessorStatusList(processorStatusList);
                    }
                    handleProcessorRequest(sections, rootGroupStatus, flowController, flowStatusReport.getProcessorStatusList(), processorStatusMap, logger);
                    break;
                case "connection":
                    if (flowStatusReport.getConnectionStatusList() == null) {
                        List<ConnectionStatusBean> connectionStatusList = new LinkedList<>();
                        flowStatusReport.setConnectionStatusList(connectionStatusList);
                    }
                    handleConnectionRequest(sections, rootGroupStatus, flowStatusReport.getConnectionStatusList(), connectionStatusMap, logger);
                    break;
                case "provenancereporting":
                    if (flowStatusReport.getRemoteProcessGroupStatusList() == null) {
                        List<ReportingTaskStatus> reportingTaskStatusList = new LinkedList<>();
                        flowStatusReport.setReportingTaskStatusList(reportingTaskStatusList);
                    }
                    handleReportingTaskRequest(sections, flowController, flowStatusReport.getReportingTaskStatusList(), logger);
                    break;
                case "controllerservices":
                    if (flowStatusReport.getControllerServiceStatusList() == null) {
                        List<ControllerServiceStatus> controllerServiceStatusList = new LinkedList<>();
                        flowStatusReport.setControllerServiceStatusList(controllerServiceStatusList);
                    }
                    handleControllerServices(sections, flowController, flowStatusReport.getControllerServiceStatusList(), logger);
                    break;
            }
        } catch (Exception e) {
            logger.error("Hit exception while requesting status for item '" + item + "'", e);
            errorsGeneratingReport.add("Unable to get status for request '" + item + "' due to:" + e);
        }
    }
    return flowStatusReport;
}
Also used : ConnectionStatusBean(org.apache.nifi.minifi.commons.status.connection.ConnectionStatusBean) InstanceStatus(org.apache.nifi.minifi.commons.status.instance.InstanceStatus) ProcessorStatusBean(org.apache.nifi.minifi.commons.status.processor.ProcessorStatusBean) ConnectionStatus(org.apache.nifi.controller.status.ConnectionStatus) ReportingTaskStatus(org.apache.nifi.minifi.commons.status.reportingTask.ReportingTaskStatus) ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) FlowStatusReport(org.apache.nifi.minifi.commons.status.FlowStatusReport) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) LinkedList(java.util.LinkedList) RemoteProcessGroupStatusBean(org.apache.nifi.minifi.commons.status.rpg.RemoteProcessGroupStatusBean) ControllerServiceStatus(org.apache.nifi.minifi.commons.status.controllerservice.ControllerServiceStatus) SystemDiagnosticsStatus(org.apache.nifi.minifi.commons.status.system.SystemDiagnosticsStatus)

Example 17 with ProcessorStatus

use of org.apache.nifi.controller.status.ProcessorStatus in project nifi by apache.

the class DataDogReportingTask method updateAllMetricGroups.

private void updateAllMetricGroups(ProcessGroupStatus processGroupStatus) {
    final List<ProcessorStatus> processorStatuses = new ArrayList<>();
    populateProcessorStatuses(processGroupStatus, processorStatuses);
    for (final ProcessorStatus processorStatus : processorStatuses) {
        updateMetrics(metricsService.getProcessorMetrics(processorStatus), Optional.of(processorStatus.getName()), defaultTags);
    }
    final List<ConnectionStatus> connectionStatuses = new ArrayList<>();
    populateConnectionStatuses(processGroupStatus, connectionStatuses);
    for (ConnectionStatus connectionStatus : connectionStatuses) {
        Map<String, String> connectionStatusTags = new HashMap<>(defaultTags);
        connectionStatusTags.putAll(metricsService.getConnectionStatusTags(connectionStatus));
        updateMetrics(metricsService.getConnectionStatusMetrics(connectionStatus), Optional.<String>absent(), connectionStatusTags);
    }
    final List<PortStatus> inputPortStatuses = new ArrayList<>();
    populateInputPortStatuses(processGroupStatus, inputPortStatuses);
    for (PortStatus portStatus : inputPortStatuses) {
        Map<String, String> portTags = new HashMap<>(defaultTags);
        portTags.putAll(metricsService.getPortStatusTags(portStatus));
        updateMetrics(metricsService.getPortStatusMetrics(portStatus), Optional.<String>absent(), portTags);
    }
    final List<PortStatus> outputPortStatuses = new ArrayList<>();
    populateOutputPortStatuses(processGroupStatus, outputPortStatuses);
    for (PortStatus portStatus : outputPortStatuses) {
        Map<String, String> portTags = new HashMap<>(defaultTags);
        portTags.putAll(metricsService.getPortStatusTags(portStatus));
        updateMetrics(metricsService.getPortStatusMetrics(portStatus), Optional.<String>absent(), portTags);
    }
    updateMetrics(metricsService.getJVMMetrics(virtualMachineMetrics), Optional.<String>absent(), defaultTags);
    updateMetrics(metricsService.getDataFlowMetrics(processGroupStatus), Optional.<String>absent(), defaultTags);
}
Also used : HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayList(java.util.ArrayList) PortStatus(org.apache.nifi.controller.status.PortStatus) ConnectionStatus(org.apache.nifi.controller.status.ConnectionStatus) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus)

Example 18 with ProcessorStatus

use of org.apache.nifi.controller.status.ProcessorStatus in project nifi by apache.

the class TestMetricsService method testGetProcessGroupStatusMetrics.

// test group status metric retrieving
@Test
public void testGetProcessGroupStatusMetrics() {
    ProcessorStatus procStatus = new ProcessorStatus();
    List<ProcessorStatus> processorStatuses = new ArrayList<>();
    processorStatuses.add(procStatus);
    status.setProcessorStatus(processorStatuses);
    final Map<String, Double> metrics = metricsService.getDataFlowMetrics(status);
    Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_RECEIVED));
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_RECEIVED));
    Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_SENT));
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_SENT));
    Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_QUEUED));
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_QUEUED));
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_READ));
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_WRITTEN));
    Assert.assertTrue(metrics.containsKey(MetricNames.ACTIVE_THREADS));
}
Also used : ArrayList(java.util.ArrayList) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) Test(org.junit.Test)

Example 19 with ProcessorStatus

use of org.apache.nifi.controller.status.ProcessorStatus in project nifi by apache.

the class TestMetricsService method testGetProcessorGroupStatusMetrics.

// test processor status metric retrieving
@Test
public void testGetProcessorGroupStatusMetrics() {
    ProcessorStatus procStatus = new ProcessorStatus();
    List<ProcessorStatus> processorStatuses = new ArrayList<>();
    processorStatuses.add(procStatus);
    status.setProcessorStatus(processorStatuses);
    final Map<String, Double> metrics = metricsService.getProcessorMetrics(procStatus);
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_READ));
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_WRITTEN));
    Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_RECEIVED));
    Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_SENT));
    Assert.assertTrue(metrics.containsKey(MetricNames.ACTIVE_THREADS));
}
Also used : ArrayList(java.util.ArrayList) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) Test(org.junit.Test)

Example 20 with ProcessorStatus

use of org.apache.nifi.controller.status.ProcessorStatus in project nifi by apache.

the class FlowController method getProcessorStatus.

private ProcessorStatus getProcessorStatus(final RepositoryStatusReport report, final ProcessorNode procNode, final Predicate<Authorizable> isAuthorized) {
    final boolean isProcessorAuthorized = isAuthorized.evaluate(procNode);
    final ProcessorStatus status = new ProcessorStatus();
    status.setId(procNode.getIdentifier());
    status.setGroupId(procNode.getProcessGroup().getIdentifier());
    status.setName(isProcessorAuthorized ? procNode.getName() : procNode.getIdentifier());
    status.setType(isProcessorAuthorized ? procNode.getComponentType() : "Processor");
    final FlowFileEvent entry = report.getReportEntries().get(procNode.getIdentifier());
    if (entry == null) {
        status.setInputBytes(0L);
        status.setInputCount(0);
        status.setOutputBytes(0L);
        status.setOutputCount(0);
        status.setBytesWritten(0L);
        status.setBytesRead(0L);
        status.setProcessingNanos(0);
        status.setInvocations(0);
        status.setAverageLineageDuration(0L);
        status.setFlowFilesRemoved(0);
    } else {
        final int processedCount = entry.getFlowFilesOut();
        final long numProcessedBytes = entry.getContentSizeOut();
        status.setOutputBytes(numProcessedBytes);
        status.setOutputCount(processedCount);
        final int inputCount = entry.getFlowFilesIn();
        final long inputBytes = entry.getContentSizeIn();
        status.setInputBytes(inputBytes);
        status.setInputCount(inputCount);
        final long readBytes = entry.getBytesRead();
        status.setBytesRead(readBytes);
        final long writtenBytes = entry.getBytesWritten();
        status.setBytesWritten(writtenBytes);
        status.setProcessingNanos(entry.getProcessingNanoseconds());
        status.setInvocations(entry.getInvocations());
        status.setAverageLineageDuration(entry.getAverageLineageMillis());
        status.setFlowFilesReceived(entry.getFlowFilesReceived());
        status.setBytesReceived(entry.getBytesReceived());
        status.setFlowFilesSent(entry.getFlowFilesSent());
        status.setBytesSent(entry.getBytesSent());
        status.setFlowFilesRemoved(entry.getFlowFilesRemoved());
        if (isProcessorAuthorized) {
            status.setCounters(entry.getCounters());
        }
    }
    // removed). This saves on validation costs that would be unnecessary most of the time.
    if (ScheduledState.DISABLED.equals(procNode.getScheduledState())) {
        status.setRunStatus(RunStatus.Disabled);
    } else if (ScheduledState.RUNNING.equals(procNode.getScheduledState())) {
        status.setRunStatus(RunStatus.Running);
    } else if (!procNode.isValid()) {
        status.setRunStatus(RunStatus.Invalid);
    } else {
        status.setRunStatus(RunStatus.Stopped);
    }
    status.setExecutionNode(procNode.getExecutionNode());
    status.setActiveThreadCount(processScheduler.getActiveThreadCount(procNode));
    return status;
}
Also used : FlowFileEvent(org.apache.nifi.controller.repository.FlowFileEvent) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus)

Aggregations

ProcessorStatus (org.apache.nifi.controller.status.ProcessorStatus)31 ProcessGroupStatus (org.apache.nifi.controller.status.ProcessGroupStatus)21 ArrayList (java.util.ArrayList)18 ConnectionStatus (org.apache.nifi.controller.status.ConnectionStatus)12 PortStatus (org.apache.nifi.controller.status.PortStatus)9 RemoteProcessGroupStatus (org.apache.nifi.controller.status.RemoteProcessGroupStatus)9 Test (org.junit.Test)9 List (java.util.List)6 Map (java.util.Map)6 ProcessorNode (org.apache.nifi.controller.ProcessorNode)6 ProcessGroup (org.apache.nifi.groups.ProcessGroup)6 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)6 HashMap (java.util.HashMap)5 Set (java.util.Set)5 ValidationResult (org.apache.nifi.components.ValidationResult)5 Collection (java.util.Collection)4 Collections (java.util.Collections)4 Date (java.util.Date)4 LinkedHashMap (java.util.LinkedHashMap)4 LinkedHashSet (java.util.LinkedHashSet)4