@Override public String toString() { return coordinate.toString(); }
public BundleDetails build() { return new BundleDetails(this); } }
private static String getClassBundleKey(final String classType, final BundleCoordinate bundleCoordinate) { return classType + "_" + bundleCoordinate.getCoordinate(); }
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); }
protected void verifyCreate(final ExtensionManager extensionManager, final String type, final BundleDTO bundle) { final List<Bundle> bundles = extensionManager.getBundles(type); if (bundle != null) { final BundleCoordinate coordinate = new BundleCoordinate(bundle.getGroup(), bundle.getArtifact(), bundle.getVersion()); if (bundles.stream().filter(b -> b.getBundleDetails().getCoordinate().equals(coordinate)).count() == 0) { throw new IllegalStateException(String.format("%s is not known to this NiFi instance.", coordinate.toString())); } } else { if (bundles.isEmpty()) { throw new IllegalStateException(String.format("%s is not known to this NiFi instance.", type)); } else if (bundles.size() > 1) { throw new IllegalStateException(String.format("Multiple versions of %s exist. Please specify the desired bundle.", type)); } } } }
/** * Determines if the given controller service node has the required API as an ancestor. * * @param controllerServiceImplBundle the bundle of a controller service being referenced by a processor * @param requiredApiCoordinate the controller service API required by the processor * @return true if the controller service node has the require API as an ancestor, false otherwise */ private boolean matchesApi(final ExtensionManager extensionManager, final Bundle controllerServiceImplBundle, final BundleCoordinate requiredApiCoordinate) { // start with the coordinate of the controller service for cases where the API and service are in the same bundle BundleCoordinate controllerServiceDependencyCoordinate = controllerServiceImplBundle.getBundleDetails().getCoordinate(); boolean foundApiDependency = false; while (controllerServiceDependencyCoordinate != null) { // determine if the dependency coordinate matches the required API if (requiredApiCoordinate.equals(controllerServiceDependencyCoordinate)) { foundApiDependency = true; break; } // move to the next dependency in the chain, or stop if null final Bundle controllerServiceDependencyBundle = extensionManager.getBundle(controllerServiceDependencyCoordinate); if (controllerServiceDependencyBundle == null) { controllerServiceDependencyCoordinate = null; } else { controllerServiceDependencyCoordinate = controllerServiceDependencyBundle.getBundleDetails().getDependencyCoordinate(); } } return foundApiDependency; }
@Override public void discoverExtensions(final Set<Bundle> narBundles) { // get the current context class loader ClassLoader currentContextClassLoader = Thread.currentThread().getContextClassLoader(); // consider each nar class loader for (final Bundle bundle : narBundles) { // Must set the context class loader to the nar classloader itself // so that static initialization techniques that depend on the context class loader will work properly final ClassLoader ncl = bundle.getClassLoader(); Thread.currentThread().setContextClassLoader(ncl); loadExtensions(bundle); // Create a look-up from coordinate to bundle bundleCoordinateBundleLookup.put(bundle.getBundleDetails().getCoordinate(), bundle); } // restore the current context class loader if appropriate if (currentContextClassLoader != null) { Thread.currentThread().setContextClassLoader(currentContextClassLoader); } }
@Override public void discoverExtensions(final Bundle systemBundle, final Set<Bundle> narBundles) { // load the system bundle first so that any extensions found in JARs directly in lib will be registered as // being from the system bundle and not from all the other NARs loadExtensions(systemBundle); bundleCoordinateBundleLookup.put(systemBundle.getBundleDetails().getCoordinate(), systemBundle); discoverExtensions(narBundles); }
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; }
/** * Gets the bundle with the given coordinate. * * @param bundleCoordinate the coordinate of the bundle to find * @return the bundle with the coordinate, or an empty optional */ private Optional<Bundle> getBundle(final BundleCoordinate bundleCoordinate) { return initContext.bundles.values().stream() .filter(b -> b.getBundleDetails().getCoordinate().equals(bundleCoordinate)) .findFirst(); }
private BundleCoordinate toCoordinate(final Bundle bundle) { return new BundleCoordinate(bundle.getGroup(), bundle.getArtifact(), bundle.getVersion()); }
public BundleCoordinate(final String group, final String id, final String version) { this.group = isBlank(group) ? DEFAULT_GROUP : group; this.id = id; this.version = isBlank(version) ? DEFAULT_VERSION : version; if (isBlank(id)) { throw new IllegalStateException("Id is required for BundleCoordinate"); } this.coordinate = this.group + ":" + this.id + ":" + this.version; }
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; }
private static BundleCoordinate findBundleForType(final ExtensionManager extensionManager, final String type, final BundleCoordinate desiredCoordinate) { final List<Bundle> bundles = extensionManager.getBundles(type); if (bundles.isEmpty()) { throw new IllegalStateException(String.format("%s is not known to this NiFi instance.", type)); } else if (bundles.size() > 1) { if (desiredCoordinate == null) { throw new IllegalStateException(String.format("Multiple versions of %s exist.", type)); } else { throw new IllegalStateException(String.format("Multiple versions of %s exist. No exact match for %s.", type, desiredCoordinate)); } } else { return bundles.get(0).getBundleDetails().getCoordinate(); } }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (!(obj instanceof BundleCoordinate)) { return false; } final BundleCoordinate other = (BundleCoordinate) obj; return getCoordinate().equals(other.getCoordinate()); }
public static BundleCoordinate createBundleCoordinate(final Bundle bundle) { return new BundleCoordinate(bundle.getGroup(), bundle.getArtifact(), bundle.getVersion()); }
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; }
private ClassLoaderDiagnosticsDTO createClassLoaderDiagnosticsDto(final ClassLoader classLoader) { final ClassLoaderDiagnosticsDTO dto = new ClassLoaderDiagnosticsDTO(); final Bundle bundle = extensionManager.getBundle(classLoader); if (bundle != null) { dto.setBundle(createBundleDto(bundle.getBundleDetails().getCoordinate())); } final ClassLoader parentClassLoader = classLoader.getParent(); if (parentClassLoader != null) { dto.setParentClassLoader(createClassLoaderDiagnosticsDto(parentClassLoader)); } return dto; }
private BundleCoordinate getCoordinate(final String type, final BundleDTO dto) { BundleCoordinate coordinate; try { coordinate = BundleUtils.getCompatibleBundle(extensionManager, type, dto); } catch (final IllegalStateException e) { if (dto == null) { coordinate = BundleCoordinate.UNKNOWN_COORDINATE; } else { coordinate = new BundleCoordinate(dto.getGroup(), dto.getArtifact(), dto.getVersion()); } } return coordinate; }
/** * 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; }