Search in sources :

Example 6 with TemplateBean

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

the class DynamicClassLoaderExtensionAdaper method adapt.

public IDynamicExtension adapt(IDynamicMonitor monitor) throws Exception {
    DynamicDistributionUtils.checkCancelOrNot(monitor);
    resolve();
    TemplateBean templateBean = getTemplateBean();
    DynamicConfiguration configuration = getConfiguration();
    String id = configuration.getId();
    String distributionName = templateBean.getDistribution();
    String templateId = templateBean.getId();
    IDynamicExtension classLoaderExtension = DynamicFactory.getInstance().createDynamicExtension();
    classLoaderExtension.setExtensionId(DynamicDistributionUtils.getExtensionId(DynamicDistributionUtils.getPluginKey(distributionName, templateId, id, ATTR_POINT)));
    classLoaderExtension.setExtensionPoint(ATTR_POINT);
    List<ClassLoaderBean> classLoaders = templateBean.getClassLoaders();
    if (classLoaders != null) {
        for (ClassLoaderBean classLoader : classLoaders) {
            DynamicDistributionUtils.checkCancelOrNot(monitor);
            DynamicClassloaderAdapter classLoaderAdapter = new DynamicClassloaderAdapter(templateBean, configuration, classLoader, moduleGroupBeanAdapterMap);
            IDynamicConfiguration dynamicClassLoader = classLoaderAdapter.adapt(monitor);
            classLoaderExtension.addConfiguration(dynamicClassLoader);
        }
    }
    return classLoaderExtension;
}
Also used : IDynamicConfiguration(org.talend.core.runtime.dynamic.IDynamicConfiguration) IDynamicConfiguration(org.talend.core.runtime.dynamic.IDynamicConfiguration) DynamicConfiguration(org.talend.hadoop.distribution.dynamic.DynamicConfiguration) IDynamicExtension(org.talend.core.runtime.dynamic.IDynamicExtension) TemplateBean(org.talend.hadoop.distribution.dynamic.bean.TemplateBean) ClassLoaderBean(org.talend.hadoop.distribution.dynamic.bean.ClassLoaderBean)

Example 7 with TemplateBean

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

the class DynamicModuleAdapter method adaptExclusions.

private List<ExclusionNode> adaptExclusions(List<ExclusionBean> exclusionBeans, IDynamicMonitor monitor) throws Exception {
    List<ExclusionNode> exclusionNodes = new ArrayList<>();
    if (exclusionBeans != null && !exclusionBeans.isEmpty()) {
        TemplateBean templBean = getTemplateBean();
        DynamicConfiguration dynamicConfiguration = getConfiguration();
        for (ExclusionBean exclusionBean : exclusionBeans) {
            DynamicExclusionAdapter adapter = new DynamicExclusionAdapter(templBean, dynamicConfiguration, exclusionBean);
            adapter.adapt(monitor);
            exclusionNodes.add(adapter.getExclusionNode());
        }
    }
    return exclusionNodes;
}
Also used : IDynamicConfiguration(org.talend.core.runtime.dynamic.IDynamicConfiguration) DynamicConfiguration(org.talend.hadoop.distribution.dynamic.DynamicConfiguration) ArrayList(java.util.ArrayList) ExclusionBean(org.talend.hadoop.distribution.dynamic.bean.ExclusionBean) ExclusionNode(org.talend.designer.maven.aether.node.ExclusionNode) TemplateBean(org.talend.hadoop.distribution.dynamic.bean.TemplateBean)

Example 8 with TemplateBean

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

the class DynamicModuleAdapter method adapt.

public List<IDynamicConfiguration> adapt(IDynamicMonitor monitor, boolean multiThread) throws Exception {
    DynamicDistributionUtils.checkCancelOrNot(monitor);
    resolve();
    if (monitor != null) {
        String mvnUri = moduleBean.getMvnUri();
        if (StringUtils.isEmpty(mvnUri)) {
            mvnUri = getMvnUri();
        }
        monitor.setTaskName(// $NON-NLS-1$
        Messages.getString("DynamicModuleAdapter.monitor.buildModule", moduleBean.getId(), mvnUri));
    }
    TemplateBean templateBean = getTemplateBean();
    DynamicConfiguration configuration = getConfiguration();
    String distribution = configuration.getDistribution();
    String hadoopVersion = configuration.getVersion();
    String id = configuration.getId();
    List<ESparkVersion> selectedSparkVersions = configuration.getSelectedSparkVersions();
    List<IDynamicConfiguration> librariesNeeded = new ArrayList<>();
    List<String> sparkVersions = moduleBean.getSupportedSparkVersions();
    if (sparkVersions != null && !sparkVersions.isEmpty()) {
        boolean isSupport = false;
        for (String sparkVersion : sparkVersions) {
            try {
                ESparkVersion eSparkVersion = ESparkVersion.valueOf(sparkVersion);
                if (selectedSparkVersions.contains(eSparkVersion)) {
                    isSupport = true;
                    break;
                }
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
        }
        if (!isSupport) {
            this.isSkipped = true;
            return librariesNeeded;
        }
    }
    String type = moduleBean.getType();
    if (ModuleBean.TYPE_BASE.equalsIgnoreCase(type)) {
        String groupId = moduleBean.getGroupId();
        String artifactId = moduleBean.getArtifactId();
        String scope = moduleBean.getScope();
        String extension = moduleBean.getExtension();
        String classifier = moduleBean.getClassifier();
        String moduleVersion = moduleBean.getVersion();
        String useStudioRepository = moduleBean.getUseStudioRepository();
        if (StringUtils.isNotEmpty(useStudioRepository)) {
            ExceptionHandler.process(// $NON-NLS-1$
            new Exception("Currently useStudioRepository is only supported by STANDARD type, will be ignored"), Priority.WARN);
        }
        boolean useLatest = Boolean.valueOf(moduleBean.getUseLatest());
        if (StringUtils.isBlank(extension)) {
            extension = null;
        }
        List<ExclusionBean> exclusionBeans = moduleBean.getExclusions();
        List<ExclusionNode> exclusions = null;
        if (exclusionBeans != null && !exclusionBeans.isEmpty()) {
            exclusions = adaptExclusions(exclusionBeans, monitor);
        }
        DependencyNode dependencyNode = null;
        DependencyNode baseNode = new DependencyNode();
        baseNode.setGroupId(groupId);
        baseNode.setArtifactId(artifactId);
        baseNode.setClassifier(classifier);
        baseNode.setExtension(extension);
        baseNode.setScope(scope);
        if (useLatest) {
            moduleVersion = dependencyResolver.getLatestVersion(groupId, artifactId, null, null, monitor);
        }
        baseNode.setVersion(moduleVersion);
        if (exclusions != null && !exclusions.isEmpty()) {
            baseNode.setExclusions(exclusions);
        }
        try {
            dependencyNode = dependencyResolver.collectDependencies(baseNode, monitor, multiThread);
            librariesNeeded = createLibrariesNeeded(dependencyNode, distribution, hadoopVersion, id, moduleBean, runtimeIds, templateBean);
        } catch (VersionNotFoundException e) {
            ExceptionHandler.process(e);
        }
    } else if (ModuleBean.TYPE_REFERENCE.equalsIgnoreCase(type)) {
        List<ExclusionBean> exclusions = moduleBean.getExclusions();
        if (exclusions != null && !exclusions.isEmpty()) {
            throw new UnsupportedOperationException(// $NON-NLS-1$
            Messages.getString("DynamicModuleAdapter.exception.exclusion.unsupport", type));
        }
        String jarName = moduleBean.getJarName();
        ModuleNeeded moduleNeeded = existingModuleMap.get(jarName);
        if (moduleNeeded == null) {
            throw new UnsupportedOperationException(// $NON-NLS-1$
            Messages.getString("DynamicModuleAdapter.exception.reference.notFound", jarName));
        }
        runtimeIds.add(moduleNeeded.getId());
    } else if (ModuleBean.TYPE_STANDARD.equalsIgnoreCase(type)) {
        List<ExclusionBean> exclusions = moduleBean.getExclusions();
        if (exclusions != null && !exclusions.isEmpty()) {
            throw new UnsupportedOperationException(// $NON-NLS-1$
            Messages.getString("DynamicModuleAdapter.exception.exclusion.unsupport", type));
        }
        String beanId = moduleBean.getId();
        String runtimeId = DynamicDistributionUtils.getPluginKey(distribution, hadoopVersion, id, beanId);
        if (!registedModules.contains(runtimeId)) {
            IDynamicConfiguration libraryNeeded = createLibraryNeeded(moduleBean);
            libraryNeeded.setAttribute(ATTR_ID, runtimeId);
            librariesNeeded.add(libraryNeeded);
            List<String> registedRuntimeIds = new ArrayList<>();
            registedRuntimeIds.add(runtimeId);
            registedModules.add(runtimeId);
        }
        runtimeIds.add(runtimeId);
    }
    return librariesNeeded;
}
Also used : IDynamicConfiguration(org.talend.core.runtime.dynamic.IDynamicConfiguration) ArrayList(java.util.ArrayList) ExclusionBean(org.talend.hadoop.distribution.dynamic.bean.ExclusionBean) ExclusionNode(org.talend.designer.maven.aether.node.ExclusionNode) VersionNotFoundException(org.talend.hadoop.distribution.dynamic.VersionNotFoundException) ESparkVersion(org.talend.hadoop.distribution.ESparkVersion) IDynamicConfiguration(org.talend.core.runtime.dynamic.IDynamicConfiguration) DynamicConfiguration(org.talend.hadoop.distribution.dynamic.DynamicConfiguration) DependencyNode(org.talend.designer.maven.aether.node.DependencyNode) ArrayList(java.util.ArrayList) List(java.util.List) TemplateBean(org.talend.hadoop.distribution.dynamic.bean.TemplateBean) VersionNotFoundException(org.talend.hadoop.distribution.dynamic.VersionNotFoundException) ModuleNeeded(org.talend.core.model.general.ModuleNeeded)

Example 9 with TemplateBean

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

the class AbstractDynamicDistribution method getCompatibleTemplate.

@Override
public TemplateBean getCompatibleTemplate(IDynamicMonitor monitor, String version) throws Exception {
    if (monitor == null) {
        monitor = new DummyDynamicMonitor();
    }
    VersionStringComparator versionStringComparator = new VersionStringComparator();
    // 1. try to get compatible bean
    if (templateBeanCompatibleVersionMap == null) {
        getCompatibleVersions(monitor);
    }
    Set<Entry<TemplateBean, List<String>>> entrySet = templateBeanCompatibleVersionMap.entrySet();
    TemplateBean bestTemplateBean = null;
    // choose the biggest distance, normally means compatible with higher versions
    int distance = -1;
    for (Entry<TemplateBean, List<String>> entry : entrySet) {
        List<String> list = entry.getValue();
        Collections.sort(list, versionStringComparator);
        int size = list.size();
        int index = list.indexOf(version);
        if (0 <= index) {
            int curDistance = size - index;
            if (distance < curDistance) {
                distance = curDistance;
                bestTemplateBean = entry.getKey();
            }
        }
    }
    // 2. try to get bean from all beans
    if (bestTemplateBean == null) {
        List<String> allVersions = getAllVersions(monitor);
        Collections.sort(allVersions, versionStringComparator);
        // choose the shorted distance, normally means compatible with higher versions
        distance = -1;
        for (Entry<TemplateBean, List<String>> entry : entrySet) {
            List<String> list = entry.getValue();
            Collections.sort(list, versionStringComparator);
            String topVersion = list.get(list.size() - 1);
            String baseVersion = list.get(0);
            int curDistance = -1;
            if (versionStringComparator.compare(version, baseVersion) < 0) {
                curDistance = allVersions.indexOf(baseVersion) - allVersions.indexOf(version);
            } else {
                curDistance = allVersions.indexOf(version) - allVersions.indexOf(topVersion);
            }
            if (distance < 0 || curDistance < distance) {
                distance = curDistance;
                bestTemplateBean = entry.getKey();
            }
        }
    }
    return bestTemplateBean;
}
Also used : Entry(java.util.Map.Entry) DummyDynamicMonitor(org.talend.designer.maven.aether.DummyDynamicMonitor) VersionStringComparator(org.talend.designer.maven.aether.comparator.VersionStringComparator) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) TemplateBean(org.talend.hadoop.distribution.dynamic.bean.TemplateBean)

Example 10 with TemplateBean

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

the class AbstractDynamicDistribution method getTemplates.

@Override
public List<TemplateBean> getTemplates(IDynamicMonitor monitor) throws Exception {
    if (Boolean.valueOf(System.getProperty(PROPERTY_FORCE_REFRESH_CACHE))) {
        templateBeansCache = null;
    }
    if (templateBeansCache != null) {
        return templateBeansCache;
    }
    List<TemplateBean> templates = new ArrayList<>();
    Bundle bundle = getBundle();
    Enumeration<URL> entries = bundle.findEntries(getTemplateFolderPath(), null, true);
    if (entries != null) {
        while (entries.hasMoreElements()) {
            try {
                ObjectMapper om = new ObjectMapper();
                URL curUrl = entries.nextElement();
                if (curUrl != null) {
                    String templateFilePath = FileLocator.toFileURL(curUrl).getPath();
                    TemplateBean bean = om.readValue(new File(templateFilePath), TemplateBean.class);
                    if (ICDPDistribution.DISTRIBUTION_NAME.equals(bean.getDistribution()) && "CDP7xDistributionTemplate".equals(bean.getTemplateId())) {
                        bean.setDistribution(ICDPDistribution.DISTRIBUTION_NAME_WIZARD);
                    }
                    templates.add(bean);
                }
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
        }
    }
    templateBeansCache = templates;
    return templateBeansCache;
}
Also used : Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) TemplateBean(org.talend.hadoop.distribution.dynamic.bean.TemplateBean) File(java.io.File) URL(java.net.URL) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

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