Search in sources :

Example 1 with DummyDynamicMonitor

use of org.talend.designer.maven.aether.DummyDynamicMonitor in project tbd-studio-se by Talend.

the class DynamicDistributionManager method getUsersIdDynamicDistributionMap.

private Map<String, IDynamicPlugin> getUsersIdDynamicDistributionMap() throws Exception {
    if (usersIdDistributionMap != null) {
        String systemCacheVersion = HadoopDistributionsHelper.getCacheVersion();
        if (StringUtils.equals(systemCacheVersion, usersIdDistributionMapCacheVersion)) {
            return usersIdDistributionMap;
        }
    }
    usersIdDistributionMap = new HashMap<>();
    usersIdDistributionMapCacheVersion = HadoopDistributionsHelper.getCacheVersion();
    IDynamicMonitor monitor = new DummyDynamicMonitor();
    List<IDynamicPlugin> allBuiltinDynamicPlugins = getAllUsersDynamicPlugins(monitor);
    if (allBuiltinDynamicPlugins != null && !allBuiltinDynamicPlugins.isEmpty()) {
        for (IDynamicPlugin dynamicPlugin : allBuiltinDynamicPlugins) {
            IDynamicPluginConfiguration pluginConfiguration = dynamicPlugin.getPluginConfiguration();
            if (pluginConfiguration != null) {
                String id = pluginConfiguration.getId();
                usersIdDistributionMap.put(id, dynamicPlugin);
            }
        }
    }
    return usersIdDistributionMap;
}
Also used : IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin) DummyDynamicMonitor(org.talend.designer.maven.aether.DummyDynamicMonitor) IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration) IDynamicMonitor(org.talend.designer.maven.aether.IDynamicMonitor)

Example 2 with DummyDynamicMonitor

use of org.talend.designer.maven.aether.DummyDynamicMonitor in project tbd-studio-se by Talend.

the class DynamicDistributionManager method getBuiltinIdDynamicDistributionMap.

private Map<String, IDynamicPlugin> getBuiltinIdDynamicDistributionMap() throws Exception {
    if (builtinIdDistributionMap != null) {
        String systemCacheVersion = HadoopDistributionsHelper.getCacheVersion();
        if (StringUtils.equals(systemCacheVersion, builtinIdDistributionMapCacheVersion)) {
            return builtinIdDistributionMap;
        }
    }
    builtinIdDistributionMap = new HashMap<>();
    builtinIdDistributionMapCacheVersion = HadoopDistributionsHelper.getCacheVersion();
    IDynamicMonitor monitor = new DummyDynamicMonitor();
    List<IDynamicPlugin> allBuiltinDynamicPlugins = getAllBuiltinDynamicPlugins(monitor);
    if (allBuiltinDynamicPlugins != null && !allBuiltinDynamicPlugins.isEmpty()) {
        for (IDynamicPlugin dynamicPlugin : allBuiltinDynamicPlugins) {
            IDynamicPluginConfiguration pluginConfiguration = dynamicPlugin.getPluginConfiguration();
            if (pluginConfiguration != null) {
                String id = pluginConfiguration.getId();
                builtinIdDistributionMap.put(id, dynamicPlugin);
            }
        }
    }
    return builtinIdDistributionMap;
}
Also used : IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin) DummyDynamicMonitor(org.talend.designer.maven.aether.DummyDynamicMonitor) IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration) IDynamicMonitor(org.talend.designer.maven.aether.IDynamicMonitor)

Example 3 with DummyDynamicMonitor

use of org.talend.designer.maven.aether.DummyDynamicMonitor in project tbd-studio-se by Talend.

the class AbstractDynamicDistributionsGroup method getCompatibleDistribution.

@Override
public IDynamicDistribution getCompatibleDistribution(IDynamicMonitor monitor, String version) throws Exception {
    if (monitor == null) {
        monitor = new DummyDynamicMonitor();
    }
    VersionStringComparator versionStringComparator = new VersionStringComparator();
    // 1. try to get dynamicDistribution from compatible list
    Set<Entry<IDynamicDistribution, List<String>>> entrySet = getCompatibleDistribuionVersionMap(monitor).entrySet();
    IDynamicDistribution bestDistribution = null;
    // choose the biggest distance, normally means compatible with higher versions
    int distance = -1;
    for (Entry<IDynamicDistribution, 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;
                bestDistribution = entry.getKey();
            }
        }
    }
    // 2. try to get dynamicDistribution from all list
    if (bestDistribution == null) {
        List<String> allVersions = new ArrayList<>();
        List<String> allVersionsCached = getAllVersionList(monitor);
        if (allVersionsCached != null) {
            allVersions.addAll(allVersionsCached);
        }
        Collections.sort(allVersions, versionStringComparator);
        // choose the shortest distance, normally means compatible with higher versions
        distance = -1;
        for (Entry<IDynamicDistribution, 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;
                bestDistribution = entry.getKey();
            }
        }
    }
    return bestDistribution;
}
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) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 4 with DummyDynamicMonitor

use of org.talend.designer.maven.aether.DummyDynamicMonitor in project tbd-studio-se by Talend.

the class DynamicDistributionOptionForm method initExistingConfigurationInfos.

private void initExistingConfigurationInfos() throws Exception {
    existingConfigurationNames = new HashSet<>();
    existingConfigurationIdMap = new HashMap<>();
    IDynamicMonitor monitor = new DummyDynamicMonitor();
    DynamicDistributionManager dynDistrManager = DynamicDistributionManager.getInstance();
    List<IDynamicPlugin> allDynamicPlugins = new LinkedList<>();
    List<IDynamicPlugin> allBuiltinDynamicPlugins = dynDistrManager.getAllBuiltinDynamicPlugins(monitor);
    if (allBuiltinDynamicPlugins != null && !allBuiltinDynamicPlugins.isEmpty()) {
        allDynamicPlugins.addAll(allBuiltinDynamicPlugins);
    }
    List<IDynamicPlugin> allUsesDynamicPlugins = dynDistrManager.getAllUsersDynamicPlugins(monitor);
    if (allUsesDynamicPlugins != null && !allUsesDynamicPlugins.isEmpty()) {
        allDynamicPlugins.addAll(allUsesDynamicPlugins);
    }
    if (allDynamicPlugins != null && !allDynamicPlugins.isEmpty()) {
        Iterator<IDynamicPlugin> iter = allDynamicPlugins.iterator();
        while (iter.hasNext()) {
            IDynamicPlugin dynPlugin = iter.next();
            IDynamicPluginConfiguration pluginConfiguration = dynPlugin.getPluginConfiguration();
            existingConfigurationNames.add(pluginConfiguration.getName());
            existingConfigurationIdMap.put(pluginConfiguration.getId(), dynPlugin);
        }
    }
}
Also used : DynamicDistributionManager(org.talend.hadoop.distribution.dynamic.DynamicDistributionManager) IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin) DummyDynamicMonitor(org.talend.designer.maven.aether.DummyDynamicMonitor) IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration) IDynamicMonitor(org.talend.designer.maven.aether.IDynamicMonitor) LinkedList(java.util.LinkedList)

Example 5 with DummyDynamicMonitor

use of org.talend.designer.maven.aether.DummyDynamicMonitor in project tbd-studio-se by Talend.

the class DynamicDistributionPreferenceForm method addListeners.

private void addListeners() {
    if (ITalendCorePrefConstants.DYNAMIC_DISTRIBUTION_SETTING == showPart) {
        distributionCombo.addSelectionChangedListener(new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                refreshVersionList(new DummyDynamicMonitor());
                updateButtons();
            }
        });
        versionCombo.addSelectionChangedListener(new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                updateButtons();
            }
        });
        buildConfigBtn.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                try {
                    IStructuredSelection selection = (IStructuredSelection) distributionCombo.getSelection();
                    if (selection == null) {
                        ExceptionHandler.process(new Exception(// $NON-NLS-1$
                        Messages.getString("DynamicDistributionPreferenceForm.exception.noDistributionSelected")));
                        return;
                    }
                    String distribution = (String) selection.getFirstElement();
                    if (distribution == null) {
                        ExceptionHandler.process(new Exception(// $NON-NLS-1$
                        Messages.getString("DynamicDistributionPreferenceForm.exception.noDistributionSelected")));
                        return;
                    }
                    IDynamicDistributionsGroup dynamicDistributionsGroup = DynamicDistributionManager.getInstance().getDynamicDistributionGroup(distribution);
                    DynamicDistributionSetupData configData = new DynamicDistributionSetupData();
                    configData.setDynamicDistributionsGroup(dynamicDistributionsGroup);
                    DynamicDistributionSetupWizard wizard = new DynamicDistributionSetupWizard(configData);
                    WizardDialog wizardDialog = new WizardDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), wizard);
                    wizardDialog.setMinimumPageSize(600, 400);
                    wizardDialog.create();
                    if (wizardDialog.open() == IDialogConstants.OK_ID) {
                    // nothing to do
                    }
                    IDynamicMonitor monitor = new DummyDynamicMonitor();
                    refreshVersionList(monitor);
                } catch (Throwable ex) {
                    ExceptionHandler.process(ex);
                }
                updateButtons();
            }
        });
        deleteBtn.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                onDeleteBtnPressed();
                updateButtons();
            }
        });
    } else {
        setupDistriCombo.addSelectionChangedListener(new ISelectionChangedListener() {

            @Override
            public void selectionChanged(SelectionChangedEvent event) {
                try {
                    loadRepositorySetupGroup();
                } catch (Exception e) {
                    ExceptionHandler.process(e);
                }
                updateButtons();
            }
        });
        overrideDefaultSetupBtn.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                updateButtons();
            }
        });
        repositoryText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                String newRepositoryText = repositoryText.getText();
                if (StringUtils.equals(newRepositoryText, repositoryUrlCache)) {
                    return;
                }
                repositoryUrlCache = newRepositoryText;
                updateButtons();
            }
        });
        anonymousBtn.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                updateButtons();
            }
        });
        userText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                String newUsername = userText.getText();
                if (StringUtils.equals(newUsername, usernameCache)) {
                    return;
                }
                usernameCache = newUsername;
                updateButtons();
            }
        });
        passwordText.addModifyListener(new ModifyListener() {

            @Override
            public void modifyText(ModifyEvent e) {
                String newPassword = passwordText.getText();
                if (StringUtils.equals(newPassword, passwordCache)) {
                    return;
                }
                passwordCache = newPassword;
                updateButtons();
            }
        });
        checkConnectionBtn.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                if (!isComplete()) {
                    return;
                }
                TypedReturnCode tc = new TypedReturnCode();
                try {
                    IDynamicDistributionsGroup distriGroup = getSelectedSetupDynamicDistriGroup();
                    DynamicConfiguration dynamicConfiguration = new DynamicConfiguration();
                    dynamicConfiguration.setDistribution(distriGroup.getDistribution());
                    IDependencyResolver dependencyResolver = distriGroup.getDependencyResolver(dynamicConfiguration);
                    tc = dependencyResolver.checkConnection(repositoryText.getText(), userText.getText(), passwordText.getText());
                } catch (Exception e1) {
                    ExceptionHandler.process(e1);
                    tc.setOk(false);
                    tc.setMessage(e1.getMessage());
                }
                showCheckConnectionInformation(true, tc);
            }
        });
    }
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) IDependencyResolver(org.talend.hadoop.distribution.dynamic.resolver.IDependencyResolver) DynamicDistributionSetupWizard(org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupWizard) ModifyEvent(org.eclipse.swt.events.ModifyEvent) IDynamicDistributionsGroup(org.talend.hadoop.distribution.dynamic.IDynamicDistributionsGroup) DynamicConfiguration(org.talend.hadoop.distribution.dynamic.DynamicConfiguration) TypedReturnCode(org.talend.utils.sugars.TypedReturnCode) DummyDynamicMonitor(org.talend.designer.maven.aether.DummyDynamicMonitor) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DynamicDistributionSetupData(org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupData) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IDynamicMonitor(org.talend.designer.maven.aether.IDynamicMonitor)

Aggregations

DummyDynamicMonitor (org.talend.designer.maven.aether.DummyDynamicMonitor)13 IDynamicMonitor (org.talend.designer.maven.aether.IDynamicMonitor)10 IDynamicPlugin (org.talend.core.runtime.dynamic.IDynamicPlugin)6 IDynamicPluginConfiguration (org.talend.core.runtime.dynamic.IDynamicPluginConfiguration)5 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)4 AbstractDynamicDistributionForm (org.talend.repository.hadoopcluster.ui.dynamic.form.AbstractDynamicDistributionForm)4 ICheckListener (org.talend.repository.hadoopcluster.ui.dynamic.form.AbstractDynamicDistributionForm.ICheckListener)4 LinkedList (java.util.LinkedList)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 VersionStringComparator (org.talend.designer.maven.aether.comparator.VersionStringComparator)2 DynamicDistributionSetupData (org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupData)2 DynamicDistributionPreferenceForm (org.talend.repository.hadoopcluster.ui.dynamic.form.DynamicDistributionPreferenceForm)2 File (java.io.File)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1