Search in sources :

Example 11 with FlowStatusReport

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

the class StatusConfigReporterTest method controllerServiceStatusBulletins.

@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);
}
Also used : FlowStatusReport(org.apache.nifi.minifi.commons.status.FlowStatusReport) Test(org.junit.Test)

Example 12 with FlowStatusReport

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

the class StatusConfigReporterTest method provenanceReportingTaskStatusBulletins.

@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);
}
Also used : FlowStatusReport(org.apache.nifi.minifi.commons.status.FlowStatusReport) Test(org.junit.Test)

Example 13 with FlowStatusReport

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

the class StatusConfigReporterTest method instanceStatusBulletins.

@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);
}
Also used : FlowStatusReport(org.apache.nifi.minifi.commons.status.FlowStatusReport) Test(org.junit.Test)

Example 14 with FlowStatusReport

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

the class StatusConfigReporterTest method provenanceReportingTaskStatusAll.

@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);
}
Also used : FlowStatusReport(org.apache.nifi.minifi.commons.status.FlowStatusReport) Test(org.junit.Test)

Example 15 with FlowStatusReport

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

the class RunMiNiFi method getFlowStatusReport.

public FlowStatusReport getFlowStatusReport(String statusRequest, final int port, final String secretKey, final Logger logger) throws IOException {
    logger.debug("Pinging {}", port);
    try (final Socket socket = new Socket("localhost", port)) {
        final OutputStream out = socket.getOutputStream();
        final String commandWithArgs = FLOW_STATUS_REPORT_CMD + " " + secretKey + " " + statusRequest + "\n";
        out.write((commandWithArgs).getBytes(StandardCharsets.UTF_8));
        logger.debug("Sending command to MiNiFi: {}", commandWithArgs);
        out.flush();
        logger.debug("Sent FLOW_STATUS_REPORT_CMD to MiNiFi");
        socket.setSoTimeout(5000);
        final InputStream in = socket.getInputStream();
        ObjectInputStream ois = new ObjectInputStream(in);
        logger.debug("FLOW_STATUS_REPORT_CMD response received");
        Object o = ois.readObject();
        ois.close();
        out.close();
        try {
            return FlowStatusReport.class.cast(o);
        } catch (ClassCastException e) {
            String message = String.class.cast(o);
            FlowStatusReport flowStatusReport = new FlowStatusReport();
            flowStatusReport.setErrorsGeneratingReport(Collections.singletonList("Failed to get status report from MiNiFi due to:" + message));
            return flowStatusReport;
        }
    } catch (EOFException | ClassNotFoundException | SocketTimeoutException e) {
        throw new IllegalStateException("Failed to get the status report from the MiNiFi process. Potentially due to the process currently being down (restarting or otherwise).", e);
    }
}
Also used : ObjectInputStream(java.io.ObjectInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) TeeInputStream(org.apache.commons.io.input.TeeInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FlowStatusReport(org.apache.nifi.minifi.commons.status.FlowStatusReport) SocketTimeoutException(java.net.SocketTimeoutException) EOFException(java.io.EOFException) Socket(java.net.Socket) ObjectInputStream(java.io.ObjectInputStream)

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