use of org.pentaho.di.job.Job in project pentaho-kettle by pentaho.
the class JobEntrySetVariablesTest method setUp.
@Before
public void setUp() throws Exception {
job = new Job(null, new JobMeta());
entry = new JobEntrySetVariables();
job.getJobMeta().addJobEntry(new JobEntryCopy(entry));
entry.setParentJob(job);
job.setStopped(false);
}
use of org.pentaho.di.job.Job in project pentaho-kettle by pentaho.
the class GetJobStatusServletIT method testGetJobStatusServletEscapesHtmlWhenTransFound.
@Test
public void testGetJobStatusServletEscapesHtmlWhenTransFound() throws ServletException, IOException {
KettleLogStore.init();
HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
Job mockJob = mock(Job.class);
JobMeta mockJobMeta = mock(JobMeta.class);
LogChannelInterface mockLogChannelInterface = mock(LogChannelInterface.class);
mockJob.setName(ServletTestUtils.BAD_STRING);
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter(out);
when(mockHttpServletRequest.getContextPath()).thenReturn(GetJobStatusServlet.CONTEXT_PATH);
when(mockHttpServletRequest.getParameter(anyString())).thenReturn(ServletTestUtils.BAD_STRING);
when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
when(mockJobMap.getJob(any(CarteObjectEntry.class))).thenReturn(mockJob);
when(mockJob.getLogChannel()).thenReturn(mockLogChannelInterface);
when(mockJob.getJobMeta()).thenReturn(mockJobMeta);
when(mockJobMeta.getMaximum()).thenReturn(new Point(10, 10));
getJobStatusServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
assertFalse(out.toString().contains(ServletTestUtils.BAD_STRING));
}
use of org.pentaho.di.job.Job in project pentaho-kettle by pentaho.
the class StopJobServletIT method testStopJobServletEscapesHtmlWhenTransFound.
@Test
public void testStopJobServletEscapesHtmlWhenTransFound() throws ServletException, IOException {
KettleLogStore.init();
HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
Job mockJob = mock(Job.class);
JobMeta mockJobMeta = mock(JobMeta.class);
LogChannelInterface mockLogChannelInterface = mock(LogChannelInterface.class);
mockJob.setName(ServletTestUtils.BAD_STRING);
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter(out);
when(mockHttpServletRequest.getContextPath()).thenReturn(StopJobServlet.CONTEXT_PATH);
when(mockHttpServletRequest.getParameter(anyString())).thenReturn(ServletTestUtils.BAD_STRING);
when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
when(mockJobMap.getJob(any(CarteObjectEntry.class))).thenReturn(mockJob);
when(mockJob.getLogChannelId()).thenReturn(ServletTestUtils.BAD_STRING);
when(mockJob.getLogChannel()).thenReturn(mockLogChannelInterface);
when(mockJob.getJobMeta()).thenReturn(mockJobMeta);
when(mockJobMeta.getMaximum()).thenReturn(new Point(10, 10));
stopJobServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("H1", out.toString())));
}
use of org.pentaho.di.job.Job in project pentaho-platform by pentaho.
the class KettleComponent method executeJob.
private boolean executeJob(final JobMeta jobMeta, final Repository repository) {
boolean success = true;
Job job = null;
try {
if (jobMeta != null) {
try {
job = new Job(repository, jobMeta);
} catch (Exception e) {
throw new KettleComponentException(Messages.getInstance().getErrorString("Kettle.ERROR_0021_BAD_JOB_METADATA"), // $NON-NLS-1$
e);
}
}
if (job == null) {
debug(getKettleLog(true));
throw new KettleComponentException(Messages.getInstance().getErrorString(// $NON-NLS-1$
"Kettle.ERROR_0021_BAD_JOB_METADATA"));
}
// Remember where to get our execution logging from
//
logChannelId = job.getLogChannelId();
try {
if (ComponentBase.debug) {
// $NON-NLS-1$
debug(Messages.getInstance().getString("Kettle.DEBUG_STARTING_JOB"));
}
LogLevel lvl = getLogLevel();
job.setLogLevel(lvl);
job.start();
} catch (Exception e) {
throw new KettleComponentException(Messages.getInstance().getErrorString("Kettle.ERROR_0022_JOB_START_FAILED"), // $NON-NLS-1$
e);
}
try {
// etc.
if (ComponentBase.debug) {
// $NON-NLS-1$
debug(Messages.getInstance().getString("Kettle.DEBUG_JOB_RUNNING"));
}
job.waitUntilFinished();
if (job.getResult().getNrErrors() > 0) {
debug(getKettleLog(true));
throw new KettleComponentException(Messages.getInstance().getErrorString(// $NON-NLS-1$
"Kettle.ERROR_0014_ERROR_DURING_EXECUTE"));
}
} catch (Exception e) {
throw new KettleComponentException(Messages.getInstance().getErrorString("Kettle.ERROR_0014_ERROR_DURING_EXECUTE"), // $NON-NLS-1$
e);
} finally {
if (job != null) {
cleanLogChannel(job);
}
}
// Dump the Kettle log...
debug(getKettleLog(false));
} catch (KettleComponentException e) {
success = false;
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("Kettle.ERROR_0008_ERROR_RUNNING", e.toString()), e);
}
prepareKettleOutput(job);
return success;
}
use of org.pentaho.di.job.Job 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