Search in sources :

Example 21 with IDynamicPluginConfiguration

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

the class AbstractDynamicDistributionsGroup method unregister.

@Override
public void unregister(IDynamicPlugin dynamicPlugin, IDynamicMonitor monitor, boolean reloadLibCache) throws Exception {
    boolean unregisted = false;
    IDynamicPluginConfiguration pluginConfiguration = dynamicPlugin.getPluginConfiguration();
    String templateId = pluginConfiguration.getTemplateId();
    IDynamicDistribution dynamicDistribution = getDynamicDistributionForId(templateId, monitor);
    if (dynamicDistribution != null) {
        dynamicDistribution.unregister(dynamicPlugin, monitor, reloadLibCache);
        unregisted = true;
    }
    if (!unregisted) {
        throw new Exception("No dynamic distribution serivce found for " + pluginConfiguration.getTemplateId());
    }
}
Also used : IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration)

Example 22 with IDynamicPluginConfiguration

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

Example 23 with IDynamicPluginConfiguration

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

the class AbstractDynamicDistribution method register.

@Override
public void register(IDynamicPlugin dynamicPlugin, IDynamicMonitor monitor) throws Exception {
    DynamicDistributionManager dynamicDistributionManager = DynamicDistributionManager.getInstance();
    IDynamicPlugin copiedDynamicPlugin = DynamicFactory.getInstance().createPluginFromJson(dynamicPlugin.toXmlJson().toString());
    Project project = ProjectManager.getInstance().getProjectFromProjectTechLabel((String) copiedDynamicPlugin.getPluginConfiguration().getAttribute(DynamicConstants.ATTR_PROJECT_TECHNICAL_NAME));
    IDynamicDistributionPreference dynamicDistributionPreference = dynamicDistributionManager.getDynamicDistributionGroup(getDistributionName()).getDynamicDistributionPreference(project);
    Bundle bundle = getBundle();
    DynamicPluginAdapter pluginAdapter = new DynamicPluginAdapter(copiedDynamicPlugin, dynamicDistributionPreference, bundle);
    pluginAdapter.adapt();
    IDynamicPluginConfiguration pluginConfiguration = pluginAdapter.getPluginConfiguration();
    String id = pluginConfiguration.getId();
    try {
        IDynamicDistributionTemplate existingTemplate = registedDistribution.get(id);
        if (existingTemplate != null) {
            unloadDistribution(existingTemplate, true);
            DynamicPluginAdapter existingPluginAdapter = existingTemplate.getPluginAdapter();
            IDynamicPluginConfiguration existingPluginConfig = existingPluginAdapter.getPluginConfiguration();
            String existingProjectName = (String) existingPluginConfig.getAttribute(DynamicConstants.ATTR_PROJECT_TECHNICAL_NAME);
            ExceptionHandler.log("Dynamic distribution: " + existingProjectName + "/" + id + " already exists, unloaded the old one and reload the new one");
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    boolean isBuiltin = Boolean.parseBoolean((String) pluginConfiguration.getAttribute(DynamicConstants.ATTR_IS_BUILTIN));
    if (isBuiltin) {
        // $NON-NLS-1$
        pluginConfiguration.setName(Messages.getString("DynamicDistribution.name.builtin", pluginConfiguration.getName()));
    } else {
        Project currentProject = ProjectManager.getInstance().getCurrentProject();
        String curProjLabel = currentProject.getTechnicalLabel();
        String projLabel = (String) pluginConfiguration.getAttribute(DynamicConstants.ATTR_PROJECT_TECHNICAL_NAME);
        if (StringUtils.equals(curProjLabel, projLabel)) {
            // $NON-NLS-1$
            projLabel = Messages.getString("DynamicDistribution.name.current");
        }
        pluginConfiguration.setName(// $NON-NLS-1$
        Messages.getString(// $NON-NLS-1$
        "DynamicDistribution.name.project", // $NON-NLS-1$
        pluginConfiguration.getName(), projLabel));
    }
    IDynamicDistributionTemplate distributionTemplate = initTemplate(pluginAdapter, monitor);
    registedDistribution.put(pluginConfiguration.getId(), distributionTemplate);
    distributionTemplate.registOsgiServices();
    if (Boolean.getBoolean(PROP_LOAD_DYNAMIC_DISTRIBUTION_MODULE)) {
        distributionTemplate.registPluginExtensions();
    }
}
Also used : Project(org.talend.core.model.general.Project) IDynamicDistributionPreference(org.talend.hadoop.distribution.dynamic.pref.IDynamicDistributionPreference) DynamicPluginAdapter(org.talend.hadoop.distribution.dynamic.adapter.DynamicPluginAdapter) IDynamicDistributionTemplate(org.talend.hadoop.distribution.dynamic.template.IDynamicDistributionTemplate) IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin) Bundle(org.osgi.framework.Bundle) IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration)

Example 24 with IDynamicPluginConfiguration

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

the class DynamicDistributionManager method getAllUsersDynamicPluginsForProject.

public List<IDynamicPlugin> getAllUsersDynamicPluginsForProject(Project project, IDynamicMonitor monitor) throws Exception {
    IProject eProject = ResourceUtils.getProject(project);
    IFolder usersFolder = ResourceUtils.getFolder(eProject, getUserStoragePath(), false);
    if (usersFolder == null || !usersFolder.exists()) {
        return null;
    }
    List<IDynamicPlugin> dynamicPlugins = new ArrayList<>();
    String absoluteFolderPath = usersFolder.getLocation().toPortableString();
    File folder = new File(absoluteFolderPath);
    List<String> files = getAllFiles(folder);
    if (files != null && 0 < files.size()) {
        String projTechName = project.getTechnicalLabel();
        for (String absolutePath : files) {
            try {
                String jsonContent = DynamicServiceUtil.readFile(new File(absolutePath));
                IDynamicPlugin dynamicPlugin = DynamicFactory.getInstance().createPluginFromJson(jsonContent);
                IDynamicPluginConfiguration pluginConfiguration = dynamicPlugin.getPluginConfiguration();
                pluginConfiguration.setAttribute(DynamicConstants.ATTR_FILE_PATH, absolutePath);
                pluginConfiguration.setAttribute(DynamicConstants.ATTR_IS_BUILTIN, Boolean.FALSE.toString());
                pluginConfiguration.setAttribute(DynamicConstants.ATTR_PROJECT_TECHNICAL_NAME, projTechName);
                dynamicPlugins.add(dynamicPlugin);
            } catch (Exception e) {
                ExceptionHandler.process(e);
            }
        }
    }
    return dynamicPlugins;
}
Also used : IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin) ArrayList(java.util.ArrayList) File(java.io.File) IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 25 with IDynamicPluginConfiguration

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

the class DynamicDistributionManager method saveUsersDynamicPlugin.

public void saveUsersDynamicPlugin(IDynamicPlugin dynamicPlugin, IDynamicMonitor monitor) throws Exception {
    IDynamicPluginConfiguration pluginConfiguration = dynamicPlugin.getPluginConfiguration();
    Object obj = pluginConfiguration.getAttribute(DynamicConstants.ATTR_FILE_PATH);
    try {
        String filePath = (String) obj;
        if (StringUtils.isEmpty(filePath)) {
            IProject eProject = ResourceUtils.getProject(ProjectManager.getInstance().getCurrentProject());
            IFolder usersFolder = ResourceUtils.getFolder(eProject, getUserStoragePath(), false);
            if (usersFolder == null || !usersFolder.exists()) {
                ResourceUtils.createFolder(usersFolder);
            }
            String folderPath = usersFolder.getLocation().toPortableString();
            String fileName = pluginConfiguration.getId();
            // $NON-NLS-1$ //$NON-NLS-2$
            filePath = folderPath + "/" + fileName + "." + DISTRIBUTION_FILE_EXTENSION;
        }
        saveUsersDynamicPlugin(dynamicPlugin, filePath, monitor);
    } finally {
    // nothing to do
    }
}
Also used : IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IDynamicPluginConfiguration (org.talend.core.runtime.dynamic.IDynamicPluginConfiguration)38 IDynamicPlugin (org.talend.core.runtime.dynamic.IDynamicPlugin)16 DynamicPluginAdapter (org.talend.hadoop.distribution.dynamic.adapter.DynamicPluginAdapter)10 Set (java.util.Set)6 NodeComponentTypeBean (org.talend.hadoop.distribution.NodeComponentTypeBean)6 File (java.io.File)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 DummyDynamicMonitor (org.talend.designer.maven.aether.DummyDynamicMonitor)5 IDynamicMonitor (org.talend.designer.maven.aether.IDynamicMonitor)5 IDynamicDistributionTemplate (org.talend.hadoop.distribution.dynamic.template.IDynamicDistributionTemplate)4 ArrayList (java.util.ArrayList)3 Project (org.talend.core.model.general.Project)3 DynamicConfiguration (org.talend.hadoop.distribution.dynamic.DynamicConfiguration)3 DynamicDistributionSetupData (org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupData)3 IFolder (org.eclipse.core.resources.IFolder)2 IProject (org.eclipse.core.resources.IProject)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 Bundle (org.osgi.framework.Bundle)2 LoginException (org.talend.commons.exception.LoginException)2 PersistenceException (org.talend.commons.exception.PersistenceException)2