Search in sources :

Example 1 with NiFiFlowAnalyzer

use of org.apache.nifi.atlas.NiFiFlowAnalyzer 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

MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 AtlasServiceException (org.apache.atlas.AtlasServiceException)1 NiFiFlow (org.apache.nifi.atlas.NiFiFlow)1 NiFiFlowAnalyzer (org.apache.nifi.atlas.NiFiFlowAnalyzer)1 ProcessGroupStatus (org.apache.nifi.controller.status.ProcessGroupStatus)1