Search in sources :

Example 6 with TemporaryClassLoaderContext

use of com.alibaba.alink.common.io.plugin.TemporaryClassLoaderContext in project Alink by alibaba.

the class HiveClassLoaderFactory method installSecurity.

private void installSecurity(ClassLoader classLoader) {
    if (installed == null || !installed) {
        try (TemporaryClassLoaderContext context = TemporaryClassLoaderContext.of(classLoader)) {
            if (System.getProperties().containsKey("java.security.krb5.conf") && Files.exists(Paths.get(System.getProperty("java.security.krb5.conf")))) {
                Configuration configuration = GlobalConfiguration.loadConfiguration();
                if (!(configuration.containsKey(ConfigConstants.PATH_HADOOP_CONFIG))) {
                    LOG.warn("Could not find hadoop configure, but the krb file has been set.");
                    installed = true;
                    return;
                }
                try {
                    Class<?> initializer = Class.forName("com.alibaba.alink.common.io.catalog.hive.plugin.initializer.HivePluginInitializer", true, classLoader);
                    Method method = initializer.getMethod("initialize", String.class);
                    method.invoke(null, configuration.getString(ConfigConstants.PATH_HADOOP_CONFIG, null));
                } catch (ClassNotFoundException e) {
                    LOG.warn("Could not find HivePluginInitializer.", e);
                } catch (NoSuchMethodException e) {
                    LOG.warn("Could not find the initialize method.", e);
                } catch (IllegalAccessException | InvocationTargetException e) {
                    LOG.warn("Invoke the initialize error.", e);
                }
            }
        }
        installed = true;
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) GlobalConfiguration(org.apache.flink.configuration.GlobalConfiguration) TemporaryClassLoaderContext(com.alibaba.alink.common.io.plugin.TemporaryClassLoaderContext) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

TemporaryClassLoaderContext (com.alibaba.alink.common.io.plugin.TemporaryClassLoaderContext)6 Path (org.apache.flink.core.fs.Path)5 IOException (java.io.IOException)4 Configuration (org.apache.flink.configuration.Configuration)4 FileSystemFactory (org.apache.flink.core.fs.FileSystemFactory)3 BaseFileSystem (com.alibaba.alink.common.io.filesystem.BaseFileSystem)1 FilePath (com.alibaba.alink.common.io.filesystem.FilePath)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 GlobalConfiguration (org.apache.flink.configuration.GlobalConfiguration)1 FileSystem (org.apache.flink.core.fs.FileSystem)1