Search in sources :

Example 91 with Job

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);
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) Job(org.pentaho.di.job.Job) Before(org.junit.Before)

Example 92 with Job

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));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JobMeta(org.pentaho.di.job.JobMeta) StringWriter(java.io.StringWriter) HttpServletResponse(javax.servlet.http.HttpServletResponse) Point(org.pentaho.di.core.gui.Point) Job(org.pentaho.di.job.Job) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 93 with Job

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())));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JobMeta(org.pentaho.di.job.JobMeta) StringWriter(java.io.StringWriter) HttpServletResponse(javax.servlet.http.HttpServletResponse) Point(org.pentaho.di.core.gui.Point) Job(org.pentaho.di.job.Job) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 94 with Job

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;
}
Also used : Job(org.pentaho.di.job.Job) KettleException(org.pentaho.di.core.exception.KettleException) UnknownParamException(org.pentaho.di.core.parameters.UnknownParamException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) LogLevel(org.pentaho.di.core.logging.LogLevel)

Example 95 with Job

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

Job (org.pentaho.di.job.Job)95 JobMeta (org.pentaho.di.job.JobMeta)44 Test (org.junit.Test)35 Result (org.pentaho.di.core.Result)22 KettleException (org.pentaho.di.core.exception.KettleException)20 PrintWriter (java.io.PrintWriter)17 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)17 Trans (org.pentaho.di.trans.Trans)14 IOException (java.io.IOException)11 Before (org.junit.Before)11 Point (org.pentaho.di.core.gui.Point)11 LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)11 JobExecutionConfiguration (org.pentaho.di.job.JobExecutionConfiguration)10 Repository (org.pentaho.di.repository.Repository)10 ArrayList (java.util.ArrayList)9 ServletException (javax.servlet.ServletException)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 SimpleLoggingObject (org.pentaho.di.core.logging.SimpleLoggingObject)9 JobConfiguration (org.pentaho.di.job.JobConfiguration)9