Search in sources :

Example 1 with DynamicDistributionSetupData

use of org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupData in project tbd-studio-se by Talend.

the class DynamicDistributionOptionForm method checkImportConfigText.

private boolean checkImportConfigText() {
    try {
        if (!importConfigBtn.getSelection()) {
            return true;
        }
        StringBuffer messageBuffer = new StringBuffer();
        importConfigText.setBackground(null);
        importConfigText.setToolTipText(importConfigText.getText());
        String importConfig = importConfigText.getText();
        if (StringUtils.isEmpty(importConfig)) {
            // $NON-NLS-1$
            String errorMessage = Messages.getString("DynamicDistributionOptionForm.importConfigText.check.empty");
            showMessage(errorMessage, WizardPage.ERROR);
            importConfigText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
            importConfigText.setToolTipText(errorMessage);
            return false;
        }
        if (importedDynamicPlugin == null) {
            // $NON-NLS-1$
            String errorMessage = Messages.getString("DynamicDistributionOptionForm.importConfigText.check.empty");
            importConfigText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
            importConfigText.setToolTipText(errorMessage);
            showMessage(errorMessage, WizardPage.ERROR);
            return false;
        }
        // 1. check plugin configuration
        IDynamicPluginConfiguration pluginConfiguration = importedDynamicPlugin.getPluginConfiguration();
        if (pluginConfiguration == null) {
            // $NON-NLS-1$
            String errorMessage = Messages.getString("DynamicDistributionOptionForm.importConfigText.check.noConfiguration");
            importConfigText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
            importConfigText.setToolTipText(errorMessage);
            showMessage(errorMessage, WizardPage.ERROR);
            return false;
        }
        DynamicDistributionSetupData dynamicBuildConfigurationData = getDynamicDistributionSetupData();
        // 2. check distribution
        IDynamicDistributionsGroup dynamicDistributionsGroup = dynamicBuildConfigurationData.getDynamicDistributionsGroup();
        if (!dynamicDistributionsGroup.getDistribution().equalsIgnoreCase(pluginConfiguration.getDistribution())) {
            String errorMessage = // $NON-NLS-1$
            Messages.getString(// $NON-NLS-1$
            "DynamicDistributionOptionForm.importConfigText.check.wrongDistribution", pluginConfiguration.getDistribution(), dynamicDistributionsGroup.getDistribution());
            importConfigText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
            importConfigText.setToolTipText(errorMessage);
            showMessage(errorMessage, WizardPage.ERROR);
            return false;
        }
        // 3. check id
        boolean isIdSame = false;
        String id = pluginConfiguration.getId();
        if (StringUtils.isEmpty(id)) {
            // $NON-NLS-1$
            String errorMessage = Messages.getString("DynamicDistributionOptionForm.importConfigText.check.badId.empty");
            importConfigText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
            importConfigText.setToolTipText(errorMessage);
            showMessage(errorMessage, WizardPage.ERROR);
            return false;
        }
        if (id.contains(".")) {
            // $NON-NLS-1$
            String errorMessage = // $NON-NLS-1$
            Messages.getString(// $NON-NLS-1$
            "DynamicDistributionOptionForm.importConfigText.check.badId.invalid", id);
            importConfigText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
            importConfigText.setToolTipText(errorMessage);
            showMessage(errorMessage, WizardPage.ERROR);
            return false;
        }
        IDynamicPlugin existingDynamicPlugin = getDynamicPluginById(id);
        if (existingDynamicPlugin != null) {
            IDynamicPluginConfiguration existingPluginConfig = existingDynamicPlugin.getPluginConfiguration();
            String distribution = existingPluginConfig.getDistribution();
            if (!dynamicDistributionsGroup.getDistribution().equalsIgnoreCase(distribution)) {
                String errorMessage = Messages.getString(// $NON-NLS-1$
                "DynamicDistributionOptionForm.importConfigText.check.badId.exist.diffDistribution", // $NON-NLS-1$
                id, dynamicDistributionsGroup.getDistribution(), // $NON-NLS-1$
                distribution);
                importConfigText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
                importConfigText.setToolTipText(errorMessage);
                showMessage(errorMessage, WizardPage.ERROR);
                return false;
            }
            String errorMessage = Messages.getString(// $NON-NLS-1$
            "DynamicDistributionOptionForm.importConfigText.check.badId.exist.sameDistribution", id);
            // $NON-NLS-1$
            messageBuffer.append(errorMessage).append("\n");
            isIdSame = true;
        }
        // 4. check name
        String name = pluginConfiguration.getName();
        if (!isIdSame && isConfigurationNameExist(name)) {
            Calendar cal = Calendar.getInstance();
            Date date = cal.getTime();
            String newName = name + // $NON-NLS-1$
            Messages.getString(// $NON-NLS-1$
            "DynamicDistributionOptionForm.importConfigText.check.badName.exist.desc", date.toString());
            pluginConfiguration.setName(newName);
            String errorMessage = // $NON-NLS-1$
            Messages.getString(// $NON-NLS-1$
            "DynamicDistributionOptionForm.importConfigText.check.badName.exist", name, newName);
            // $NON-NLS-1$
            messageBuffer.append(errorMessage).append("\n");
        }
        if (0 < messageBuffer.length()) {
            String warnMessage = messageBuffer.toString();
            importConfigText.setBackground(LoginDialogV2.YELLOW_COLOR);
            importConfigText.setToolTipText(warnMessage);
            showMessage(warnMessage, WizardPage.WARNING);
        }
        pluginConfiguration.setAttribute(DynamicConstants.ATTR_PROJECT_TECHNICAL_NAME, ProjectManager.getInstance().getCurrentProject().getTechnicalLabel());
        getDynamicDistributionSetupData().setDynamicPlugin(importedDynamicPlugin);
        return true;
    } catch (Exception e) {
        importConfigText.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
        importConfigText.setToolTipText(e.getMessage());
        return false;
    }
}
Also used : IDynamicDistributionsGroup(org.talend.hadoop.distribution.dynamic.IDynamicDistributionsGroup) IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin) Calendar(java.util.Calendar) DynamicDistributionSetupData(org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupData) IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration) Date(java.util.Date) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with DynamicDistributionSetupData

use of org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupData in project tbd-studio-se by Talend.

the class DynamicDistributionOptionForm method getVersionList.

private List<String> getVersionList() throws Exception {
    final List<List<String>> result = new ArrayList<>();
    try {
        DynamicDistributionSetupData dynConfigData = getDynamicDistributionSetupData();
        IDynamicDistributionsGroup dynDistrGroup = dynConfigData.getDynamicDistributionsGroup();
        final Throwable[] throwable = new Throwable[1];
        final boolean showOnlyCompatibleVersions = showOnlyCompatibleBtn.getSelection();
        run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    IDynamicMonitor dMonitor = new AbsDynamicProgressMonitor(monitor) {

                        @Override
                        public void writeMessage(String message) {
                            if (isDebuging()) {
                                System.out.print(message);
                            }
                        }
                    };
                    // $NON-NLS-1$
                    dMonitor.beginTask(// $NON-NLS-1$
                    Messages.getString("DynamicDistributionOptionForm.progress.fetchVersions"), IDynamicMonitor.UNKNOWN);
                    List<String> version = null;
                    if (showOnlyCompatibleVersions) {
                        version = dynDistrGroup.getCompatibleVersions(dMonitor);
                    } else {
                        version = dynDistrGroup.getAllVersions(dMonitor);
                    }
                    result.add(version);
                } catch (Exception e) {
                    throwable[0] = e;
                }
            }
        });
        if (throwable[0] != null) {
            throw throwable[0];
        }
    } catch (Throwable ex) {
        ExceptionHandler.process(ex);
        String message = ex.getMessage();
        if (StringUtils.isEmpty(message)) {
            // $NON-NLS-1$
            message = Messages.getString("ExceptionDialog.message.empty");
        }
        // $NON-NLS-1$
        ExceptionMessageDialog.openError(getShell(), Messages.getString("ExceptionDialog.title"), message, ex);
    }
    if (result.isEmpty()) {
        return null;
    }
    return result.get(0);
}
Also used : ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDynamicDistributionsGroup(org.talend.hadoop.distribution.dynamic.IDynamicDistributionsGroup) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) DynamicDistributionSetupData(org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupData) IDynamicMonitor(org.talend.designer.maven.aether.IDynamicMonitor) AbsDynamicProgressMonitor(org.talend.designer.maven.aether.AbsDynamicProgressMonitor)

Example 3 with DynamicDistributionSetupData

use of org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupData in project tbd-studio-se by Talend.

the class DynamicDistributionOptionForm method createNewDynamicDistribution.

private boolean createNewDynamicDistribution() {
    try {
        final IDynamicPlugin[] result = new IDynamicPlugin[1];
        final Throwable[] throwable = new Throwable[1];
        run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    DynamicDistributionSetupData dynConfigData = getDynamicDistributionSetupData();
                    IDynamicDistributionsGroup dynDistrGroup = dynConfigData.getDynamicDistributionsGroup();
                    IDynamicMonitor dMonitor = new AbsDynamicProgressMonitor(monitor) {

                        @Override
                        public void writeMessage(String message) {
                            if (isDebuging()) {
                                System.out.print(message);
                            }
                        }
                    };
                    // step 1. build dynamic plugin basing on template
                    dMonitor.beginTask(// $NON-NLS-1$
                    Messages.getString(// $NON-NLS-1$
                    "DynamicDistributionOptionForm.progress.building", dynamicConfiguration.getName()), IDynamicMonitor.UNKNOWN);
                    IDynamicPlugin dynamicPlugin = dynDistrGroup.buildDynamicPlugin(dMonitor, dynamicConfiguration);
                    result[0] = dynamicPlugin;
                    // step 2. save dynamic plugin and refresh cache
                    if (dynamicPlugin != null) {
                        saveDynamicDistribution(dynamicPlugin, dynDistrGroup, ActionType.NewConfig, dMonitor);
                    }
                } catch (Throwable e) {
                    throwable[0] = e;
                }
            }
        });
        if (throwable[0] != null) {
            throw throwable[0];
        }
        IDynamicPlugin newDynamicPlugin = result[0];
        if (newDynamicPlugin == null) {
            // $NON-NLS-1$
            throw new Exception(Messages.getString("DynamicDistributionOptionForm.newConfig.exception.noPluginGenerated"));
        }
        return true;
    } catch (Throwable e) {
        ExceptionHandler.process(e);
        String message = e.getMessage();
        if (StringUtils.isEmpty(message)) {
            // $NON-NLS-1$
            message = Messages.getString("ExceptionDialog.message.empty");
        }
        // $NON-NLS-1$
        ExceptionMessageDialog.openError(getShell(), Messages.getString("ExceptionDialog.title"), message, e);
    }
    return false;
}
Also used : IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IDynamicDistributionsGroup(org.talend.hadoop.distribution.dynamic.IDynamicDistributionsGroup) DynamicDistributionSetupData(org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupData) IDynamicMonitor(org.talend.designer.maven.aether.IDynamicMonitor) AbsDynamicProgressMonitor(org.talend.designer.maven.aether.AbsDynamicProgressMonitor)

Example 4 with DynamicDistributionSetupData

use of org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupData in project tbd-studio-se by Talend.

the class DynamicDistributionDetailsForm method performOk.

@Override
public boolean performOk() {
    try {
        final Throwable[] throwable = new Throwable[1];
        run(true, true, new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                DynamicDistributionSetupData dynamicBuildConfigurationData = getDynamicDistributionSetupData();
                try {
                    IDynamicMonitor dMonitor = new AbsDynamicProgressMonitor(monitor) {

                        @Override
                        public void writeMessage(String message) {
                            if (isDebuging()) {
                                System.out.print(message);
                            }
                        }
                    };
                    saveDynamicDistribution(newDynamicPluginCache, dynamicBuildConfigurationData.getDynamicDistributionsGroup(), dynamicBuildConfigurationData.getActionType(), dMonitor);
                } catch (Exception e) {
                    throwable[0] = e;
                }
            }
        });
        if (throwable[0] != null) {
            throw throwable[0];
        }
        return true;
    } catch (Throwable e) {
        ExceptionHandler.process(e);
        String message = e.getMessage();
        if (StringUtils.isEmpty(message)) {
            // $NON-NLS-1$
            message = Messages.getString("ExceptionDialog.message.empty");
        }
        // $NON-NLS-1$
        ExceptionMessageDialog.openError(getShell(), Messages.getString("ExceptionDialog.title"), message, e);
    }
    return false;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) DynamicDistributionSetupData(org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupData) InvocationTargetException(java.lang.reflect.InvocationTargetException) IDynamicMonitor(org.talend.designer.maven.aether.IDynamicMonitor) AbsDynamicProgressMonitor(org.talend.designer.maven.aether.AbsDynamicProgressMonitor) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress)

Example 5 with DynamicDistributionSetupData

use of org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupData in project tbd-studio-se by Talend.

the class DynamicDistributionDetailsForm method initData.

private void initData() {
    try {
        DynamicDistributionSetupData dynConfigData = getDynamicDistributionSetupData();
        IDynamicPlugin originPlugin = dynConfigData.getDynamicPlugin();
        if (originPlugin == originPluginCache) {
            return;
        }
        originPluginCache = originPlugin;
        newDynamicPluginCache = DynamicFactory.getInstance().createPluginFromJson(originPluginCache.toXmlJson().toString());
        IDynamicPluginConfiguration pluginConfiguration = newDynamicPluginCache.getPluginConfiguration();
        String name = (String) pluginConfiguration.getAttribute(DynamicConstants.ATTR_USER_INPUTED_NAME);
        if (StringUtils.isEmpty(name)) {
            name = pluginConfiguration.getName();
        }
        nameCache = name;
        dynamicConfigNameText.setText(name);
        initTableViewData(newDynamicPluginCache);
    } catch (Exception e) {
        ExceptionHandler.process(e);
        String message = e.getMessage();
        if (StringUtils.isEmpty(message)) {
            // $NON-NLS-1$
            message = Messages.getString("ExceptionDialog.message.empty");
        }
        // $NON-NLS-1$
        ExceptionMessageDialog.openError(getShell(), Messages.getString("ExceptionDialog.title"), message, e);
    }
}
Also used : IDynamicPlugin(org.talend.core.runtime.dynamic.IDynamicPlugin) DynamicDistributionSetupData(org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupData) IDynamicPluginConfiguration(org.talend.core.runtime.dynamic.IDynamicPluginConfiguration) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

DynamicDistributionSetupData (org.talend.repository.hadoopcluster.ui.dynamic.DynamicDistributionSetupData)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 IDynamicDistributionsGroup (org.talend.hadoop.distribution.dynamic.IDynamicDistributionsGroup)6 IDynamicPlugin (org.talend.core.runtime.dynamic.IDynamicPlugin)4 IDynamicMonitor (org.talend.designer.maven.aether.IDynamicMonitor)4 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)3 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)3 IDynamicPluginConfiguration (org.talend.core.runtime.dynamic.IDynamicPluginConfiguration)3 AbsDynamicProgressMonitor (org.talend.designer.maven.aether.AbsDynamicProgressMonitor)3 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 DummyDynamicMonitor (org.talend.designer.maven.aether.DummyDynamicMonitor)2 DynamicConfiguration (org.talend.hadoop.distribution.dynamic.DynamicConfiguration)2 Calendar (java.util.Calendar)1 Date (java.util.Date)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1