StatusConfigReporter { 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) { try { final RequestItem requestItem = new RequestItem(item); switch (requestItem.queryType.toLowerCase().trim()) { case "systemdiagnostics": SystemDiagnosticsStatus systemDiagnosticsStatus = parseSystemDiagnosticsRequest(flowController.getSystemDiagnostics(), requestItem.options); flowStatusReport.setSystemDiagnosticsStatus(systemDiagnosticsStatus); break; case "instance": InstanceStatus instanceStatus = parseInstanceRequest(requestItem.options, flowController, rootGroupStatus); flowStatusReport.setInstanceStatus(instanceStatus); break; case "remoteprocessgroup": if (flowStatusReport.getRemoteProcessGroupStatusList() == null) { List<RemoteProcessGroupStatusBean> remoteProcessGroupStatusList = new LinkedList<>(); flowStatusReport.setRemoteProcessGroupStatusList(remoteProcessGroupStatusList); } handleRemoteProcessGroupRequest(requestItem, rootGroupStatus, flowController, flowStatusReport.getRemoteProcessGroupStatusList(), remoteProcessGroupStatusMap, logger); break; case "processor": if (flowStatusReport.getProcessorStatusList() == null) { List<ProcessorStatusBean> processorStatusList = new LinkedList<>(); flowStatusReport.setProcessorStatusList(processorStatusList); } handleProcessorRequest(requestItem, rootGroupStatus, flowController, flowStatusReport.getProcessorStatusList(), processorStatusMap, logger); break; case "connection": if (flowStatusReport.getConnectionStatusList() == null) { List<ConnectionStatusBean> connectionStatusList = new LinkedList<>(); flowStatusReport.setConnectionStatusList(connectionStatusList); } handleConnectionRequest(requestItem, rootGroupStatus, flowStatusReport.getConnectionStatusList(), connectionStatusMap, logger); break; case "provenancereporting": if (flowStatusReport.getRemoteProcessGroupStatusList() == null) { List<ReportingTaskStatus> reportingTaskStatusList = new LinkedList<>(); flowStatusReport.setReportingTaskStatusList(reportingTaskStatusList); } handleReportingTaskRequest(requestItem, flowController, flowStatusReport.getReportingTaskStatusList(), logger); break; case "controllerservices": if (flowStatusReport.getControllerServiceStatusList() == null) { List<ControllerServiceStatus> controllerServiceStatusList = new LinkedList<>(); flowStatusReport.setControllerServiceStatusList(controllerServiceStatusList); } handleControllerServices(requestItem, 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; } private  StatusConfigReporter(); static FlowStatusReport getStatus(FlowController flowController, String statusRequest, Logger logger);  }
@Test public void individualProcessorStatusHealth() throws Exception { populateProcessor(false, false); String statusRequest = "processor:UpdateAttributeProcessorId:health"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addProcessorStatus(expected, true, false, false, false, false); assertEquals(expected, actual); }
@Test public void processorStatusWithValidationErrors() throws Exception { populateProcessor(true, false); String statusRequest = "processor:all:health"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addProcessorStatus(expected, true, true, false, false, false); assertEquals(expected, actual); }
@Test public void processorStatusAll() throws Exception { populateProcessor(true, true); String statusRequest = "processor:all:health, stats, bulletins"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addProcessorStatus(expected, true, true, true, true, true); assertEquals(expected, actual); }
@Test public void connectionStatusHealth() throws Exception { populateConnection(); String statusRequest = "connection:all:health"; FlowStatusReport status = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addConnectionStatus(expected, true, false); assertEquals(expected, status); }
@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); }
@Test public void connectionAndProcessorStatusHealth() throws Exception { populateConnection(); populateProcessor(false, false); String statusRequest = "connection:connectionId:health; processor:UpdateAttributeProcessorId:health"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); addConnectionStatus(expected, true, false); addProcessorStatus(expected, true, false, false, false, false); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); assertEquals(expected, actual); }
@Test public void provenanceReportingTaskStatusHealth() throws Exception { populateReportingTask(false, false); String statusRequest = "provenanceReporting:health"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addReportingTaskStatus(expected, true, false, false, false); assertEquals(expected, actual); }
@Test public void provenanceReportingTaskStatusBulletins() throws Exception { populateReportingTask(true, false); String statusRequest = "provenanceReporting:bulletins"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addReportingTaskStatus(expected, false, false, true, true); assertEquals(expected, actual); }
@Test public void provenanceReportingTaskStatusAll() throws Exception { populateReportingTask(true, true); String statusRequest = "provenanceReporting:health,bulletins"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addReportingTaskStatus(expected, true, true, true, true); assertEquals(expected, actual); }
@Test public void systemDiagnosticHeap() throws Exception { populateSystemDiagnostics(); String statusRequest = "systemDiagnostics:heap"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addSystemDiagnosticStatus(expected, true, false, false, false, false); assertEquals(expected, actual); }
@Test public void systemDiagnosticProcessorStats() throws Exception { populateSystemDiagnostics(); String statusRequest = "systemDiagnostics:processorStats"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addSystemDiagnosticStatus(expected, false, true, false, false, false); assertEquals(expected, actual); }
@Test public void systemDiagnosticFlowFileRepo() throws Exception { populateSystemDiagnostics(); String statusRequest = "systemDiagnostics:flowfilerepositoryusage"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addSystemDiagnosticStatus(expected, false, false, true, false, false); assertEquals(expected, actual); }
@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); }
@Test public void systemDiagnosticGarbageCollection() throws Exception { populateSystemDiagnostics(); String statusRequest = "systemDiagnostics:garbagecollection"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addSystemDiagnosticStatus(expected, false, false, false, false, true); assertEquals(expected, actual); }
@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); }
@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); }
@Test public void instanceStatusBulletins() throws Exception { populateInstance(true); String statusRequest = "instance:bulletins"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addInstanceStatus(expected, false, false, true, true); assertEquals(expected, actual); }
@Test public void instanceStatusStats() throws Exception { populateInstance(false); String statusRequest = "instance:stats"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addInstanceStatus(expected, false, true, false, false); assertEquals(expected, actual); }
@Test public void instanceStatusAll() throws Exception { populateInstance(true); String statusRequest = "instance:stats, bulletins, health"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addInstanceStatus(expected, true, true, true, true); assertEquals(expected, actual); }
@Test public void controllerServiceStatusHealth() throws Exception { populateControllerService(false, false); String statusRequest = "controllerServices:health"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addControllerServiceStatus(expected, true, false, false, false); assertEquals(expected, actual); }
@Test public void controllerServiceStatusBulletins() throws Exception { populateControllerService(false, true); String statusRequest = "controllerServices:bulletins"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addControllerServiceStatus(expected, false, false, true, true); assertEquals(expected, actual); }
@Test public void controllerServiceStatusAll() throws Exception { populateControllerService(true, true); String statusRequest = "controllerServices:bulletins, health"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addControllerServiceStatus(expected, true, true, true, true); assertEquals(expected, actual); }
@Test public void remoteProcessGroupStatusHealth() throws Exception { populateRemoteProcessGroup(false, false); String statusRequest = "remoteProcessGroup:all:health"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addExpectedRemoteProcessGroupStatus(expected, true, false, false, false, false, false); assertEquals(expected, actual); }
@Test public void remoteProcessGroupStatusBulletins() throws Exception { populateRemoteProcessGroup(true, false); String statusRequest = "remoteProcessGroup:all:bulletins"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addExpectedRemoteProcessGroupStatus(expected, false, false, false, false, true, true); assertEquals(expected, actual); }
@Test public void remoteProcessGroupStatusInputPorts() throws Exception { populateRemoteProcessGroup(false, false); String statusRequest = "remoteProcessGroup:all:inputPorts"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addExpectedRemoteProcessGroupStatus(expected, false, true, false, false, false, false); assertEquals(expected, actual); }
@Test public void remoteProcessGroupStatusOutputPorts() throws Exception { populateRemoteProcessGroup(false, false); String statusRequest = "remoteProcessGroup:all:outputPorts"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addExpectedRemoteProcessGroupStatus(expected, false, false, true, false, false, false); assertEquals(expected, actual); }
@Test public void remoteProcessGroupStatusStats() throws Exception { populateRemoteProcessGroup(false, false); String statusRequest = "remoteProcessGroup:all:stats"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addExpectedRemoteProcessGroupStatus(expected, false, false, false, true, false, false); assertEquals(expected, actual); }
@Test public void remoteProcessGroupStatusAll() throws Exception { populateRemoteProcessGroup(true, true); String statusRequest = "remoteProcessGroup:all:health, bulletins, inputPorts, outputPorts, stats"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addExpectedRemoteProcessGroupStatus(expected, true, true, true, true, true, true); assertEquals(expected, actual); }
@Test public void statusEverything() throws Exception { when(bulletinRepo.findBulletins(anyObject())).thenReturn(Collections.emptyList()); populateControllerService(true, false); populateInstance(true); populateSystemDiagnostics(); populateReportingTask(false, true); populateConnection(); populateProcessor(true, false); populateRemoteProcessGroup(false, true); String statusRequest = "controllerServices:bulletins,health; processor:all:health,stats,bulletins; instance:bulletins,health,stats ; systemDiagnostics:garbagecollection, heap, " + "processorstats, contentrepositoryusage, flowfilerepositoryusage; connection:all:health,stats; provenanceReporting:health,bulletins; remoteProcessGroup:all:health, " + "bulletins, inputPorts, outputPorts, stats"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addControllerServiceStatus(expected, true, true, true, false); addInstanceStatus(expected, true, true, true, true); addSystemDiagnosticStatus(expected, true, true, true, true, true); addReportingTaskStatus(expected, true, true, true, false); addConnectionStatus(expected, true, true); addProcessorStatus(expected, true, true, true, true, false); addExpectedRemoteProcessGroupStatus(expected, true, true, true, true, true, false); assertEquals(expected, actual); }
@Test public void processorStatusHealth() throws Exception { populateProcessor(false, false); String statusRequest = "processor:all:health"; FlowStatusReport actual = StatusConfigReporter.getStatus(mockFlowController, statusRequest, LoggerFactory.getLogger(StatusConfigReporterTest.class)); FlowStatusReport expected = new FlowStatusReport(); expected.setErrorsGeneratingReport(Collections.EMPTY_LIST); addProcessorStatus(expected, true, false, false, false, false); assertEquals(expected, actual); }