use of org.pentaho.di.job.JobConfiguration in project pdi-platform-plugin by pentaho.
the class PdiAction method executeJob.
/**
* Executes a PDI job
*
* @param jobMeta
* @param repository
* @param logWriter
* @return
* @throws ActionExecutionException
*/
protected void executeJob(final JobMeta jobMeta, final Repository repository, final LogWriter logWriter) throws ActionExecutionException {
localJob = null;
if (jobMeta != null) {
JobExecutionConfiguration jobExConfig = newJobExecutionConfiguration();
if (logLevel != null) {
jobExConfig.setLogLevel(LogLevel.getLogLevelForCode(logLevel));
}
if (clearLog != null) {
jobExConfig.setClearingLog(Boolean.valueOf(clearLog));
}
if (runSafeMode != null) {
jobExConfig.setSafeModeEnabled(Boolean.valueOf(runSafeMode));
}
if (expandingRemoteJob != null) {
jobExConfig.setExpandingRemoteJob(Boolean.valueOf(expandingRemoteJob));
}
if (startCopyName != null) {
jobExConfig.setStartCopyName(startCopyName);
}
try {
localJob = newJob(repository, jobMeta);
localJob.setArguments(arguments);
localJob.shareVariablesWith(jobMeta);
String carteObjectId = UUID.randomUUID().toString();
localJob.setContainerObjectId(carteObjectId);
CarteSingleton.getInstance().getJobMap().addJob(getJobName(carteObjectId), carteObjectId, localJob, new JobConfiguration(localJob.getJobMeta(), jobExConfig));
} catch (Exception e) {
throw new ActionExecutionException(Messages.getInstance().getErrorString("Kettle.ERROR_0021_BAD_JOB_METADATA"), // $NON-NLS-1$
e);
}
}
if (localJob == null) {
if (log.isDebugEnabled()) {
log.debug(pdiUserAppender.getBuffer().toString());
}
throw new ActionExecutionException(Messages.getInstance().getErrorString(// $NON-NLS-1$
"Kettle.ERROR_0021_BAD_JOB_METADATA"));
}
if (localJob != null) {
try {
if (log.isDebugEnabled()) {
// $NON-NLS-1$
log.debug(Messages.getInstance().getString("Kettle.DEBUG_STARTING_JOB"));
}
if (startCopyName != null) {
JobEntryCopy startJobEntryCopy = jobMeta.findJobEntry(startCopyName);
localJob.setStartJobEntryCopy(startJobEntryCopy);
}
localJob.setLogLevel(LogLevel.getLogLevelForCode(logLevel));
localJob.start();
} catch (Throwable e) {
throw new ActionExecutionException(Messages.getInstance().getErrorString("Kettle.ERROR_0022_JOB_START_FAILED"), // $NON-NLS-1$
e);
}
// It's running in a separate tread to allow monitoring, etc.
if (log.isDebugEnabled()) {
// $NON-NLS-1$
log.debug(Messages.getInstance().getString("Kettle.DEBUG_JOB_RUNNING"));
}
localJob.waitUntilFinished();
int jobErrors = localJob.getErrors();
long jobResultErrors = localJob.getResult().getNrErrors();
if ((jobErrors > 0) || (jobResultErrors > 0)) {
if (log.isDebugEnabled()) {
log.debug(pdiUserAppender.getBuffer().toString());
}
// don't throw exception, because the scheduler may try to run this job again
log.error(org.pentaho.platform.plugin.kettle.messages.Messages.getInstance().getErrorString(// $NON-NLS-1$
"PdiAction.ERROR_0008_JOB_HAD_ERRORS", Integer.toString(jobErrors), Long.toString(jobResultErrors)));
return;
}
// Dump the Kettle log...
if (log.isDebugEnabled()) {
log.debug(pdiUserAppender.getBuffer().toString());
}
}
}
Aggregations