Search in sources :

Example 1 with ESparkVersion

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

the class DynamicDistributionUtils method convert2ESparkVersions.

public static List<ESparkVersion> convert2ESparkVersions(List<String> sparkVersions) {
    List<ESparkVersion> versions = new ArrayList<>();
    for (String sparkVersion : sparkVersions) {
        try {
            ESparkVersion eSparkVersion = ESparkVersion.valueOf(sparkVersion);
            if (eSparkVersion == null) {
                throw new Exception(// $NON-NLS-1$
                Messages.getString(// $NON-NLS-1$
                "DynamicDistributionUtils.check.sparkVersion.unsupport", sparkVersion));
            }
            versions.add(eSparkVersion);
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
    }
    Collections.sort(versions, Collections.reverseOrder(ESparkVersion.descComparator()));
    return versions;
}
Also used : ESparkVersion(org.talend.hadoop.distribution.ESparkVersion) ArrayList(java.util.ArrayList)

Example 2 with ESparkVersion

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

the class DynamicDistributionOptionForm method createControl.

protected void createControl() {
    Composite parent = this;
    Composite container = createFormContainer(parent);
    final int ALIGN_VERTICAL = getAlignVertical();
    final int ALIGN_VERTICAL_INNER = getAlignVerticalInner();
    final int ALIGN_HORIZON = getAlignHorizon();
    final int HORZON_WIDTH = getHorizonWidth();
    final int ALIGN_HORIZON_VERSION_LABEL = ALIGN_HORIZON * 2;
    newConfigBtn = new Button(container, SWT.RADIO);
    // $NON-NLS-1$
    newConfigBtn.setText(Messages.getString("DynamicDistributionOptionForm.form.newConfigBtn"));
    newConfigBtn.setSelection(true);
    FormData formData = new FormData();
    formData.top = new FormAttachment(0);
    formData.left = new FormAttachment(0);
    formData.right = new FormAttachment(100);
    newConfigBtn.setLayoutData(formData);
    newConfigGroup = new Composite(container, SWT.NONE);
    formData = new FormData();
    formData.top = new FormAttachment(newConfigBtn, 0, SWT.BOTTOM);
    formData.left = new FormAttachment(newConfigBtn, 0, SWT.LEFT);
    formData.right = new FormAttachment(newConfigBtn, 0, SWT.RIGHT);
    newConfigGroup.setLayoutData(formData);
    newConfigGroup.setLayout(new FormLayout());
    int refreshButtonWidth = 0;
    refreshButton = new Button(newConfigGroup, SWT.PUSH);
    // $NON-NLS-1$
    refreshButton.setText(Messages.getString("DynamicDistributionOptionForm.form.refresh.label"));
    formData = new FormData();
    formData.top = new FormAttachment(0, ALIGN_VERTICAL_INNER);
    refreshButtonWidth = getNewButtonSize(refreshButton).x;
    formData.width = refreshButtonWidth;
    formData.right = new FormAttachment(100);
    refreshButton.setLayoutData(formData);
    Label versionLabel = new Label(newConfigGroup, SWT.NONE);
    // $NON-NLS-1$
    versionLabel.setText(Messages.getString("DynamicDistributionOptionForm.form.versionLabel.distribution"));
    formData = new FormData();
    formData.top = new FormAttachment(refreshButton, 0, SWT.CENTER);
    formData.right = new FormAttachment(0, HORZON_WIDTH);
    versionLabel.setLayoutData(formData);
    versionsComboViewer = new ComboViewer(newConfigGroup, SWT.READ_ONLY);
    versionsComboViewer.setContentProvider(ArrayContentProvider.getInstance());
    versionsComboViewer.setLabelProvider(new LabelProvider());
    formData = new FormData();
    formData.top = new FormAttachment(refreshButton, 0, SWT.CENTER);
    formData.left = new FormAttachment(versionLabel, ALIGN_HORIZON_VERSION_LABEL, SWT.RIGHT);
    formData.right = new FormAttachment(refreshButton, -1 * ALIGN_HORIZON, SWT.LEFT);
    versionsComboViewer.getControl().setLayoutData(formData);
    showOnlyCompatibleBtn = new Button(newConfigGroup, SWT.CHECK);
    // $NON-NLS-1$
    showOnlyCompatibleBtn.setText(Messages.getString("DynamicDistributionOptionForm.form.showOnlyCompatible.label"));
    showOnlyCompatibleBtn.setSelection(true);
    formData = new FormData();
    formData.top = new FormAttachment(versionsComboViewer.getControl(), ALIGN_VERTICAL_INNER, SWT.BOTTOM);
    formData.right = new FormAttachment(versionsComboViewer.getControl(), 0, SWT.RIGHT);
    showOnlyCompatibleBtn.setLayoutData(formData);
    Label sparkVersionLabel = new Label(newConfigGroup, SWT.NONE);
    // $NON-NLS-1$
    sparkVersionLabel.setText(Messages.getString("DynamicDistributionOptionForm.form.versionLabel.spark"));
    formData = new FormData();
    formData.top = new FormAttachment(showOnlyCompatibleBtn, 0, SWT.CENTER);
    formData.right = new FormAttachment(versionLabel, 0, SWT.RIGHT);
    sparkVersionLabel.setLayoutData(formData);
    sparkVersionsComboViewer = new TableComboViewer(newConfigGroup, SWT.READ_ONLY | SWT.BORDER);
    sparkVersionsComboViewer.setContentProvider(ArrayContentProvider.getInstance());
    sparkVersionsComboViewer.setLabelProvider(new SparkVersionsLabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof ESparkVersion) {
                return ((ESparkVersion) element).getVersionLabel();
            }
            return super.getText(element);
        }

        @Override
        protected boolean isSelected(Object element) {
            if (selectedSparkVersions.contains(element)) {
                return true;
            } else {
                return false;
            }
        }
    });
    TableCombo tableCombo = sparkVersionsComboViewer.getTableCombo();
    tableCombo.setClosePopupAfterSelection(false);
    tableCombo.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_GRAY));
    formData = new FormData();
    formData.top = new FormAttachment(sparkVersionLabel, 0, SWT.CENTER);
    formData.left = new FormAttachment(versionsComboViewer.getControl(), 0, SWT.LEFT);
    // formData.right = new FormAttachment(showOnlyCompatibleBtn, -1 * ALIGN_HORIZON, SWT.LEFT);
    formData.width = HORZON_WIDTH;
    sparkVersionsComboViewer.getControl().setLayoutData(formData);
    editExistingConfigBtn = new Button(container, SWT.RADIO);
    // $NON-NLS-1$
    editExistingConfigBtn.setText(Messages.getString("DynamicDistributionOptionForm.form.editExistingConfigBtn"));
    formData = new FormData();
    formData.top = new FormAttachment(newConfigGroup, ALIGN_VERTICAL, SWT.BOTTOM);
    formData.left = new FormAttachment(newConfigGroup, 0, SWT.LEFT);
    formData.right = new FormAttachment(newConfigGroup, 0, SWT.RIGHT);
    editExistingConfigBtn.setLayoutData(formData);
    editExistingGroup = new Composite(container, SWT.NONE);
    formData = new FormData();
    formData.top = new FormAttachment(editExistingConfigBtn, 0, SWT.BOTTOM);
    formData.left = new FormAttachment(editExistingConfigBtn, 0, SWT.LEFT);
    formData.right = new FormAttachment(editExistingConfigBtn, 0, SWT.RIGHT);
    editExistingGroup.setLayoutData(formData);
    editExistingGroup.setLayout(new FormLayout());
    existingConfigsComboViewer = new ComboViewer(editExistingGroup, SWT.READ_ONLY);
    existingConfigsComboViewer.setContentProvider(ArrayContentProvider.getInstance());
    existingConfigsComboViewer.setLabelProvider(new DynamicDistributionsLabelProvider());
    Label existVersionLabel = new Label(editExistingGroup, SWT.NONE);
    // $NON-NLS-1$
    existVersionLabel.setText(Messages.getString("DynamicDistributionOptionForm.form.versionLabel.distribution"));
    formData = new FormData();
    formData.top = new FormAttachment(existingConfigsComboViewer.getControl(), 0, SWT.CENTER);
    formData.right = new FormAttachment(0, HORZON_WIDTH);
    existVersionLabel.setLayoutData(formData);
    formData = new FormData();
    formData.top = new FormAttachment(0, ALIGN_VERTICAL_INNER);
    formData.left = new FormAttachment(existVersionLabel, ALIGN_HORIZON_VERSION_LABEL, SWT.RIGHT);
    formData.right = new FormAttachment(100);
    existingConfigsComboViewer.getControl().setLayoutData(formData);
    importConfigBtn = new Button(container, SWT.RADIO);
    // $NON-NLS-1$
    importConfigBtn.setText(Messages.getString("DynamicDistributionOptionForm.form.importConfigBtn"));
    formData = new FormData();
    formData.top = new FormAttachment(editExistingGroup, ALIGN_VERTICAL, SWT.BOTTOM);
    formData.left = new FormAttachment(editExistingGroup, 0, SWT.LEFT);
    formData.right = new FormAttachment(editExistingGroup, 0, SWT.RIGHT);
    importConfigBtn.setLayoutData(formData);
    importConfigGroup = new Composite(container, SWT.NONE);
    formData = new FormData();
    formData.top = new FormAttachment(importConfigBtn, 0, SWT.BOTTOM);
    formData.left = new FormAttachment(importConfigBtn, 0, SWT.LEFT);
    formData.right = new FormAttachment(importConfigBtn, 0, SWT.RIGHT);
    importConfigGroup.setLayoutData(formData);
    importConfigGroup.setLayout(new FormLayout());
    importConfigText = new Text(importConfigGroup, SWT.BORDER);
    importConfigText.setEditable(false);
    importConfigBrowseBtn = new Button(importConfigGroup, SWT.PUSH);
    // $NON-NLS-1$
    importConfigBrowseBtn.setText(Messages.getString("DynamicDistributionOptionForm.form.importConfig.browse"));
    formData = new FormData();
    formData.top = new FormAttachment(0, ALIGN_VERTICAL_INNER);
    formData.left = new FormAttachment(100, -1 * getNewButtonSize(importConfigBrowseBtn).x);
    formData.right = new FormAttachment(100);
    importConfigBrowseBtn.setLayoutData(formData);
    formData = new FormData();
    formData.top = new FormAttachment(importConfigBrowseBtn, 0, SWT.CENTER);
    formData.left = new FormAttachment(0, HORZON_WIDTH + ALIGN_HORIZON_VERSION_LABEL);
    formData.right = new FormAttachment(importConfigBrowseBtn, -1 * ALIGN_HORIZON, SWT.LEFT);
    importConfigText.setLayoutData(formData);
}
Also used : FormData(org.eclipse.swt.layout.FormData) FormLayout(org.eclipse.swt.layout.FormLayout) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) TableComboViewer(org.eclipse.nebula.jface.tablecomboviewer.TableComboViewer) Point(org.eclipse.swt.graphics.Point) ESparkVersion(org.talend.hadoop.distribution.ESparkVersion) Button(org.eclipse.swt.widgets.Button) ComboViewer(org.eclipse.jface.viewers.ComboViewer) TableComboViewer(org.eclipse.nebula.jface.tablecomboviewer.TableComboViewer) SparkVersionsLabelProvider(org.talend.repository.hadoopcluster.ui.dynamic.form.labelprovider.SparkVersionsLabelProvider) DynamicDistributionsLabelProvider(org.talend.repository.hadoopcluster.ui.dynamic.form.labelprovider.DynamicDistributionsLabelProvider) TableCombo(org.eclipse.nebula.widgets.tablecombo.TableCombo) DynamicDistributionsLabelProvider(org.talend.repository.hadoopcluster.ui.dynamic.form.labelprovider.DynamicDistributionsLabelProvider) SparkVersionsLabelProvider(org.talend.repository.hadoopcluster.ui.dynamic.form.labelprovider.SparkVersionsLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 3 with ESparkVersion

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

the class DynamicDistributionOptionForm method getSelectedSparkVersionsText.

private String getSelectedSparkVersionsText() {
    // $NON-NLS-1$
    String selectionText = "";
    Collections.sort(selectedSparkVersions, Collections.reverseOrder(ESparkVersion.descComparator()));
    for (ESparkVersion version : selectedSparkVersions) {
        if (!selectionText.isEmpty()) {
            // $NON-NLS-1$
            selectionText = selectionText + ", ";
        }
        selectionText = selectionText + version.getVersionLabel();
    }
    return selectionText;
}
Also used : ESparkVersion(org.talend.hadoop.distribution.ESparkVersion)

Example 4 with ESparkVersion

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

the class DynamicDistributionOptionForm method addListeners.

protected void addListeners() {
    newConfigBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            onNewConfigSelected(newConfigBtn.getSelection());
            updateButtons();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            onNewConfigSelected(newConfigBtn.getSelection());
            updateButtons();
        }
    });
    versionsComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            onSelectVersion();
            updateButtons();
        }
    });
    sparkVersionsComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            onSparkVersionsSelected(event);
            updateButtons();
        }
    });
    sparkVersionsComboViewer.getTableCombo().getTable().addFocusListener(new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent e) {
            for (ESparkVersion sparkVersion : selectedSparkVersions) {
                sparkVersionsComboViewer.update(sparkVersion, null);
            }
        }
    });
    refreshButton.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            onRefreshBtnClicked();
            updateButtons();
        }
    });
    showOnlyCompatibleBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            onRefreshBtnClicked();
            updateButtons();
        }
    });
    editExistingConfigBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            onEditExistingSelected(editExistingConfigBtn.getSelection());
            updateButtons();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            onEditExistingSelected(editExistingConfigBtn.getSelection());
            updateButtons();
        }
    });
    importConfigBtn.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            onImportConfigSelected(importConfigBtn.getSelection());
            updateButtons();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            onImportConfigSelected(importConfigBtn.getSelection());
            updateButtons();
        }
    });
    existingConfigsComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

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

        @Override
        public void widgetSelected(SelectionEvent e) {
            try {
                onImportConfigBrowseBtnSelected();
                updateButtons();
            } catch (Exception ex) {
                importConfigText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
                importConfigText.setToolTipText(ex.getMessage());
                showMessage(ex.getMessage(), WizardPage.ERROR);
                ExceptionHandler.process(ex);
            }
        }
    });
}
Also used : ESparkVersion(org.talend.hadoop.distribution.ESparkVersion) FocusAdapter(org.eclipse.swt.events.FocusAdapter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with ESparkVersion

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

the class ComponentConditionUtilTest method generateSparkVersionShowIfConditionsTest.

@Ignore
public void generateSparkVersionShowIfConditionsTest() {
    assertNull(ComponentConditionUtil.generateSparkVersionShowIfConditions(null));
    Map<ESparkVersion, Set<DistributionVersion>> sparkVersionsMap = new HashMap<>();
    Set<DistributionVersion> distributionVersions = new LinkedHashSet<>();
    distributionVersions.add(new DistributionVersion(null, new DistributionBean(ComponentType.SPARKBATCH, "DISTRIB1", ""), "VERSION1", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    ""));
    sparkVersionsMap.put(ESparkVersion.SPARK_2_0, distributionVersions);
    distributionVersions = new LinkedHashSet<>();
    distributionVersions.add(new DistributionVersion(null, new DistributionBean(ComponentType.SPARKBATCH, "DISTRIB2", ""), "VERSION2", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    ""));
    distributionVersions.add(new DistributionVersion(null, new DistributionBean(ComponentType.SPARKBATCH, "DISTRIB3", ""), "VERSION3", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    ""));
    sparkVersionsMap.put(ESparkVersion.SPARK_1_6, distributionVersions);
    String[] showIfs = ComponentConditionUtil.generateSparkVersionShowIfConditions(sparkVersionsMap);
    assertTrue(showIfs.length == 2);
    // $NON-NLS-1$
    assertThat(Arrays.asList(showIfs), hasItem("(((DISTRIBUTION=='DISTRIB1') AND (SPARK_VERSION=='VERSION1')))"));
    assertThat(Arrays.asList(showIfs), // $NON-NLS-1$
    hasItem("(((DISTRIBUTION=='DISTRIB2') AND (SPARK_VERSION=='VERSION2')) OR ((DISTRIBUTION=='DISTRIB3') AND (SPARK_VERSION=='VERSION3')))"));
}
Also used : ESparkVersion(org.talend.hadoop.distribution.ESparkVersion) DistributionVersion(org.talend.hadoop.distribution.model.DistributionVersion) DistributionBean(org.talend.hadoop.distribution.model.DistributionBean) Ignore(org.junit.Ignore)

Aggregations

ESparkVersion (org.talend.hadoop.distribution.ESparkVersion)13 ArrayList (java.util.ArrayList)4 HashSet (java.util.HashSet)2 List (java.util.List)2 IDynamicConfiguration (org.talend.core.runtime.dynamic.IDynamicConfiguration)2 DynamicConfiguration (org.talend.hadoop.distribution.dynamic.DynamicConfiguration)2 TemplateBean (org.talend.hadoop.distribution.dynamic.bean.TemplateBean)2 DistributionVersion (org.talend.hadoop.distribution.model.DistributionVersion)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)1