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;
}
}
}
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;
}
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);
}
}
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);
}
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;
}
Aggregations