Search in sources :

Example 11 with IDynamicConfiguration

use of org.talend.core.runtime.dynamic.IDynamicConfiguration in project tbd-studio-se by Talend.

the class DynamicModuleAdapter method createLibraryNeeded.

public static IDynamicConfiguration createLibraryNeeded(ModuleBean bean) {
    IDynamicConfiguration libraryNeeded = null;
    libraryNeeded = DynamicFactory.getInstance().createDynamicConfiguration();
    libraryNeeded.setConfigurationName(TAG_NAME);
    if (bean != null) {
        String bundleID = bean.getBundleID();
        String context = bean.getContext();
        String id = bean.getId();
        String jarName = bean.getJarName();
        String language = bean.getLanguage();
        String message = bean.getMessage();
        String mvnUri = bean.getMvnUri();
        String required = bean.getRequired();
        String uriPath = bean.getUriPath();
        String excludeDependencies = bean.getExcludeDependencies();
        String useStudioRepository = bean.getUseStudioRepository();
        if (StringUtils.isBlank(mvnUri) && StringUtils.isNotBlank(bean.getGroupId()) && StringUtils.isNotBlank(bean.getArtifactId()) && StringUtils.isNotBlank(bean.getVersion())) {
            String extension = null;
            if (StringUtils.isNotBlank(bean.getExtension())) {
                extension = bean.getExtension();
            }
            String classifier = null;
            if (StringUtils.isNotBlank(bean.getClassifier())) {
                classifier = bean.getClassifier();
            }
            mvnUri = MavenUrlHelper.generateMvnUrl(bean.getGroupId(), bean.getArtifactId(), bean.getVersion(), extension, classifier);
        }
        if (StringUtils.isBlank(mvnUri)) {
            throw new RuntimeException(Messages.getString("DynamicModuleAdapter.exception.wrongConfig", bean.getId()));
        }
        if (StringUtils.isBlank(jarName)) {
            jarName = MavenUrlHelper.parseMvnUrl(mvnUri).getFileName(false);
        }
        libraryNeeded.setAttribute(ATTR_BUNDLE_ID, bundleID);
        libraryNeeded.setAttribute(ATTR_CONTEXT, context);
        libraryNeeded.setAttribute(ATTR_ID, id);
        libraryNeeded.setAttribute(ATTR_NAME, jarName);
        libraryNeeded.setAttribute(ATTR_LANGUAGE, language);
        libraryNeeded.setAttribute(ATTR_MESSAGE, message);
        libraryNeeded.setAttribute(ATTR_MVN_URI, mvnUri);
        libraryNeeded.setAttribute(ATTR_REQUIRED, required);
        libraryNeeded.setAttribute(ATTR_URI_PATH, uriPath);
        if (StringUtils.isNotEmpty(excludeDependencies)) {
            libraryNeeded.setAttribute(ATTR_EXCLUDE_DEPENDENCIES, excludeDependencies);
        } else {
            libraryNeeded.setAttribute(ATTR_EXCLUDE_DEPENDENCIES, Boolean.TRUE.toString());
        }
        if (StringUtils.isNotEmpty(useStudioRepository)) {
            libraryNeeded.setAttribute(ATTR_TEMP_USE_STUDIO_REPOSITORY, useStudioRepository);
        } else {
            libraryNeeded.removeAttribute(ATTR_TEMP_USE_STUDIO_REPOSITORY);
        }
    }
    return libraryNeeded;
}
Also used : IDynamicConfiguration(org.talend.core.runtime.dynamic.IDynamicConfiguration)

Example 12 with IDynamicConfiguration

use of org.talend.core.runtime.dynamic.IDynamicConfiguration 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 13 with IDynamicConfiguration

use of org.talend.core.runtime.dynamic.IDynamicConfiguration in project tbd-studio-se by Talend.

the class DynamicModuleAdapter method createLibrariesNeeded.

private List<IDynamicConfiguration> createLibrariesNeeded(DependencyNode node, String distribution, String version, String id, ModuleBean bean, List<String> runtimeIds, TemplateBean templateBean) {
    List<IDynamicConfiguration> librariesNeeded = new ArrayList<>();
    if (node == null) {
        return librariesNeeded;
    }
    List<String> registedRuntimeIds = new ArrayList<>();
    String registedModulesKey = getRegistedModulesKey(node);
    String jarName = node.getJarName();
    String runtimeId = DynamicDistributionUtils.getPluginKey(distribution, version, id, jarName);
    if (!registedModules.contains(registedModulesKey)) {
        ModuleNeeded moduleNeeded = null;
        if (reuseExistingJars()) {
            moduleNeeded = existingModuleMap.get(jarName);
        }
        if (moduleNeeded != null) {
            runtimeId = moduleNeeded.getId();
        } else {
            IDynamicConfiguration libraryNeeded = createLibraryNeeded(node, templateBean);
            libraryNeeded.setAttribute(ATTR_CONTEXT, bean.getContext());
            libraryNeeded.setAttribute(ATTR_ID, runtimeId);
            String useStudioRepository = bean.getUseStudioRepository();
            if (StringUtils.isNotEmpty(useStudioRepository)) {
                libraryNeeded.setAttribute(ATTR_TEMP_USE_STUDIO_REPOSITORY, useStudioRepository);
            } else {
                libraryNeeded.removeAttribute(ATTR_TEMP_USE_STUDIO_REPOSITORY);
            }
            librariesNeeded.add(libraryNeeded);
        }
        registedModules.add(registedModulesKey);
    }
    registedRuntimeIds.add(runtimeId);
    List<DependencyNode> dependencies = node.getDependencies();
    if (dependencies != null) {
        for (DependencyNode dependency : dependencies) {
            List<IDynamicConfiguration> childLibrariesNeeded = createLibrariesNeeded(dependency, distribution, version, id, bean, registedRuntimeIds, templateBean);
            librariesNeeded.addAll(childLibrariesNeeded);
        }
    }
    runtimeIds.addAll(registedRuntimeIds);
    return librariesNeeded;
}
Also used : IDynamicConfiguration(org.talend.core.runtime.dynamic.IDynamicConfiguration) DependencyNode(org.talend.designer.maven.aether.node.DependencyNode) ArrayList(java.util.ArrayList) ModuleNeeded(org.talend.core.model.general.ModuleNeeded)

Example 14 with IDynamicConfiguration

use of org.talend.core.runtime.dynamic.IDynamicConfiguration in project tbd-studio-se by Talend.

the class DynamicPluginAdapter method adapt.

/**
 * Build related informations, and remove attributes not needed
 *
 * @throws Exception
 */
public void adapt() throws Exception {
    List<IDynamicExtension> allExtensions = plugin.getAllExtensions();
    IDynamicExtension libNeededExtension = null;
    IDynamicExtension classLoaderExtension = null;
    for (IDynamicExtension extension : allExtensions) {
        if (DynamicLibraryNeededExtensionAdaper.ATTR_POINT.equals(extension.getExtensionPoint())) {
            libNeededExtension = extension;
        } else if (DynamicClassLoaderExtensionAdaper.ATTR_POINT.equals(extension.getExtensionPoint())) {
            classLoaderExtension = extension;
        }
    }
    if (libNeededExtension == null) {
        throw new Exception("Can't find extension: " + DynamicLibraryNeededExtensionAdaper.ATTR_POINT);
    }
    if (classLoaderExtension == null) {
        throw new Exception("Can't find extension: " + DynamicClassLoaderExtensionAdaper.ATTR_POINT);
    }
    List<IDynamicConfiguration> configurations = libNeededExtension.getConfigurations();
    if (configurations == null || configurations.isEmpty()) {
        throw new Exception("No libraryModuelGroup configured");
    }
    String repository = preference.getRepository();
    if (StringUtils.isEmpty(repository)) {
        repository = preference.getDefaultRepository();
    }
    String username = null;
    String password = null;
    if (!preference.isAnonymous()) {
        username = preference.getUsername();
        password = preference.getPassword();
    }
    String dynamic = String.format(ATTR_DYNAMIC_DISTRIBUTION, pluginConfiguration.getDistribution() + "_" + pluginConfiguration.getVersion());
    for (IDynamicConfiguration configuration : configurations) {
        if (DynamicModuleGroupAdapter.TAG_NAME.equals(configuration.getTagName())) {
            String templateId = (String) configuration.getAttribute(DynamicModuleGroupAdapter.ATTR_GROUP_TEMPLATE_ID);
            if (StringUtils.isEmpty(templateId)) {
                throw new Exception("Template id is not configured!");
            }
            moduleGroupTemplateMap.put(templateId, configuration);
            configuration.removeAttribute(DynamicModuleGroupAdapter.ATTR_GROUP_TEMPLATE_ID);
        } else if (DynamicModuleAdapter.TAG_NAME.equals(configuration.getTagName())) {
            String moduleId = (String) configuration.getAttribute(DynamicModuleAdapter.ATTR_ID);
            if (StringUtils.isEmpty(moduleId)) {
                throw new Exception("Module id is empty!");
            }
            moduleMap.put(moduleId, configuration);
            String useStudioRepository = (String) configuration.getAttribute(DynamicModuleAdapter.ATTR_TEMP_USE_STUDIO_REPOSITORY);
            configuration.removeAttribute(DynamicModuleAdapter.ATTR_TEMP_USE_STUDIO_REPOSITORY);
            if (!Boolean.valueOf(useStudioRepository)) {
                String mvnUri = (String) configuration.getAttribute(DynamicModuleAdapter.ATTR_MVN_URI);
                String name = (String) configuration.getAttribute(DynamicModuleAdapter.ATTR_NAME);
                if (StringUtils.isNotEmpty(mvnUri)) {
                    try {
                        MavenArtifact ma = MavenUrlHelper.parseMvnUrl(mvnUri);
                        if (name.endsWith(".pom")) {
                            ma.setType(TYPE_POM);
                        }
                        if (StringUtils.isEmpty(ma.getRepositoryUrl())) {
                            String newMvnUri = MavenUrlHelper.generateMvnUrl(username, password, repository, ma.getGroupId(), ma.getArtifactId(), ma.getVersion(), ma.getType(), ma.getClassifier(), true);
                            if (StringUtils.isEmpty(newMvnUri)) {
                                throw new Exception("Convert mvnUri failed! original uri: " + mvnUri);
                            }
                            configuration.setAttribute(DynamicModuleAdapter.ATTR_MVN_URI, newMvnUri);
                        }
                    } catch (Exception e) {
                        ExceptionHandler.process(e);
                    }
                }
            }
            Object attribute = configuration.getAttribute(DynamicModuleAdapter.ATTR_MESSAGE);
            if (attribute == null || StringUtils.isBlank(attribute.toString())) {
                configuration.setAttribute(DynamicModuleAdapter.ATTR_MESSAGE, dynamic);
            }
        }
    }
    List<IDynamicConfiguration> classLoaders = classLoaderExtension.getConfigurations();
    if (classLoaders == null || classLoaders.isEmpty()) {
        throw new Exception("No classLoader configured");
    }
    for (IDynamicConfiguration classLoader : classLoaders) {
        classLoader.removeAttribute(DynamicClassloaderAdapter.ATTR_MODULE_GROUP_TEMPLATE_ID);
    }
// plugin.setPluginConfiguration(null);
}
Also used : IDynamicConfiguration(org.talend.core.runtime.dynamic.IDynamicConfiguration) IDynamicExtension(org.talend.core.runtime.dynamic.IDynamicExtension) MavenArtifact(org.talend.core.runtime.maven.MavenArtifact)

Example 15 with IDynamicConfiguration

use of org.talend.core.runtime.dynamic.IDynamicConfiguration in project tbd-studio-se by Talend.

the class DynamicPluginAdapter method unifyModuleVersions.

private void unifyModuleVersions() throws Exception {
    Map<String, IDynamicConfiguration> latestGaMap = new HashMap<>();
    Set<IDynamicConfiguration> oldVersionModuleSet = new HashSet<>();
    Set<String> oldVersionModuleIdSet = new HashSet<>();
    for (IDynamicConfiguration module : moduleMap.values()) {
        String mvnUri = (String) module.getAttribute(DynamicModuleAdapter.ATTR_MVN_URI);
        if (StringUtils.isEmpty(mvnUri)) {
            continue;
        }
        MavenArtifact curMa = MavenUrlHelper.parseMvnUrl(mvnUri);
        String key = getGaKey(curMa);
        IDynamicConfiguration storedModuleConfig = latestGaMap.get(key);
        if (storedModuleConfig == null) {
            latestGaMap.put(key, module);
            continue;
        } else {
            String curVersion = curMa.getVersion();
            String storedMvnUri = (String) storedModuleConfig.getAttribute(DynamicModuleAdapter.ATTR_MVN_URI);
            MavenArtifact storedMa = MavenUrlHelper.parseMvnUrl(storedMvnUri);
            String storedVersion = storedMa.getVersion();
            if (0 < versionComparator.compare(curVersion, storedVersion)) {
                String storedVersionModuleId = (String) storedModuleConfig.getAttribute(DynamicModuleAdapter.ATTR_ID);
                oldVersionModuleIdSet.add(storedVersionModuleId);
                oldVersionModuleSet.add(storedModuleConfig);
                latestGaMap.put(key, module);
            } else {
                String curVersionModuleId = (String) module.getAttribute(DynamicModuleAdapter.ATTR_ID);
                oldVersionModuleIdSet.add(curVersionModuleId);
                oldVersionModuleSet.add(module);
            }
        }
    }
    if (!oldVersionModuleIdSet.isEmpty()) {
        Set<String> keepIds = new HashSet<>();
        for (IDynamicConfiguration moduleGroup : moduleGroupTemplateMap.values()) {
            List<IDynamicConfiguration> childConfigurations = moduleGroup.getChildConfigurations();
            Iterator<IDynamicConfiguration> libraryIter = childConfigurations.iterator();
            Set<String> newAddedConfigIds = new HashSet<>();
            while (libraryIter.hasNext()) {
                IDynamicConfiguration childConfig = libraryIter.next();
                String libraryId = (String) childConfig.getAttribute(DynamicModuleGroupAdapter.ATTR_LIBRARY_ID);
                if (oldVersionModuleIdSet.contains(libraryId)) {
                    IDynamicConfiguration moduleById = getModuleById(libraryId);
                    String mvnUri = (String) moduleById.getAttribute(DynamicModuleAdapter.ATTR_MVN_URI);
                    MavenArtifact ma = MavenUrlHelper.parseMvnUrl(mvnUri);
                    String key = getGaKey(ma);
                    if (StringUtils.isEmpty(key)) {
                        throw new Exception("Can't find GA key");
                    }
                    IDynamicConfiguration latestModule = latestGaMap.get(key);
                    if (latestModule == null) {
                        throw new Exception("Can't find latest module");
                    }
                    String latestModuleId = (String) latestModule.getAttribute(DynamicModuleAdapter.ATTR_ID);
                    if (TYPE_POM.equalsIgnoreCase(ma.getType())) {
                        // keep all poms
                        newAddedConfigIds.add(latestModuleId);
                        keepIds.add(libraryId);
                    } else {
                        childConfig.setAttribute(DynamicModuleGroupAdapter.ATTR_LIBRARY_ID, latestModuleId);
                    }
                }
            }
            for (String id : newAddedConfigIds) {
                IDynamicConfiguration createDynamicLibrary = DynamicModuleGroupAdapter.createDynamicLibrary(id);
                moduleGroup.addChildConfiguration(createDynamicLibrary);
            }
        }
        oldVersionModuleIdSet.removeAll(keepIds);
        moduleMap.keySet().removeAll(oldVersionModuleIdSet);
        IDynamicExtension libNeededExtension = getLibraryNeededExtension(plugin);
        List<IDynamicConfiguration> configurations = libNeededExtension.getConfigurations();
        oldVersionModuleSet = oldVersionModuleSet.stream().filter(module -> !keepIds.contains((String) module.getAttribute(DynamicModuleAdapter.ATTR_ID))).collect(Collectors.toSet());
        configurations.removeAll(oldVersionModuleSet);
        Collections.sort(configurations, new DynamicAttributeComparator());
    }
}
Also used : IDynamicConfiguration(org.talend.core.runtime.dynamic.IDynamicConfiguration) HashMap(java.util.HashMap) IDynamicExtension(org.talend.core.runtime.dynamic.IDynamicExtension) MavenArtifact(org.talend.core.runtime.maven.MavenArtifact) DynamicAttributeComparator(org.talend.hadoop.distribution.dynamic.comparator.DynamicAttributeComparator) HashSet(java.util.HashSet)

Aggregations

IDynamicConfiguration (org.talend.core.runtime.dynamic.IDynamicConfiguration)21 IDynamicExtension (org.talend.core.runtime.dynamic.IDynamicExtension)7 ArrayList (java.util.ArrayList)6 DynamicConfiguration (org.talend.hadoop.distribution.dynamic.DynamicConfiguration)5 HashSet (java.util.HashSet)4 MavenArtifact (org.talend.core.runtime.maven.MavenArtifact)4 DynamicPluginAdapter (org.talend.hadoop.distribution.dynamic.adapter.DynamicPluginAdapter)4 TemplateBean (org.talend.hadoop.distribution.dynamic.bean.TemplateBean)4 DynamicAttributeComparator (org.talend.hadoop.distribution.dynamic.comparator.DynamicAttributeComparator)4 DynamicModuleGroupData (org.talend.repository.hadoopcluster.ui.dynamic.DynamicModuleGroupData)4 List (java.util.List)3 ModuleNeeded (org.talend.core.model.general.ModuleNeeded)3 HashMap (java.util.HashMap)2 DependencyNode (org.talend.designer.maven.aether.node.DependencyNode)2 ESparkVersion (org.talend.hadoop.distribution.ESparkVersion)2 ModuleBean (org.talend.hadoop.distribution.dynamic.bean.ModuleBean)2 FileNotFoundException (java.io.FileNotFoundException)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 Test (org.junit.Test)1 ExclusionNode (org.talend.designer.maven.aether.node.ExclusionNode)1