private static PreparableReporter getPreparableReporter(String clazz) { PreparableReporter reporter = null; LOG.info("Using statistics reporter plugin:" + clazz); if (clazz != null) { reporter = (PreparableReporter) ReflectionUtils.newInstance(clazz); } return reporter; }
public static <T> T newInstance(Class<T> klass) { return _instance.newInstanceImpl(klass); }
public ReflectionUtilsInstaller(ReflectionUtils instance) { _oldInstance = ReflectionUtils.setInstance(instance); _curInstance = instance; }
when(confBlob.fetchUnzipToTemp(any())).thenReturn(300L); ReflectionUtils origRU = ReflectionUtils.setInstance(mockedRU); ServerUtils origUtils = ServerUtils.setInstance(mockedU); try { when(mockedRU.newInstanceImpl(ClientBlobStore.class)).thenReturn(blobStore); } finally { bl.close(); ReflectionUtils.setInstance(origRU); ServerUtils.setInstance(origUtils);
@Test public void testSchedulerStrategyWhitelist() { Map<String, Object> config = ConfigUtils.readStormConfig(); String allowed = DefaultResourceAwareStrategy.class.getName(); config.put(Config.NIMBUS_SCHEDULER_STRATEGY_CLASS_WHITELIST, Arrays.asList(allowed)); Object sched = ReflectionUtils.newSchedulerStrategyInstance(allowed, config); assertEquals(sched.getClass().getName(), allowed); }
@Test public void testSchedulerStrategyEmptyWhitelist() { Map<String, Object> config = ConfigUtils.readStormConfig(); String allowed = DefaultResourceAwareStrategy.class.getName(); Object sched = ReflectionUtils.newSchedulerStrategyInstance(allowed, config); assertEquals(sched.getClass().getName(), allowed); }
@SuppressWarnings("unchecked") public static <T> T newInstance(String klass) { try { return newInstance((Class<T>) Class.forName(klass)); } catch (Exception e) { throw new RuntimeException(e); } }
@Test public void testSchedulerStrategyWhitelistException() { Map<String, Object> config = ConfigUtils.readStormConfig(); String allowed = "org.apache.storm.scheduler.resource.strategies.scheduling.SomeNonExistantStrategy"; String notAllowed = DefaultResourceAwareStrategy.class.getName(); config.put(Config.NIMBUS_SCHEDULER_STRATEGY_CLASS_WHITELIST, Arrays.asList(allowed)); Assertions.assertThrows(DisallowedStrategyException.class, () -> ReflectionUtils.newSchedulerStrategyInstance(notAllowed, config)); }
@Override public void close() throws Exception { if (ReflectionUtils.setInstance(_oldInstance) != _curInstance) { throw new IllegalStateException( "Instances of this resource must be closed in reverse order of opening."); } } }
@SuppressWarnings("unchecked") public static <T> T newInstance(String klass, Map<String, Object> conf) { try { return newInstance((Class<T>) Class.forName(klass), conf); } catch (Exception e) { throw new RuntimeException(e); } }
LOG.debug("Replace backtype.storm with org.apache.storm for Config.TOPOLOGY_SCHEDULER_STRATEGY"); rasStrategy = ReflectionUtils.newSchedulerStrategyInstance(strategy, conf); rasStrategy.prepare(conf); } catch (DisallowedStrategyException e) {
/** * Return a new instance of a pluggable specified in the conf. * * @param conf The conf to read from. * @param configKey The key pointing to the pluggable class * @return an instance of the class or null if it is not specified. */ public static Object getConfiguredClass(Map<String, Object> conf, Object configKey) { if (conf.containsKey(configKey)) { return ReflectionUtils.newInstance((String) conf.get(configKey)); } return null; }
static IWaitStrategy createBackPressureWaitStrategy(Map<String, Object> topologyConf) { IWaitStrategy producerWaitStrategy = ReflectionUtils.newInstance((String) topologyConf.get(Config.TOPOLOGY_BACKPRESSURE_WAIT_STRATEGY)); producerWaitStrategy.prepare(topologyConf, WAIT_SITUATION.BACK_PRESSURE_WAIT); return producerWaitStrategy; }
public static <T> T newSchedulerStrategyInstance(String klass, Map<String, Object> conf) { List<String> allowedSchedulerStrategies = (List<String>) conf.get(Config.NIMBUS_SCHEDULER_STRATEGY_CLASS_WHITELIST); if (allowedSchedulerStrategies == null || allowedSchedulerStrategies.contains(klass)) { return newInstance(klass); } else { throw new DisallowedStrategyException(klass, allowedSchedulerStrategies); } }
public static ClientBlobStore getClientBlobStore(Map<String, Object> conf) { ClientBlobStore store = (ClientBlobStore) ReflectionUtils.newInstance((String) conf.get(Config.CLIENT_BLOBSTORE)); store.prepare(conf); return store; }
public static StormMetricsFilter getMetricsFilter(Map reporterConf) { StormMetricsFilter filter = null; Map<String, Object> filterConf = (Map) reporterConf.get("filter"); if (filterConf != null) { String clazz = (String) filterConf.get("class"); if (clazz != null) { filter = ReflectionUtils.newInstance(clazz); filter.prepare(filterConf); } } return filter; }
private void registerMetrics(TopologyContext context, Map<String, String> metrics, int bucketSize, Map<String, Object> conf) { if (metrics == null) { return; } for (Map.Entry<String, String> metric : metrics.entrySet()) { try { context.registerMetric(metric.getKey(), (IMetric) ReflectionUtils.newInstance(metric.getValue(), conf), bucketSize); } catch (Exception e) { throw new RuntimeException(e); } } }
private Object initializeInstance(String className, String representation) { try { return ReflectionUtils.newInstance(className); } catch (RuntimeException e) { Throwable cause = e.getCause(); if (cause instanceof ClassNotFoundException) { LOG.error("Can't find {} for name {}", representation, className); } else if (cause instanceof InstantiationException) { LOG.error("Throw InstantiationException {} for name {}", representation, className); } else if (cause instanceof IllegalAccessException) { LOG.error("Throw IllegalAccessException {} for name {}", representation, className); } else { LOG.error("Throw unexpected exception {} {} for name {}", cause, representation, className); } throw e; } } }
public static IHttpCredentialsPlugin getHttpCredentialsPlugin(Map<String, Object> conf, String klassName) { try { IHttpCredentialsPlugin plugin = null; if (StringUtils.isNotBlank(klassName)) { plugin = ReflectionUtils.newInstance(klassName); plugin.prepare(conf); } return plugin; } catch (Exception e) { throw new RuntimeException(e); } }
private static ITopologyActionNotifierPlugin createTopologyActionNotifier(Map<String, Object> conf) { String clazz = (String) conf.get(DaemonConfig.NIMBUS_TOPOLOGY_ACTION_NOTIFIER_PLUGIN); ITopologyActionNotifierPlugin ret = null; if (clazz != null && !clazz.isEmpty()) { ret = ReflectionUtils.newInstance(clazz); try { ret.prepare(conf); } catch (Exception e) { LOG.warn("Ignoring exception, Could not initialize {}", clazz, e); ret = null; } } return ret; }