Search in sources :

Example 11 with JobInfo

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

the class BuildJobManager method buildJob.

public void buildJob(String destinationPath, ProcessItem itemToExport, String version, String context, Map<ExportChoice, Object> exportChoiceMap, JobExportType jobExportType, boolean checkCompilationError, IProgressMonitor monitor) throws Exception {
    IProgressMonitor pMonitor = new NullProgressMonitor();
    if (monitor != null) {
        pMonitor = monitor;
    }
    final boolean oldMeasureActived = TimeMeasure.measureActive;
    if (!oldMeasureActived) {
        // not active before.
        TimeMeasure.display = TimeMeasure.displaySteps = TimeMeasure.measureActive = CommonsPlugin.isDebugMode();
    }
    final String timeMeasureId = "Build job for " + itemToExport.getProperty().getLabel() + ' ' + version;
    TimeMeasure.begin(timeMeasureId);
    try {
        final int scale = 1000;
        int total = 4;
        //$NON-NLS-1$
        pMonitor.beginTask(Messages.getString("JobScriptsExportWizardPage.newExportJobScript", jobExportType), scale * total);
        ProcessItem processItem = itemToExport;
        // get correct version
        if (!RelationshipItemBuilder.LATEST_VERSION.equals(version) && version != null && !"".equals(version) && !version.equals(processItem.getProperty().getVersion())) {
            processItem = ItemCacheManager.getProcessItem(processItem.getProperty().getId(), version);
        }
        final String label = processItem.getProperty().getLabel();
        final IBuildJobHandler buildJobHandler = BuildJobFactory.createBuildJobHandler(processItem, context, version, exportChoiceMap, jobExportType);
        ProcessUtils.setJarWithContext(ProcessUtils.needsToHaveContextInsideJar(processItem));
        final IWorkspaceRunnable op = new IWorkspaceRunnable() {

            @Override
            public void run(IProgressMonitor wrMonitor) throws CoreException {
                try {
                    wrMonitor.beginTask(Messages.getString("JobScriptsExportWizardPage.newExportJobScript", jobExportType), scale * 3);
                    TimeMeasure.step(timeMeasureId, "prepare to build job");
                    buildJobHandler.generateItemFiles(true, new SubProgressMonitor(wrMonitor, scale));
                    wrMonitor.worked(scale);
                    TimeMeasure.step(timeMeasureId, "generateItemFiles");
                    buildJobHandler.generateJobFiles(new SubProgressMonitor(wrMonitor, scale));
                    wrMonitor.worked(scale);
                    TimeMeasure.step(timeMeasureId, "generateJobFiles");
                    buildJobHandler.build(new SubProgressMonitor(wrMonitor, scale));
                    TimeMeasure.step(timeMeasureId, "build and package");
                    wrMonitor.done();
                } catch (Exception e) {
                    throw new CoreException(new org.eclipse.core.runtime.Status(IStatus.ERROR, FrameworkUtil.getBundle(this.getClass()).getSymbolicName(), "Error", e));
                }
            }

            ;
        };
        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        try {
            ISchedulingRule schedulingRule = workspace.getRoot();
            // the update the project files need to be done in the workspace runnable to avoid all
            // notification
            // of changes before the end of the modifications.
            workspace.run(op, schedulingRule, IWorkspace.AVOID_UPDATE, pMonitor);
        } catch (CoreException e) {
            Throwable cause = e.getCause();
            if (cause == null) {
                throw new PersistenceException(e);
            }
            throw new PersistenceException(cause);
        }
        ProcessUtils.setJarWithContext(false);
        IFile jobTargetFile = buildJobHandler.getJobTargetFile();
        if (jobTargetFile != null && jobTargetFile.exists()) {
            IPath jobZipLocation = jobTargetFile.getLocation();
            File jobZipFile = jobZipLocation.toFile();
            String jobZip = jobZipLocation.toString();
            if (needClasspathJar(exportChoiceMap)) {
                ExportJobUtil.deleteTempFiles();
                JavaJobExportReArchieveCreator creator = new JavaJobExportReArchieveCreator(jobZip, label);
                FilesUtils.unzip(jobZip, creator.getTmpFolder() + File.separator + label + "_" + version);
                creator.buildNewJar();
                ZipToFile.zipFile(creator.getTmpFolder(), jobZip);
                creator.deleteTempFiles();
                TimeMeasure.step(timeMeasureId, "Recreate job jar for classpath");
            }
            // TBD-2500
            Set<ProcessItem> processItems = new HashSet<ProcessItem>();
            processItems.add(processItem);
            // We get the father job childs.
            Set<JobInfo> infos = ProcessorUtilities.getChildrenJobInfo(processItem);
            Iterator<JobInfo> infoIterator = infos.iterator();
            while (infoIterator.hasNext()) {
                processItems.add(infoIterator.next().getProcessItem());
            }
            TimeMeasure.step(timeMeasureId, "getChildrenJobInfo");
            // We iterate over the job and its childs in order to re-archive them if needed.
            for (ProcessItem pi : processItems) {
                BDJobReArchieveCreator bdRecreator = new BDJobReArchieveCreator(pi, processItem);
                bdRecreator.create(jobZipFile);
            }
            TimeMeasure.step(timeMeasureId, "BDJobReArchieveCreator");
            File jobFileTarget = new File(destinationPath);
            if (jobFileTarget.isDirectory()) {
                jobFileTarget = new File(destinationPath, jobZipFile.getName());
            }
            FilesUtils.copyFile(jobZipFile, jobFileTarget);
            TimeMeasure.step(timeMeasureId, "Copy packaged file to target");
        } else if (jobTargetFile != null) {
            throw new Exception("Job was not built successfully, please check the logs for more details available on the workspace/.Java/lastGenerated.log");
        }
        if (checkCompilationError) {
            CorePlugin.getDefault().getRunProcessService().checkLastGenerationHasCompilationError(false);
        }
        pMonitor.worked(scale);
        pMonitor.done();
    } finally {
        TimeMeasure.end(timeMeasureId);
        // if active before, not disable and active still.
        if (!oldMeasureActived) {
            TimeMeasure.display = TimeMeasure.displaySteps = TimeMeasure.measureActive = false;
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) JobInfo(org.talend.core.model.process.JobInfo) JavaJobExportReArchieveCreator(org.talend.repository.ui.wizards.exportjob.JavaJobExportReArchieveCreator) HashSet(java.util.HashSet) IStatus(org.eclipse.core.runtime.IStatus) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IPath(org.eclipse.core.runtime.IPath) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) PersistenceException(org.talend.commons.exception.PersistenceException) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProcessItem(org.talend.core.model.properties.ProcessItem) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace) IBuildJobHandler(org.talend.core.runtime.process.IBuildJobHandler) PersistenceException(org.talend.commons.exception.PersistenceException) ZipToFile(org.talend.repository.ui.utils.ZipToFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 12 with JobInfo

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

the class JavaProcessUtil method getChildrenModules.

static List<ModuleNeeded> getChildrenModules(final INode node, Set<ProcessItem> searchItems, boolean forMR) {
    List<ModuleNeeded> modulesNeeded = new ArrayList<ModuleNeeded>();
    if (node.getComponent().getName().equals("tRunJob")) {
        //$NON-NLS-1$
        //$NON-NLS-1$
        IElementParameter processIdparam = node.getElementParameter("PROCESS_TYPE_PROCESS");
        IElementParameter processVersionParam = node.getElementParameter(EParameterName.PROCESS_TYPE_VERSION.getName());
        ProcessItem processItem = null;
        if (processVersionParam != null) {
            processItem = ItemCacheManager.getProcessItem((String) processIdparam.getValue(), (String) processVersionParam.getValue());
        } else {
            processItem = ItemCacheManager.getProcessItem((String) processIdparam.getValue());
        }
        //$NON-NLS-1$
        String context = (String) node.getElementParameter("PROCESS_TYPE_CONTEXT").getValue();
        if (processItem != null && !searchItems.contains(processItem)) {
            boolean seperated = //$NON-NLS-1$
            getBooleanParamValue(node, "USE_INDEPENDENT_PROCESS") || //$NON-NLS-1$
            getBooleanParamValue(node, "USE_DYNAMIC_JOB");
            if (!seperated) {
                // avoid dead loop of method call
                searchItems.add(processItem);
                JobInfo subJobInfo = new JobInfo(processItem, context);
                IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
                IProcess child = service.getProcessFromItem(subJobInfo.getProcessItem());
                getNeededModules(child, true, searchItems, modulesNeeded, forMR);
            }
        }
    }
    return modulesNeeded;
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) JobInfo(org.talend.core.model.process.JobInfo) ArrayList(java.util.ArrayList) IElementParameter(org.talend.core.model.process.IElementParameter) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) ModuleNeeded(org.talend.core.model.general.ModuleNeeded) IProcess(org.talend.core.model.process.IProcess)

Example 13 with JobInfo

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

the class AbstractMultiPageTalendEditor method refreshName.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.repository.editor.INameRefresher#refreshName()
     */
@Override
public void refreshName() {
    try {
        JobResourceManager jobResourceManager = JobResourceManager.getInstance();
        jobResourceManager.removeProtection(designerEditor);
        for (String id : designerEditor.getProtectedIds()) {
            if (designerEditor.getJobResource(id).getJobInfo().getJobName().equalsIgnoreCase(oldJobName)) {
                // delete only the job renamed
                jobResourceManager.deleteResource(designerEditor.getJobResource(id));
            }
        }
        designerEditor.resetJobResources();
        setName();
        JobInfo jobInfo = designerEditor.getCurrentJobResource().getJobInfo();
        if (jobInfo != null) {
            jobInfo.setJobName(getEditorInput().getName());
        }
        jobResourceManager.addProtection(designerEditor);
        processor.initPath();
        processor.setProcessorStates(IProcessor.STATES_EDIT);
        // modified by wzhang to fix bug 8180 in thales branding.
        if (useCodeView) {
            updateCodeEditorContent();
        }
        IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
        if (activeWorkbenchWindow != null) {
            if (activeWorkbenchWindow.getActivePage().isPartVisible(this)) {
                new ActiveProcessTracker().partBroughtToTop(this);
                DesignerPlugin.getDefault().getRunProcessService().refreshView();
            }
        }
    } catch (Exception e) {
        MessageBoxExceptionHandler.process(e);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) JobInfo(org.talend.core.model.process.JobInfo) JobResourceManager(org.talend.core.model.repository.job.JobResourceManager) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) LoginException(org.talend.commons.exception.LoginException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) ProcessorException(org.talend.designer.runprocess.ProcessorException) BusinessException(org.talend.commons.exception.BusinessException) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 14 with JobInfo

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

the class AbstractJavaProcessor method run.

@Override
public Process run(String[] optionsParam, int statisticsPort, int tracePort, IProgressMonitor monitor, IProcessMessageManager processMessageManager) throws ProcessorException {
    if (isStandardJob()) {
        Property property = this.getProperty();
        if (property != null) {
            // use the same function with ExportModelJavaProcessor, but will do for maven
            ProcessItem processItem = (ProcessItem) property.getItem();
            if (isRunAsExport()) {
                // Step 1: Export job
                archive = buildExportZip(processItem, monitor);
                // Step 2: Deploy in local(Maybe just unpack)
                unzipFolder = unzipAndDeploy(process, archive);
                // Step 3: Run job from given folder.
                return execFrom(unzipFolder + File.separatorChar + process.getName(), Level.INFO, statisticsPort, tracePort, optionsParam);
            } else {
                // If we are not in an export mode, we still have to check whether jobs need to be re-archived or
                // not.
                String version = processItem.getProperty().getVersion();
                if (//$NON-NLS-1$
                !RelationshipItemBuilder.LATEST_VERSION.equals(version) && version != null && !"".equals(version) && !version.equals(processItem.getProperty().getVersion())) {
                    processItem = ItemCacheManager.getProcessItem(processItem.getProperty().getId(), version);
                }
                Set<ProcessItem> processItems = new HashSet<>();
                processItems.add(processItem);
                // We get the father job childs.
                Set<JobInfo> infos = ProcessorUtilities.getChildrenJobInfo(processItem);
                Iterator<JobInfo> infoIterator = infos.iterator();
                while (infoIterator.hasNext()) {
                    processItems.add(infoIterator.next().getProcessItem());
                }
                // We iterate over the job and its childs in order to re-archive them if needed.
                for (ProcessItem pi : processItems) {
                    BDJobReArchieveCreator bdRecreator = new BDJobReArchieveCreator(pi, processItem);
                    bdRecreator.create(new File(this.getTalendJavaProject().getTargetFolder().getLocation().toPortableString()), false);
                }
            }
        }
    }
    return super.run(optionsParam, statisticsPort, tracePort, monitor, processMessageManager);
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) JobInfo(org.talend.core.model.process.JobInfo) Property(org.talend.core.model.properties.Property) ZipToFile(org.talend.repository.ui.utils.ZipToFile) File(java.io.File) HashSet(java.util.HashSet) BDJobReArchieveCreator(org.talend.repository.ui.wizards.exportjob.scriptsmanager.BDJobReArchieveCreator)

Example 15 with JobInfo

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

the class JavaProcessor method getBuildChildrenJobs.

@Override
public Set<JobInfo> getBuildChildrenJobs() {
    if (buildChildrenJobs == null) {
        buildChildrenJobs = new HashSet<JobInfo>();
        JobInfo lastMainJob = LastGenerationInfo.getInstance().getLastMainJob();
        Set<JobInfo> infos = null;
        if (lastMainJob == null && property != null) {
            infos = ProcessorUtilities.getChildrenJobInfo((ProcessItem) property.getItem());
        } else {
            infos = LastGenerationInfo.getInstance().getLastGeneratedjobs();
        }
        for (JobInfo jobInfo : infos) {
            buildChildrenJobs.add(jobInfo);
        }
    }
    return this.buildChildrenJobs;
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) JobInfo(org.talend.core.model.process.JobInfo)

Aggregations

JobInfo (org.talend.core.model.process.JobInfo)16 ProcessItem (org.talend.core.model.properties.ProcessItem)8 PersistenceException (org.talend.commons.exception.PersistenceException)7 ArrayList (java.util.ArrayList)6 CoreException (org.eclipse.core.runtime.CoreException)6 ProcessorException (org.talend.designer.runprocess.ProcessorException)4 HashSet (java.util.HashSet)3 IFile (org.eclipse.core.resources.IFile)3 Property (org.talend.core.model.properties.Property)3 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)3 JobResourceManager (org.talend.core.model.repository.job.JobResourceManager)3 File (java.io.File)2 IOException (java.io.IOException)2 IResource (org.eclipse.core.resources.IResource)2 SystemException (org.talend.commons.exception.SystemException)2 Item (org.talend.core.model.properties.Item)2 JobResource (org.talend.core.model.repository.job.JobResource)2 ITalendProcessJavaProject (org.talend.core.runtime.process.ITalendProcessJavaProject)2 ITalendSynchronizer (org.talend.designer.codegen.ITalendSynchronizer)2 ExportFileResource (org.talend.repository.documentation.ExportFileResource)2