private static void addBundle(final Element parentElement, final BundleCoordinate coordinate) { // group final Element groupElement = parentElement.getOwnerDocument().createElement("group"); groupElement.setTextContent(coordinate.getGroup()); // artifact final Element artifactElement = parentElement.getOwnerDocument().createElement("artifact"); artifactElement.setTextContent(coordinate.getId()); // version final Element versionElement = parentElement.getOwnerDocument().createElement("version"); versionElement.setTextContent(coordinate.getVersion()); // bundle final Element bundleElement = parentElement.getOwnerDocument().createElement("bundle"); bundleElement.appendChild(groupElement); bundleElement.appendChild(artifactElement); bundleElement.appendChild(versionElement); parentElement.appendChild(bundleElement); }
protected String formatExtensionVersion(final String type, final BundleCoordinate bundle) { final String formattedType; if (BundleCoordinate.DEFAULT_VERSION.equals(bundle.getVersion())) { formattedType = type; } else { formattedType = type + " " + bundle.getVersion(); } final String formattedBundle; if (BundleCoordinate.DEFAULT_GROUP.equals(bundle.getGroup())) { formattedBundle = bundle.getId(); } else { formattedBundle = bundle.getGroup() + " - " + bundle.getId(); } return String.format("%s from %s", formattedType, formattedBundle); }
private boolean isEqual(final BundleCoordinate coordinate, final Bundle bundle) { if (!bundle.getGroup().equals(coordinate.getGroup())) { return false; } if (!bundle.getArtifact().equals(coordinate.getId())) { return false; } if (!bundle.getVersion().equals(coordinate.getVersion())) { return false; } return true; }
/** * Documents a type of configurable component. * * @param extensionClasses types of a configurable component * @param explodedNiFiDocsDir base directory of component documentation */ public static void documentConfigurableComponent(final Set<Class> extensionClasses, final File explodedNiFiDocsDir, final ExtensionManager extensionManager) { for (final Class<?> extensionClass : extensionClasses) { if (ConfigurableComponent.class.isAssignableFrom(extensionClass)) { final String extensionClassName = extensionClass.getCanonicalName(); final Bundle bundle = extensionManager.getBundle(extensionClass.getClassLoader()); if (bundle == null) { logger.warn("No coordinate found for {}, skipping...", new Object[] {extensionClassName}); continue; } final BundleCoordinate coordinate = bundle.getBundleDetails().getCoordinate(); final String path = coordinate.getGroup() + "/" + coordinate.getId() + "/" + coordinate.getVersion() + "/" + extensionClassName; final File componentDirectory = new File(explodedNiFiDocsDir, path); componentDirectory.mkdirs(); final Class<? extends ConfigurableComponent> componentClass = extensionClass.asSubclass(ConfigurableComponent.class); try { logger.debug("Documenting: " + componentClass); document(extensionManager, componentDirectory, componentClass, coordinate); } catch (Exception e) { logger.warn("Unable to document: " + componentClass, e); } } } }
final String path = coordinate.getGroup() + "/" + coordinate.getId() + "/" + coordinate.getVersion() + "/" + name;
private ValidationResult validateControllerServiceApi(final PropertyDescriptor descriptor, final ControllerServiceNode controllerServiceNode) { final Class<? extends ControllerService> controllerServiceApiClass = descriptor.getControllerServiceDefinition(); final ClassLoader controllerServiceApiClassLoader = controllerServiceApiClass.getClassLoader(); final ExtensionManager extensionManager = serviceProvider.getExtensionManager(); final String serviceId = controllerServiceNode.getIdentifier(); final String propertyName = descriptor.getDisplayName(); final Bundle controllerServiceApiBundle = extensionManager.getBundle(controllerServiceApiClassLoader); if (controllerServiceApiBundle == null) { return createInvalidResult(serviceId, propertyName, "Unable to find bundle for ControllerService API class " + controllerServiceApiClass.getCanonicalName()); } final BundleCoordinate controllerServiceApiCoordinate = controllerServiceApiBundle.getBundleDetails().getCoordinate(); final Bundle controllerServiceBundle = extensionManager.getBundle(controllerServiceNode.getBundleCoordinate()); if (controllerServiceBundle == null) { return createInvalidResult(serviceId, propertyName, "Unable to find bundle for coordinate " + controllerServiceNode.getBundleCoordinate()); } final BundleCoordinate controllerServiceCoordinate = controllerServiceBundle.getBundleDetails().getCoordinate(); final boolean matchesApi = matchesApi(extensionManager, controllerServiceBundle, controllerServiceApiCoordinate); if (!matchesApi) { final String controllerServiceType = controllerServiceNode.getComponentType(); final String controllerServiceApiType = controllerServiceApiClass.getSimpleName(); final String explanation = new StringBuilder() .append(controllerServiceType).append(" - ").append(controllerServiceCoordinate.getVersion()) .append(" from ").append(controllerServiceCoordinate.getGroup()).append(" - ").append(controllerServiceCoordinate.getId()) .append(" is not compatible with ").append(controllerServiceApiType).append(" - ").append(controllerServiceApiCoordinate.getVersion()) .append(" from ").append(controllerServiceApiCoordinate.getGroup()).append(" - ").append(controllerServiceApiCoordinate.getId()) .toString(); return createInvalidResult(serviceId, propertyName, explanation); } return null; }
final String version = coordinate.getVersion(); final String version = firstCoordinate.getVersion();
private Bundle mapBundle(final BundleCoordinate coordinate) { final Bundle versionedBundle = new Bundle(); versionedBundle.setGroup(coordinate.getGroup()); versionedBundle.setArtifact(coordinate.getId()); versionedBundle.setVersion(coordinate.getVersion()); return versionedBundle; }
/** * Creates a bundle DTO from the specified class. * * @param coordinate bundle coordinates * @return dto */ public BundleDTO createBundleDto(final BundleCoordinate coordinate) { final BundleDTO dto = new BundleDTO(); dto.setGroup(coordinate.getGroup()); dto.setArtifact(coordinate.getId()); dto.setVersion(coordinate.getVersion()); return dto; }
public SystemDiagnosticsSnapshotDTO.VersionInfoDTO createVersionInfoDTO() { final SystemDiagnosticsSnapshotDTO.VersionInfoDTO dto = new SystemDiagnosticsSnapshotDTO.VersionInfoDTO(); dto.setJavaVendor(System.getProperty("java.vendor")); dto.setJavaVersion(System.getProperty("java.version")); dto.setOsName(System.getProperty("os.name")); dto.setOsVersion(System.getProperty("os.version")); dto.setOsArchitecture(System.getProperty("os.arch")); final Bundle frameworkBundle = NarClassLoadersHolder.getInstance().getFrameworkBundle(); if (frameworkBundle != null) { final BundleDetails frameworkDetails = frameworkBundle.getBundleDetails(); dto.setNiFiVersion(frameworkDetails.getCoordinate().getVersion()); // Get build info dto.setBuildTag(frameworkDetails.getBuildTag()); dto.setBuildRevision(frameworkDetails.getBuildRevision()); dto.setBuildBranch(frameworkDetails.getBuildBranch()); dto.setBuildTimestamp(frameworkDetails.getBuildTimestampDate()); } return dto; }
aboutDTO.setVersion(frameworkDetails.getCoordinate().getVersion());
try { final BundleCoordinate bundle = BundleUtils.getCompatibleBundle(extensionManager, processor.getType(), processor.getBundle()); processors.add(getConfigurableComponent(processor.getType(), new BundleDTO(bundle.getGroup(), bundle.getId(), bundle.getVersion()))); } catch (final IllegalStateException e) { try { final BundleCoordinate bundle = BundleUtils.getCompatibleBundle(extensionManager, controllerService.getType(), controllerService.getBundle()); controllerServices.add(getConfigurableComponent(controllerService.getType(), new BundleDTO(bundle.getGroup(), bundle.getId(), bundle.getVersion()))); } catch (final IllegalStateException e) {
/** * Discovers the compatible bundle details for the components in the specified snippet. * * @param snippet the snippet */ private void discoverCompatibleBundles(final FlowSnippetDTO snippet) { if (snippet.getProcessors() != null) { snippet.getProcessors().forEach(processor -> { final BundleCoordinate coordinate = serviceFacade.getCompatibleBundle(processor.getType(), processor.getBundle()); processor.setBundle(new BundleDTO(coordinate.getGroup(), coordinate.getId(), coordinate.getVersion())); }); } if (snippet.getControllerServices() != null) { snippet.getControllerServices().forEach(controllerService -> { final BundleCoordinate coordinate = serviceFacade.getCompatibleBundle(controllerService.getType(), controllerService.getBundle()); controllerService.setBundle(new BundleDTO(coordinate.getGroup(), coordinate.getId(), coordinate.getVersion())); }); } if (snippet.getProcessGroups() != null) { snippet.getProcessGroups().forEach(processGroup -> { discoverCompatibleBundles(processGroup.getContents()); }); } }
bundle.setArtifact(coordinate.getId()); bundle.setGroup(coordinate.getGroup()); bundle.setVersion(coordinate.getVersion()); processor.setBundle(bundle); }); bundle.setArtifact(coordinate.getId()); bundle.setGroup(coordinate.getGroup()); bundle.setVersion(coordinate.getVersion()); controllerService.setBundle(bundle); });
public void setBundleInformation(final BundleCoordinate bundleCoordinate) { // If we are handling a component that does not yet have bundle information, create a placeholder element if (this.bundleElement == null) { this.bundleElement = this.rawElement.getOwnerDocument().createElement(BUNDLE_ELEMENT_NAME); for (String elementTag : Arrays.asList(GROUP_ELEMENT_NAME, ARTIFACT_ELEMENT_NAME, VERSION_ELEMENT_NAME)) { this.bundleElement.appendChild(this.bundleElement.getOwnerDocument().createElement(elementTag)); } this.rawElement.appendChild(this.bundleElement); } setBundleInformation(bundleCoordinate.getGroup(), bundleCoordinate.getId(), bundleCoordinate.getVersion()); }
public void setBundleInformation(final BundleCoordinate bundleCoordinate) { // If we are handling a component that does not yet have bundle information, create a placeholder element if (this.bundleElement == null) { this.bundleElement = this.rawElement.getOwnerDocument().createElement(BUNDLE_ELEMENT_NAME); for (String elementTag : Arrays.asList(GROUP_ELEMENT_NAME, ARTIFACT_ELEMENT_NAME, VERSION_ELEMENT_NAME)) { this.bundleElement.appendChild(this.bundleElement.getOwnerDocument().createElement(elementTag)); } this.rawElement.appendChild(this.bundleElement); } setBundleInformation(bundleCoordinate.getGroup(), bundleCoordinate.getId(), bundleCoordinate.getVersion()); }
private void enrichComponent(EnrichingElementAdapter componentToEnrich, Map<String, Bundle> componentToEnrichVersionToBundles) throws FlowEnrichmentException { if (componentToEnrich.getBundleElement() != null) { return; } BundleCoordinate enrichingBundleCoordinate = null; if (!componentToEnrichVersionToBundles.isEmpty()) { // If there is only one supporting bundle, choose it, otherwise carry out additional analysis if (componentToEnrichVersionToBundles.size() == 1) { BundleDetails enrichingBundleDetails = componentToEnrichVersionToBundles.entrySet().iterator().next().getValue().getBundleDetails(); enrichingBundleCoordinate = enrichingBundleDetails.getCoordinate(); // Adjust the bundle to reflect the values we learned from the Extension Manager componentToEnrich.setBundleInformation(enrichingBundleCoordinate); componentToEnrich.setDependsUponBundleCoordinate(enrichingBundleDetails.getDependencyCoordinate()); } else { // multiple options final Set<String> componentToEnrichBundleVersions = componentToEnrichVersionToBundles.values().stream() .map(bundle -> bundle.getBundleDetails().getCoordinate().getVersion()).collect(Collectors.toSet()); // Select the last version of those available for the enriching bundle final String bundleVersion = componentToEnrichBundleVersions.stream().sorted().reduce((version, otherVersion) -> otherVersion).get(); final BundleCoordinate enrichingCoordinate = componentToEnrichVersionToBundles.get(bundleVersion).getBundleDetails().getCoordinate(); componentToEnrich.setBundleInformation(enrichingCoordinate); logger.warn("Multiple enriching bundle options were available for component {}. The automatically selected enriching bundle was {}", new Object[]{componentToEnrich.getComponentClass(), enrichingCoordinate}); } } else { logger.warn("Could not find any eligible bundles for {}. Automatic start of the flow cannot be guaranteed.", componentToEnrich.getComponentClass()); } }
private void enrichComponent(EnrichingElementAdapter componentToEnrich, Map<String, Bundle> componentToEnrichVersionToBundles) throws FlowEnrichmentException { if (componentToEnrich.getBundleElement() != null) { return; } BundleCoordinate enrichingBundleCoordinate = null; if (!componentToEnrichVersionToBundles.isEmpty()) { // If there is only one supporting bundle, choose it, otherwise carry out additional analysis if (componentToEnrichVersionToBundles.size() == 1) { BundleDetails enrichingBundleDetails = componentToEnrichVersionToBundles.entrySet().iterator().next().getValue().getBundleDetails(); enrichingBundleCoordinate = enrichingBundleDetails.getCoordinate(); // Adjust the bundle to reflect the values we learned from the Extension Manager componentToEnrich.setBundleInformation(enrichingBundleCoordinate); componentToEnrich.setDependsUponBundleCoordinate(enrichingBundleDetails.getDependencyCoordinate()); } else { // multiple options final Set<String> componentToEnrichBundleVersions = componentToEnrichVersionToBundles.values().stream() .map(bundle -> bundle.getBundleDetails().getCoordinate().getVersion()).collect(Collectors.toSet()); // Select the last version of those available for the enriching bundle final String bundleVersion = componentToEnrichBundleVersions.stream().sorted().reduce((version, otherVersion) -> otherVersion).get(); final BundleCoordinate enrichingCoordinate = componentToEnrichVersionToBundles.get(bundleVersion).getBundleDetails().getCoordinate(); componentToEnrich.setBundleInformation(enrichingCoordinate); logger.warn("Multiple enriching bundle options were available for component {}. The automatically selected enriching bundle was {}", new Object[]{componentToEnrich.getComponentClass(), enrichingCoordinate}); } } else { logger.warn("Could not find any eligible bundles for {}. Automatic start of the flow cannot be guaranteed.", componentToEnrich.getComponentClass()); } }
private ValidationResult validateControllerServiceApi(final PropertyDescriptor descriptor, final ControllerServiceNode controllerServiceNode) { final Class<? extends ControllerService> controllerServiceApiClass = descriptor.getControllerServiceDefinition(); final ClassLoader controllerServiceApiClassLoader = controllerServiceApiClass.getClassLoader(); final String serviceId = controllerServiceNode.getIdentifier(); final String propertyName = descriptor.getDisplayName(); final Bundle controllerServiceApiBundle = ExtensionManager.getBundle(controllerServiceApiClassLoader); if (controllerServiceApiBundle == null) { return createInvalidResult(serviceId, propertyName, "Unable to find bundle for ControllerService API class " + controllerServiceApiClass.getCanonicalName()); } final BundleCoordinate controllerServiceApiCoordinate = controllerServiceApiBundle.getBundleDetails().getCoordinate(); final Bundle controllerServiceBundle = ExtensionManager.getBundle(controllerServiceNode.getBundleCoordinate()); if (controllerServiceBundle == null) { return createInvalidResult(serviceId, propertyName, "Unable to find bundle for coordinate " + controllerServiceNode.getBundleCoordinate()); } final BundleCoordinate controllerServiceCoordinate = controllerServiceBundle.getBundleDetails().getCoordinate(); final boolean matchesApi = matchesApi(controllerServiceBundle, controllerServiceApiCoordinate); if (!matchesApi) { final String controllerServiceType = controllerServiceNode.getComponentType(); final String controllerServiceApiType = controllerServiceApiClass.getSimpleName(); final String explanation = new StringBuilder() .append(controllerServiceType).append(" - ").append(controllerServiceCoordinate.getVersion()) .append(" from ").append(controllerServiceCoordinate.getGroup()).append(" - ").append(controllerServiceCoordinate.getId()) .append(" is not compatible with ").append(controllerServiceApiType).append(" - ").append(controllerServiceApiCoordinate.getVersion()) .append(" from ").append(controllerServiceApiCoordinate.getGroup()).append(" - ").append(controllerServiceApiCoordinate.getId()) .toString(); return createInvalidResult(serviceId, propertyName, explanation); } return null; }
final Map<String, Bundle> componentToEnrichVersionToBundles = minifi.getBundles(componentToEnrichClass) .stream() .collect(Collectors.toMap(bundle -> bundle.getBundleDetails().getCoordinate().getVersion(), bundle -> bundle));