List of usage examples for org.apache.hadoop.conf Configuration getClassByName
public Class<?> getClassByName(String name) throws ClassNotFoundException
From source file:org.apache.parquet.hadoop.util.ConfigurationUtil.java
License:Apache License
public static Class<?> getClassFromConfig(Configuration configuration, String configName, Class<?> assignableFrom) { final String className = configuration.get(configName); if (className == null) { return null; }//from w w w . j a va 2s .c o m try { final Class<?> foundClass = configuration.getClassByName(className); if (!assignableFrom.isAssignableFrom(foundClass)) { throw new BadConfigurationException("class " + className + " set in job conf at " + configName + " is not a subclass of " + assignableFrom.getCanonicalName()); } return foundClass; } catch (ClassNotFoundException e) { throw new BadConfigurationException( "could not instantiate class " + className + " set in job conf at " + configName, e); } }
From source file:org.apache.parquet.thrift.pig.TupleToThriftWriteSupport.java
License:Apache License
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override// w w w . ja va 2s . co m public WriteContext init(Configuration configuration) { try { Class<?> clazz = configuration.getClassByName(className).asSubclass(TBase.class); thriftWriteSupport = new ThriftWriteSupport(clazz); pigToThrift = new PigToThrift(clazz); return thriftWriteSupport.init(configuration); } catch (ClassNotFoundException e) { throw new BadConfigurationException("The thrift class name was not found: " + className, e); } catch (ClassCastException e) { throw new BadConfigurationException("The thrift class name should extend TBase: " + className, e); } }
From source file:org.apache.sentry.api.service.thrift.SentryPolicyStoreProcessor.java
License:Apache License
SentryPolicyStoreProcessor(String name, Configuration conf, SentryStoreInterface store) throws Exception { super();// w ww .j av a2s . com this.name = name; this.conf = conf; this.sentryStore = store; this.notificationHandlerInvoker = new NotificationHandlerInvoker(conf, createHandlers(conf)); this.audit = new SentryAuditLogger(conf); adminGroups = ImmutableSet.copyOf( toTrimedLower(Sets.newHashSet(conf.getStrings(ServerConfig.ADMIN_GROUPS, new String[] {})))); Iterable<String> pluginClasses = ConfUtilties.CLASS_SPLITTER.split( conf.get(ServerConfig.SENTRY_POLICY_STORE_PLUGINS, ServerConfig.SENTRY_POLICY_STORE_PLUGINS_DEFAULT) .trim()); for (String pluginClassStr : pluginClasses) { Class<?> clazz = conf.getClassByName(pluginClassStr); if (!SentryPolicyStorePlugin.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("Sentry Plugin [" + pluginClassStr + "] is not a " + SentryPolicyStorePlugin.class.getName()); } SentryPolicyStorePlugin plugin = (SentryPolicyStorePlugin) clazz.newInstance(); plugin.initialize(conf, sentryStore); sentryPlugins.add(plugin); } initMetrics(); }
From source file:org.apache.sentry.binding.metastore.SentryMetastorePostEventListener.java
License:Apache License
public SentryMetastorePostEventListener(Configuration config) { super(config); sentryClientFactory = new SentryServiceClientFactory(); authzConf = HiveAuthzConf.getAuthzConf((HiveConf) config); server = new Server(authzConf.get(AuthzConfVars.AUTHZ_SERVER_NAME.getVar())); Iterable<String> pluginClasses = ConfUtilties.CLASS_SPLITTER.split(config .get(ServerConfig.SENTRY_METASTORE_PLUGINS, ServerConfig.SENTRY_METASTORE_PLUGINS_DEFAULT).trim()); try {/*from www . j a va 2s .c o m*/ for (String pluginClassStr : pluginClasses) { Class<?> clazz = config.getClassByName(pluginClassStr); if (!SentryMetastoreListenerPlugin.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("Class [" + pluginClassStr + "] is not a " + SentryMetastoreListenerPlugin.class.getName()); } SentryMetastoreListenerPlugin plugin = (SentryMetastoreListenerPlugin) clazz .getConstructor(Configuration.class).newInstance(config); sentryPlugins.add(plugin); } } catch (Exception e) { LOGGER.error("Could not initialize Plugin !!", e); throw new RuntimeException(e); } }
From source file:org.apache.sentry.binding.metastore.SentryMetastorePostEventListenerBase.java
License:Apache License
public SentryMetastorePostEventListenerBase(Configuration config) { super(config); if (!(config instanceof HiveConf)) { String error = "Could not initialize Plugin - Configuration is not an instanceof HiveConf"; LOGGER.error(error);//from ww w.j a v a2 s . c o m throw new RuntimeException(error); } authzConf = HiveAuthzConf.getAuthzConf((HiveConf) config); server = new Server(authzConf.get(AuthzConfVars.AUTHZ_SERVER_NAME.getVar())); Iterable<String> pluginClasses = ConfUtilties.CLASS_SPLITTER.split(config .get(ServerConfig.SENTRY_METASTORE_PLUGINS, ServerConfig.SENTRY_METASTORE_PLUGINS_DEFAULT).trim()); try { for (String pluginClassStr : pluginClasses) { Class<?> clazz = config.getClassByName(pluginClassStr); if (!SentryMetastoreListenerPlugin.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("Class [" + pluginClassStr + "] is not a " + SentryMetastoreListenerPlugin.class.getName()); } SentryMetastoreListenerPlugin plugin = (SentryMetastoreListenerPlugin) clazz .getConstructor(Configuration.class, Configuration.class).newInstance(config, authzConf); sentryPlugins.add(plugin); } } catch (Exception e) { LOGGER.error("Could not initialize Plugin !!", e); throw new RuntimeException(e); } }
From source file:org.apache.sentry.binding.metastore.SentryMetastorePostEventListenerBaseV2.java
License:Apache License
public SentryMetastorePostEventListenerBaseV2(Configuration config) { super(config); if (!(config instanceof HiveConf)) { String error = "Could not initialize Plugin - Configuration is not an instanceof HiveConf"; LOGGER.error(error);/*from www . ja va2s.c o m*/ throw new RuntimeException(error); } authzConf = HiveAuthzConf.getAuthzConf((HiveConf) config); server = new Server(authzConf.get(AuthzConfVars.AUTHZ_SERVER_NAME.getVar())); Iterable<String> pluginClasses = ConfUtilties.CLASS_SPLITTER.split(config .get(ServerConfig.SENTRY_METASTORE_PLUGINS, ServerConfig.SENTRY_METASTORE_PLUGINS_DEFAULT).trim()); try { for (String pluginClassStr : pluginClasses) { Class<?> clazz = config.getClassByName(pluginClassStr); if (!SentryMetastoreListenerPlugin.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("Class [" + pluginClassStr + "] is not a " + SentryMetastoreListenerPlugin.class.getName()); } SentryMetastoreListenerPlugin plugin = (SentryMetastoreListenerPlugin) clazz .getConstructor(Configuration.class, Configuration.class).newInstance(config, authzConf); sentryPlugins.add(plugin); } } catch (Exception e) { LOGGER.error("Could not initialize Plugin !!", e); throw new RuntimeException(e); } }
From source file:org.apache.sentry.provider.db.service.thrift.SentryPolicyStoreProcessor.java
License:Apache License
SentryPolicyStoreProcessor(String name, Configuration conf, SentryStore store) throws Exception { super();//from w ww .j av a2 s .co m this.name = name; this.conf = conf; this.sentryStore = store; this.notificationHandlerInvoker = new NotificationHandlerInvoker(conf, createHandlers(conf)); adminGroups = ImmutableSet.copyOf( toTrimedLower(Sets.newHashSet(conf.getStrings(ServerConfig.ADMIN_GROUPS, new String[] {})))); Iterable<String> pluginClasses = ConfUtilties.CLASS_SPLITTER.split( conf.get(ServerConfig.SENTRY_POLICY_STORE_PLUGINS, ServerConfig.SENTRY_POLICY_STORE_PLUGINS_DEFAULT) .trim()); for (String pluginClassStr : pluginClasses) { Class<?> clazz = conf.getClassByName(pluginClassStr); if (!SentryPolicyStorePlugin.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("Sentry Plugin [" + pluginClassStr + "] is not a " + SentryPolicyStorePlugin.class.getName()); } SentryPolicyStorePlugin plugin = (SentryPolicyStorePlugin) clazz.newInstance(); plugin.initialize(conf, sentryStore); sentryPlugins.add(plugin); } initMetrics(); }
From source file:org.apache.sentry.service.thrift.SentryService.java
License:Apache License
private SentryStoreInterface getSentryStore(Configuration conf) { String sentryStoreClass = conf.get(ServerConfig.SENTRY_STORE, ServerConfig.SENTRY_STORE_DEFAULT); try {/*from w w w .ja va 2 s. c om*/ Class<?> sentryClazz = conf.getClassByName(sentryStoreClass); Constructor<?> sentryConstructor = sentryClazz.getConstructor(Configuration.class); Object sentryObj = sentryConstructor.newInstance(conf); if (sentryObj instanceof SentryStoreInterface) { LOGGER.info("Instantiating sentry store class: " + sentryStoreClass); return (SentryStoreInterface) sentryConstructor.newInstance(conf); } // The supplied class doesn't implement SentryStoreIface. Let's try to use a proxy // instance. // In practice, the following should only be used in development phase, as there are // cases where using a proxy can fail, and result in runtime errors. LOGGER.warn(String.format("Trying to use a proxy instance (duck-typing) for the " + "supplied SentryStore, since the specified class %s does not implement " + "SentryStoreIface.", sentryStoreClass)); return new DynamicProxy<>(sentryObj, SentryStoreInterface.class, sentryStoreClass).createProxy(); } catch (Exception e) { throw new IllegalStateException("Could not create " + sentryStoreClass, e); } }
From source file:org.apache.sqoop.ConnFactory.java
License:Apache License
/** * Create the ManagerFactory instances that should populate * the factories list./*from w ww. j a v a 2s.c o m*/ */ private void instantiateFactories(Configuration conf) { loadManagersFromConfDir(conf); String[] classNameArray = conf.getStrings(FACTORY_CLASS_NAMES_KEY, DEFAULT_FACTORY_CLASS_NAMES); for (String className : classNameArray) { try { className = className.trim(); // Ignore leading/trailing whitespace. ManagerFactory factory = ReflectionUtils .newInstance((Class<? extends ManagerFactory>) conf.getClassByName(className), conf); LOG.debug("Loaded manager factory: " + className); factories.add(factory); } catch (ClassNotFoundException cnfe) { LOG.error("Could not load ManagerFactory " + className + " (not found)"); } } }
From source file:org.apache.sqoop.io.CodecMap.java
License:Apache License
/** * Given a codec name, instantiate the concrete implementation * class that implements it./*from w ww. j a va 2 s .c o m*/ * @throws com.cloudera.sqoop.io.UnsupportedCodecException if a codec cannot * be found with the supplied name. */ public static CompressionCodec getCodec(String codecName, Configuration conf) throws com.cloudera.sqoop.io.UnsupportedCodecException { // Try standard Hadoop mechanism first CompressionCodec codec = getCodecByName(codecName, conf); if (codec != null) { return codec; } // Fall back to Sqoop mechanism String codecClassName = null; try { codecClassName = getCodecClassName(codecName); if (null == codecClassName) { return null; } Class<? extends CompressionCodec> codecClass = (Class<? extends CompressionCodec>) conf .getClassByName(codecClassName); return (CompressionCodec) ReflectionUtils.newInstance(codecClass, conf); } catch (ClassNotFoundException cnfe) { throw new com.cloudera.sqoop.io.UnsupportedCodecException( "Cannot find codec class " + codecClassName + " for codec " + codecName); } }