Search in sources :

Example 11 with JobletProcessItem

use of org.talend.core.model.properties.JobletProcessItem in project tdi-studio-se by Talend.

the class RemoveDuplicatedContextGroupMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    List<?> contexts = null;
    if (item instanceof ProcessItem) {
        // process, process_mr, process_storm, route, routelet.
        ProcessItem processItem = (ProcessItem) item;
        contexts = processItem.getProcess().getContext();
    } else if (item instanceof JobletProcessItem) {
        JobletProcessItem jobletItem = (JobletProcessItem) item;
        contexts = jobletItem.getJobletProcess().getContext();
    }
    Set<String> nameSet = new HashSet<String>();
    Iterator<?> iterator = contexts.listIterator();
    int count = 0;
    while (iterator.hasNext()) {
        Object obj = iterator.next();
        if (obj instanceof ContextType) {
            ContextType context = (ContextType) obj;
            if (nameSet.contains(context.getName())) {
                iterator.remove();
                count++;
            } else {
                nameSet.add(context.getName());
            }
        }
    }
    if (count > 0) {
        try {
            ProxyRepositoryFactory.getInstance().save(item, true);
            return ExecutionResult.SUCCESS_NO_ALERT;
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    } else {
        return ExecutionResult.NOTHING_TO_DO;
    }
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) PersistenceException(org.talend.commons.exception.PersistenceException) HashSet(java.util.HashSet)

Example 12 with JobletProcessItem

use of org.talend.core.model.properties.JobletProcessItem in project tdi-studio-se by Talend.

the class FixUnevenItemContextParametersMigrationTask method execute.

@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
    EList<ContextType> contexts = null;
    String defualtGroupName = null;
    if (item instanceof ProcessItem) {
        // process, process_mr, process_storm, route, routelet.
        ProcessItem processItem = (ProcessItem) item;
        contexts = processItem.getProcess().getContext();
        defualtGroupName = processItem.getProcess().getDefaultContext();
    } else if (item instanceof JobletProcessItem) {
        JobletProcessItem jobletItem = (JobletProcessItem) item;
        contexts = jobletItem.getJobletProcess().getContext();
        defualtGroupName = jobletItem.getJobletProcess().getDefaultContext();
    } else if (item instanceof ContextItem) {
        ContextItem contextItem = (ContextItem) item;
        contexts = contextItem.getContext();
        defualtGroupName = contextItem.getDefaultContext();
    }
    try {
        ContextType defaultGroup = null;
        for (ContextType context : contexts) {
            if (context.getName().equals(defualtGroupName)) {
                defaultGroup = context;
                break;
            }
        }
        if (defaultGroup == null && contexts.size() > 0) {
            defaultGroup = contexts.get(0);
        }
        boolean contextChanged = false;
        if (defaultGroup != null) {
            Map<String, ContextParameterType> paramMap = new HashMap<String, ContextParameterType>();
            List<String> paramNameList = new ArrayList<String>();
            paramMap.putAll(collectDefaultGroupParams(defaultGroup, paramNameList));
            for (ContextType context : contexts) {
                if (context == defaultGroup) {
                    continue;
                }
                Map<String, ContextParameterType> otherGroupParam = collectDefaultGroupParams(context, paramNameList);
                for (String paramName : otherGroupParam.keySet()) {
                    if (!paramMap.containsKey(paramName)) {
                        paramMap.put(paramName, otherGroupParam.get(paramName));
                    }
                }
            }
            // make sure all groups have the same param list
            for (ContextType context : contexts) {
                EList<ContextParameterType> params = context.getContextParameter();
                List<String> paramNames = new ArrayList<String>(paramNameList);
                for (ContextParameterType param : params) {
                    if (paramNames.contains(param.getName())) {
                        paramNames.remove(param.getName());
                    }
                }
                if (!paramNames.isEmpty()) {
                    contextChanged = true;
                    for (String paramToAdd : paramNames) {
                        ContextParameterType toAdd = paramMap.get(paramToAdd);
                        context.getContextParameter().add(EcoreUtil.copy(toAdd));
                    }
                }
            }
            // change param order if needed
            for (ContextType context : contexts) {
                EList<ContextParameterType> params = context.getContextParameter();
                List<ContextParameterType> copyOfParam = new ArrayList<ContextParameterType>(params);
                for (int i = 0; i < copyOfParam.size(); i++) {
                    ContextParameterType param = copyOfParam.get(i);
                    int indexOf = paramNameList.indexOf(param.getName());
                    if (i != indexOf) {
                        contextChanged = true;
                        params.remove(param);
                        params.add(indexOf, param);
                    }
                }
            }
            // make sure params in different groups have the same repository id and type as default group
            for (ContextType context : contexts) {
                EList<ContextParameterType> params = context.getContextParameter();
                for (ContextParameterType param : params) {
                    ContextParameterType paramDefault = paramMap.get(param.getName());
                    if (!paramDefault.getType().equals(param.getType())) {
                        contextChanged = true;
                        param.setType(paramDefault.getType());
                    }
                    if (paramDefault.getRepositoryContextId() == null && param.getRepositoryContextId() != null || (paramDefault.getRepositoryContextId() != null && !paramDefault.getRepositoryContextId().equals(param.getRepositoryContextId()))) {
                        contextChanged = true;
                        param.setRepositoryContextId(paramDefault.getRepositoryContextId());
                    }
                }
            }
        }
        if (contextChanged) {
            ProxyRepositoryFactory.getInstance().save(item, true);
            return ExecutionResult.SUCCESS_NO_ALERT;
        }
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ContextItem(org.talend.core.model.properties.ContextItem) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) PersistenceException(org.talend.commons.exception.PersistenceException) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 13 with JobletProcessItem

use of org.talend.core.model.properties.JobletProcessItem in project tdi-studio-se by Talend.

the class AbstractMultiPageTalendEditor method updateCodeEditorContent.

private void updateCodeEditorContent() {
    if (!(processor.getProperty().getItem() instanceof JobletProcessItem)) {
        FileEditorInput input = createFileEditorInput();
        codeEditor.setInput(input);
    }
}
Also used : JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) FileEditorInput(org.eclipse.ui.part.FileEditorInput)

Example 14 with JobletProcessItem

use of org.talend.core.model.properties.JobletProcessItem in project tdi-studio-se by Talend.

the class AbstractMultiPageTalendEditor method covertJobscriptOnPageChange.

private void covertJobscriptOnPageChange() {
    try {
        boolean isDirty = jobletEditor.isDirty();
        jobletEditor.doSave(null);
        IProcess2 oldProcess = getProcess();
        ICreateXtextProcessService n = CorePlugin.getDefault().getCreateXtextProcessService();
        Item item = oldProcess.getProperty().getItem();
        ProcessType processType = null;
        if (item instanceof ProcessItem) {
            processType = n.convertDesignerEditorInput(((IFile) jobletEditor.getEditorInput().getAdapter(IResource.class)).getLocation().toOSString(), oldProcess.getProperty());
        } else if (item instanceof JobletProcessItem) {
            processType = n.convertJobletDesignerEditorInput(((IFile) jobletEditor.getEditorInput().getAdapter(IResource.class)).getLocation().toOSString(), oldProcess.getProperty());
        }
        if (item instanceof ProcessItem) {
            ((Process) oldProcess).updateProcess(processType);
        } else if (item instanceof JobletProcessItem) {
            ((Process) oldProcess).updateProcess(processType);
        }
        oldProcess.getUpdateManager().updateAll();
        designerEditor.setDirty(isDirty);
        List<Node> nodes = (List<Node>) oldProcess.getGraphicalNodes();
        List<Node> newNodes = new ArrayList<Node>();
        newNodes.addAll(nodes);
        for (Node node : newNodes) {
            node.getProcess().checkStartNodes();
            node.checkAndRefreshNode();
            IElementParameter ep = node.getElementParameter("ACTIVATE");
            if (ep != null && ep.getValue().equals(Boolean.FALSE)) {
                node.setPropertyValue(EParameterName.ACTIVATE.getName(), true);
                node.setPropertyValue(EParameterName.ACTIVATE.getName(), false);
            } else if (ep != null && ep.getValue().equals(Boolean.TRUE)) {
                node.setPropertyValue(EParameterName.ACTIVATE.getName(), false);
                node.setPropertyValue(EParameterName.ACTIVATE.getName(), true);
            }
            for (IElementParameter param : node.getElementParameters()) {
                if (!param.getChildParameters().isEmpty()) {
                    if (param.getValue() != null && param.getValue() instanceof String && ((String) param.getValue()).contains(":")) {
                        String[] splited = ((String) param.getValue()).split(":");
                        String childNameNeeded = splited[0].trim();
                        String valueChild = TalendQuoteUtils.removeQuotes(splited[1].trim());
                        if (param.getChildParameters().containsKey(childNameNeeded)) {
                            param.getChildParameters().get(childNameNeeded).setValue(valueChild);
                        }
                    }
                }
            }
            if (node.getNodeContainer() instanceof JobletContainer) {
                JobletContainer jc = (JobletContainer) node.getNodeContainer();
                if (node.isMapReduceStart()) {
                    //$NON-NLS-1$
                    jc.updateState("UPDATE_STATUS", "", jc.getPercentMap(), jc.getPercentReduce());
                }
            }
        }
    } catch (PersistenceException e) {
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) AbstractJobletContainer(org.talend.designer.core.ui.editor.jobletcontainer.AbstractJobletContainer) JobletContainer(org.talend.designer.core.ui.editor.jobletcontainer.JobletContainer) INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) ICreateXtextProcessService(org.talend.core.services.ICreateXtextProcessService) Process(org.talend.designer.core.ui.editor.process.Process) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) IProcess2(org.talend.core.model.process.IProcess2) PersistenceException(org.talend.commons.exception.PersistenceException) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) List(java.util.List) IResource(org.eclipse.core.resources.IResource)

Example 15 with JobletProcessItem

use of org.talend.core.model.properties.JobletProcessItem in project tdi-studio-se by Talend.

the class ComponentChooseDialog method propaHadoopCfgChanges.

/**
     * DOC ycbai Comment method "propaHadoopCfgChanges".
     *
     * <P>
     * Propagate the changes from hadoop cluster to M/R process when drag&drop hadoop subnode from repository view to
     * M/R process.
     * </P>
     *
     * @param repositoryNode
     */
private void propaHadoopCfgChanges(IRepositoryNode repositoryNode) {
    if (repositoryNode == null || repositoryNode.getObject() == null) {
        return;
    }
    IHadoopClusterService hadoopClusterService = HadoopRepositoryUtil.getHadoopClusterService();
    if (hadoopClusterService == null || !hadoopClusterService.isHadoopSubnode(repositoryNode)) {
        return;
    }
    IProcess process = editor.getProcess();
    if (!ComponentCategory.CATEGORY_4_MAPREDUCE.getName().equals(process.getComponentsType()) && !ComponentCategory.CATEGORY_4_SPARK.getName().equals(process.getComponentsType()) && !ComponentCategory.CATEGORY_4_SPARKSTREAMING.getName().equals(process.getComponentsType())) {
        return;
    }
    if ((process instanceof IProcess2) && (((IProcess2) process).getProperty().getItem() instanceof JobletProcessItem)) {
        return;
    }
    Item subItem = repositoryNode.getObject().getProperty().getItem();
    String propertyParamName = MR_PROPERTY_PREFIX + EParameterName.PROPERTY_TYPE.getName();
    String propertyRepTypeParamName = MR_PROPERTY_PREFIX + EParameterName.REPOSITORY_PROPERTY_TYPE.getName();
    IElementParameter propertyParam = process.getElementParameter(propertyParamName);
    if (propertyParam == null) {
        return;
    }
    String repositoryValue = propertyParam.getRepositoryValue();
    if (repositoryValue == null) {
        return;
    }
    //$NON-NLS-1$
    String[] supportedRepositoryTypes = repositoryValue.split("\\|");
    String repositoryType = hadoopClusterService.getRepositoryTypeOfHadoopSubItem(subItem);
    if (!ArrayUtils.contains(supportedRepositoryTypes, repositoryType)) {
        return;
    }
    Item hadoopClusterItem = hadoopClusterService.getHadoopClusterBySubitemId(new Project(ProjectManager.getInstance().getProject(subItem)), subItem.getProperty().getId());
    String hadoopClusterId = hadoopClusterItem.getProperty().getId();
    if (EmfComponent.REPOSITORY.equals(propertyParam.getValue())) {
        // do nothing when select the same hadoop cluster.
        String propertyId = (String) process.getElementParameter(propertyRepTypeParamName).getValue();
        if (hadoopClusterId.equals(propertyId)) {
            return;
        }
    }
    Connection connection = ((ConnectionItem) subItem).getConnection();
    if (hadoopClusterService.hasDiffsFromClusterToProcess(subItem, process)) {
        boolean confirmUpdate = MessageDialog.openConfirm(editor.getSite().getShell(), //$NON-NLS-1$
        Messages.getString("TalendEditorDropTargetListener.updateHadoopCfgDialog.title"), //$NON-NLS-1$
        Messages.getString("TalendEditorDropTargetListener.updateHadoopCfgDialog.msg"));
        if (confirmUpdate) {
            // Update spark mode to YARN_CLIENT if repository
            if (ComponentCategory.CATEGORY_4_SPARK.getName().equals(process.getComponentsType()) || ComponentCategory.CATEGORY_4_SPARKSTREAMING.getName().equals(process.getComponentsType())) {
                IElementParameter sparkLocalParam = process.getElementParameter(HadoopConstants.SPARK_LOCAL_MODE);
                IElementParameter sparkParam = process.getElementParameter(HadoopConstants.SPARK_MODE);
                if (sparkLocalParam != null && (Boolean) (sparkLocalParam.getValue())) {
                    sparkLocalParam.setValue(false);
                }
                if (sparkParam != null && !HadoopConstants.SPARK_MODE_YARN_CLIENT.equals(sparkParam.getValue())) {
                    sparkParam.setValue(HadoopConstants.SPARK_MODE_YARN_CLIENT);
                }
            }
            propertyParam.setValue(EmfComponent.REPOSITORY);
            ChangeValuesFromRepository command = new ChangeValuesFromRepository(process, connection, propertyRepTypeParamName, subItem.getProperty().getId());
            execCommandStack(command);
        }
    }
}
Also used : ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) EbcdicConnectionItem(org.talend.core.model.properties.EbcdicConnectionItem) HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) PolylineConnection(org.eclipse.draw2d.PolylineConnection) MDMConnection(org.talend.core.model.metadata.builder.connection.MDMConnection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) CDCConnection(org.talend.core.model.metadata.builder.connection.CDCConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) EbcdicConnectionItem(org.talend.core.model.properties.EbcdicConnectionItem) RulesItem(org.talend.core.model.properties.RulesItem) HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) FileItem(org.talend.core.model.properties.FileItem) Project(org.talend.core.model.general.Project) IHadoopClusterService(org.talend.core.hadoop.IHadoopClusterService) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) IProcess2(org.talend.core.model.process.IProcess2) IElementParameter(org.talend.core.model.process.IElementParameter) IProcess(org.talend.core.model.process.IProcess)

Aggregations

JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)40 ProcessItem (org.talend.core.model.properties.ProcessItem)30 Item (org.talend.core.model.properties.Item)21 PersistenceException (org.talend.commons.exception.PersistenceException)18 ArrayList (java.util.ArrayList)17 IProcess2 (org.talend.core.model.process.IProcess2)13 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)12 List (java.util.List)11 EList (org.eclipse.emf.common.util.EList)11 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)10 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)9 INode (org.talend.core.model.process.INode)8 ContextItem (org.talend.core.model.properties.ContextItem)8 Point (org.eclipse.draw2d.geometry.Point)7 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)7 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 JobletProcess (org.talend.designer.joblet.model.JobletProcess)6 IOException (java.io.IOException)5 CoreException (org.eclipse.core.runtime.CoreException)5