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(); } }
private static StateProvider instantiateStateProvider(final ExtensionManager extensionManager, final String type) throws ClassNotFoundException, InstantiationException, IllegalAccessException { final ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader(); try { final List<Bundle> bundles = extensionManager.getBundles(type); if (bundles.size() == 0) { throw new IllegalStateException(String.format("The specified class '%s' is not known to this nifi.", type)); } if (bundles.size() > 1) { throw new IllegalStateException(String.format("Multiple bundles found for the specified class '%s', only one is allowed.", type)); } final Bundle bundle = bundles.get(0); final ClassLoader detectedClassLoaderForType = bundle.getClassLoader(); final Class<?> rawClass = Class.forName(type, true, detectedClassLoaderForType); Thread.currentThread().setContextClassLoader(detectedClassLoaderForType); final Class<? extends StateProvider> mgrClass = rawClass.asSubclass(StateProvider.class); return withNarClassLoader(mgrClass.newInstance()); } finally { if (ctxClassLoader != null) { Thread.currentThread().setContextClassLoader(ctxClassLoader); } } }
public FlowFilePrioritizer createPrioritizer(final String type) throws InstantiationException, IllegalAccessException, ClassNotFoundException { FlowFilePrioritizer prioritizer; final ClassLoader ctxClassLoader = Thread.currentThread().getContextClassLoader(); try { final List<Bundle> prioritizerBundles = flowController.getExtensionManager().getBundles(type); if (prioritizerBundles.size() == 0) { throw new IllegalStateException(String.format("The specified class '%s' is not known to this nifi.", type)); } if (prioritizerBundles.size() > 1) { throw new IllegalStateException(String.format("Multiple bundles found for the specified class '%s', only one is allowed.", type)); } final Bundle bundle = prioritizerBundles.get(0); final ClassLoader detectedClassLoaderForType = bundle.getClassLoader(); final Class<?> rawClass = Class.forName(type, true, detectedClassLoaderForType); Thread.currentThread().setContextClassLoader(detectedClassLoaderForType); final Class<? extends FlowFilePrioritizer> prioritizerClass = rawClass.asSubclass(FlowFilePrioritizer.class); final Object processorObj = prioritizerClass.newInstance(); prioritizer = prioritizerClass.cast(processorObj); return prioritizer; } finally { if (ctxClassLoader != null) { Thread.currentThread().setContextClassLoader(ctxClassLoader); } } }
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)); } } } }
private LoginIdentityProvider createLoginIdentityProvider(final String identifier, final String loginIdentityProviderClassName) throws Exception { final List<Bundle> loginIdentityProviderBundles = extensionManager.getBundles(loginIdentityProviderClassName);
Thread.currentThread().setContextClassLoader(NarThreadContextClassLoader.getInstance()); try { final List<Bundle> bundles = extensionManager.getBundles(implementationClassName); if (bundles.size() == 0) { throw new IllegalStateException(String.format("The specified implementation class '%s' is not known to this nifi.", implementationClassName));
private UserGroupProvider createUserGroupProvider(final String identifier, final String userGroupProviderClassName) throws Exception { final List<Bundle> userGroupProviderBundles = extensionManager.getBundles(userGroupProviderClassName);
private AccessPolicyProvider createAccessPolicyProvider(final String identifier, final String accessPolicyProviderClassName) throws Exception { final List<Bundle> accessPolicyProviderBundles = extensionManager.getBundles(accessPolicyProviderClassName);
for (final Class<?> c : extensionManager.getExtensions(Processor.class)) { final String name = c.getName(); processorClasses.put(name, extensionManager.getBundles(name).stream().map(bundle -> bundle.getBundleDetails().getCoordinate()).collect(Collectors.toSet())); for (final Class<?> c : extensionManager.getExtensions(ControllerService.class)) { final String name = c.getName(); controllerServiceClasses.put(name, extensionManager.getBundles(name).stream().map(bundle -> bundle.getBundleDetails().getCoordinate()).collect(Collectors.toSet()));
private static BundleCoordinate findCompatibleBundle(final ExtensionManager extensionManager, final String type, final BundleDTO bundleDTO, final boolean allowCompatibleBundle) { final BundleCoordinate coordinate = new BundleCoordinate(bundleDTO.getGroup(), bundleDTO.getArtifact(), bundleDTO.getVersion()); final Bundle bundle = extensionManager.getBundle(coordinate); if (bundle == null) { if (allowCompatibleBundle) { return findBundleForType(extensionManager, type, coordinate); } else { throw new IllegalStateException(String.format("%s from %s is not known to this NiFi instance.", type, coordinate)); } } else { final List<BundleCoordinate> bundlesForType = extensionManager.getBundles(type).stream().map(b -> b.getBundleDetails().getCoordinate()).collect(Collectors.toList()); if (bundlesForType.contains(coordinate)) { return coordinate; } else { throw new IllegalStateException(String.format("Found bundle %s but does not support %s", coordinate, type)); } } }
private Authorizer createAuthorizer(final String identifier, final String authorizerClassName, final String classpathResources) throws Exception { final List<Bundle> authorizerBundles = extensionManager.getBundles(authorizerClassName);
for (final Class<?> c : extensionManager.getExtensions(Processor.class)) { final String name = c.getName(); processorClasses.put(name, extensionManager.getBundles(name).stream().map(bundle -> bundle.getBundleDetails().getCoordinate()).collect(Collectors.toSet())); for (final Class<?> c : extensionManager.getExtensions(ControllerService.class)) { final String name = c.getName(); controllerServiceClasses.put(name, extensionManager.getBundles(name).stream().map(bundle -> bundle.getBundleDetails().getCoordinate()).collect(Collectors.toSet()));
for (final Class<? extends ConfigurableComponent> linkedComponent : linkedComponents ) { final String linkedComponentName = linkedComponent.getName(); final List<Bundle> linkedComponentBundles = extensionManager.getBundles(linkedComponentName); if (linkedComponentBundles != null && linkedComponentBundles.size() > 0) { final Bundle firstLinkedComponentBundle = linkedComponentBundles.get(0); final List<Bundle> linkedComponentBundles = extensionManager.getBundles(className);
final BundleCoordinate processorToAddCoordinate = toCoordinate(processorToAdd.getBundle()); final boolean bundleExists = flowController.getExtensionManager().getBundles(processorToAddClass).stream() .anyMatch(b -> processorToAddCoordinate.equals(b.getBundleDetails().getCoordinate())); final BundleCoordinate serviceToAddCoordinate = toCoordinate(serviceToAdd.getBundle()); final boolean bundleExists = flowController.getExtensionManager().getBundles(serviceToAddClass).stream() .anyMatch(b -> serviceToAddCoordinate.equals(b.getBundleDetails().getCoordinate()));
public ReportingTaskDTO createReportingTaskDto(final ReportingTaskNode reportingTaskNode) { final BundleCoordinate bundleCoordinate = reportingTaskNode.getBundleCoordinate(); final List<Bundle> compatibleBundles = extensionManager.getBundles(reportingTaskNode.getCanonicalClassName()).stream().filter(bundle -> { final BundleCoordinate coordinate = bundle.getBundleDetails().getCoordinate(); return bundleCoordinate.getGroup().equals(coordinate.getGroup()) && bundleCoordinate.getId().equals(coordinate.getId());
public ControllerServiceDTO createControllerServiceDto(final ControllerServiceNode controllerServiceNode) { final BundleCoordinate bundleCoordinate = controllerServiceNode.getBundleCoordinate(); final List<Bundle> compatibleBundles = extensionManager.getBundles(controllerServiceNode.getCanonicalClassName()).stream().filter(bundle -> { final BundleCoordinate coordinate = bundle.getBundleDetails().getCoordinate(); return bundleCoordinate.getGroup().equals(coordinate.getGroup()) && bundleCoordinate.getId().equals(coordinate.getId());
final List<Bundle> compatibleBundles = extensionManager.getBundles(node.getCanonicalClassName()).stream().filter(bundle -> { final BundleCoordinate coordinate = bundle.getBundleDetails().getCoordinate(); return bundleCoordinate.getGroup().equals(coordinate.getGroup()) && bundleCoordinate.getId().equals(coordinate.getId());
protected List<Bundle> getBundles(final String bundleClass) { return ExtensionManager.getBundles(bundleClass); } }
protected List<Bundle> getBundles(final String bundleClass) { return ExtensionManager.getBundles(bundleClass); } }
private LoginIdentityProvider createLoginIdentityProvider(final String identifier, final String loginIdentityProviderClassName) throws Exception { final List<Bundle> loginIdentityProviderBundles = ExtensionManager.getBundles(loginIdentityProviderClassName);