Search in sources :

Example 11 with ProcessGroupStatus

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

the class AmbariReportingTask method onTrigger.

@Override
public void onTrigger(final ReportingContext context) {
    final String metricsCollectorUrl = context.getProperty(METRICS_COLLECTOR_URL).evaluateAttributeExpressions().getValue();
    final String applicationId = context.getProperty(APPLICATION_ID).evaluateAttributeExpressions().getValue();
    final String hostname = context.getProperty(HOSTNAME).evaluateAttributeExpressions().getValue();
    final boolean pgIdIsSet = context.getProperty(PROCESS_GROUP_ID).isSet();
    final String processGroupId = pgIdIsSet ? context.getProperty(PROCESS_GROUP_ID).evaluateAttributeExpressions().getValue() : null;
    final long start = System.currentTimeMillis();
    // send the metrics from last execution
    if (previousMetrics != null) {
        final WebTarget metricsTarget = client.target(metricsCollectorUrl);
        final Invocation.Builder invocation = metricsTarget.request();
        final Entity<String> entity = Entity.json(previousMetrics.toString());
        getLogger().debug("Sending metrics {} to Ambari", new Object[] { entity.getEntity() });
        final Response response = invocation.post(entity);
        if (response.getStatus() == Response.Status.OK.getStatusCode()) {
            final long completedMillis = TimeUnit.NANOSECONDS.toMillis(System.currentTimeMillis() - start);
            getLogger().info("Successfully sent metrics to Ambari in {} ms", new Object[] { completedMillis });
        } else {
            final String responseEntity = response.hasEntity() ? response.readEntity(String.class) : "unknown error";
            getLogger().error("Error sending metrics to Ambari due to {} - {}", new Object[] { response.getStatus(), responseEntity });
        }
    }
    // calculate the current metrics, but store them to be sent next time
    final ProcessGroupStatus status = processGroupId == null ? context.getEventAccess().getControllerStatus() : context.getEventAccess().getGroupStatus(processGroupId);
    if (status != null) {
        final Map<String, String> statusMetrics = metricsService.getMetrics(status, pgIdIsSet);
        final Map<String, String> jvmMetrics = metricsService.getMetrics(virtualMachineMetrics);
        final MetricsBuilder metricsBuilder = new MetricsBuilder(factory);
        final JsonObject metricsObject = metricsBuilder.applicationId(applicationId).instanceId(status.getId()).hostname(hostname).timestamp(start).addAllMetrics(statusMetrics).addAllMetrics(jvmMetrics).build();
        previousMetrics = metricsObject;
    } else {
        getLogger().error("No process group status with ID = {}", new Object[] { processGroupId });
        previousMetrics = null;
    }
}
Also used : Response(javax.ws.rs.core.Response) ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) Invocation(javax.ws.rs.client.Invocation) JsonObject(javax.json.JsonObject) WebTarget(javax.ws.rs.client.WebTarget) MetricsBuilder(org.apache.nifi.reporting.ambari.api.MetricsBuilder)

Example 12 with ProcessGroupStatus

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

the class TestNiFiFlowAnalyzer method testMultiPathsJoint.

@Test
public void testMultiPathsJoint() throws Exception {
    ProcessGroupStatus rootPG = createEmptyProcessGroupStatus();
    final ProcessorStatus pr0 = createProcessor(rootPG, "org.apache.nifi.processors.standard.GenerateFlowFile");
    final ProcessorStatus pr1 = createProcessor(rootPG, "org.apache.nifi.processors.standard.UpdateAttribute");
    final ProcessorStatus pr2 = createProcessor(rootPG, "org.apache.nifi.processors.standard.ListenTCP");
    final ProcessorStatus pr3 = createProcessor(rootPG, "org.apache.nifi.processors.standard.LogAttribute");
    // Result should be as follows:
    // pathA = 0 -> 1 (-> 3)
    // pathB = 2 (-> 3)
    // pathC = 3
    connect(rootPG, pr0, pr1);
    connect(rootPG, pr1, pr3);
    connect(rootPG, pr2, pr3);
    final NiFiFlowAnalyzer analyzer = new NiFiFlowAnalyzer();
    final NiFiFlow nifiFlow = new NiFiFlow(rootPG.getId());
    nifiFlow.setClusterName("cluster1");
    analyzer.analyzeProcessGroup(nifiFlow, rootPG);
    assertEquals(4, nifiFlow.getProcessors().size());
    analyzer.analyzePaths(nifiFlow);
    final Map<String, NiFiFlowPath> paths = nifiFlow.getFlowPaths();
    assertEquals(3, paths.size());
    // Order is not guaranteed
    final NiFiFlowPath pathA = paths.get(pr0.getId());
    final NiFiFlowPath pathB = paths.get(pr2.getId());
    final NiFiFlowPath pathC = paths.get(pr3.getId());
    assertEquals(2, pathA.getProcessComponentIds().size());
    assertEquals(1, pathB.getProcessComponentIds().size());
    assertEquals(1, pathC.getProcessComponentIds().size());
    // A queue is added as input for the joint point.
    assertEquals(1, pathC.getInputs().size());
    final AtlasObjectId queue = pathC.getInputs().iterator().next();
    assertEquals(TYPE_NIFI_QUEUE, queue.getTypeName());
    assertEquals(toQualifiedName("cluster1", pathC.getId()), queue.getUniqueAttributes().get(ATTR_QUALIFIED_NAME));
    // Should be able to find a path from a given processor GUID.
    final NiFiFlowPath pathForPr0 = nifiFlow.findPath(pr0.getId());
    final NiFiFlowPath pathForPr1 = nifiFlow.findPath(pr1.getId());
    final NiFiFlowPath pathForPr2 = nifiFlow.findPath(pr2.getId());
    final NiFiFlowPath pathForPr3 = nifiFlow.findPath(pr3.getId());
    assertEquals(pathA, pathForPr0);
    assertEquals(pathA, pathForPr1);
    assertEquals(pathB, pathForPr2);
    assertEquals(pathC, pathForPr3);
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) Test(org.junit.Test)

Example 13 with ProcessGroupStatus

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

the class TestNiFiFlowAnalyzer method testMultiPaths.

@Test
public void testMultiPaths() throws Exception {
    ProcessGroupStatus rootPG = createEmptyProcessGroupStatus();
    final ProcessorStatus pr0 = createProcessor(rootPG, "GenerateFlowFile");
    final ProcessorStatus pr1 = createProcessor(rootPG, "UpdateAttribute");
    final ProcessorStatus pr2 = createProcessor(rootPG, "ListenTCP");
    final ProcessorStatus pr3 = createProcessor(rootPG, "LogAttribute");
    connect(rootPG, pr0, pr1);
    connect(rootPG, pr2, pr3);
    final NiFiFlowAnalyzer analyzer = new NiFiFlowAnalyzer();
    final NiFiFlow nifiFlow = new NiFiFlow(rootPG.getId());
    analyzer.analyzeProcessGroup(nifiFlow, rootPG);
    assertEquals(4, nifiFlow.getProcessors().size());
    analyzer.analyzePaths(nifiFlow);
    final Map<String, NiFiFlowPath> paths = nifiFlow.getFlowPaths();
    assertEquals(2, paths.size());
    // Order is not guaranteed
    final NiFiFlowPath pathA = paths.get(pr0.getId());
    final NiFiFlowPath pathB = paths.get(pr2.getId());
    assertEquals(2, pathA.getProcessComponentIds().size());
    assertEquals(2, pathB.getProcessComponentIds().size());
    // Should be able to find a path from a given processor GUID.
    final NiFiFlowPath pathForPr0 = nifiFlow.findPath(pr0.getId());
    final NiFiFlowPath pathForPr1 = nifiFlow.findPath(pr1.getId());
    final NiFiFlowPath pathForPr2 = nifiFlow.findPath(pr2.getId());
    final NiFiFlowPath pathForPr3 = nifiFlow.findPath(pr3.getId());
    assertEquals(pathA, pathForPr0);
    assertEquals(pathA, pathForPr1);
    assertEquals(pathB, pathForPr2);
    assertEquals(pathB, pathForPr3);
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) Test(org.junit.Test)

Example 14 with ProcessGroupStatus

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

the class TestNiFiFlowAnalyzer method testSingleProcessor.

@Test
public void testSingleProcessor() throws Exception {
    ProcessGroupStatus rootPG = createEmptyProcessGroupStatus();
    final ProcessorStatus pr0 = createProcessor(rootPG, "GenerateFlowFile");
    final NiFiFlowAnalyzer analyzer = new NiFiFlowAnalyzer();
    final NiFiFlow nifiFlow = new NiFiFlow(rootPG.getId());
    analyzer.analyzeProcessGroup(nifiFlow, rootPG);
    assertEquals(1, nifiFlow.getProcessors().size());
    analyzer.analyzePaths(nifiFlow);
    final Map<String, NiFiFlowPath> paths = nifiFlow.getFlowPaths();
    assertEquals(1, paths.size());
    // first path
    final NiFiFlowPath path0 = paths.get(pr0.getId());
    assertEquals(path0.getId(), path0.getProcessComponentIds().get(0));
    assertEquals(rootPG.getId(), path0.getGroupId());
    // Should be able to find a path from a given processor GUID.
    final NiFiFlowPath pathForPr0 = nifiFlow.findPath(pr0.getId());
    assertEquals(path0, pathForPr0);
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) Test(org.junit.Test)

Example 15 with ProcessGroupStatus

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

the class TestNiFiFlowAnalyzer method testProcessorsWithinSinglePath.

@Test
public void testProcessorsWithinSinglePath() throws Exception {
    ProcessGroupStatus rootPG = createEmptyProcessGroupStatus();
    final ProcessorStatus pr0 = createProcessor(rootPG, "GenerateFlowFile");
    final ProcessorStatus pr1 = createProcessor(rootPG, "UpdateAttribute");
    connect(rootPG, pr0, pr1);
    final NiFiFlowAnalyzer analyzer = new NiFiFlowAnalyzer();
    final NiFiFlow nifiFlow = new NiFiFlow(rootPG.getId());
    analyzer.analyzeProcessGroup(nifiFlow, rootPG);
    assertEquals(2, nifiFlow.getProcessors().size());
    analyzer.analyzePaths(nifiFlow);
    final Map<String, NiFiFlowPath> paths = nifiFlow.getFlowPaths();
    assertEquals(1, paths.size());
    // Should be able to find a path from a given processor GUID.
    final NiFiFlowPath pathForPr0 = nifiFlow.findPath(pr0.getId());
    final NiFiFlowPath pathForPr1 = nifiFlow.findPath(pr1.getId());
    final NiFiFlowPath path0 = paths.get(pr0.getId());
    assertEquals(path0, pathForPr0);
    assertEquals(path0, pathForPr1);
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) Test(org.junit.Test)

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