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