Search in sources :

Example 1 with LogWriter

use of org.pentaho.di.core.logging.LogWriter in project pdi-platform-plugin by pentaho.

the class PdiAction method execute.

/**
 * Execute the specified transformation in the chosen repository.
 */
public void execute() throws Exception {
    // Reset the flag
    transPrepExecutionFailure = false;
    IAuthorizationPolicy authorizationPolicy = PentahoSystem.get(IAuthorizationPolicy.class, PentahoSessionHolder.getSession());
    if (!authorizationPolicy.isAllowed(RepositoryExecuteAction.NAME)) {
        throw new IllegalStateException(org.pentaho.platform.plugin.kettle.messages.Messages.getInstance().getErrorString(// $NON-NLS-1$
        "PdiAction.ERROR_0010_NO_PERMISSION_TO_EXECUTE"));
    }
    if (log.isDebugEnabled()) {
        // $NON-NLS-1$
        log.debug(Messages.getInstance().getString("Kettle.DEBUG_START"));
    }
    validate();
    TransMeta transMeta = null;
    JobMeta jobMeta = null;
    // $NON-NLS-1$
    LogWriter logWriter = LogWriter.getInstance("Kettle-pentaho", false);
    // initialize environment variables
    KettleSystemListener.environmentInit(PentahoSessionHolder.getSession());
    pdiUserAppender = KettleLogStore.getAppender();
    Repository repository = connectToRepository(logWriter);
    LoggingBufferAppender loggingBufferAppender = new LoggingBufferAppender(pdiUserAppender);
    logWriter.addAppender(loggingBufferAppender);
    try {
        if (transformation != null) {
            // to populate available databases, etc in "standard" kettle fashion
            try {
                transMeta = createTransMetaJCR(repository);
            } catch (Throwable t) {
            // ignored
            }
            if (transMeta == null) {
                transMeta = createTransMeta(repository, logWriter);
            }
            if (transMeta == null) {
                throw new IllegalStateException(org.pentaho.platform.plugin.kettle.messages.Messages.getInstance().getErrorString(// $NON-NLS-1$
                "PdiAction.ERROR_0004_FAILED_TRANSMETA_CREATION"));
            }
            executeTransformation(transMeta, logWriter);
        } else if (job != null) {
            // to populate available databases, etc in "standard" kettle fashion
            try {
                jobMeta = createJobMetaJCR(repository);
            } catch (Throwable t) {
            // ignored
            }
            if (jobMeta == null) {
                jobMeta = createJobMeta(repository, logWriter);
            }
            if (jobMeta == null) {
                throw new IllegalStateException(org.pentaho.platform.plugin.kettle.messages.Messages.getInstance().getErrorString(// $NON-NLS-1$
                "PdiAction.ERROR_0005_FAILED_JOBMETA_CREATION"));
            }
            executeJob(jobMeta, repository, logWriter);
        }
    } finally {
        logWriter.removeAppender(loggingBufferAppender);
        if (repository != null) {
            if (log.isDebugEnabled()) {
                // $NON-NLS-1$
                log.debug(Messages.getInstance().getString("Kettle.DEBUG_DISCONNECTING"));
            }
            repository.disconnect();
        }
    }
    XMLHandlerCache.getInstance().clear();
}
Also used : IAuthorizationPolicy(org.pentaho.platform.api.engine.IAuthorizationPolicy) JobMeta(org.pentaho.di.job.JobMeta) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Repository(org.pentaho.di.repository.Repository) LogWriter(org.pentaho.di.core.logging.LogWriter) TransMeta(org.pentaho.di.trans.TransMeta)

Example 2 with LogWriter

use of org.pentaho.di.core.logging.LogWriter in project pdi-platform-plugin by pentaho.

the class PdiActionTest method testSetParamsIntoExecuteConfigInExecuteTrans.

@Test
public void testSetParamsIntoExecuteConfigInExecuteTrans() throws ActionExecutionException {
    PdiAction action = spy(new PdiAction());
    TransMeta meta = mock(TransMeta.class);
    LogWriter logWriter = mock(LogWriter.class);
    Trans trans = mock(Trans.class);
    Log log = mock(Log.class);
    TransExecutionConfiguration transExecutionConfiguration = mock(TransExecutionConfiguration.class);
    action.setLogger(log);
    action.setLogLevel(TEST_LOG_LEVEL_PARAM);
    action.setClearLog(TEST_TRUE_BOOLEAN_PARAM);
    action.setRunSafeMode(TEST_FALSE_BOOLEAN_PARAM);
    action.setGatheringMetrics(TEST_FALSE_BOOLEAN_PARAM);
    doReturn(trans).when(action).newTrans(meta);
    doReturn(true).when(action).customizeTrans(trans, logWriter);
    doReturn(false).when(log).isDebugEnabled();
    doReturn(transExecutionConfiguration).when(action).newTransExecutionConfiguration();
    action.executeTransformation(meta, logWriter);
    verify(transExecutionConfiguration).setLogLevel(LogLevel.getLogLevelForCode(TEST_LOG_LEVEL_PARAM));
    verify(transExecutionConfiguration).setClearingLog(Boolean.valueOf(TEST_TRUE_BOOLEAN_PARAM));
    verify(transExecutionConfiguration).setSafeModeEnabled(Boolean.valueOf(TEST_FALSE_BOOLEAN_PARAM));
    verify(transExecutionConfiguration).setGatheringMetrics(Boolean.valueOf(TEST_FALSE_BOOLEAN_PARAM));
}
Also used : TransExecutionConfiguration(org.pentaho.di.trans.TransExecutionConfiguration) LogWriter(org.pentaho.di.core.logging.LogWriter) Log(org.apache.commons.logging.Log) TransMeta(org.pentaho.di.trans.TransMeta) Trans(org.pentaho.di.trans.Trans) Test(org.junit.Test)

Example 3 with LogWriter

use of org.pentaho.di.core.logging.LogWriter in project pdi-platform-plugin by pentaho.

the class PdiActionTest method testSetParamsIntoExecuteConfigInExecuteJob.

@Test
public void testSetParamsIntoExecuteConfigInExecuteJob() throws ActionExecutionException {
    PdiAction action = spy(new PdiAction());
    JobMeta meta = mock(JobMeta.class);
    Repository repository = mock(Repository.class);
    LogWriter logWriter = mock(LogWriter.class);
    Job job = mock(Job.class);
    Log log = mock(Log.class);
    JobExecutionConfiguration jobExecutionConfiguration = mock(JobExecutionConfiguration.class);
    Result result = mock(Result.class);
    action.setLogger(log);
    action.setLogLevel(TEST_LOG_LEVEL_PARAM);
    action.setClearLog(TEST_TRUE_BOOLEAN_PARAM);
    action.setRunSafeMode(TEST_FALSE_BOOLEAN_PARAM);
    action.setExpandingRemoteJob(TEST_FALSE_BOOLEAN_PARAM);
    action.setStartCopyName(TEST_START_COPY_NAME_PARAM);
    doReturn(job).when(action).newJob(repository, meta);
    doReturn(false).when(log).isDebugEnabled();
    doReturn(jobExecutionConfiguration).when(action).newJobExecutionConfiguration();
    doReturn(result).when(job).getResult();
    action.executeJob(meta, repository, logWriter);
    verify(jobExecutionConfiguration).setLogLevel(LogLevel.getLogLevelForCode(TEST_LOG_LEVEL_PARAM));
    verify(jobExecutionConfiguration).setClearingLog(Boolean.valueOf(TEST_TRUE_BOOLEAN_PARAM));
    verify(jobExecutionConfiguration).setSafeModeEnabled(Boolean.valueOf(TEST_FALSE_BOOLEAN_PARAM));
    verify(jobExecutionConfiguration).setExpandingRemoteJob(Boolean.valueOf(TEST_FALSE_BOOLEAN_PARAM));
    verify(jobExecutionConfiguration).setStartCopyName(TEST_START_COPY_NAME_PARAM);
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) FileSystemBackedUnifiedRepository(org.pentaho.platform.repository2.unified.fs.FileSystemBackedUnifiedRepository) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Repository(org.pentaho.di.repository.Repository) LogWriter(org.pentaho.di.core.logging.LogWriter) Log(org.apache.commons.logging.Log) Job(org.pentaho.di.job.Job) JobExecutionConfiguration(org.pentaho.di.job.JobExecutionConfiguration) Result(org.pentaho.di.core.Result) Test(org.junit.Test)

Aggregations

LogWriter (org.pentaho.di.core.logging.LogWriter)3 Log (org.apache.commons.logging.Log)2 Test (org.junit.Test)2 JobMeta (org.pentaho.di.job.JobMeta)2 Repository (org.pentaho.di.repository.Repository)2 TransMeta (org.pentaho.di.trans.TransMeta)2 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)2 Result (org.pentaho.di.core.Result)1 Job (org.pentaho.di.job.Job)1 JobExecutionConfiguration (org.pentaho.di.job.JobExecutionConfiguration)1 Trans (org.pentaho.di.trans.Trans)1 TransExecutionConfiguration (org.pentaho.di.trans.TransExecutionConfiguration)1 IAuthorizationPolicy (org.pentaho.platform.api.engine.IAuthorizationPolicy)1 FileSystemBackedUnifiedRepository (org.pentaho.platform.repository2.unified.fs.FileSystemBackedUnifiedRepository)1