use of org.pentaho.di.ui.job.dialog.JobExecutionConfigurationDialog in project pentaho-kettle by pentaho.
the class SpoonJobDelegate method executeJob.
public void executeJob(JobMeta jobMeta, boolean local, boolean remote, Date replayDate, boolean safe, String startCopyName, int startCopyNr) throws KettleException {
if (jobMeta == null) {
return;
}
JobExecutionConfiguration executionConfiguration = spoon.getJobExecutionConfiguration();
// Remember the variables set previously
//
Object[] data = spoon.variables.getData();
String[] fields = spoon.variables.getRowMeta().getFieldNames();
Map<String, String> variableMap = new HashMap<>();
for (int idx = 0; idx < fields.length; idx++) {
variableMap.put(fields[idx], data[idx].toString());
}
executionConfiguration.setVariables(variableMap);
executionConfiguration.getUsedVariables(jobMeta);
executionConfiguration.setReplayDate(replayDate);
executionConfiguration.setRepository(spoon.rep);
executionConfiguration.setSafeModeEnabled(safe);
executionConfiguration.setStartCopyName(startCopyName);
executionConfiguration.setStartCopyNr(startCopyNr);
executionConfiguration.getUsedArguments(jobMeta, spoon.getArguments(), spoon.getMetaStore());
executionConfiguration.setLogLevel(DefaultLogLevel.getLogLevel());
JobExecutionConfigurationDialog dialog = newJobExecutionConfigurationDialog(executionConfiguration, jobMeta);
if (!jobMeta.isShowDialog() || dialog.open()) {
JobGraph jobGraph = spoon.getActiveJobGraph();
jobGraph.jobLogDelegate.addJobLog();
//
for (String varName : executionConfiguration.getVariables().keySet()) {
String varValue = executionConfiguration.getVariables().get(varName);
jobMeta.setVariable(varName, varValue);
}
//
for (String paramName : executionConfiguration.getParams().keySet()) {
String paramValue = executionConfiguration.getParams().get(paramName);
jobMeta.setParameterValue(paramName, paramValue);
}
jobMeta.activateParameters();
//
if (executionConfiguration.getLogLevel() != null) {
jobMeta.setLogLevel(executionConfiguration.getLogLevel());
}
//
if (executionConfiguration.getStartCopyName() != null) {
jobMeta.setStartCopyName(executionConfiguration.getStartCopyName());
}
// Set the run options
//
jobMeta.setClearingLog(executionConfiguration.isClearingLog());
jobMeta.setSafeModeEnabled(executionConfiguration.isSafeModeEnabled());
jobMeta.setExpandingRemoteJob(executionConfiguration.isExpandingRemoteJob());
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.SpoonJobMetaExecutionStart.id, jobMeta);
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.SpoonJobExecutionConfiguration.id, executionConfiguration);
try {
ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.SpoonTransBeforeStart.id, new Object[] { executionConfiguration, jobMeta, jobMeta, spoon.getRepository() });
} catch (KettleException e) {
log.logError(e.getMessage(), jobMeta.getFilename());
return;
}
if (!executionConfiguration.isExecutingLocally() && !executionConfiguration.isExecutingRemotely()) {
if (jobMeta.hasChanged()) {
jobGraph.showSaveFileMessage();
}
}
//
if (executionConfiguration.isExecutingLocally()) {
jobGraph.startJob(executionConfiguration);
} else if (executionConfiguration.isExecutingRemotely()) {
// Executing remotely
// Check if jobMeta has changed
jobGraph.handleJobMetaChanges(jobMeta);
// Activate the parameters, turn them into variables...
// jobMeta.hasChanged()
jobMeta.activateParameters();
if (executionConfiguration.getRemoteServer() != null) {
Job.sendToSlaveServer(jobMeta, executionConfiguration, spoon.rep, spoon.metaStore);
spoon.delegates.slaves.addSpoonSlave(executionConfiguration.getRemoteServer());
} else {
MessageBox mb = new MessageBox(spoon.getShell(), SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "Spoon.Dialog.NoRemoteServerSpecified.Message"));
mb.setText(BaseMessages.getString(PKG, "Spoon.Dialog.NoRemoteServerSpecified.Title"));
mb.open();
}
}
}
}
use of org.pentaho.di.ui.job.dialog.JobExecutionConfigurationDialog in project pentaho-kettle by pentaho.
the class SpoonJobDelegateTest method testSetParamsIntoMetaInExecuteJob.
@Test
@SuppressWarnings("ResultOfMethodCallIgnored")
public void testSetParamsIntoMetaInExecuteJob() throws KettleException {
doCallRealMethod().when(delegate).executeJob(jobMeta, true, false, null, false, null, 0);
JobExecutionConfiguration jobExecutionConfiguration = mock(JobExecutionConfiguration.class);
RowMetaInterface rowMeta = mock(RowMetaInterface.class);
Shell shell = mock(Shell.class);
JobExecutionConfigurationDialog jobExecutionConfigurationDialog = mock(JobExecutionConfigurationDialog.class);
JobGraph activeJobGraph = mock(JobGraph.class);
activeJobGraph.jobLogDelegate = mock(JobLogDelegate.class);
doReturn(jobExecutionConfiguration).when(spoon).getJobExecutionConfiguration();
doReturn(rowMeta).when(spoon.variables).getRowMeta();
doReturn(EMPTY_STRING_ARRAY).when(rowMeta).getFieldNames();
doReturn(shell).when(spoon).getShell();
doReturn(jobExecutionConfigurationDialog).when(delegate).newJobExecutionConfigurationDialog(jobExecutionConfiguration, jobMeta);
doReturn(activeJobGraph).when(spoon).getActiveJobGraph();
doReturn(MAP_WITH_TEST_VARIABLE).when(jobExecutionConfiguration).getVariables();
doReturn(MAP_WITH_TEST_PARAM).when(jobExecutionConfiguration).getParams();
doReturn(TEST_LOG_LEVEL).when(jobExecutionConfiguration).getLogLevel();
doReturn(TEST_START_COPY_NAME).when(jobExecutionConfiguration).getStartCopyName();
doReturn(TEST_BOOLEAN_PARAM).when(jobExecutionConfiguration).isClearingLog();
doReturn(TEST_BOOLEAN_PARAM).when(jobExecutionConfiguration).isSafeModeEnabled();
doReturn(TEST_BOOLEAN_PARAM).when(jobExecutionConfiguration).isExpandingRemoteJob();
delegate.executeJob(jobMeta, true, false, null, false, null, 0);
verify(jobMeta).setVariable(TEST_VARIABLE_KEY, TEST_VARIABLE_VALUE);
verify(jobMeta).setParameterValue(TEST_PARAM_KEY, TEST_PARAM_VALUE);
verify(jobMeta).activateParameters();
verify(jobMeta).setLogLevel(TEST_LOG_LEVEL);
verify(jobMeta).setStartCopyName(TEST_START_COPY_NAME);
verify(jobMeta).setClearingLog(TEST_BOOLEAN_PARAM);
verify(jobMeta).setSafeModeEnabled(TEST_BOOLEAN_PARAM);
verify(jobMeta).setExpandingRemoteJob(TEST_BOOLEAN_PARAM);
}
Aggregations