private static String getClassBundleKey(final String classType, final BundleCoordinate bundleCoordinate) { return classType + "_" + bundleCoordinate.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()); }
@Override public void logClassLoaderMapping() { final StringBuilder builder = new StringBuilder(); builder.append("Extension Type Mapping to Bundle:"); for (final Map.Entry<Class, Set<Class>> entry : definitionMap.entrySet()) { builder.append("\n\t=== ").append(entry.getKey().getSimpleName()).append(" Type ==="); for (final Class type : entry.getValue()) { final List<Bundle> bundles = classNameBundleLookup.containsKey(type.getName()) ? classNameBundleLookup.get(type.getName()) : Collections.emptyList(); builder.append("\n\t").append(type.getName()); for (final Bundle bundle : bundles) { final String coordinate = bundle.getBundleDetails().getCoordinate().getCoordinate(); final String workingDir = bundle.getBundleDetails().getWorkingDirectory().getPath(); builder.append("\n\t\t").append(coordinate).append(" || ").append(workingDir); } } builder.append("\n\t=== End ").append(entry.getKey().getSimpleName()).append(" types ==="); } logger.info(builder.toString()); } }
private <T extends ConfigurableComponent> LoggableComponent<T> createLoggableComponent(Class<T> nodeType) throws ClassNotFoundException, IllegalAccessException, InstantiationException { final ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader(); try { final Bundle bundle = extensionManager.getBundle(bundleCoordinate); if (bundle == null) { throw new IllegalStateException("Unable to find bundle for coordinate " + bundleCoordinate.getCoordinate()); } final ClassLoader detectedClassLoader = extensionManager.createInstanceClassLoader(type, identifier, bundle, classpathUrls == null ? Collections.emptySet() : classpathUrls); final Class<?> rawClass = Class.forName(type, true, detectedClassLoader); Thread.currentThread().setContextClassLoader(detectedClassLoader); final Object extensionInstance = rawClass.newInstance(); final ComponentLog componentLog = new SimpleProcessLogger(identifier, extensionInstance); final TerminationAwareLogger terminationAwareLogger = new TerminationAwareLogger(componentLog); final T cast = nodeType.cast(extensionInstance); return new LoggableComponent<>(cast, bundleCoordinate, terminationAwareLogger); } finally { if (ctxClassLoader != null) { Thread.currentThread().setContextClassLoader(ctxClassLoader); } } } }
@Override public void verifyCanUpdateBundle(final BundleCoordinate incomingCoordinate) throws IllegalArgumentException { final BundleCoordinate existingCoordinate = getBundleCoordinate(); // determine if this update is changing the bundle for the processor if (!existingCoordinate.equals(incomingCoordinate)) { // if it is changing the bundle, only allow it to change to a different version within same group and id if (!existingCoordinate.getGroup().equals(incomingCoordinate.getGroup()) || !existingCoordinate.getId().equals(incomingCoordinate.getId())) { throw new IllegalArgumentException(String.format( "Unable to update component %s from %s to %s because bundle group and id must be the same.", getIdentifier(), existingCoordinate.getCoordinate(), incomingCoordinate.getCoordinate())); } } }
if (extensions.isEmpty()) { LOGGER.debug("No documentation to generate for {} because no extensions were found", new Object[]{bundleCoordinate.getCoordinate()}); } else { LOGGER.debug("Generating documentation for {} extensions in {}", new Object[]{extensions.size(), bundleCoordinate.getCoordinate()}); DocGenerator.documentConfigurableComponent(extensions, docsWorkingDir, extensionManager);
private void updateBundle(ReportingTaskNode reportingTask, ReportingTaskDTO reportingTaskDTO) { final BundleDTO bundleDTO = reportingTaskDTO.getBundle(); if (bundleDTO != null) { final ExtensionManager extensionManager = reportingTaskProvider.getExtensionManager(); final BundleCoordinate incomingCoordinate = BundleUtils.getBundle(extensionManager, reportingTask.getCanonicalClassName(), bundleDTO); final BundleCoordinate existingCoordinate = reportingTask.getBundleCoordinate(); if (!existingCoordinate.getCoordinate().equals(incomingCoordinate.getCoordinate())) { try { // we need to use the property descriptors from the temp component here in case we are changing from a ghost component to a real component final ConfigurableComponent tempComponent = extensionManager.getTempComponent(reportingTask.getCanonicalClassName(), incomingCoordinate); final Set<URL> additionalUrls = reportingTask.getAdditionalClasspathResources(tempComponent.getPropertyDescriptors()); reloadComponent.reload(reportingTask, reportingTask.getCanonicalClassName(), incomingCoordinate, additionalUrls); } catch (ReportingTaskInstantiationException e) { throw new NiFiCoreException(String.format("Unable to update reporting task %s from %s to %s due to: %s", reportingTaskDTO.getId(), reportingTask.getBundleCoordinate().getCoordinate(), incomingCoordinate.getCoordinate(), e.getMessage()), e); } } } }
final String dependencyCoordinateStr = bundleDependencyCoordinate.getCoordinate(); logger.warn(String.format("While loading '%s' unable to locate exact NAR dependency '%s'. Only found one possible match '%s'. Continuing...", bundleDetail.getCoordinate().getCoordinate(), dependencyCoordinateStr, coordinate.getCoordinate()));
private void updateBundle(final ControllerServiceNode controllerService, final ControllerServiceDTO controllerServiceDTO) { final BundleDTO bundleDTO = controllerServiceDTO.getBundle(); if (bundleDTO != null) { final ExtensionManager extensionManager = serviceProvider.getExtensionManager(); final BundleCoordinate incomingCoordinate = BundleUtils.getBundle(extensionManager, controllerService.getCanonicalClassName(), bundleDTO); final BundleCoordinate existingCoordinate = controllerService.getBundleCoordinate(); if (!existingCoordinate.getCoordinate().equals(incomingCoordinate.getCoordinate())) { try { // we need to use the property descriptors from the temp component here in case we are changing from a ghost component to a real component final ConfigurableComponent tempComponent = extensionManager.getTempComponent(controllerService.getCanonicalClassName(), incomingCoordinate); final Set<URL> additionalUrls = controllerService.getAdditionalClasspathResources(tempComponent.getPropertyDescriptors()); flowController.getReloadComponent().reload(controllerService, controllerService.getCanonicalClassName(), incomingCoordinate, additionalUrls); } catch (ControllerServiceInstantiationException e) { throw new NiFiCoreException(String.format("Unable to update controller service %s from %s to %s due to: %s", controllerServiceDTO.getId(), controllerService.getBundleCoordinate().getCoordinate(), incomingCoordinate.getCoordinate(), e.getMessage()), e); } } } }
private void updateBundle(ProcessorNode processor, ProcessorDTO processorDTO) { final BundleDTO bundleDTO = processorDTO.getBundle(); if (bundleDTO != null) { final ExtensionManager extensionManager = flowController.getExtensionManager(); final BundleCoordinate incomingCoordinate = BundleUtils.getBundle(extensionManager, processor.getCanonicalClassName(), bundleDTO); final BundleCoordinate existingCoordinate = processor.getBundleCoordinate(); if (!existingCoordinate.getCoordinate().equals(incomingCoordinate.getCoordinate())) { try { // we need to use the property descriptors from the temp component here in case we are changing from a ghost component to a real component final ConfigurableComponent tempComponent = extensionManager.getTempComponent(processor.getCanonicalClassName(), incomingCoordinate); final Set<URL> additionalUrls = processor.getAdditionalClasspathResources(tempComponent.getPropertyDescriptors()); flowController.getReloadComponent().reload(processor, processor.getCanonicalClassName(), incomingCoordinate, additionalUrls); } catch (ProcessorInstantiationException e) { throw new NiFiCoreException(String.format("Unable to update processor %s from %s to %s due to: %s", processorDTO.getId(), processor.getBundleCoordinate().getCoordinate(), incomingCoordinate.getCoordinate(), e.getMessage()), e); } } } }
final String narCoordinate = narDetail.getCoordinate().getCoordinate(); if (narCoordinatesToWorkingDir.containsKey(narCoordinate)) { final String existingNarWorkingDir = narCoordinatesToWorkingDir.get(narCoordinate); narCoordinateClassLoaderLookup.put(narDetail.getCoordinate().getCoordinate(), jettyClassLoader); narDetailsIter.remove(); narClassLoader = createNarClassLoader(narDetail.getWorkingDirectory(), jettyClassLoader); } else { final String dependencyCoordinateStr = narDependencyCoordinate.getCoordinate(); if (narCoordinateClassLoaderLookup.containsKey(coordinate.getCoordinate())) { logger.warn(String.format("While loading '%s' unable to locate exact NAR dependency '%s'. Only found one possible match '%s'. Continuing...", narDetail.getCoordinate().getCoordinate(), dependencyCoordinateStr, coordinate.getCoordinate())); final ClassLoader narDependencyClassLoader = narCoordinateClassLoaderLookup.get(coordinate.getCoordinate()); narClassLoader = createNarClassLoader(narDetail.getWorkingDirectory(), narDependencyClassLoader); if (bundleClassLoader != null) { narDirectoryBundleLookup.put(narDetail.getWorkingDirectory().getCanonicalPath(), new Bundle(narDetail, bundleClassLoader)); narCoordinateClassLoaderLookup.put(narDetail.getCoordinate().getCoordinate(), narClassLoader); narDetailsIter.remove();
final Bundle csBundle = getExtensionManager().getBundle(bundleCoordinate); if (csBundle == null) { throw new IllegalStateException("Unable to find bundle for coordinate " + bundleCoordinate.getCoordinate());
final Bundle bundle = extensionManager.getBundle(bundleCoordinate); if (bundle == null) { throw new IllegalStateException("Unable to find bundle for coordinate " + bundleCoordinate.getCoordinate());
+ bundle.getBundleDetails().getCoordinate().getCoordinate() + " but that class name is already loaded/registered from " + registeredBundle.getBundleDetails().getCoordinate() + " and multiple versions are not supported for this type"
.sorted((a, b) -> a.getCoordinate().compareTo(b.getCoordinate())) .map(this::createBundleDto) .collect(Collectors.toCollection(LinkedHashSet::new));
private static String getClassBundleKey(final String classType, final BundleCoordinate bundleCoordinate) { return classType + "_" + bundleCoordinate.getCoordinate(); }
private static String getClassBundleKey(final String classType, final BundleCoordinate bundleCoordinate) { return classType + "_" + bundleCoordinate.getCoordinate(); }
public static void logClassLoaderMapping() { final StringBuilder builder = new StringBuilder(); builder.append("Extension Type Mapping to Bundle:"); for (final Map.Entry<Class, Set<Class>> entry : definitionMap.entrySet()) { builder.append("\n\t=== ").append(entry.getKey().getSimpleName()).append(" Type ==="); for (final Class type : entry.getValue()) { final List<Bundle> bundles = classNameBundleLookup.containsKey(type.getName()) ? classNameBundleLookup.get(type.getName()) : Collections.emptyList(); builder.append("\n\t").append(type.getName()); for (final Bundle bundle : bundles) { final String coordinate = bundle.getBundleDetails().getCoordinate().getCoordinate(); final String workingDir = bundle.getBundleDetails().getWorkingDirectory().getPath(); builder.append("\n\t\t").append(coordinate).append(" || ").append(workingDir); } } builder.append("\n\t=== End ").append(entry.getKey().getSimpleName()).append(" types ==="); } logger.info(builder.toString()); } }
public static void logClassLoaderMapping() { final StringBuilder builder = new StringBuilder(); builder.append("Extension Type Mapping to Bundle:"); for (final Map.Entry<Class, Set<Class>> entry : definitionMap.entrySet()) { builder.append("\n\t=== ").append(entry.getKey().getSimpleName()).append(" Type ==="); for (final Class type : entry.getValue()) { final List<Bundle> bundles = classNameBundleLookup.containsKey(type.getName()) ? classNameBundleLookup.get(type.getName()) : Collections.emptyList(); builder.append("\n\t").append(type.getName()); for (final Bundle bundle : bundles) { final String coordinate = bundle.getBundleDetails().getCoordinate().getCoordinate(); final String workingDir = bundle.getBundleDetails().getWorkingDirectory().getPath(); builder.append("\n\t\t").append(coordinate).append(" || ").append(workingDir); } } builder.append("\n\t=== End ").append(entry.getKey().getSimpleName()).append(" types ==="); } logger.info(builder.toString()); } }
@Override public void verifyCanUpdateBundle(final BundleCoordinate incomingCoordinate) throws IllegalArgumentException { final BundleCoordinate existingCoordinate = getBundleCoordinate(); // determine if this update is changing the bundle for the processor if (!existingCoordinate.equals(incomingCoordinate)) { // if it is changing the bundle, only allow it to change to a different version within same group and id if (!existingCoordinate.getGroup().equals(incomingCoordinate.getGroup()) || !existingCoordinate.getId().equals(incomingCoordinate.getId())) { throw new IllegalArgumentException(String.format( "Unable to update component %s from %s to %s because bundle group and id must be the same.", getIdentifier(), existingCoordinate.getCoordinate(), incomingCoordinate.getCoordinate())); } } }