use of org.apache.nifi.controller.status.ProcessGroupStatus in project nifi by apache.
the class TestSiteToSiteStatusReportingTask method testComponentNameFilter_nested.
@Test
public void testComponentNameFilter_nested() throws IOException, InitializationException {
final ProcessGroupStatus pgStatus = generateProcessGroupStatus("root", "Awesome", 2, 0);
final Map<PropertyDescriptor, String> properties = new HashMap<>();
properties.put(SiteToSiteStatusReportingTask.BATCH_SIZE, "4");
properties.put(SiteToSiteStatusReportingTask.COMPONENT_NAME_FILTER_REGEX, "Awesome.*processor.*");
properties.put(SiteToSiteStatusReportingTask.COMPONENT_TYPE_FILTER_REGEX, ".*");
MockSiteToSiteStatusReportingTask task = initTask(properties, pgStatus);
task.onTrigger(context);
// 3 + (3 * 3) + (3 * 3 * 3) = 39, or 10 batches of 4
assertEquals(10, 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("root.1.1.processor.1", componentId.getString());
}
use of org.apache.nifi.controller.status.ProcessGroupStatus in project nifi by apache.
the class TestSiteToSiteStatusReportingTask method testComponentTypeFilter.
@Test
public void testComponentTypeFilter() 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, "(ProcessGroup|RootProcessGroup)");
MockSiteToSiteStatusReportingTask task = initTask(properties, pgStatus);
task.onTrigger(context);
// Only root pg and 3 child pgs
assertEquals(1, 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 testComponentNameFilter.
@Test
public void testComponentNameFilter() 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.*processor.*");
properties.put(SiteToSiteStatusReportingTask.COMPONENT_TYPE_FILTER_REGEX, ".*");
MockSiteToSiteStatusReportingTask task = initTask(properties, pgStatus);
task.onTrigger(context);
// 3 processors for each of 4 groups
assertEquals(3, 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("root.1.processor.1", componentId.getString());
}
use of org.apache.nifi.controller.status.ProcessGroupStatus in project nifi by apache.
the class MetricsReportingTask method onTrigger.
/**
* Report the registered metrics.
*
* @param context used for getting the most recent {@link ProcessGroupStatus}.
*/
@Override
public void onTrigger(ReportingContext context) {
String groupId = context.getProperty(PROCESS_GROUP_ID).evaluateAttributeExpressions().getValue();
ProcessGroupStatus statusToReport = groupId == null ? context.getEventAccess().getControllerStatus() : context.getEventAccess().getGroupStatus(groupId);
if (statusToReport != null) {
currentStatusReference.set(statusToReport);
reporter.report();
} else {
getLogger().error("Process group with provided group id could not be found.");
}
}
use of org.apache.nifi.controller.status.ProcessGroupStatus in project nifi by apache.
the class MetricsReportingTaskTest method setUp.
/**
* Set up the test environment and mock behaviour. This includes registering {@link #reporterServiceStub} in the
* different contexts, overriding {@link MetricsReportingTask#currentStatusReference} and instantiating the test
* subject.
*/
@Before
public void setUp() throws Exception {
Map<String, ControllerService> services = new HashMap<>();
services.put(REPORTER_SERVICE_IDENTIFIER, reporterServiceStub);
testedReportingTask = new MetricsReportingTask();
reportingContextStub = new MockReportingContext(services, new MockStateManager(testedReportingTask), new MockVariableRegistry());
rootGroupStatus = new ProcessGroupStatus();
innerGroupStatus = new ProcessGroupStatus();
when(reporterServiceStub.createReporter(any())).thenReturn(reporterMock);
when(reporterServiceStub.getIdentifier()).thenReturn(REPORTER_SERVICE_IDENTIFIER);
reportingContextStub.setProperty(MetricsReportingTask.REPORTER_SERVICE.getName(), REPORTER_SERVICE_IDENTIFIER);
reportingContextStub.addControllerService(reporterServiceStub, REPORTER_SERVICE_IDENTIFIER);
configurationContextStub = new MockConfigurationContext(reportingContextStub.getProperties(), reportingContextStub.getControllerServiceLookup());
reportingInitContextStub = new MockReportingInitializationContext(TEST_INIT_CONTEXT_ID, TEST_INIT_CONTEXT_NAME, new MockComponentLog(TEST_TASK_ID, testedReportingTask));
}
Aggregations