Search in sources :

Example 11 with JobConfiguration

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());
        }
    }
}
Also used : JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) JobExecutionConfiguration(org.pentaho.di.job.JobExecutionConfiguration) JobConfiguration(org.pentaho.di.job.JobConfiguration) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) ActionValidationException(org.pentaho.platform.api.engine.ActionValidationException) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) FileNotFoundException(java.io.FileNotFoundException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettleException(org.pentaho.di.core.exception.KettleException) KettleSecurityException(org.pentaho.di.core.exception.KettleSecurityException)

Aggregations

JobConfiguration (org.pentaho.di.job.JobConfiguration)11 Job (org.pentaho.di.job.Job)9 SimpleLoggingObject (org.pentaho.di.core.logging.SimpleLoggingObject)7 JobExecutionConfiguration (org.pentaho.di.job.JobExecutionConfiguration)7 KettleException (org.pentaho.di.core.exception.KettleException)6 JobMeta (org.pentaho.di.job.JobMeta)6 IOException (java.io.IOException)5 PrintWriter (java.io.PrintWriter)5 ServletException (javax.servlet.ServletException)5 JobAdapter (org.pentaho.di.job.JobAdapter)4 Repository (org.pentaho.di.repository.Repository)4 OutputStream (java.io.OutputStream)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 FileObject (org.apache.commons.vfs2.FileObject)2 LogLevel (org.pentaho.di.core.logging.LogLevel)2 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)2 Trans (org.pentaho.di.trans.Trans)2 TransConfiguration (org.pentaho.di.trans.TransConfiguration)2 TransExecutionConfiguration (org.pentaho.di.trans.TransExecutionConfiguration)2