Search in sources :

Example 36 with ProcessorException

use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.

the class TestComponentsAction method generateCode.

public void generateCode(File[] tempFile, String componentPath) {
    for (File file : tempFile) {
        if (file.length() > 0) {
            URI uri = URI.createFileURI(file.toString());
            TalendFilePackage.eINSTANCE.getNsURI();
            Resource resource = new ResourceSetImpl().getResource(uri, true);
            ProcessType processType = (ProcessType) EcoreUtil.getObjectByType(resource.getContents(), TalendFilePackage.eINSTANCE.getProcessType());
            IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
            ProcessItem item = PropertiesFactory.eINSTANCE.createProcessItem();
            item.setProcess(processType);
            item.setProperty(PropertiesFactory.eINSTANCE.createProperty());
            item.getProperty().setLabel(TestParameter.TEST_DIR);
            item.getProperty().setAuthor(PropertiesFactory.eINSTANCE.createUser());
            item.getProperty().setId(file.getName());
            item.getProperty().setStatusCode(file.getName());
            item.getProperty().setVersion(TestParameter.VERSION);
            IProcess process = service.getProcessFromProcessItem(item);
            setDefaultProperties(process, componentPath);
            IProcessor processor = ProcessorUtilities.getProcessor(process, item.getProperty(), process.getContextManager().getDefaultContext());
            try {
                // generate
                //$NON-NLS-1$
                log.info(TestParameter.GENERATE_START + " : " + file.getName());
                // processor.generateCode(process.getContextManager().getDefaultContext(), false, false, true);
                processor.generateCode(false, false, true);
                //$NON-NLS-1$
                log.info(TestParameter.GENERATE_END + " : " + file.getName());
                // run
                //$NON-NLS-1$
                log.info(TestParameter.RUN_START + " : " + file.getName());
                java.lang.Process runningProcess = processor.run(IProcessor.NO_STATISTICS, IProcessor.NO_TRACES, null);
                StringBuffer errBuff = new StringBuffer();
                if (isRunOK(runningProcess, errBuff)) {
                    //$NON-NLS-1$
                    log.info(TestParameter.RUN_SUCCESS + " : " + file.getName());
                } else {
                    // 2 possibilities : OK not found / error stream
                    //$NON-NLS-1$
                    log.error(TestParameter.RUN_FAIL + " : " + file.getName(), new Exception(errBuff.toString()));
                }
            } catch (ProcessorException e) {
                log.error(e.getMessage(), e);
            }
        }
    }
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) ProcessorException(org.talend.designer.runprocess.ProcessorException) Resource(org.eclipse.emf.ecore.resource.Resource) IProcessor(org.talend.designer.runprocess.IProcessor) URI(org.eclipse.emf.common.util.URI) ProcessorException(org.talend.designer.runprocess.ProcessorException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ProcessItem(org.talend.core.model.properties.ProcessItem) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) File(java.io.File) IProcess(org.talend.core.model.process.IProcess)

Example 37 with ProcessorException

use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.

the class JobScriptsManager method getCommandByTalendJob.

protected String getCommandByTalendJob(String targetPlatform, ProcessItem processItem, String context, boolean needContext, int statisticPort, int tracePort, String... codeOptions) {
    String[] cmd = new String[] {};
    try {
        IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
        IProcess currentProcess = service.getProcessFromProcessItem(processItem);
        cmd = ProcessorUtilities.getCommandLine(true, targetPlatform, true, currentProcess, processItem.getProperty(), context, needContext, statisticPort, tracePort, codeOptions);
    } catch (ProcessorException e) {
        ExceptionHandler.process(e);
    }
    return ProcessorUtilities.generateCmdByTalendJob(cmd);
}
Also used : ProcessorException(org.talend.designer.runprocess.ProcessorException) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcess(org.talend.core.model.process.IProcess)

Example 38 with ProcessorException

use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.

the class JSONShadowProcess method run.

public CsvArray run() throws ProcessorException {
    IProcess talendProcess = buildProcess();
    IProcessor processor = ProcessorUtilities.getProcessor(talendProcess, null);
    processor.setProxyParameters(getProxyParameters());
    // try {
    // Delete previous Perl generated file
    File previousFile = outPath.toFile();
    if (previousFile.exists()) {
        previousFile.delete();
    }
    // Process ps = processor.run(process.getContextManager().getDefaultContext(), Processor.NO_STATISTICS,
    // Processor.NO_TRACES,Processor.WATCH_ALLOWED);//Old
    IContext context = talendProcess.getContextManager().getDefaultContext();
    processor.setContext(context);
    process = processor.run(IProcessor.NO_STATISTICS, IProcessor.NO_TRACES, null);
    ProcessStreamTrashReader.readAndForget(process);
    if (!outPath.toFile().exists()) {
        //$NON-NLS-1$
        throw new ProcessorException(Messages.getString("ShadowProcess.notGeneratedOutputException"));
    }
    try {
        CsvArray array = new CsvArray();
        array = array.createFrom(outPath.toFile(), currentProcessEncoding);
        return array;
    } catch (IOException ioe) {
        throw new ProcessorException(ioe);
    }
}
Also used : IContext(org.talend.core.model.process.IContext) ProcessorException(org.talend.designer.runprocess.ProcessorException) CsvArray(org.talend.core.utils.CsvArray) IProcessor(org.talend.designer.runprocess.IProcessor) IOException(java.io.IOException) IProcess(org.talend.core.model.process.IProcess) File(java.io.File)

Example 39 with ProcessorException

use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.

the class JobExportAction method exportJobScript.

private boolean exportJobScript(List<? extends IRepositoryNode> nodes, String version, String bundleVersion, IProgressMonitor monitor) {
    manager.setJobVersion(version);
    manager.setBundleVersion(bundleVersion);
    List<ExportFileResource> processes = getProcesses(nodes, "");
    boolean isNotFirstTime = directoryName != null;
    if (isNotFirstTime && processes != null) {
        for (ExportFileResource process : processes) {
            process.setDirectoryName(directoryName);
        }
    }
    try {
        ProxyRepositoryFactory.getInstance().initialize();
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    ItemCacheManager.clearCache();
    if (!isMultiNodes()) {
        // TODO : bug with export?
        for (ExportFileResource process : processes) {
            process.removeAllMap();
            ProcessItem processItem = (ProcessItem) process.getItem();
            if (!processItem.getProperty().getVersion().equals(version)) {
                // update with the correct version.
                process.setProcess(ItemCacheManager.getProcessItem(processItem.getProperty().getId(), version));
            }
        }
    }
    manager.setProgressMonitor(monitor);
    List<ExportFileResource> resourcesToExport = null;
    try {
        resourcesToExport = manager.getExportResources(processes.toArray(new ExportFileResource[] {}));
        IStructuredSelection selection = new StructuredSelection(nodes);
        // if job has compile error, will not export to avoid problem if run jobscript
        boolean hasErrors = CorePlugin.getDefault().getRunProcessService().checkExportProcess(selection, true);
        if (hasErrors) {
            manager.deleteTempFiles();
            return false;
        }
    } catch (ProcessorException e) {
        MessageBoxExceptionHandler.process(e);
        return false;
    }
    boolean addClasspathJar = true;
    IDesignerCoreUIService designerCoreUIService = CoreUIPlugin.getDefault().getDesignerCoreUIService();
    if (designerCoreUIService != null) {
        addClasspathJar = designerCoreUIService.getPreferenceStore().getBoolean(IRepositoryPrefConstants.ADD_CLASSPATH_JAR);
    }
    if (isMultiNodes() || addClasspathJar) {
        manager.setTopFolder(resourcesToExport);
    }
    doArchiveExport(monitor, resourcesToExport);
    clean();
    ProcessorUtilities.resetExportConfig();
    // no need to regenerate if run in export model
    // boolean generated = generatedCodes(version, monitor, processes);
    // if (!generated) {
    // return false;
    // }
    //$NON-NLS-1$
    monitor.subTask(Messages.getString("JobScriptsExportWizardPage.newExportSuccess", type));
    if (addClasspathJar) {
        reBuildJobZipFile(processes);
    } else {
        String zipFile = getTempDestinationValue();
        String destinationZipFile = manager.getDestinationPath();
        FileCopyUtils.copy(zipFile, destinationZipFile);
    }
    return true;
}
Also used : ProcessorException(org.talend.designer.runprocess.ProcessorException) ProcessItem(org.talend.core.model.properties.ProcessItem) ExportFileResource(org.talend.repository.documentation.ExportFileResource) PersistenceException(org.talend.commons.exception.PersistenceException) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IDesignerCoreUIService(org.talend.core.ui.services.IDesignerCoreUIService) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 40 with ProcessorException

use of org.talend.designer.runprocess.ProcessorException in project tdi-studio-se by Talend.

the class JobExportAction method generatedCodes.

/**
     * DOC ggu Comment method "generatedCodes".
     * 
     * @param version
     * @param monitor
     * @param processes
     */
protected boolean generatedCodes(String version, IProgressMonitor monitor, List<ExportFileResource> processes) {
    String projectName = ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getProject().getLabel();
    List<JobResource> jobResources = new ArrayList<JobResource>();
    for (ExportFileResource process : processes) {
        ProcessItem processItem = (ProcessItem) process.getItem();
        JobInfo jobInfo = new JobInfo(processItem, processItem.getProcess().getDefaultContext(), version);
        jobResources.add(new JobResource(projectName, jobInfo));
        Set<JobInfo> jobInfos = ProcessorUtilities.getChildrenJobInfo(processItem);
        for (JobInfo subjobInfo : jobInfos) {
            jobResources.add(new JobResource(projectName, subjobInfo));
        }
    }
    JobResourceManager reManager = JobResourceManager.getInstance();
    for (JobResource r : jobResources) {
        if (reManager.isProtected(r)) {
            try {
                ProcessorUtilities.generateCode(r.getJobInfo().getJobId(), r.getJobInfo().getContextName(), r.getJobInfo().getJobVersion(), false, false, monitor);
            } catch (ProcessorException e) {
                MessageBoxExceptionHandler.process(e);
                return false;
            }
        }
    }
    return true;
}
Also used : ProcessorException(org.talend.designer.runprocess.ProcessorException) ProcessItem(org.talend.core.model.properties.ProcessItem) ExportFileResource(org.talend.repository.documentation.ExportFileResource) JobInfo(org.talend.core.model.process.JobInfo) JobResource(org.talend.core.model.repository.job.JobResource) ArrayList(java.util.ArrayList) JobResourceManager(org.talend.core.model.repository.job.JobResourceManager)

Aggregations

ProcessorException (org.talend.designer.runprocess.ProcessorException)40 IOException (java.io.IOException)15 File (java.io.File)11 IProcessor (org.talend.designer.runprocess.IProcessor)11 CoreException (org.eclipse.core.runtime.CoreException)10 ProcessItem (org.talend.core.model.properties.ProcessItem)10 CsvArray (org.talend.core.utils.CsvArray)10 IContext (org.talend.core.model.process.IContext)9 Status (org.eclipse.core.runtime.Status)8 IProcess (org.talend.core.model.process.IProcess)8 ExportFileResource (org.talend.repository.documentation.ExportFileResource)7 IFile (org.eclipse.core.resources.IFile)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 ILaunchConfiguration (org.eclipse.debug.core.ILaunchConfiguration)5 PersistenceException (org.talend.commons.exception.PersistenceException)5 ExportChoice (org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ArrayList (java.util.ArrayList)4 IStatus (org.eclipse.core.runtime.IStatus)4 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)4