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;
}
Aggregations