Search in sources :

Example 16 with ProcessGroupStatus

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

the class SiteToSiteStatusReportingTask method serializeProcessGroupStatus.

/**
 * Serialize the ProcessGroupStatus and add it to the JsonArrayBuilder.
 * @param arrayBuilder
 *            The JSON Array builder
 * @param factory
 *            The JSON Builder Factory
 * @param status
 *            The ProcessGroupStatus
 * @param df
 *            A date format
 * @param hostname
 *            The current hostname
 * @param applicationName
 *            The root process group name
 * @param platform
 *            The configured platform
 * @param parentId
 *            The parent's component id
 */
void serializeProcessGroupStatus(final JsonArrayBuilder arrayBuilder, final JsonBuilderFactory factory, final ProcessGroupStatus status, final DateFormat df, final String hostname, final String applicationName, final String platform, final String parentId, final Date currentDate) {
    final JsonObjectBuilder builder = factory.createObjectBuilder();
    final String componentType = (parentId == null) ? "RootProcessGroup" : "ProcessGroup";
    final String componentName = status.getName();
    if (componentMatchesFilters(componentType, componentName)) {
        addCommonFields(builder, df, hostname, applicationName, platform, parentId, currentDate, componentType, componentName);
        addField(builder, "componentId", status.getId());
        addField(builder, "bytesRead", status.getBytesRead());
        addField(builder, "bytesWritten", status.getBytesWritten());
        addField(builder, "bytesReceived", status.getBytesReceived());
        addField(builder, "bytesSent", status.getBytesSent());
        addField(builder, "bytesTransferred", status.getBytesTransferred());
        addField(builder, "flowFilesReceived", status.getFlowFilesReceived());
        addField(builder, "flowFilesSent", status.getFlowFilesSent());
        addField(builder, "flowFilesTransferred", status.getFlowFilesTransferred());
        addField(builder, "inputContentSize", status.getInputContentSize());
        addField(builder, "inputCount", status.getInputCount());
        addField(builder, "outputContentSize", status.getOutputContentSize());
        addField(builder, "outputCount", status.getOutputCount());
        addField(builder, "queuedContentSize", status.getQueuedContentSize());
        addField(builder, "activeThreadCount", status.getActiveThreadCount());
        addField(builder, "queuedCount", status.getQueuedCount());
        arrayBuilder.add(builder.build());
    }
    for (ProcessGroupStatus childGroupStatus : status.getProcessGroupStatus()) {
        serializeProcessGroupStatus(arrayBuilder, factory, childGroupStatus, df, hostname, applicationName, platform, status.getId(), currentDate);
    }
    for (ProcessorStatus processorStatus : status.getProcessorStatus()) {
        serializeProcessorStatus(arrayBuilder, factory, processorStatus, df, hostname, applicationName, platform, status.getId(), currentDate);
    }
    for (ConnectionStatus connectionStatus : status.getConnectionStatus()) {
        serializeConnectionStatus(arrayBuilder, factory, connectionStatus, df, hostname, applicationName, platform, status.getId(), currentDate);
    }
    for (PortStatus portStatus : status.getInputPortStatus()) {
        serializePortStatus("InputPort", arrayBuilder, factory, portStatus, df, hostname, applicationName, platform, status.getId(), currentDate);
    }
    for (PortStatus portStatus : status.getOutputPortStatus()) {
        serializePortStatus("OutputPort", arrayBuilder, factory, portStatus, df, hostname, applicationName, platform, status.getId(), currentDate);
    }
    for (RemoteProcessGroupStatus remoteProcessGroupStatus : status.getRemoteProcessGroupStatus()) {
        serializeRemoteProcessGroupStatus(arrayBuilder, factory, remoteProcessGroupStatus, df, hostname, applicationName, platform, status.getId(), currentDate);
    }
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) PortStatus(org.apache.nifi.controller.status.PortStatus) JsonObjectBuilder(javax.json.JsonObjectBuilder) ConnectionStatus(org.apache.nifi.controller.status.ConnectionStatus) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus)

Example 17 with ProcessGroupStatus

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

the class TestSiteToSiteStatusReportingTask method generateProcessGroupStatus.

public static ProcessGroupStatus generateProcessGroupStatus(String id, String namePrefix, int maxRecursion, int currentDepth) {
    Collection<ConnectionStatus> cStatus = new ArrayList<>();
    Collection<PortStatus> ipStatus = new ArrayList<>();
    Collection<PortStatus> opStatus = new ArrayList<>();
    Collection<ProcessorStatus> pStatus = new ArrayList<>();
    Collection<RemoteProcessGroupStatus> rpgStatus = new ArrayList<>();
    Collection<ProcessGroupStatus> childPgStatus = new ArrayList<>();
    if (currentDepth < maxRecursion) {
        for (int i = 1; i < 4; i++) {
            childPgStatus.add(generateProcessGroupStatus(id + "." + i, namePrefix + "." + i, maxRecursion, currentDepth + 1));
        }
    }
    for (int i = 1; i < 4; i++) {
        pStatus.add(generateProcessorStatus(id + ".processor." + i, namePrefix + ".processor." + i));
    }
    for (int i = 1; i < 4; i++) {
        cStatus.add(generateConnectionStatus(id + ".connection." + i, namePrefix + ".connection." + i));
    }
    for (int i = 1; i < 4; i++) {
        rpgStatus.add(generateRemoteProcessGroupStatus(id + ".rpg." + i, namePrefix + ".rpg." + i));
    }
    for (int i = 1; i < 4; i++) {
        ipStatus.add(generatePortStatus(id + ".ip." + i, namePrefix + ".ip." + i));
    }
    for (int i = 1; i < 4; i++) {
        opStatus.add(generatePortStatus(id + ".op." + i, namePrefix + ".op." + i));
    }
    ProcessGroupStatus pgStatus = new ProcessGroupStatus();
    pgStatus.setId(id);
    pgStatus.setName(namePrefix + "-" + UUID.randomUUID().toString());
    pgStatus.setInputPortStatus(ipStatus);
    pgStatus.setOutputPortStatus(opStatus);
    pgStatus.setProcessGroupStatus(childPgStatus);
    pgStatus.setRemoteProcessGroupStatus(rpgStatus);
    pgStatus.setProcessorStatus(pStatus);
    pgStatus.setActiveThreadCount(1);
    pgStatus.setBytesRead(2L);
    pgStatus.setBytesReceived(3l);
    pgStatus.setBytesSent(4l);
    pgStatus.setBytesTransferred(5l);
    pgStatus.setBytesWritten(6l);
    pgStatus.setConnectionStatus(cStatus);
    pgStatus.setFlowFilesReceived(7);
    pgStatus.setFlowFilesSent(8);
    pgStatus.setFlowFilesTransferred(9);
    pgStatus.setInputContentSize(10l);
    pgStatus.setInputCount(11);
    pgStatus.setOutputContentSize(12l);
    pgStatus.setOutputCount(13);
    pgStatus.setQueuedContentSize(14l);
    pgStatus.setQueuedCount(15);
    return pgStatus;
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) ArrayList(java.util.ArrayList) PortStatus(org.apache.nifi.controller.status.PortStatus) ConnectionStatus(org.apache.nifi.controller.status.ConnectionStatus) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus)

Example 18 with ProcessGroupStatus

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

the class TestSiteToSiteStatusReportingTask method testSerializedForm.

@Test
public void testSerializedForm() throws IOException, InitializationException {
    final ProcessGroupStatus pgStatus = generateProcessGroupStatus("root", "Awesome", 1, 0);
    final Map<PropertyDescriptor, String> properties = new HashMap<>();
    properties.put(SiteToSiteStatusReportingTask.BATCH_SIZE, "4");
    properties.put(SiteToSiteStatusReportingTask.COMPONENT_NAME_FILTER_REGEX, "Awesome.*");
    properties.put(SiteToSiteStatusReportingTask.COMPONENT_TYPE_FILTER_REGEX, ".*");
    MockSiteToSiteStatusReportingTask task = initTask(properties, pgStatus);
    task.onTrigger(context);
    assertEquals(16, task.dataSent.size());
    final String msg = new String(task.dataSent.get(0), StandardCharsets.UTF_8);
    JsonReader jsonReader = Json.createReader(new ByteArrayInputStream(msg.getBytes()));
    JsonString componentId = jsonReader.readArray().getJsonObject(0).getJsonString("componentId");
    assertEquals(pgStatus.getId(), componentId.getString());
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) JsonReader(javax.json.JsonReader) JsonString(javax.json.JsonString) JsonString(javax.json.JsonString) Test(org.junit.Test)

Example 19 with ProcessGroupStatus

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

the class TestSiteToSiteStatusReportingTask method testConnectionStatus.

@Test
public void testConnectionStatus() throws IOException, InitializationException {
    final ProcessGroupStatus pgStatus = generateProcessGroupStatus("root", "Awesome", 1, 0);
    final Map<PropertyDescriptor, String> properties = new HashMap<>();
    properties.put(SiteToSiteStatusReportingTask.BATCH_SIZE, "4");
    properties.put(SiteToSiteStatusReportingTask.COMPONENT_NAME_FILTER_REGEX, "Awesome.*");
    properties.put(SiteToSiteStatusReportingTask.COMPONENT_TYPE_FILTER_REGEX, "(Connection)");
    MockSiteToSiteStatusReportingTask task = initTask(properties, pgStatus);
    task.onTrigger(context);
    final String msg = new String(task.dataSent.get(0), StandardCharsets.UTF_8);
    JsonReader jsonReader = Json.createReader(new ByteArrayInputStream(msg.getBytes()));
    JsonString backpressure = jsonReader.readArray().getJsonObject(0).getJsonString("isBackPressureEnabled");
    assertEquals("true", backpressure.getString());
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) RemoteProcessGroupStatus(org.apache.nifi.controller.status.RemoteProcessGroupStatus) PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) JsonReader(javax.json.JsonReader) JsonString(javax.json.JsonString) JsonString(javax.json.JsonString) Test(org.junit.Test)

Example 20 with ProcessGroupStatus

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

the class StandardGangliaReporter method onTrigger.

@Override
public void onTrigger(final ReportingContext context) {
    final ProcessGroupStatus rootGroupStatus = context.getEventAccess().getControllerStatus();
    this.latestStatus.set(rootGroupStatus);
    gangliaReporter.run();
    getLogger().info("{} Sent metrics to Ganglia", new Object[] { this });
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus)

Aggregations

ProcessGroupStatus (org.apache.nifi.controller.status.ProcessGroupStatus)46 ProcessorStatus (org.apache.nifi.controller.status.ProcessorStatus)21 RemoteProcessGroupStatus (org.apache.nifi.controller.status.RemoteProcessGroupStatus)19 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)12 HashMap (java.util.HashMap)12 ConnectionStatus (org.apache.nifi.controller.status.ConnectionStatus)11 ProcessGroup (org.apache.nifi.groups.ProcessGroup)11 RemoteProcessGroup (org.apache.nifi.groups.RemoteProcessGroup)11 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)10 PortStatus (org.apache.nifi.controller.status.PortStatus)10 Port (org.apache.nifi.connectable.Port)8 RemoteGroupPort (org.apache.nifi.remote.RemoteGroupPort)8 RootGroupPort (org.apache.nifi.remote.RootGroupPort)8 Connection (org.apache.nifi.connectable.Connection)7 ProcessorNode (org.apache.nifi.controller.ProcessorNode)6 VersionedProcessGroup (org.apache.nifi.registry.flow.VersionedProcessGroup)6 IOException (java.io.IOException)5 Collection (java.util.Collection)5 Date (java.util.Date)5