Search in sources :

Example 1 with FlowStatusReport

use of org.apache.nifi.minifi.commons.status.FlowStatusReport 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 2 with FlowStatusReport

use of org.apache.nifi.minifi.commons.status.FlowStatusReport in project nifi-minifi by apache.

the class StatusConfigReporterTest method systemDiagnosticContentRepo.

@Test
public void systemDiagnosticContentRepo() throws Exception {
    populateSystemDiagnostics();
    String statusRequest = "systemDiagnostics:contentrepositoryusage";
    FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class));
    FlowStatusReport expected = new FlowStatusReport();
    expected.setErrorsGeneratingReport(Collections.EMPTY_LIST);
    addSystemDiagnosticStatus(expected, false, false, false, true, false);
    assertEquals(expected, actual);
}
Also used : FlowStatusReport(org.apache.nifi.minifi.commons.status.FlowStatusReport) Test(org.junit.Test)

Example 3 with FlowStatusReport

use of org.apache.nifi.minifi.commons.status.FlowStatusReport in project nifi-minifi by apache.

the class StatusConfigReporterTest method systemDiagnosticAll.

@Test
public void systemDiagnosticAll() throws Exception {
    populateSystemDiagnostics();
    String statusRequest = "systemDiagnostics:garbagecollection, heap, processorstats, contentrepositoryusage, flowfilerepositoryusage";
    FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class));
    FlowStatusReport expected = new FlowStatusReport();
    expected.setErrorsGeneratingReport(Collections.EMPTY_LIST);
    addSystemDiagnosticStatus(expected, true, true, true, true, true);
    assertEquals(expected, actual);
}
Also used : FlowStatusReport(org.apache.nifi.minifi.commons.status.FlowStatusReport) Test(org.junit.Test)

Example 4 with FlowStatusReport

use of org.apache.nifi.minifi.commons.status.FlowStatusReport in project nifi-minifi by apache.

the class StatusConfigReporterTest method connectionStatusAll.

@Test
public void connectionStatusAll() throws Exception {
    populateConnection();
    String statusRequest = "connection:all:health, stats";
    FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class));
    FlowStatusReport expected = new FlowStatusReport();
    expected.setErrorsGeneratingReport(Collections.EMPTY_LIST);
    addConnectionStatus(expected, true, true);
    assertEquals(expected, actual);
}
Also used : FlowStatusReport(org.apache.nifi.minifi.commons.status.FlowStatusReport) Test(org.junit.Test)

Example 5 with FlowStatusReport

use of org.apache.nifi.minifi.commons.status.FlowStatusReport in project nifi-minifi by apache.

the class StatusConfigReporterTest method instanceStatusHealth.

@Test
public void instanceStatusHealth() throws Exception {
    populateInstance(false);
    String statusRequest = "instance:health";
    FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class));
    FlowStatusReport expected = new FlowStatusReport();
    expected.setErrorsGeneratingReport(Collections.EMPTY_LIST);
    addInstanceStatus(expected, true, false, false, false);
    assertEquals(expected, actual);
}
Also used : FlowStatusReport(org.apache.nifi.minifi.commons.status.FlowStatusReport) Test(org.junit.Test)

Aggregations

FlowStatusReport (org.apache.nifi.minifi.commons.status.FlowStatusReport)34 Test (org.junit.Test)29 LinkedList (java.util.LinkedList)2 Logger (org.slf4j.Logger)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 EOFException (java.io.EOFException)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 OutputStream (java.io.OutputStream)1 Field (java.lang.reflect.Field)1 Socket (java.net.Socket)1 SocketTimeoutException (java.net.SocketTimeoutException)1 Properties (java.util.Properties)1 TeeInputStream (org.apache.commons.io.input.TeeInputStream)1 ConnectionStatus (org.apache.nifi.controller.status.ConnectionStatus)1 ProcessGroupStatus (org.apache.nifi.controller.status.ProcessGroupStatus)1