public TopologyComponentBundleResource(StreamlineAuthorizer authorizer, StreamCatalogService catalogService, EnvironmentService environmentService, Subject subject) { this.authorizer = authorizer; this.catalogService = catalogService; this.environmentService = environmentService; this.subject = subject; this.hintProviderProxyUtil = new ProxyUtil<>(ComponentBundleHintProvider.class); }
/** * Loads the jar from jarPath and instantiates {@link Notifier} specified in className. */ private Notifier loadNotifier(String jarPath, String className) { try { LOG.info("Instantiating class {} via ProxyUtil", className); return this.notifierProxyUtil.loadClassFromJar(jarPath, className); } catch (Exception e) { throw new RuntimeException(e); } } }
private boolean verifyCustomProcessorImplFromJar (java.io.File jarFile, CustomProcessorInfo customProcessorInfo) { boolean result = false; try { Collection<String> impls = ProxyUtil.canonicalNames(ProxyUtil.loadAllClassesFromJar(jarFile, CustomProcessorRuntime.class)); if ((impls != null) && impls.contains(customProcessorInfo.getCustomProcessorImpl())) { result = true; } } catch (IOException e) { //swallow to return false } return result; }
public O loadClassFromJar(String jarPath, String classFqdn) throws ClassNotFoundException, MalformedURLException, InstantiationException, IllegalAccessException { ClassLoader classLoader; if (isClassLoadedFromParent(classFqdn)) { classLoader = parentClassLoader; } else { classLoader = findCachedClassLoader(jarPath); if (classLoader == null) { classLoader = getJarAddedClassLoader(jarPath); } } O actualObject = initInstanceFromClassloader(classFqdn, classLoader); return createClassLoaderAwareProxyInstance(classLoader, actualObject); }
public O loadClassFromLibDirectory(Path libDirectory, String classFqdn) throws MalformedURLException, InstantiationException, IllegalAccessException, ClassNotFoundException { ClassLoader classLoader; if (isClassLoadedFromParent(classFqdn)) { classLoader = parentClassLoader; } else { File file = libDirectory.toFile(); classLoader = findCachedClassLoader(file.getAbsolutePath()); if (classLoader == null) { classLoader = getJarsAddedClassLoader(file); } } O actualObject = initInstanceFromClassloader(classFqdn, classLoader); return createClassLoaderAwareProxyInstance(classLoader, actualObject); }
/** * Creates an instance of the given class which is loaded from the given jar or current class loader if {@code jarId} is null. * * @param <T> type of the object to be created * @param jarId id of the jar resource * @param fqcn FullyQualifiedClassName of the object to be created * @param klass Class instance of the object to be created * @return instance of the given class loaded from the given jar or current class loader if {@code jarId} is null. */ protected <T> T getInstance(Long jarId, String fqcn, Class<T> klass) { T instance = null; if (fqcn != null) { try { if (jarId != null) { ProxyUtil<T> proxyUtil = new ProxyUtil<>(klass, AbstractSplitJoinActionRuntime.class.getClassLoader()); String jarPath = getJarPathFor(jarId); instance = proxyUtil.loadClassFromJar(jarPath, fqcn); } else { // FQCN is given but no jarId then that class is assumed to be accessible from current class loader. instance = (T) Class.forName(fqcn, true, Thread.currentThread().getContextClassLoader()).newInstance(); } } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new RuntimeException(e.getMessage(), e); } } return instance; } }
FluxComponent getFluxComponent(StreamlineComponent streamlineComponent) { ProxyUtil<FluxComponent> proxyUtil = new ProxyUtil<>(FluxComponent.class); try { FluxComponent fluxComponent = proxyUtil.loadClassFromLibDirectory(extraJarsLocation, streamlineComponent.getTransformationClass()); return fluxComponent; } catch (ClassNotFoundException | MalformedURLException | InstantiationException | IllegalAccessException e) { LOG.error("Error while creating flux component", e); throw new RuntimeException(e); } } }
private void loadTransformationClassForBundle (TopologyComponentBundle topologyComponentBundle, java.io.File bundleJar) { if (topologyComponentBundle.getStreamingEngine().equals(TopologyLayoutConstants.STORM_STREAMING_ENGINE)) { if (topologyComponentBundle.getBuiltin()) { // no transformation class validations for top level topology type if (topologyComponentBundle.getType() == TopologyComponentBundle.TopologyComponentType.TOPOLOGY) { return; } try { FluxComponent fluxComponent = (FluxComponent) Class.forName(topologyComponentBundle.getTransformationClass()).newInstance(); } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { LOG.debug("Got exception", e); throw new RuntimeException("Check transformationClass property. Cannot load builtin transformation class " + topologyComponentBundle .getTransformationClass()); } } else { ProxyUtil<FluxComponent> fluxComponentProxyUtil = new ProxyUtil<FluxComponent>(FluxComponent.class); try { fluxComponentProxyUtil.loadClassFromJar(bundleJar.getAbsolutePath(), topologyComponentBundle.getTransformationClass()); } catch (IOException | ClassNotFoundException | IllegalAccessException | InstantiationException ex) { LOG.debug("Got exception", ex); throw new RuntimeException("Cannot load transformation class " + topologyComponentBundle.getTransformationClass() + " from bundle Jar: " + bundleJar.getAbsolutePath()); } } } }
public NotificationServiceImpl(Map<String, Object> config, NotificationStore store) { LOG.info("Initializing NotificationServiceImpl with config {}, notification store {}", config, store); this.notificationStore = Optional.ofNullable(store); if(config.get(QUEUEHANDLER_THREADS) != null) { this.queueHandler = new NotificationQueueHandler(((Number)config.get(QUEUEHANDLER_THREADS)).intValue()); } else { this.queueHandler = new NotificationQueueHandler(); } this.notifierProxyUtil = new ProxyUtil<>(Notifier.class); }
@Override public boolean apply(@Nullable Class<?> s) { try { proxyUtil.loadClassFromJar(jarFile.getAbsolutePath(), s.getName()); return true; } catch (Throwable ex) { LOG.warn("class {} is concrete subtype of {}, but can't be initialized due to exception:", s, superTypeClass, ex); return false; } } });
public static Collection<Class<?>> loadAllClassesFromJar(final File jarFile, final Class<?> superTypeClass) throws IOException { List<Class<?>> classes = JarReader.findConcreteSubtypesOfClass(jarFile, superTypeClass); final ProxyUtil<?> proxyUtil = new ProxyUtil<>(superTypeClass); return Collections2.filter(classes, new Predicate<Class<?>>() { @Override public boolean apply(@Nullable Class<?> s) { try { proxyUtil.loadClassFromJar(jarFile.getAbsolutePath(), s.getName()); return true; } catch (Throwable ex) { LOG.warn("class {} is concrete subtype of {}, but can't be initialized due to exception:", s, superTypeClass, ex); return false; } } }); }
provider = clazz.newInstance(); } else { provider = hintProviderProxyUtil.loadClassFromJar(bundle.getBundleJar(), providerClass);