Github user apiri commented on a diff in the pull request:
https://github.com/apache/nifi-minifi/pull/99#discussion_r150919043
--- Diff:
minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-runtime/src/main/java/org/apache/nifi/minifi/MiNiFi.java
---
@@ -241,4 +268,203 @@ public static void main(String[] args) {
logger.error("Failure to launch MiNiFi due to " + t, t);
}
}
+
+ /* Handle Flow bundle enrichment */
+ protected static void enrichFlowWithBundleInformation(FlowParser
flowParser, NiFiProperties niFiProperties) throws FlowEnrichmentException {
+ final Path flowPath =
niFiProperties.getFlowConfigurationFile().toPath();
+ logger.debug("Enriching generated {} with bundling information",
flowPath.toAbsolutePath());
+
+ try {
+ final Document flowDocument =
flowParser.parse(flowPath.toAbsolutePath().toFile());
+
+ if (flowDocument == null) {
+ throw new FlowEnrichmentException("Unable to successfully
parse the specified flow at " + flowPath.toAbsolutePath());
+ }
+
+ final Map<String, EnrichingElementAdapter>
componentDependsUponMap = new HashMap<>();
+ // Aggregate all dependency mappings of all component types
that need to have a bundle evaluated
+ for (String typeElementName :
Arrays.asList(PROCESSOR_TAG_NAME, CONTROLLER_SERVICE_TAG_NAME,
REPORTING_TASK_TAG_NAME)) {
+ final NodeList componentNodeList =
flowDocument.getElementsByTagName(typeElementName);
+ mapComponents(componentNodeList).forEach((id, metadata) ->
componentDependsUponMap.merge(id, metadata, (destination, source) -> {
+
destination.addDependencyIds(source.getDependencyIds());
+ return destination;
+ }));
+ }
+
+ for (Map.Entry<String, EnrichingElementAdapter> componentEntry
: componentDependsUponMap.entrySet()) {
+
+ // If this particular component has already had bundle
information applied, skip it
+ EnrichingElementAdapter componentToEnrich =
componentEntry.getValue();
+ if (componentToEnrich.getBundleElement() != null) {
+ continue;
+ }
+
+ final EnrichingElementAdapter elementToEnrich =
componentToEnrich;
+ final String bundleClassLookup =
elementToEnrich.getComponentClass();
+ final List<Bundle> bundles =
ExtensionManager.getBundles(bundleClassLookup);
+ BundleCoordinate enrichingBundle = null;
+ // If there is only one supporting bundle, choose it,
otherwise defer to the other item
+ if (bundles.size() == 1) {
+ enrichingBundle =
bundles.get(0).getBundleDetails().getCoordinate();
+ } else if (bundles.size() > 1) {
+
--- End diff --
There most certainly is. I think I lost a commit in my branch juggling.
Let me try to dig it out.
---