use of org.talend.hadoop.distribution.dynamic.bean.ModuleBean in project tbd-studio-se by Talend.
the class DynamicLibraryNeededExtensionAdaper method adapt.
public IDynamicExtension adapt(IDynamicMonitor monitor) throws Exception {
DynamicDistributionUtils.checkCancelOrNot(monitor);
resolve();
TemplateBean templateBean = getTemplateBean();
DynamicConfiguration configuration = getConfiguration();
String templateId = templateBean.getId();
String distributionName = configuration.getDistribution();
String id = configuration.getId();
IDynamicExtension libNeededExtension = DynamicFactory.getInstance().createDynamicExtension();
libNeededExtension.setExtensionId(DynamicDistributionUtils.getExtensionId(DynamicDistributionUtils.getPluginKey(distributionName, templateId, id, ATTR_POINT)));
libNeededExtension.setExtensionPoint(ATTR_POINT);
List<ModuleBean> modules = templateBean.getModules();
if (modules != null) {
try {
Exception[] ex = new Exception[1];
Set<String> registedModules = Collections.synchronizedSet(new LinkedHashSet<>());
for (ModuleBean moduleBean : modules) {
DynamicDistributionUtils.checkCancelOrNot(monitor);
Runnable runnable = new Runnable() {
int count = 0;
@Override
public void run() {
try {
DynamicModuleAdapter dynamicModuleAdapter = new DynamicModuleAdapter(templateBean, configuration, moduleBean, dependencyResolver, registedModules);
List<IDynamicConfiguration> librariesNeeded = dynamicModuleAdapter.adapt(monitor, isEnableMultiThread());
if (librariesNeeded != null && !librariesNeeded.isEmpty()) {
addDynamicConfigurations(libNeededExtension, librariesNeeded);
}
String beanId = moduleBean.getId();
moduleBeanAdapterMap.put(beanId, dynamicModuleAdapter);
} catch (Exception e) {
Throwable rootCause = ExceptionUtils.getRootCause(e);
if (e instanceof FileNotFoundException || rootCause instanceof FileNotFoundException) {
if (count < 5) {
count++;
run();
} else {
ex[0] = e;
}
} else {
ex[0] = e;
}
}
}
};
if (isEnableMultiThread()) {
getThreadPool().execute(runnable);
continue;
} else {
runnable.run();
if (ex[0] != null) {
throw ex[0];
}
}
}
if (isEnableMultiThread()) {
int totalTasks = modules.size();
if (monitor != null) {
monitor.beginTask(// $NON-NLS-1$
Messages.getString("DynamicLibraryNeededExtensionAdaper.monitor.waitAllFinish", totalTasks), totalTasks);
}
int completed = 0;
while (true) {
int activeCount = getThreadPool().getActiveCount();
if (activeCount <= 0) {
break;
}
if (monitor != null) {
int newCompleted = (int) getThreadPool().getCompletedTaskCount();
int newWorked = newCompleted - completed;
completed = newCompleted;
monitor.setTaskName(// $NON-NLS-1$
Messages.getString(// $NON-NLS-1$
"DynamicLibraryNeededExtensionAdaper.monitor.waitAllFinish", activeCount));
monitor.worked(newWorked);
}
Thread.sleep(200);
DynamicDistributionUtils.checkCancelOrNot(monitor);
if (ex[0] != null) {
throw ex[0];
}
}
}
} finally {
if (isEnableMultiThread()) {
if (monitor != null) {
// $NON-NLS-1$
monitor.beginTask("", IProgressMonitor.UNKNOWN);
}
getThreadPool().clearThreads();
threadPool = null;
}
}
}
List<ModuleGroupBean> moduleGroups = templateBean.getModuleGroups();
if (moduleGroups != null) {
for (ModuleGroupBean moduleGroupBean : moduleGroups) {
DynamicDistributionUtils.checkCancelOrNot(monitor);
DynamicModuleGroupAdapter libNeededGroupAdapter = new DynamicModuleGroupAdapter(templateBean, configuration, moduleGroupBean, moduleBeanAdapterMap);
IDynamicConfiguration dynamicModuleGroup = libNeededGroupAdapter.adapt(monitor);
if (dynamicModuleGroup != null) {
libNeededExtension.addConfiguration(dynamicModuleGroup);
String groupId = moduleGroupBean.getId();
moduleGroupBeanAdapterMap.put(groupId, libNeededGroupAdapter);
}
}
}
return libNeededExtension;
}
use of org.talend.hadoop.distribution.dynamic.bean.ModuleBean in project tbd-studio-se by Talend.
the class DynamicModuleAdapterTest method testAdapt.
@Test
public void testAdapt() throws Exception {
TemplateBean templateBean = new TemplateBean();
// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
ModuleBean moduleBean = new ModuleBean(ModuleBean.TYPE_BASE, "org.apache.hive", "hive-jdbc", "2.1.0.2.6.5.5000-33");
DynamicDistributionManager dynamicDistributionManager = DynamicDistributionManager.getInstance();
DynamicConfiguration configuration = new DynamicConfiguration();
// $NON-NLS-1$
configuration.setDistribution("HORTONWORKS");
// $NON-NLS-1$
configuration.setVersion("2.6.5.5000-33");
IDependencyResolver dependencyResolver = dynamicDistributionManager.getDependencyResolver(configuration);
Set<String> registeredModules = new HashSet<String>();
DynamicModuleAdapter dynamicModuleAdapter = new DynamicModuleAdapter(templateBean, configuration, moduleBean, dependencyResolver, registeredModules);
List<IDynamicConfiguration> librariesNeeded = dynamicModuleAdapter.adapt(null, false);
librariesNeeded.stream().forEach(l -> System.out.println(l.toString()));
Assert.assertTrue(librariesNeeded.size() > 1);
}
Aggregations