Search in sources :

Example 1 with DynamicClassLoader

use of org.talend.core.classloader.DynamicClassLoader in project tdq-studio-se by Talend.

the class AliasAndManaDriverHelper method getImpalaClassLoader.

public ClassLoader getImpalaClassLoader(IMetadataConnection metadataConn) {
    IHadoopDistributionService hadoopService = getHadoopDistributionService();
    if (hadoopService != null) {
        String distribution = (String) metadataConn.getParameter(ConnParameterKeys.CONN_PARA_KEY_IMPALA_DISTRIBUTION);
        String version = (String) metadataConn.getParameter(ConnParameterKeys.CONN_PARA_KEY_IMPALA_VERSION);
        IHDistribution impalaDistribution = hadoopService.getImpalaDistributionManager().getDistribution(distribution, false);
        if (impalaDistribution != null) {
            String impalaIndex = EDatabaseTypeName.IMPALA.getProduct() + ClassLoaderFactory.KEY_SEPARATOR + impalaDistribution.getName();
            if (impalaDistribution.useCustom()) {
                String jarsStr = (String) metadataConn.getParameter(ConnParameterKeys.CONN_PARA_KEY_HADOOP_CUSTOM_JARS);
                // $NON-NLS-1$
                String index = "CustomImpala" + ClassLoaderFactory.KEY_SEPARATOR + impalaIndex + ClassLoaderFactory.KEY_SEPARATOR + metadataConn.getId();
                DynamicClassLoader classLoader = ClassLoaderFactory.getCustomClassLoader(index, jarsStr);
                if (classLoader != null) {
                    return classLoader;
                }
            } else {
                IHDistributionVersion impalaVersion = impalaDistribution.getHDVersion(version, false);
                if (impalaVersion != null) {
                    boolean isKeb = Boolean.valueOf((String) metadataConn.getParameter(ConnParameterKeys.CONN_PARA_KEY_USE_KRB));
                    DynamicClassLoader classLoader = ClassLoaderFactory.getClassLoader(impalaIndex + ClassLoaderFactory.KEY_SEPARATOR + impalaVersion.getVersion() + // $NON-NLS-1$//$NON-NLS-2$
                    (isKeb ? "?USE_KRB" : ""));
                    // if not work for extension point, try modules from hadoop distribution
                    if (classLoader == null) {
                        classLoader = ClassLoaderFactory.getClassLoader(impalaVersion);
                    }
                    if (classLoader != null) {
                        return classLoader;
                    }
                }
            }
        }
    }
    return this.getClass().getClassLoader();
}
Also used : DynamicClassLoader(org.talend.core.classloader.DynamicClassLoader) IHadoopDistributionService(org.talend.core.hadoop.IHadoopDistributionService) IHDistributionVersion(org.talend.core.runtime.hd.IHDistributionVersion) IHDistribution(org.talend.core.runtime.hd.IHDistribution)

Example 2 with DynamicClassLoader

use of org.talend.core.classloader.DynamicClassLoader in project tdq-studio-se by Talend.

the class SqlexplorerService method loadManagedDriverForHive.

/**
 * TDDQ-8113 load hive drive by DynamicClassLoader,then set the attribute for Hive ManagedDriver.
 *
 * @param connection
 */
private void loadManagedDriverForHive(DatabaseConnection connection) {
    DriverManager driverManager = SQLExplorerPlugin.getDefault().getDriverModel();
    String id = AliasAndManaDriverHelper.getInstance().joinManagedDriverId(connection);
    ManagedDriver manDr = driverManager.getDriver(id);
    IMetadataConnection metadataConnection = ConvertionHelper.convert(connection);
    ClassLoader classLoader = null;
    if (EDatabaseTypeName.IMPALA.getXmlName().equalsIgnoreCase(connection.getDatabaseType())) {
        classLoader = AliasAndManaDriverHelper.getInstance().getImpalaClassLoader(metadataConnection);
    } else {
        classLoader = HiveClassLoaderFactory.getInstance().getClassLoader(metadataConnection);
    }
    if (classLoader != null && classLoader instanceof DynamicClassLoader) {
        DynamicClassLoader dynClassLoader = (DynamicClassLoader) classLoader;
        String libStorePath = dynClassLoader.getLibStorePath();
        File libFolder = new File(libStorePath);
        if (libFolder.exists()) {
            List<String> relaPathLs = new ArrayList<String>();
            relaPathLs.addAll(dynClassLoader.getLibraries());
            Set<String> findAllJarPath = findAllJarPath(libFolder, relaPathLs);
            if (!findAllJarPath.isEmpty()) {
                manDr.getJars().addAll(findAllJarPath);
                try {
                    manDr.registerHiveSQLDriver(connection);
                } catch (ClassNotFoundException e) {
                    log.error(e);
                } catch (InstantiationException e) {
                    log.error(e);
                } catch (IllegalAccessException e) {
                    log.error(e);
                }
            }
        }
    }
}
Also used : DynamicClassLoader(org.talend.core.classloader.DynamicClassLoader) ManagedDriver(net.sourceforge.sqlexplorer.dbproduct.ManagedDriver) ArrayList(java.util.ArrayList) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) DynamicClassLoader(org.talend.core.classloader.DynamicClassLoader) URLClassLoader(java.net.URLClassLoader) MyURLClassLoader(net.sourceforge.sqlexplorer.util.MyURLClassLoader) DriverManager(net.sourceforge.sqlexplorer.dbproduct.DriverManager) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Aggregations

DynamicClassLoader (org.talend.core.classloader.DynamicClassLoader)2 File (java.io.File)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 DriverManager (net.sourceforge.sqlexplorer.dbproduct.DriverManager)1 ManagedDriver (net.sourceforge.sqlexplorer.dbproduct.ManagedDriver)1 MyURLClassLoader (net.sourceforge.sqlexplorer.util.MyURLClassLoader)1 IFile (org.eclipse.core.resources.IFile)1 IHadoopDistributionService (org.talend.core.hadoop.IHadoopDistributionService)1 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)1 IHDistribution (org.talend.core.runtime.hd.IHDistribution)1 IHDistributionVersion (org.talend.core.runtime.hd.IHDistributionVersion)1