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();
}
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);
}
}
}
}
}
Aggregations