Search in sources :

Example 6 with ActionExecutionException

use of org.pentaho.platform.api.engine.ActionExecutionException in project pdi-platform-plugin by pentaho.

the class PdiAction method executeTransformation.

/**
 * Executes a PDI transformation
 *
 * @param transMeta
 * @param logWriter
 * @return
 * @throws ActionExecutionException
 */
protected void executeTransformation(final TransMeta transMeta, final LogWriter logWriter) throws ActionExecutionException {
    localTrans = null;
    if (transMeta != null) {
        TransExecutionConfiguration transExConfig = newTransExecutionConfiguration();
        if (logLevel != null) {
            transExConfig.setLogLevel(LogLevel.getLogLevelForCode(logLevel));
        }
        if (clearLog != null) {
            transExConfig.setClearingLog(Boolean.valueOf(clearLog));
        }
        if (runSafeMode != null) {
            transExConfig.setSafeModeEnabled(Boolean.valueOf(runSafeMode));
        }
        if (gatheringMetrics != null) {
            transExConfig.setGatheringMetrics(Boolean.valueOf(gatheringMetrics));
        }
        try {
            localTrans = newTrans(transMeta);
            localTrans.setArguments(arguments);
            localTrans.shareVariablesWith(transMeta);
            String carteObjectId = UUID.randomUUID().toString();
            localTrans.setContainerObjectId(carteObjectId);
            CarteSingleton.getInstance().getTransformationMap().addTransformation(getTransformationName(carteObjectId), carteObjectId, localTrans, new TransConfiguration(localTrans.getTransMeta(), transExConfig));
        } catch (Exception e) {
            throw new ActionExecutionException(Messages.getInstance().getErrorString("Kettle.ERROR_0010_BAD_TRANSFORMATION_METADATA"), // $NON-NLS-1$
            e);
        }
    }
    if (localTrans == null) {
        throw new ActionExecutionException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "Kettle.ERROR_0010_BAD_TRANSFORMATION_METADATA"));
    }
    if (localTrans != null) {
        // OK, we have the transformation, now run it!
        if (!customizeTrans(localTrans, logWriter)) {
            throw new ActionExecutionException(Messages.getInstance().getErrorString(// $NON-NLS-1$
            "Kettle.ERROR_0028_CUSTOMIZATION_FUNCITON_FAILED"));
        }
        if (log.isDebugEnabled()) {
            // $NON-NLS-1$
            log.debug(Messages.getInstance().getString("Kettle.DEBUG_PREPARING_TRANSFORMATION"));
        }
        try {
            localTrans.setLogLevel(LogLevel.getLogLevelForCode(logLevel));
            localTrans.setSafeModeEnabled(Boolean.valueOf(runSafeMode));
            localTrans.prepareExecution(transMeta.getArguments());
        } catch (Exception e) {
            transPrepExecutionFailure = true;
            // don't throw exception, because the scheduler may try to run this transformation again
            // $NON-NLS-1$
            log.error(Messages.getInstance().getErrorString("Kettle.ERROR_0011_TRANSFORMATION_PREPARATION_FAILED"), e);
            return;
        }
        String stepName = null;
        try {
            if (log.isDebugEnabled()) {
                // $NON-NLS-1$
                log.debug(Messages.getInstance().getString("Kettle.DEBUG_FINDING_STEP_IMPORTER"));
            }
            stepName = getMonitorStepName();
            if (stepName != null) {
                registerAsStepListener(stepName, localTrans);
            }
        } catch (Exception e) {
            throw new ActionExecutionException(Messages.getInstance().getErrorString("Kettle.ERROR_0012_ROW_LISTENER_CREATE_FAILED"), // $NON-NLS-1$
            e);
        }
        try {
            if (log.isDebugEnabled()) {
                // $NON-NLS-1$
                log.debug(Messages.getInstance().getString("Kettle.DEBUG_FINDING_STEP_IMPORTER"));
            }
            if (injectorStep != null) {
                registerAsProducer(injectorStep, localTrans);
            }
        } catch (Exception e) {
            throw new ActionExecutionException(Messages.getInstance().getErrorString("Kettle.ERROR_0012_ROW_INJECTOR_CREATE_FAILED"), // $NON-NLS-1$
            e);
        }
        try {
            if (log.isDebugEnabled()) {
                // $NON-NLS-1$
                log.debug(Messages.getInstance().getString("Kettle.DEBUG_STARTING_TRANSFORMATION"));
            }
            localTrans.startThreads();
        } catch (Exception e) {
            throw new ActionExecutionException(Messages.getInstance().getErrorString("Kettle.ERROR_0013_TRANSFORMATION_START_FAILED"), // $NON-NLS-1$
            e);
        }
        // inject rows if necessary
        if (injectorRows != null) {
            // create a row meta
            try {
                if (log.isDebugEnabled()) {
                    // $NON-NLS-1$
                    log.debug(Messages.getInstance().getString("Injecting rows"));
                }
                RowMeta rowMeta = new RowMeta();
                RowMetaInterface rowMetaInterface = transMeta.getStepFields(injectorStep);
                rowMeta.addRowMeta(rowMetaInterface);
                // inject the rows
                Object[] row = injectorRows.next();
                while (row != null) {
                    rowInjector.putRow(rowMeta, row);
                    row = injectorRows.next();
                }
                rowInjector.finished();
            } catch (Exception e) {
                // $NON-NLS-1$
                throw new ActionExecutionException(Messages.getInstance().getErrorString("Row injection failed"), e);
            }
        }
        try {
            // It's running in a separate thread to allow monitoring, etc.
            if (log.isDebugEnabled()) {
                // $NON-NLS-1$
                log.debug(Messages.getInstance().getString("Kettle.DEBUG_TRANSFORMATION_RUNNING"));
            }
            localTrans.waitUntilFinished();
            localTrans.cleanup();
        } catch (Exception e) {
            int transErrors = localTrans.getErrors();
            throw new ActionExecutionException(org.pentaho.platform.plugin.kettle.messages.Messages.getInstance().getErrorString("PdiAction.ERROR_0009_TRANSFORMATION_HAD_ERRORS", Integer.toString(transErrors)), // $NON-NLS-1$
            e);
        }
        // Dump the Kettle log...
        if (log.isDebugEnabled()) {
            log.debug(pdiUserAppender.getBuffer().toString());
        }
        // Build written row output
        if (transformationOutputRows != null) {
            transformationOutputRowsCount = transformationOutputRows.getRowCount();
        }
        // Build error row output
        if (transformationOutputErrorRows != null) {
            transformationOutputErrorRowsCount = transformationOutputErrorRows.getRowCount();
        }
    }
}
Also used : TransExecutionConfiguration(org.pentaho.di.trans.TransExecutionConfiguration) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) TransConfiguration(org.pentaho.di.trans.TransConfiguration) 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)

Example 7 with ActionExecutionException

use of org.pentaho.platform.api.engine.ActionExecutionException in project pdi-platform-plugin by pentaho.

the class PdiAction method createJobMetaJCR.

private JobMeta createJobMetaJCR(Repository repository) throws ActionExecutionException {
    JobMeta jobMeta = new JobMeta();
    try {
        IUnifiedRepository unifiedRepository = PentahoSystem.get(IUnifiedRepository.class, null);
        RepositoryFile jobFile = unifiedRepository.getFile(idTopath(job));
        jobMeta = repository.loadJob(new StringObjectId((String) jobFile.getId()), null);
    } catch (Throwable e) {
        throw new ActionExecutionException(org.pentaho.platform.plugin.kettle.messages.Messages.getInstance().getErrorString("PdiAction.ERROR_0006_FAILED_TRANSMETA_CREATION", directory, transformation), // $NON-NLS-1$
        e);
    }
    if (arguments != null) {
        jobMeta.setArguments(arguments);
    }
    if (logLevel != null) {
        jobMeta.setLogLevel(LogLevel.getLogLevelForCode(logLevel));
    }
    populateInputs(jobMeta, jobMeta);
    return jobMeta;
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) StringObjectId(org.pentaho.di.repository.StringObjectId) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Example 8 with ActionExecutionException

use of org.pentaho.platform.api.engine.ActionExecutionException in project pdi-platform-plugin by pentaho.

the class PdiAction method createTransMeta.

private TransMeta createTransMeta(Repository repository, LogWriter logWriter) throws ActionExecutionException {
    // TODO: do we need to set a parameter on the job or trans meta called
    // ${pentaho.solutionpath} to mimic the old in-line xml replacement behavior
    // (see scm history for an illustration of this)?
    // TODO: beware of BISERVER-50
    EngineMetaLoader engineMetaUtil = new EngineMetaLoader(repository);
    TransMeta transMeta;
    try {
        transMeta = engineMetaUtil.loadTransMeta(directory, transformation);
    } catch (FileNotFoundException e) {
        throw new ActionExecutionException(org.pentaho.platform.plugin.kettle.messages.Messages.getInstance().getErrorString("PdiAction.ERROR_0006_FAILED_TRANSMETA_CREATION", directory, transformation), // $NON-NLS-1$
        e);
    }
    if (arguments != null) {
        transMeta.setArguments(arguments);
    }
    if (logLevel != null) {
        transMeta.setLogLevel(LogLevel.getLogLevelForCode(logLevel));
    }
    populateInputs(transMeta, transMeta);
    return transMeta;
}
Also used : TransMeta(org.pentaho.di.trans.TransMeta) FileNotFoundException(java.io.FileNotFoundException) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException)

Example 9 with ActionExecutionException

use of org.pentaho.platform.api.engine.ActionExecutionException 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)

Example 10 with ActionExecutionException

use of org.pentaho.platform.api.engine.ActionExecutionException in project pdi-platform-plugin by pentaho.

the class PdiAction method createTransMetaJCR.

private TransMeta createTransMetaJCR(Repository repository) throws ActionExecutionException {
    TransMeta transMeta = new TransMeta();
    try {
        IUnifiedRepository unifiedRepository = PentahoSystem.get(IUnifiedRepository.class, null);
        RepositoryFile transFile = unifiedRepository.getFile(idTopath(transformation));
        transMeta = repository.loadTransformation(new StringObjectId((String) transFile.getId()), null);
    } catch (Throwable e) {
        throw new ActionExecutionException(org.pentaho.platform.plugin.kettle.messages.Messages.getInstance().getErrorString("PdiAction.ERROR_0006_FAILED_TRANSMETA_CREATION", directory, transformation), // $NON-NLS-1$
        e);
    }
    if (arguments != null) {
        transMeta.setArguments(arguments);
    }
    if (logLevel != null) {
        transMeta.setLogLevel(LogLevel.getLogLevelForCode(logLevel));
    }
    populateInputs(transMeta, transMeta);
    return transMeta;
}
Also used : TransMeta(org.pentaho.di.trans.TransMeta) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) StringObjectId(org.pentaho.di.repository.StringObjectId) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository)

Aggregations

ActionExecutionException (org.pentaho.platform.api.engine.ActionExecutionException)10 FileNotFoundException (java.io.FileNotFoundException)6 ActionValidationException (org.pentaho.platform.api.engine.ActionValidationException)4 KettleException (org.pentaho.di.core.exception.KettleException)3 KettleSecurityException (org.pentaho.di.core.exception.KettleSecurityException)3 KettleStepException (org.pentaho.di.core.exception.KettleStepException)3 KettleValueException (org.pentaho.di.core.exception.KettleValueException)3 UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)3 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 List (java.util.List)2 JobMeta (org.pentaho.di.job.JobMeta)2 StringObjectId (org.pentaho.di.repository.StringObjectId)2 TransMeta (org.pentaho.di.trans.TransMeta)2 ActionInitializationException (org.pentaho.platform.api.engine.ActionInitializationException)2 ActionSequenceException (org.pentaho.platform.api.engine.ActionSequenceException)2 UnresolvedParameterException (org.pentaho.platform.api.engine.UnresolvedParameterException)2 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1