Search in sources :

Example 6 with IDynamicExtension

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

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

use of org.talend.core.runtime.dynamic.IDynamicExtension 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)

Example 9 with IDynamicExtension

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

the class DynamicTemplateAdapter method adapt.

public void adapt(IDynamicMonitor monitor) throws Exception {
    DynamicDistributionUtils.checkCancelOrNot(monitor);
    resolve();
    TemplateBean templateBean = getTemplateBean();
    DynamicConfiguration configuration = getConfiguration();
    // use id instead of version
    templateBean.setDynamicVersion(configuration.getId());
    DynamicDistributionManager dynamicDistributionManager = DynamicDistributionManager.getInstance();
    IDependencyResolver dependencyResolver = dynamicDistributionManager.getDependencyResolver(configuration);
    dynamicPlugin = DynamicFactory.getInstance().createDynamicPlugin();
    distriConfigAdapter = new DynamicDistribConfigAdapter(templateBean, configuration);
    IDynamicPluginConfiguration pluginConfiguration = distriConfigAdapter.adapt(monitor);
    dynamicPlugin.setPluginConfiguration(pluginConfiguration);
    moduleBeanAdapterMap = new HashMap<>();
    moduleGroupBeanAdapterMap = new HashMap<>();
    DynamicLibraryNeededExtensionAdaper libNeededExtAdapter = new DynamicLibraryNeededExtensionAdaper(templateBean, configuration, dependencyResolver, moduleBeanAdapterMap, moduleGroupBeanAdapterMap);
    libNeededExtAdapter.enableMultiThread(!Boolean.getBoolean(PROPERTY_DISABLE_MULTI_THTREAD));
    IDynamicExtension dynamicLibNeededExtension = libNeededExtAdapter.adapt(monitor);
    dynamicPlugin.addExtension(dynamicLibNeededExtension);
    DynamicClassLoaderExtensionAdaper clsLoaderAdapter = new DynamicClassLoaderExtensionAdaper(templateBean, configuration, moduleGroupBeanAdapterMap);
    IDynamicExtension dynamicClsLoaderExtension = clsLoaderAdapter.adapt(monitor);
    dynamicPlugin.addExtension(dynamicClsLoaderExtension);
}
Also used : DynamicConfiguration(org.talend.hadoop.distribution.dynamic.DynamicConfiguration) IDynamicExtension(org.talend.core.runtime.dynamic.IDynamicExtension) DynamicDistributionManager(org.talend.hadoop.distribution.dynamic.DynamicDistributionManager) TemplateBean(org.talend.hadoop.distribution.dynamic.bean.TemplateBean) IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration) IDependencyResolver(org.talend.hadoop.distribution.dynamic.resolver.IDependencyResolver)

Aggregations

IDynamicExtension (org.talend.core.runtime.dynamic.IDynamicExtension)9 IDynamicConfiguration (org.talend.core.runtime.dynamic.IDynamicConfiguration)7 MavenArtifact (org.talend.core.runtime.maven.MavenArtifact)3 DynamicConfiguration (org.talend.hadoop.distribution.dynamic.DynamicConfiguration)3 TemplateBean (org.talend.hadoop.distribution.dynamic.bean.TemplateBean)3 DynamicAttributeComparator (org.talend.hadoop.distribution.dynamic.comparator.DynamicAttributeComparator)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 FileNotFoundException (java.io.FileNotFoundException)1 IDynamicPluginConfiguration (org.talend.core.runtime.dynamic.IDynamicPluginConfiguration)1 DynamicDistributionManager (org.talend.hadoop.distribution.dynamic.DynamicDistributionManager)1 ClassLoaderBean (org.talend.hadoop.distribution.dynamic.bean.ClassLoaderBean)1 ModuleBean (org.talend.hadoop.distribution.dynamic.bean.ModuleBean)1 ModuleGroupBean (org.talend.hadoop.distribution.dynamic.bean.ModuleGroupBean)1 IDependencyResolver (org.talend.hadoop.distribution.dynamic.resolver.IDependencyResolver)1