Search in sources :

Example 36 with ProcessGroupStatus

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

the class TestAmbariReportingTask method setup.

@Before
public void setup() {
    status = new ProcessGroupStatus();
    status.setId("1234");
    status.setFlowFilesReceived(5);
    status.setBytesReceived(10000);
    status.setFlowFilesSent(10);
    status.setBytesSent(20000);
    status.setQueuedCount(100);
    status.setQueuedContentSize(1024L);
    status.setBytesRead(60000L);
    status.setBytesWritten(80000L);
    status.setActiveThreadCount(5);
    // create a processor status with processing time
    ProcessorStatus procStatus = new ProcessorStatus();
    procStatus.setProcessingNanos(123456789);
    Collection<ProcessorStatus> processorStatuses = new ArrayList<>();
    processorStatuses.add(procStatus);
    status.setProcessorStatus(processorStatuses);
    // create a group status with processing time
    ProcessGroupStatus groupStatus = new ProcessGroupStatus();
    groupStatus.setProcessorStatus(processorStatuses);
    Collection<ProcessGroupStatus> groupStatuses = new ArrayList<>();
    groupStatuses.add(groupStatus);
    status.setProcessGroupStatus(groupStatuses);
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) ArrayList(java.util.ArrayList) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) Before(org.junit.Before)

Example 37 with ProcessGroupStatus

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

the class TestMetricsService method testGetProcessGroupStatusMetricsWithID.

@Test
public void testGetProcessGroupStatusMetricsWithID() {
    ProcessGroupStatus status = new ProcessGroupStatus();
    String id = "1234";
    status.setId(id);
    status.setFlowFilesReceived(5);
    status.setBytesReceived(10000);
    status.setFlowFilesSent(10);
    status.setBytesSent(20000);
    status.setQueuedCount(100);
    status.setQueuedContentSize(1024L);
    status.setBytesRead(60000L);
    status.setBytesWritten(80000L);
    status.setActiveThreadCount(5);
    // create a processor status with processing time
    ProcessorStatus procStatus = new ProcessorStatus();
    procStatus.setProcessingNanos(123456789);
    Collection<ProcessorStatus> processorStatuses = new ArrayList<>();
    processorStatuses.add(procStatus);
    status.setProcessorStatus(processorStatuses);
    // create a group status with processing time
    ProcessGroupStatus groupStatus = new ProcessGroupStatus();
    groupStatus.setProcessorStatus(processorStatuses);
    Collection<ProcessGroupStatus> groupStatuses = new ArrayList<>();
    groupStatuses.add(groupStatus);
    status.setProcessGroupStatus(groupStatuses);
    final MetricsService service = new MetricsService();
    final Map<String, String> metrics = service.getMetrics(status, true);
    Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_RECEIVED + MetricNames.METRIC_NAME_SEPARATOR + id));
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) ArrayList(java.util.ArrayList) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) Test(org.junit.Test)

Example 38 with ProcessGroupStatus

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

the class TestMetricsService method testGetProcessGroupStatusMetrics.

@Test
public void testGetProcessGroupStatusMetrics() {
    ProcessGroupStatus status = new ProcessGroupStatus();
    status.setId("1234");
    status.setFlowFilesReceived(5);
    status.setBytesReceived(10000);
    status.setFlowFilesSent(10);
    status.setBytesSent(20000);
    status.setQueuedCount(100);
    status.setQueuedContentSize(1024L);
    status.setBytesRead(60000L);
    status.setBytesWritten(80000L);
    status.setActiveThreadCount(5);
    // create a processor status with processing time
    ProcessorStatus procStatus = new ProcessorStatus();
    procStatus.setProcessingNanos(123456789);
    Collection<ProcessorStatus> processorStatuses = new ArrayList<>();
    processorStatuses.add(procStatus);
    status.setProcessorStatus(processorStatuses);
    // create a group status with processing time
    ProcessGroupStatus groupStatus = new ProcessGroupStatus();
    groupStatus.setProcessorStatus(processorStatuses);
    Collection<ProcessGroupStatus> groupStatuses = new ArrayList<>();
    groupStatuses.add(groupStatus);
    status.setProcessGroupStatus(groupStatuses);
    final MetricsService service = new MetricsService();
    final Map<String, String> metrics = service.getMetrics(status, false);
    Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_RECEIVED));
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_RECEIVED));
    Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_SENT));
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_SENT));
    Assert.assertTrue(metrics.containsKey(MetricNames.FLOW_FILES_QUEUED));
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_QUEUED));
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_READ));
    Assert.assertTrue(metrics.containsKey(MetricNames.BYTES_WRITTEN));
    Assert.assertTrue(metrics.containsKey(MetricNames.ACTIVE_THREADS));
    Assert.assertTrue(metrics.containsKey(MetricNames.TOTAL_TASK_DURATION_SECONDS));
    Assert.assertTrue(metrics.containsKey(MetricNames.TOTAL_TASK_DURATION_NANOS));
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) ArrayList(java.util.ArrayList) ProcessorStatus(org.apache.nifi.controller.status.ProcessorStatus) Test(org.junit.Test)

Example 39 with ProcessGroupStatus

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

the class NiFiFlowAnalyzer method analyzeProcessGroup.

private void analyzeProcessGroup(final ProcessGroupStatus processGroupStatus, final NiFiFlow nifiFlow) {
    processGroupStatus.getConnectionStatus().forEach(c -> nifiFlow.addConnection(c));
    processGroupStatus.getProcessorStatus().forEach(p -> nifiFlow.addProcessor(p));
    processGroupStatus.getRemoteProcessGroupStatus().forEach(r -> nifiFlow.addRemoteProcessGroup(r));
    processGroupStatus.getInputPortStatus().forEach(p -> nifiFlow.addInputPort(p));
    processGroupStatus.getOutputPortStatus().forEach(p -> nifiFlow.addOutputPort(p));
    // Analyze child ProcessGroups recursively.
    for (ProcessGroupStatus child : processGroupStatus.getProcessGroupStatus()) {
        analyzeProcessGroup(child, nifiFlow);
    }
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus)

Example 40 with ProcessGroupStatus

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

the class ReportLineageToAtlas method createNiFiFlow.

private NiFiFlow createNiFiFlow(ReportingContext context, NiFiAtlasClient atlasClient) {
    final ProcessGroupStatus rootProcessGroup = context.getEventAccess().getGroupStatus("root");
    final String flowName = rootProcessGroup.getName();
    final String nifiUrl = context.getProperty(ATLAS_NIFI_URL).evaluateAttributeExpressions().getValue();
    final String clusterName;
    try {
        final String nifiHostName = new URL(nifiUrl).getHost();
        clusterName = clusterResolvers.fromHostNames(nifiHostName);
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException("Failed to parse NiFi URL, " + e.getMessage(), e);
    }
    NiFiFlow existingNiFiFlow = null;
    try {
        // Retrieve Existing NiFiFlow from Atlas.
        existingNiFiFlow = atlasClient.fetchNiFiFlow(rootProcessGroup.getId(), clusterName);
    } catch (AtlasServiceException e) {
        if (ClientResponse.Status.NOT_FOUND.equals(e.getStatus())) {
            getLogger().debug("Existing flow was not found for {}@{}", new Object[] { rootProcessGroup.getId(), clusterName });
        } else {
            throw new RuntimeException("Failed to fetch existing NiFI flow. " + e, e);
        }
    }
    final NiFiFlow nifiFlow = existingNiFiFlow != null ? existingNiFiFlow : new NiFiFlow(rootProcessGroup.getId());
    nifiFlow.setFlowName(flowName);
    nifiFlow.setUrl(nifiUrl);
    nifiFlow.setClusterName(clusterName);
    final NiFiFlowAnalyzer flowAnalyzer = new NiFiFlowAnalyzer();
    flowAnalyzer.analyzeProcessGroup(nifiFlow, rootProcessGroup);
    flowAnalyzer.analyzePaths(nifiFlow);
    return nifiFlow;
}
Also used : ProcessGroupStatus(org.apache.nifi.controller.status.ProcessGroupStatus) NiFiFlowAnalyzer(org.apache.nifi.atlas.NiFiFlowAnalyzer) MalformedURLException(java.net.MalformedURLException) AtlasServiceException(org.apache.atlas.AtlasServiceException) NiFiFlow(org.apache.nifi.atlas.NiFiFlow) URL(java.net.URL)

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