Search in sources :

Example 1 with TemplateBean

use of org.talend.hadoop.distribution.dynamic.bean.TemplateBean in project tbd-studio-se by Talend.

the class DynamicDistribConfigAdapter method adapt.

public IDynamicPluginConfiguration adapt(IDynamicMonitor monitor) throws Exception {
    DynamicDistributionUtils.checkCancelOrNot(monitor);
    resolve();
    IDynamicPluginConfiguration pluginConfiguration = DynamicFactory.getInstance().createDynamicPluginConfiguration();
    TemplateBean templateBean = getTemplateBean();
    DynamicConfiguration configuration = getConfiguration();
    String distribution = templateBean.getDistribution();
    String templateId = templateBean.getTemplateId();
    if (!StringUtils.equals(distribution, configuration.getDistribution())) {
        throw new Exception(// $NON-NLS-1$
        Messages.getString("DynamicDistriConfigAdapter.diffDistri", distribution, configuration.getDistribution()));
    }
    String projectTechnicalName = ProjectManager.getInstance().getCurrentProject().getTechnicalLabel();
    // String id = projectTechnicalName + "_" + configuration.getId(); //$NON-NLS-1$
    String id = configuration.getId();
    pluginConfiguration.setId(id);
    pluginConfiguration.setName(configuration.getName());
    pluginConfiguration.setVersion(configuration.getVersion());
    pluginConfiguration.setDescription(configuration.getDescription());
    pluginConfiguration.setDistribution(distribution);
    pluginConfiguration.setTemplateId(templateId);
    pluginConfiguration.setRepository(configuration.getRemoteRepositoryUrl());
    pluginConfiguration.setAttribute(DynamicConstants.ATTR_PROJECT_TECHNICAL_NAME, projectTechnicalName);
    pluginConfiguration.setAttribute(DynamicConstants.ATTR_SELECTED_SPARK_VERSIONS, DynamicDistributionUtils.convert2SparkVersions(configuration.getSelectedSparkVersions()));
    return pluginConfiguration;
}
Also used : DynamicConfiguration(org.talend.hadoop.distribution.dynamic.DynamicConfiguration) TemplateBean(org.talend.hadoop.distribution.dynamic.bean.TemplateBean) IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration)

Example 2 with TemplateBean

use of org.talend.hadoop.distribution.dynamic.bean.TemplateBean in project tbd-studio-se by Talend.

the class DynamicModuleAdapter method resolve.

@Override
protected void resolve() throws Exception {
    if (isResolved()) {
        return;
    }
    TemplateBean templateBean = getTemplateBean();
    String artifactId = (String) DynamicDistributionUtils.calculate(templateBean, moduleBean.getArtifactId());
    String bundleID = (String) DynamicDistributionUtils.calculate(templateBean, moduleBean.getBundleID());
    String context = (String) DynamicDistributionUtils.calculate(templateBean, moduleBean.getContext());
    String classifier = (String) DynamicDistributionUtils.calculate(templateBean, moduleBean.getClassifier());
    String groupId = (String) DynamicDistributionUtils.calculate(templateBean, moduleBean.getGroupId());
    String language = (String) DynamicDistributionUtils.calculate(templateBean, moduleBean.getLanguage());
    String id = (String) DynamicDistributionUtils.calculate(templateBean, moduleBean.getId());
    String jarName = (String) DynamicDistributionUtils.calculate(templateBean, moduleBean.getJarName());
    String message = (String) DynamicDistributionUtils.calculate(templateBean, moduleBean.getMessage());
    String mvnUri = (String) DynamicDistributionUtils.calculate(templateBean, moduleBean.getMvnUri());
    String required = (String) DynamicDistributionUtils.calculate(templateBean, moduleBean.getRequired());
    String scope = (String) DynamicDistributionUtils.calculate(templateBean, moduleBean.getScope());
    String type = (String) DynamicDistributionUtils.calculate(templateBean, moduleBean.getType());
    String uriPath = (String) DynamicDistributionUtils.calculate(templateBean, moduleBean.getUriPath());
    String version = (String) DynamicDistributionUtils.calculate(templateBean, moduleBean.getVersion());
    String useLatest = (String) DynamicDistributionUtils.calculate(templateBean, moduleBean.getUseLatest());
    String excludeDependencies = (String) DynamicDistributionUtils.calculate(templateBean, moduleBean.getExcludeDependencies());
    String useStudioRepository = (String) DynamicDistributionUtils.calculate(templateBean, moduleBean.getUseStudioRepository());
    String extension = (String) DynamicDistributionUtils.calculate(templateBean, moduleBean.getExtension());
    moduleBean.setArtifactId(artifactId);
    moduleBean.setBundleID(bundleID);
    moduleBean.setContext(context);
    moduleBean.setClassifier(classifier);
    moduleBean.setGroupId(groupId);
    moduleBean.setLanguage(language);
    moduleBean.setId(id);
    moduleBean.setJarName(jarName);
    moduleBean.setMessage(message);
    moduleBean.setMvnUri(mvnUri);
    moduleBean.setScope(scope);
    moduleBean.setRequired(required);
    moduleBean.setType(type);
    moduleBean.setUriPath(uriPath);
    moduleBean.setVersion(version);
    moduleBean.setUseLatest(useLatest);
    moduleBean.setExcludeDependencies(excludeDependencies);
    moduleBean.setUseStudioRepository(useStudioRepository);
    moduleBean.setExtension(extension);
    setResolved(true);
}
Also used : TemplateBean(org.talend.hadoop.distribution.dynamic.bean.TemplateBean)

Example 3 with TemplateBean

use of org.talend.hadoop.distribution.dynamic.bean.TemplateBean in project tbd-studio-se by Talend.

the class DynamicClassloaderAdapter method resolve.

@Override
protected void resolve() throws Exception {
    if (isResolved()) {
        return;
    }
    TemplateBean templateBean = getTemplateBean();
    String id = (String) DynamicDistributionUtils.calculate(templateBean, classLoaderBean.getId());
    String index = (String) DynamicDistributionUtils.calculate(templateBean, classLoaderBean.getIndex());
    String moduleGroup = (String) DynamicDistributionUtils.calculate(templateBean, classLoaderBean.getModuleGroup());
    classLoaderBean.setId(id);
    classLoaderBean.setIndex(index);
    classLoaderBean.setModuleGroup(moduleGroup);
    setResolved(true);
}
Also used : TemplateBean(org.talend.hadoop.distribution.dynamic.bean.TemplateBean)

Example 4 with TemplateBean

use of org.talend.hadoop.distribution.dynamic.bean.TemplateBean 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;
}
Also used : IDynamicConfiguration(org.talend.core.runtime.dynamic.IDynamicConfiguration) ModuleGroupBean(org.talend.hadoop.distribution.dynamic.bean.ModuleGroupBean) FileNotFoundException(java.io.FileNotFoundException) FileNotFoundException(java.io.FileNotFoundException) IDynamicConfiguration(org.talend.core.runtime.dynamic.IDynamicConfiguration) DynamicConfiguration(org.talend.hadoop.distribution.dynamic.DynamicConfiguration) IDynamicExtension(org.talend.core.runtime.dynamic.IDynamicExtension) ModuleBean(org.talend.hadoop.distribution.dynamic.bean.ModuleBean) TemplateBean(org.talend.hadoop.distribution.dynamic.bean.TemplateBean)

Example 5 with TemplateBean

use of org.talend.hadoop.distribution.dynamic.bean.TemplateBean in project tbd-studio-se by Talend.

the class DynamicModuleGroupAdapter method resolve.

@Override
protected void resolve() throws Exception {
    if (isResolved()) {
        return;
    }
    TemplateBean templateBean = getTemplateBean();
    String id = (String) DynamicDistributionUtils.calculate(templateBean, moduleGroupBean.getId());
    List<String> modules = moduleGroupBean.getModules();
    List<String> conditions = moduleGroupBean.getConditions();
    moduleGroupBean.setId(id);
    if (modules != null) {
        List<String> resolvedModules = new ArrayList<>();
        for (String module : modules) {
            String resolvedModule = (String) DynamicDistributionUtils.calculate(templateBean, module);
            resolvedModules.add(resolvedModule);
        }
        moduleGroupBean.setModules(resolvedModules);
    }
    if (conditions != null) {
        List<String> resolvedConditions = new ArrayList<>();
        for (String condition : conditions) {
            String resolvedCondition = (String) DynamicDistributionUtils.calculate(templateBean, condition);
            resolvedConditions.add(resolvedCondition);
        }
        moduleGroupBean.setConditions(resolvedConditions);
    }
    setResolved(true);
}
Also used : ArrayList(java.util.ArrayList) TemplateBean(org.talend.hadoop.distribution.dynamic.bean.TemplateBean)

Aggregations

TemplateBean (org.talend.hadoop.distribution.dynamic.bean.TemplateBean)17 DynamicConfiguration (org.talend.hadoop.distribution.dynamic.DynamicConfiguration)7 ArrayList (java.util.ArrayList)5 IDynamicConfiguration (org.talend.core.runtime.dynamic.IDynamicConfiguration)5 IDynamicExtension (org.talend.core.runtime.dynamic.IDynamicExtension)3 IDependencyResolver (org.talend.hadoop.distribution.dynamic.resolver.IDependencyResolver)3 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 IDynamicPluginConfiguration (org.talend.core.runtime.dynamic.IDynamicPluginConfiguration)2 VersionStringComparator (org.talend.designer.maven.aether.comparator.VersionStringComparator)2 ExclusionNode (org.talend.designer.maven.aether.node.ExclusionNode)2 ESparkVersion (org.talend.hadoop.distribution.ESparkVersion)2 DynamicDistributionManager (org.talend.hadoop.distribution.dynamic.DynamicDistributionManager)2 ExclusionBean (org.talend.hadoop.distribution.dynamic.bean.ExclusionBean)2 ModuleBean (org.talend.hadoop.distribution.dynamic.bean.ModuleBean)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 URL (java.net.URL)1