Search in sources :

Example 31 with ProcessGroupStatus

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());
}
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 32 with ProcessGroupStatus

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());
}
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 33 with ProcessGroupStatus

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());
}
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 34 with ProcessGroupStatus

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.");
    }
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus)

Example 35 with ProcessGroupStatus

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));
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) MockConfigurationContext(org.apache.nifi.util.MockConfigurationContext) HashMap(java.util.HashMap) MockStateManager(org.apache.nifi.state.MockStateManager) MockComponentLog(org.apache.nifi.util.MockComponentLog) MockVariableRegistry(org.apache.nifi.util.MockVariableRegistry) MockReportingInitializationContext(org.apache.nifi.util.MockReportingInitializationContext) ControllerService(org.apache.nifi.controller.ControllerService) MockReportingContext(org.apache.nifi.util.MockReportingContext) Before(org.junit.Before)

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