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);
}
}
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;
}
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());
}
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());
}
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 });
}
Aggregations