Search in sources :

Example 1 with DynamicConfiguration

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

the class DynamicDistribConfigAdapter method adapt.

public IDynamicPluginConfiguration adapt(IDynamicMonitor monitor) throws Exception {
    DynamicDistributionUtils.checkCancelOrNot(monitor);
    resolve();
    IDynamicPluginConfiguration pluginConfiguration = DynamicFactory.getInstance().createDynamicPluginConfiguration();
    TemplateBean templateBean = getTemplateBean();
    DynamicConfiguration configuration = getConfiguration();
    String distribution = templateBean.getDistribution();
    String templateId = templateBean.getTemplateId();
    if (!StringUtils.equals(distribution, configuration.getDistribution())) {
        throw new Exception(// $NON-NLS-1$
        Messages.getString("DynamicDistriConfigAdapter.diffDistri", distribution, configuration.getDistribution()));
    }
    String projectTechnicalName = ProjectManager.getInstance().getCurrentProject().getTechnicalLabel();
    // String id = projectTechnicalName + "_" + configuration.getId(); //$NON-NLS-1$
    String id = configuration.getId();
    pluginConfiguration.setId(id);
    pluginConfiguration.setName(configuration.getName());
    pluginConfiguration.setVersion(configuration.getVersion());
    pluginConfiguration.setDescription(configuration.getDescription());
    pluginConfiguration.setDistribution(distribution);
    pluginConfiguration.setTemplateId(templateId);
    pluginConfiguration.setRepository(configuration.getRemoteRepositoryUrl());
    pluginConfiguration.setAttribute(DynamicConstants.ATTR_PROJECT_TECHNICAL_NAME, projectTechnicalName);
    pluginConfiguration.setAttribute(DynamicConstants.ATTR_SELECTED_SPARK_VERSIONS, DynamicDistributionUtils.convert2SparkVersions(configuration.getSelectedSparkVersions()));
    return pluginConfiguration;
}
Also used : DynamicConfiguration(org.talend.hadoop.distribution.dynamic.DynamicConfiguration) TemplateBean(org.talend.hadoop.distribution.dynamic.bean.TemplateBean) IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration)

Example 2 with DynamicConfiguration

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

the class AbstractDependencyResolver method listHadoopVersions.

@Override
public List<String> listHadoopVersions(String baseVersion, String topVersion, IDynamicMonitor monitor) throws Exception {
    // $NON-NLS-1$
    String groupId = "org.apache.hadoop";
    // $NON-NLS-1$
    String artifactId = "hadoop-client";
    DynamicConfiguration configuration = getConfiguration();
    IDynamicDistributionPreference preference = configuration.getPreference();
    String remoteRepositoryUrl = preference.getRepository();
    String username = null;
    String password = null;
    if (!preference.isAnonymous()) {
        username = preference.getUsername();
        password = preference.getPassword();
    }
    String localRepositoryPath = getLocalRepositoryPath();
    List<String> versionRange = DynamicDistributionAetherUtils.versionRange(remoteRepositoryUrl, username, password, localRepositoryPath, groupId, artifactId, baseVersion, topVersion, monitor);
    return getCleanHadoopVersion(versionRange);
}
Also used : IDynamicDistributionPreference(org.talend.hadoop.distribution.dynamic.pref.IDynamicDistributionPreference) DynamicConfiguration(org.talend.hadoop.distribution.dynamic.DynamicConfiguration)

Example 3 with DynamicConfiguration

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

the class AbstractDependencyResolver method getDependencyVersionByHadoopVersion.

@Override
public String getDependencyVersionByHadoopVersion(String groupId, String artifactId, IDynamicMonitor monitor) throws Exception {
    DynamicConfiguration configuration = getConfiguration();
    String distributionVersion = configuration.getVersion();
    IDynamicDistributionPreference preference = configuration.getPreference();
    String remoteRepositoryUrl = preference.getRepository();
    String username = null;
    String password = null;
    if (!preference.isAnonymous()) {
        username = preference.getUsername();
        password = preference.getPassword();
    }
    String localRepositoryPath = getLocalRepositoryPath();
    List<String> versionRange = DynamicDistributionAetherUtils.versionRange(remoteRepositoryUrl, username, password, localRepositoryPath, groupId, artifactId, null, null, monitor);
    String dependencyVersion = getVersionByHadoopVersion(versionRange, distributionVersion);
    return dependencyVersion;
}
Also used : IDynamicDistributionPreference(org.talend.hadoop.distribution.dynamic.pref.IDynamicDistributionPreference) DynamicConfiguration(org.talend.hadoop.distribution.dynamic.DynamicConfiguration)

Example 4 with DynamicConfiguration

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

the class DynamicLibraryNeededExtensionAdaper method adapt.

public IDynamicExtension adapt(IDynamicMonitor monitor) throws Exception {
    DynamicDistributionUtils.checkCancelOrNot(monitor);
    resolve();
    TemplateBean templateBean = getTemplateBean();
    DynamicConfiguration configuration = getConfiguration();
    String templateId = templateBean.getId();
    String distributionName = configuration.getDistribution();
    String id = configuration.getId();
    IDynamicExtension libNeededExtension = DynamicFactory.getInstance().createDynamicExtension();
    libNeededExtension.setExtensionId(DynamicDistributionUtils.getExtensionId(DynamicDistributionUtils.getPluginKey(distributionName, templateId, id, ATTR_POINT)));
    libNeededExtension.setExtensionPoint(ATTR_POINT);
    List<ModuleBean> modules = templateBean.getModules();
    if (modules != null) {
        try {
            Exception[] ex = new Exception[1];
            Set<String> registedModules = Collections.synchronizedSet(new LinkedHashSet<>());
            for (ModuleBean moduleBean : modules) {
                DynamicDistributionUtils.checkCancelOrNot(monitor);
                Runnable runnable = new Runnable() {

                    int count = 0;

                    @Override
                    public void run() {
                        try {
                            DynamicModuleAdapter dynamicModuleAdapter = new DynamicModuleAdapter(templateBean, configuration, moduleBean, dependencyResolver, registedModules);
                            List<IDynamicConfiguration> librariesNeeded = dynamicModuleAdapter.adapt(monitor, isEnableMultiThread());
                            if (librariesNeeded != null && !librariesNeeded.isEmpty()) {
                                addDynamicConfigurations(libNeededExtension, librariesNeeded);
                            }
                            String beanId = moduleBean.getId();
                            moduleBeanAdapterMap.put(beanId, dynamicModuleAdapter);
                        } catch (Exception e) {
                            Throwable rootCause = ExceptionUtils.getRootCause(e);
                            if (e instanceof FileNotFoundException || rootCause instanceof FileNotFoundException) {
                                if (count < 5) {
                                    count++;
                                    run();
                                } else {
                                    ex[0] = e;
                                }
                            } else {
                                ex[0] = e;
                            }
                        }
                    }
                };
                if (isEnableMultiThread()) {
                    getThreadPool().execute(runnable);
                    continue;
                } else {
                    runnable.run();
                    if (ex[0] != null) {
                        throw ex[0];
                    }
                }
            }
            if (isEnableMultiThread()) {
                int totalTasks = modules.size();
                if (monitor != null) {
                    monitor.beginTask(// $NON-NLS-1$
                    Messages.getString("DynamicLibraryNeededExtensionAdaper.monitor.waitAllFinish", totalTasks), totalTasks);
                }
                int completed = 0;
                while (true) {
                    int activeCount = getThreadPool().getActiveCount();
                    if (activeCount <= 0) {
                        break;
                    }
                    if (monitor != null) {
                        int newCompleted = (int) getThreadPool().getCompletedTaskCount();
                        int newWorked = newCompleted - completed;
                        completed = newCompleted;
                        monitor.setTaskName(// $NON-NLS-1$
                        Messages.getString(// $NON-NLS-1$
                        "DynamicLibraryNeededExtensionAdaper.monitor.waitAllFinish", activeCount));
                        monitor.worked(newWorked);
                    }
                    Thread.sleep(200);
                    DynamicDistributionUtils.checkCancelOrNot(monitor);
                    if (ex[0] != null) {
                        throw ex[0];
                    }
                }
            }
        } finally {
            if (isEnableMultiThread()) {
                if (monitor != null) {
                    // $NON-NLS-1$
                    monitor.beginTask("", IProgressMonitor.UNKNOWN);
                }
                getThreadPool().clearThreads();
                threadPool = null;
            }
        }
    }
    List<ModuleGroupBean> moduleGroups = templateBean.getModuleGroups();
    if (moduleGroups != null) {
        for (ModuleGroupBean moduleGroupBean : moduleGroups) {
            DynamicDistributionUtils.checkCancelOrNot(monitor);
            DynamicModuleGroupAdapter libNeededGroupAdapter = new DynamicModuleGroupAdapter(templateBean, configuration, moduleGroupBean, moduleBeanAdapterMap);
            IDynamicConfiguration dynamicModuleGroup = libNeededGroupAdapter.adapt(monitor);
            if (dynamicModuleGroup != null) {
                libNeededExtension.addConfiguration(dynamicModuleGroup);
                String groupId = moduleGroupBean.getId();
                moduleGroupBeanAdapterMap.put(groupId, libNeededGroupAdapter);
            }
        }
    }
    return libNeededExtension;
}
Also used : IDynamicConfiguration(org.talend.core.runtime.dynamic.IDynamicConfiguration) ModuleGroupBean(org.talend.hadoop.distribution.dynamic.bean.ModuleGroupBean) FileNotFoundException(java.io.FileNotFoundException) FileNotFoundException(java.io.FileNotFoundException) IDynamicConfiguration(org.talend.core.runtime.dynamic.IDynamicConfiguration) DynamicConfiguration(org.talend.hadoop.distribution.dynamic.DynamicConfiguration) IDynamicExtension(org.talend.core.runtime.dynamic.IDynamicExtension) ModuleBean(org.talend.hadoop.distribution.dynamic.bean.ModuleBean) TemplateBean(org.talend.hadoop.distribution.dynamic.bean.TemplateBean)

Example 5 with DynamicConfiguration

use of org.talend.hadoop.distribution.dynamic.DynamicConfiguration 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

DynamicConfiguration (org.talend.hadoop.distribution.dynamic.DynamicConfiguration)15 TemplateBean (org.talend.hadoop.distribution.dynamic.bean.TemplateBean)7 IDynamicConfiguration (org.talend.core.runtime.dynamic.IDynamicConfiguration)6 DynamicDistributionManager (org.talend.hadoop.distribution.dynamic.DynamicDistributionManager)4 Test (org.junit.Test)3 IDynamicExtension (org.talend.core.runtime.dynamic.IDynamicExtension)3 IDynamicPluginConfiguration (org.talend.core.runtime.dynamic.IDynamicPluginConfiguration)3 IDependencyResolver (org.talend.hadoop.distribution.dynamic.resolver.IDependencyResolver)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ExclusionNode (org.talend.designer.maven.aether.node.ExclusionNode)2 ESparkVersion (org.talend.hadoop.distribution.ESparkVersion)2 IDynamicDistributionsGroup (org.talend.hadoop.distribution.dynamic.IDynamicDistributionsGroup)2 ExclusionBean (org.talend.hadoop.distribution.dynamic.bean.ExclusionBean)2 ModuleBean (org.talend.hadoop.distribution.dynamic.bean.ModuleBean)2 IDynamicDistributionPreference (org.talend.hadoop.distribution.dynamic.pref.IDynamicDistributionPreference)2 DynamicDistributionSetupData (org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupData)2 FileNotFoundException (java.io.FileNotFoundException)1 List (java.util.List)1