Search in sources :

Example 26 with IContext

use of org.talend.core.model.process.IContext in project tdi-studio-se by Talend.

the class OpenContextChooseComboDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    // basicComp = new Composite(parent.getShell(), SWT.NONE);
    basicComp = (Composite) super.createDialogArea(parent);
    basicComp.setLayout(new FormLayout());
    basicComp.setSize(200, 200);
    Label label = new Label(basicComp, SWT.NONE);
    //$NON-NLS-1$
    label.setText(Messages.getString("OpenContextChooseComboDialog.context"));
    contextCombo = new Combo(basicComp, SWT.DROP_DOWN | SWT.READ_ONLY);
    // layout for label
    FormData labelCompData = new FormData();
    labelCompData.top = new FormAttachment(20, 0);
    labelCompData.bottom = new FormAttachment(50, 10);
    labelCompData.left = new FormAttachment(0, 10);
    labelCompData.right = new FormAttachment(contextCombo, 0);
    label.setLayoutData(labelCompData);
    // layout for combo
    FormData contexComboFormData = new FormData();
    contexComboFormData.top = new FormAttachment(10, 0);
    contexComboFormData.bottom = new FormAttachment(50, 10);
    contexComboFormData.left = new FormAttachment(label, 30);
    contexComboFormData.right = new FormAttachment(60, 10);
    contextCombo.setLayoutData(contexComboFormData);
    List<String> names = new ArrayList<String>();
    for (IContext context : allContexts) {
        if (context != null) {
            String name = context.getName();
            names.add(name);
        }
    }
    contextCombo.setItems(names.toArray(new String[0]));
    contextCombo.select(0);
    return basicComp;
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) FormData(org.eclipse.swt.layout.FormData) IContext(org.talend.core.model.process.IContext) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) Combo(org.eclipse.swt.widgets.Combo) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 27 with IContext

use of org.talend.core.model.process.IContext in project tdi-studio-se by Talend.

the class ExportProcessorHelper method exportJob.

public String exportJob(Processor processor, int statisticsPort, int tracePort, String watchParam, String log4jLevel, final IProgressMonitor progressMonitor) throws ProcessorException {
    ProcessItem processItem = (ProcessItem) processor.getProperty().getItem();
    processName = processor.getProperty().getLabel();
    //$NON-NLS-1$
    File archiveFile = new File(getTmpExportFolder(), "remote_run_export-" + processName + FileExtensions.ZIP_FILE_SUFFIX);
    Properties prop = new Properties();
    if (watchParam != null) {
        prop.setProperty(TalendProcessArgumentConstant.ARG_ENABLE_WATCH, watchParam);
    }
    // FIXME, maybe should try another way. it's not good, I think.
    // update directly the .item (without save it) in case of prompt
    // then the generation will be correct automatically in the .properties
    IContext context = processor.getContext();
    if (context != null) {
        List<IContextParameter> contextParameterList = context.getContextParameterList();
        if (contextParameterList != null && contextParameterList.size() > 0) {
            for (IContextParameter contextParameter : contextParameterList) {
                if (!contextParameter.isPromptNeeded()) {
                    continue;
                }
                for (Object curCType : processItem.getProcess().getContext()) {
                    ContextType cType = (ContextType) curCType;
                    if (context.getName().equals(cType.getName())) {
                        for (Object curParam : cType.getContextParameter()) {
                            ContextParameterType cParamType = (ContextParameterType) curParam;
                            if (contextParameter.getName().equals(cParamType.getName())) {
                                cParamType.setRawValue(contextParameter.getValue());
                            }
                        }
                    }
                }
            }
        }
    }
    export(progressMonitor, processItem, ERepositoryObjectType.getItemType(processItem), processor.getContext().getName(), archiveFile.toString(), log4jLevel, false, statisticsPort, tracePort, prop);
    return archiveFile.toString();
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) IContext(org.talend.core.model.process.IContext) ProcessItem(org.talend.core.model.properties.ProcessItem) Properties(java.util.Properties) File(java.io.File) IContextParameter(org.talend.core.model.process.IContextParameter) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 28 with IContext

use of org.talend.core.model.process.IContext in project tdi-studio-se by Talend.

the class RunProcessContext method exec.

/**
     * Launch the process.
     */
public void exec(final Shell shell) {
    if (process instanceof org.talend.designer.core.ui.editor.process.Process) {
        org.talend.designer.core.ui.editor.process.Process prs = (org.talend.designer.core.ui.editor.process.Process) process;
        prs.checkDifferenceWithRepository();
    }
    checkTraces();
    if (ProcessContextComposite.promptConfirmLauch(shell, getSelectedContext(), process)) {
        if (getSelectedTargetExecutionConfig() == null || !getSelectedTargetExecutionConfig().isRemote()) {
            // tos run to collect
            IPreferenceStore preferenceStore = RunProcessPlugin.getDefault().getPreferenceStore();
            int num = preferenceStore.getInt(RunProcessTokenCollector.TOS_COUNT_RUNS.getPrefKey());
            preferenceStore.setValue(RunProcessTokenCollector.TOS_COUNT_RUNS.getPrefKey(), num + 1);
        }
        ClearPerformanceAction clearPerfAction = new ClearPerformanceAction();
        clearPerfAction.setProcess(process);
        clearPerfAction.run();
        ClearTraceAction clearTraceAction = new ClearTraceAction();
        clearTraceAction.setProcess(process);
        clearTraceAction.run();
        if (monitorPerf) {
            this.getStatisticsPort();
        }
        final IProcessor processor = getProcessor(process, process.getProperty());
        IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
        try {
            progressService.run(false, true, new IRunnableWithProgress() {

                @Override
                public void run(final IProgressMonitor monitor) {
                    final IProgressMonitor progressMonitor = new EventLoopProgressMonitor(monitor);
                    //$NON-NLS-1$
                    progressMonitor.beginTask(Messages.getString("ProcessComposite.buildTask"), IProgressMonitor.UNKNOWN);
                    testPort();
                    // findNewStatsPort();
                    if (monitorPerf || monitorTrace) {
                        if (traceConnectionsManager != null) {
                            traceConnectionsManager.clear();
                        }
                        traceConnectionsManager = getTraceConnectionsManager(process);
                        traceConnectionsManager.init();
                    }
                    final IContext context = getSelectedContext();
                    if (monitorPerf) {
                        clearThreads();
                        perfMonitor = getPerformanceMonitor();
                        //$NON-NLS-1$
                        new Thread(perfMonitor, "PerfMonitor_" + process.getLabel()).start();
                        perMonitorList.add(perfMonitor);
                    }
                    // findNewTracesPort();
                    if (monitorTrace) {
                        traceMonitor = new TraceMonitor();
                        //$NON-NLS-1$
                        new Thread(traceMonitor, "TraceMonitor_" + process.getLabel()).start();
                    }
                    final String watchParam = RunProcessContext.this.isWatchAllowed() ? TalendProcessArgumentConstant.CMD_ARG_WATCH : null;
                    final String log4jRuntimeLevel = getLog4jRuntimeLevel();
                    processor.setContext(context);
                    ((IEclipseProcessor) processor).setTargetExecutionConfig(getSelectedTargetExecutionConfig());
                    final boolean oldMeasureActived = TimeMeasure.measureActive;
                    if (!oldMeasureActived) {
                        // not active before.
                        TimeMeasure.display = TimeMeasure.displaySteps = TimeMeasure.measureActive = CommonsPlugin.isDebugMode();
                    }
                    //$NON-NLS-1$
                    final String generateCodeId = "Generate job source codes and compile before run";
                    TimeMeasure.begin(generateCodeId);
                    try {
                        ProcessorUtilities.generateCode(processor, process, context, getStatisticsPort() != IProcessor.NO_STATISTICS, getTracesPort() != IProcessor.NO_TRACES && hasConnectionTrace(), true, progressMonitor);
                    } catch (Throwable e) {
                        // catch any Exception or Error to kill the process,
                        // see bug 0003567
                        running = true;
                        ExceptionHandler.process(e);
                        kill();
                    } finally {
                        progressMonitor.done();
                    // System.out.println("exitValue:" +
                    // ps.exitValue());
                    }
                    TimeMeasure.end(generateCodeId);
                    // if active before, not disable and active still.
                    if (!oldMeasureActived) {
                        TimeMeasure.display = TimeMeasure.displaySteps = TimeMeasure.measureActive = false;
                    }
                    final boolean[] refreshUiAndWait = new boolean[1];
                    refreshUiAndWait[0] = true;
                    final Display display = shell.getDisplay();
                    new Thread(new Runnable() {

                        @Override
                        public void run() {
                            display.syncExec(new Runnable() {

                                @Override
                                public void run() {
                                    try {
                                        startingMessageWritten = false;
                                        // before launching
                                        if (!JobErrorsChecker.hasErrors(shell)) {
                                            ps = processor.run(getStatisticsPort(), getTracesPort(), watchParam, log4jRuntimeLevel, progressMonitor, processMessageManager);
                                        }
                                        if (ps != null && !progressMonitor.isCanceled()) {
                                            setRunning(true);
                                            psMonitor = createProcessMonitor(ps);
                                            startingMessageWritten = true;
                                            final String startingPattern = Messages.getString(//$NON-NLS-1$
                                            "ProcessComposite.startPattern");
                                            MessageFormat mf = new MessageFormat(startingPattern);
                                            String welcomeMsg = mf.format(new Object[] { process.getLabel(), new Date() });
                                            processMessageManager.addMessage(new ProcessMessage(MsgType.CORE_OUT, //$NON-NLS-1$
                                            welcomeMsg + "\r\n"));
                                            processMonitorThread = new Thread(psMonitor);
                                            processMonitorThread.start();
                                        } else {
                                            kill();
                                            running = true;
                                            setRunning(false);
                                        }
                                    } catch (Throwable e) {
                                        // catch any Exception or Error
                                        // to kill the process, see bug
                                        // 0003567
                                        running = true;
                                        Throwable cause = e.getCause();
                                        if (cause != null && cause.getClass().equals(InterruptedException.class)) {
                                            setRunning(false);
                                            addErrorMessage(e);
                                        } else {
                                            ExceptionHandler.process(e);
                                            addErrorMessage(e);
                                            kill();
                                        }
                                    } finally {
                                        // progressMonitor.done();
                                        refreshUiAndWait[0] = false;
                                    }
                                }
                            });
                        }
                    }, "RunProcess_" + process.getLabel()).start();
                    while (refreshUiAndWait[0] && !progressMonitor.isCanceled()) {
                        if (!display.readAndDispatch()) {
                            display.sleep();
                        }
                        synchronized (this) {
                            try {
                                final long waitTime = 50;
                                wait(waitTime);
                            } catch (InterruptedException e) {
                            // Do nothing
                            }
                        }
                    }
                }
            });
        } catch (InvocationTargetException e1) {
            addErrorMessage(e1);
        } catch (InterruptedException e1) {
            addErrorMessage(e1);
        }
    } else {
        // See bug 0003567: When a prompt from context is cancelled or a
        // fatal error occurs during a job exec the
        // Kill button have to be pressed manually.
        this.running = true;
        setRunning(false);
    }
}
Also used : IContext(org.talend.core.model.process.IContext) ClearTraceAction(org.talend.designer.runprocess.ui.actions.ClearTraceAction) IProcess(org.talend.core.model.process.IProcess) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressService(org.eclipse.ui.progress.IProgressService) MessageFormat(java.text.MessageFormat) EventLoopProgressMonitor(org.talend.commons.ui.swt.dialogs.EventLoopProgressMonitor) Date(java.util.Date) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ClearPerformanceAction(org.talend.designer.runprocess.ui.actions.ClearPerformanceAction) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Display(org.eclipse.swt.widgets.Display)

Example 29 with IContext

use of org.talend.core.model.process.IContext in project tdi-studio-se by Talend.

the class JavaProcessor method initPath.

@Override
public void initPath() throws ProcessorException {
    IContext initContext = this.context;
    if (initContext == null) {
        initContext = this.process.getContextManager().getDefaultContext();
    }
    initCodePath(initContext);
}
Also used : IContext(org.talend.core.model.process.IContext)

Example 30 with IContext

use of org.talend.core.model.process.IContext in project tdi-studio-se by Talend.

the class UpdateManagerUtils method doExecuteUpdates.

private static boolean doExecuteUpdates(final List<UpdateResult> results, final boolean updateAllJobs) {
    if (results == null || results.isEmpty()) {
        return false;
    }
    try {
        IWorkspaceRunnable op = new IWorkspaceRunnable() {

            @Override
            public void run(IProgressMonitor monitor) throws CoreException {
                monitor.setCanceled(false);
                int size = (results.size() * 2 + 1) * UpdatesConstants.SCALE;
                //$NON-NLS-1$
                monitor.beginTask(Messages.getString("UpdateManagerUtils.Update"), size);
                ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                // first list by job we need to update
                Map<String, Set<String>> jobIdToVersion = new HashMap<String, Set<String>>();
                Map<String, Boolean> jobIdClosed = new HashMap<String, Boolean>();
                for (UpdateResult result : results) {
                    // if (!result.isChecked()) {
                    // continue;
                    // }
                    String id = result.getObjectId();
                    String version = result.getObjectVersion();
                    if (id == null) {
                        if (result.getJob() != null && result.getJob() instanceof IProcess) {
                            IProcess process = (IProcess) result.getJob();
                            if (process instanceof IProcess2 && ERepositoryStatus.LOCK_BY_OTHER.equals(factory.getStatus(((IProcess2) process).getProperty().getItem()))) {
                                // file.
                                continue;
                            }
                            id = process.getId();
                            version = process.getVersion();
                            result.setObjectId(id);
                            result.setObjectVersion(version);
                        } else {
                            continue;
                        }
                    }
                    Set<String> versionList;
                    if (!jobIdToVersion.containsKey(id)) {
                        versionList = new HashSet<String>();
                        jobIdToVersion.put(id, versionList);
                    } else {
                        versionList = jobIdToVersion.get(id);
                    }
                    versionList.add(version);
                    //$NON-NLS-1$
                    jobIdClosed.put(id + " - " + version, result.isFromItem());
                }
                // now will execute updates only for the job selected depends this list.
                for (String currentId : jobIdToVersion.keySet()) {
                    for (String version : jobIdToVersion.get(currentId)) {
                        IRepositoryViewObject currentObj = null;
                        //$NON-NLS-1$
                        boolean closedItem = jobIdClosed.get(currentId + " - " + version);
                        IProcess process = null;
                        Item item = null;
                        if (closedItem) {
                            // if item is closed, then just load it.
                            boolean checkOnlyLastVersion = Boolean.parseBoolean(DesignerPlugin.getDefault().getPreferenceStore().getString(//$NON-NLS-1$
                            "checkOnlyLastVersion"));
                            try {
                                if (checkOnlyLastVersion || version == null) {
                                    currentObj = factory.getLastVersion(currentId);
                                } else {
                                    List<IRepositoryViewObject> allVersion = factory.getAllVersion(currentId);
                                    for (IRepositoryViewObject obj : allVersion) {
                                        if (obj.getVersion().equals(version)) {
                                            currentObj = obj;
                                        }
                                    }
                                }
                            } catch (PersistenceException e) {
                                ExceptionHandler.process(e);
                            }
                            if (currentObj == null) {
                                // item not found, don't do anything
                                continue;
                            }
                            item = currentObj.getProperty().getItem();
                            IDesignerCoreService designerCoreService = CorePlugin.getDefault().getDesignerCoreService();
                            if (item instanceof ProcessItem) {
                                process = designerCoreService.getProcessFromProcessItem((ProcessItem) item);
                            } else if (item instanceof JobletProcessItem) {
                                process = designerCoreService.getProcessFromJobletProcessItem((JobletProcessItem) item);
                            }
                        }
                        for (UpdateResult result : results) {
                            // }
                            if (!StringUtils.equals(currentId, result.getObjectId())) {
                                // not the current job we need to update
                                continue;
                            }
                            if (closedItem) {
                                if (result.getJob() == null) {
                                    result.setJob(process);
                                } else {
                                    process = (IProcess) result.getJob();
                                }
                                IUpdateItemType jobletContextType = UpdateManagerProviderDetector.INSTANCE.getUpdateItemType(UpdateManagerHelper.TYPE_JOBLET_CONTEXT);
                                if (process != null && jobletContextType != null && (jobletContextType.equals(result.getUpdateType()))) {
                                    if ((result.getParameter() instanceof List) && process.getContextManager() != null) {
                                        process.getContextManager().setListContext((List<IContext>) result.getParameter());
                                    }
                                }
                            }
                            // execute
                            executeUpdate(result, monitor, updateAllJobs);
                            if (closedItem) {
                                result.setJob(null);
                            }
                        }
                        boolean isTestContainer = false;
                        ITestContainerProviderService testContainerService = null;
                        if (GlobalServiceRegister.getDefault().isServiceRegistered(ITestContainerProviderService.class)) {
                            testContainerService = (ITestContainerProviderService) GlobalServiceRegister.getDefault().getService(ITestContainerProviderService.class);
                            if (testContainerService != null) {
                                isTestContainer = testContainerService.isTestContainerItem(item);
                            }
                        }
                        if (closedItem && process instanceof IProcess2) {
                            IProcess2 process2 = (IProcess2) process;
                            ProcessType processType;
                            try {
                                processType = process2.saveXmlFile(false);
                                if (isTestContainer) {
                                    testContainerService.setTestContainerProcess(processType, item);
                                } else if (item instanceof JobletProcessItem) {
                                    ((JobletProcessItem) item).setJobletProcess((JobletProcess) processType);
                                } else {
                                    ((ProcessItem) item).setProcess(processType);
                                }
                                factory.save(item);
                            } catch (IOException e) {
                                ExceptionHandler.process(e);
                            } catch (PersistenceException e) {
                                ExceptionHandler.process(e);
                            }
                        }
                        if (closedItem && !ERepositoryStatus.LOCK_BY_USER.equals(factory.getStatus(item))) {
                            // unload item from memory, but only if this one is not locked by current user.
                            try {
                                factory.unloadResources(item.getProperty());
                            } catch (PersistenceException e) {
                                ExceptionHandler.process(e);
                            }
                        }
                    }
                }
                UpdateManagerProviderDetector.INSTANCE.postUpdate(results);
                // update joblet reference
                upadateJobletReferenceInfor();
                final List<UpdateResult> tempResults = new ArrayList<UpdateResult>(results);
                // refresh
                Display.getDefault().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        refreshRelatedViewers(tempResults);
                        // hyWang add method checkandRefreshProcess for bug7248
                        checkandRefreshProcess(tempResults);
                    }
                });
                monitor.worked(1 * UpdatesConstants.SCALE);
                monitor.done();
            }
        };
        IRunnableWithProgress iRunnableWithProgress = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                IWorkspace workspace = ResourcesPlugin.getWorkspace();
                try {
                    ISchedulingRule schedulingRule = workspace.getRoot();
                    workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, monitor);
                } catch (CoreException e) {
                    throw new InvocationTargetException(e);
                }
            }
        };
        try {
            new ProgressMonitorDialog(null).run(false, false, iRunnableWithProgress);
        } catch (InvocationTargetException e) {
            ExceptionHandler.process(e);
        } catch (InterruptedException e) {
        }
        return !results.isEmpty();
    } finally {
        results.clear();
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) IContext(org.talend.core.model.process.IContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JobletProcess(org.talend.designer.joblet.model.JobletProcess) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Item(org.talend.core.model.properties.Item) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) IUpdateItemType(org.talend.core.model.update.IUpdateItemType) List(java.util.List) ArrayList(java.util.ArrayList) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess) UpdateResult(org.talend.core.model.update.UpdateResult) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) IOException(java.io.IOException) ITestContainerProviderService(org.talend.core.ui.ITestContainerProviderService) InvocationTargetException(java.lang.reflect.InvocationTargetException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) CoreException(org.eclipse.core.runtime.CoreException) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IWorkspace(org.eclipse.core.resources.IWorkspace) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Aggregations

IContext (org.talend.core.model.process.IContext)46 IContextParameter (org.talend.core.model.process.IContextParameter)14 ArrayList (java.util.ArrayList)13 List (java.util.List)11 IProcess (org.talend.core.model.process.IProcess)10 ProcessorException (org.talend.designer.runprocess.ProcessorException)10 HashMap (java.util.HashMap)9 ProcessItem (org.talend.core.model.properties.ProcessItem)8 IOException (java.io.IOException)7 IElementParameter (org.talend.core.model.process.IElementParameter)7 IProcessor (org.talend.designer.runprocess.IProcessor)7 File (java.io.File)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 IContextManager (org.talend.core.model.process.IContextManager)6 HashSet (java.util.HashSet)5 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)5 IProcess2 (org.talend.core.model.process.IProcess2)5 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)5 Map (java.util.Map)4