Search in sources :

Example 1 with JobEntrySpecial

use of org.pentaho.di.job.entries.special.JobEntrySpecial in project pentaho-kettle by pentaho.

the class SpoonJobDelegate method newJobEntry.

public JobEntryCopy newJobEntry(JobMeta jobMeta, String type_desc, boolean openit) {
    PluginRegistry registry = PluginRegistry.getInstance();
    PluginInterface jobPlugin;
    try {
        jobPlugin = PluginRegistry.getInstance().findPluginWithName(JobEntryPluginType.class, type_desc);
        if (jobPlugin == null) {
            // Check if it's not START or DUMMY
            if (JobMeta.STRING_SPECIAL_START.equals(type_desc) || JobMeta.STRING_SPECIAL_DUMMY.equals(type_desc)) {
                jobPlugin = registry.findPluginWithId(JobEntryPluginType.class, JobMeta.STRING_SPECIAL);
            }
        }
        if (jobPlugin != null) {
            // Determine name & number for this entry.
            // See if the name is already used...
            // 
            String entry_name = type_desc;
            int nr = 2;
            JobEntryCopy check = jobMeta.findJobEntry(entry_name, 0, true);
            while (check != null) {
                entry_name = type_desc + " " + nr++;
                check = jobMeta.findJobEntry(entry_name, 0, true);
            }
            // Generate the appropriate class...
            JobEntryInterface jei = (JobEntryInterface) registry.loadClass(jobPlugin);
            jei.setPluginId(jobPlugin.getIds()[0]);
            jei.setName(entry_name);
            if (jei.isSpecial()) {
                if (JobMeta.STRING_SPECIAL_START.equals(type_desc)) {
                    // Check if start is already on the canvas...
                    if (jobMeta.findStart() != null) {
                        JobGraph.showOnlyStartOnceMessage(spoon.getShell());
                        return null;
                    }
                    ((JobEntrySpecial) jei).setStart(true);
                    jei.setName(JobMeta.STRING_SPECIAL_START);
                }
                if (JobMeta.STRING_SPECIAL_DUMMY.equals(type_desc)) {
                    ((JobEntrySpecial) jei).setDummy(true);
                // jei.setName(JobMeta.STRING_SPECIAL_DUMMY); // Don't overwrite the name
                }
            }
            if (openit) {
                JobEntryDialogInterface d = getJobEntryDialog(jei, jobMeta);
                if (d != null && d.open() != null) {
                    JobEntryCopy jge = new JobEntryCopy();
                    jge.setEntry(jei);
                    jge.setLocation(50, 50);
                    jge.setNr(0);
                    jobMeta.addJobEntry(jge);
                    // Verify that the name is not already used in the job.
                    // 
                    jobMeta.renameJobEntryIfNameCollides(jge);
                    spoon.addUndoNew(jobMeta, new JobEntryCopy[] { jge }, new int[] { jobMeta.indexOfJobEntry(jge) });
                    spoon.refreshGraph();
                    spoon.refreshTree();
                    return jge;
                } else {
                    return null;
                }
            } else {
                JobEntryCopy jge = new JobEntryCopy();
                jge.setEntry(jei);
                jge.setLocation(50, 50);
                jge.setNr(0);
                jobMeta.addJobEntry(jge);
                spoon.addUndoNew(jobMeta, new JobEntryCopy[] { jge }, new int[] { jobMeta.indexOfJobEntry(jge) });
                spoon.refreshGraph();
                spoon.refreshTree();
                return jge;
            }
        } else {
            return null;
        }
    } catch (Throwable e) {
        new ErrorDialog(spoon.getShell(), BaseMessages.getString(PKG, "Spoon.ErrorDialog.UnexpectedErrorCreatingNewJobGraphEntry.Title"), BaseMessages.getString(PKG, "Spoon.ErrorDialog.UnexpectedErrorCreatingNewJobGraphEntry.Message"), new Exception(e));
        return null;
    }
}
Also used : JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobEntrySpecial(org.pentaho.di.job.entries.special.JobEntrySpecial) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) JobEntryDialogInterface(org.pentaho.di.job.entry.JobEntryDialogInterface) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) InvocationTargetException(java.lang.reflect.InvocationTargetException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) KettleException(org.pentaho.di.core.exception.KettleException) JobEntryPluginType(org.pentaho.di.core.plugins.JobEntryPluginType)

Example 2 with JobEntrySpecial

use of org.pentaho.di.job.entries.special.JobEntrySpecial in project pentaho-kettle by pentaho.

the class Job method execute.

/**
 * Execute a job without previous results. This is a job entry point (not recursive)<br>
 * <br>
 *
 * @return the result of the execution
 *
 * @throws KettleException
 */
private Result execute() throws KettleException {
    try {
        log.snap(Metrics.METRIC_JOB_START);
        finished.set(false);
        stopped.set(false);
        KettleEnvironment.setExecutionInformation(this, rep);
        log.logMinimal(BaseMessages.getString(PKG, "Job.Comment.JobStarted"));
        ExtensionPointHandler.callExtensionPoint(log, KettleExtensionPoint.JobStart.id, this);
        // Start the tracking...
        JobEntryResult jerStart = new JobEntryResult(null, null, BaseMessages.getString(PKG, "Job.Comment.JobStarted"), BaseMessages.getString(PKG, "Job.Reason.Started"), null, 0, null);
        jobTracker.addJobTracker(new JobTracker(jobMeta, jerStart));
        active.set(true);
        // Where do we start?
        JobEntryCopy startpoint;
        // synchronize this to a parent job if needed.
        // 
        Object syncObject = this;
        if (parentJob != null) {
            // parallel execution in a job
            syncObject = parentJob;
        }
        synchronized (syncObject) {
            beginProcessing();
        }
        Result res = null;
        if (startJobEntryCopy == null) {
            startpoint = jobMeta.findJobEntry(JobMeta.STRING_SPECIAL_START, 0, false);
        } else {
            startpoint = startJobEntryCopy;
            res = startJobEntryResult;
        }
        if (startpoint == null) {
            throw new KettleJobException(BaseMessages.getString(PKG, "Job.Log.CounldNotFindStartingPoint"));
        }
        JobEntryResult jerEnd = null;
        if (startpoint.isStart()) {
            // Perform optional looping in the special Start job entry...
            // 
            // long iteration = 0;
            boolean isFirst = true;
            JobEntrySpecial jes = (JobEntrySpecial) startpoint.getEntry();
            while ((jes.isRepeat() || isFirst) && !isStopped()) {
                isFirst = false;
                res = execute(0, null, startpoint, null, BaseMessages.getString(PKG, "Job.Reason.Started"));
            // 
            // if (iteration > 0 && (iteration % 500) == 0) {
            // System.out.println("other 500 iterations: " + iteration);
            // }
            // iteration++;
            // 
            }
            jerEnd = new JobEntryResult(res, jes.getLogChannelId(), BaseMessages.getString(PKG, "Job.Comment.JobFinished"), BaseMessages.getString(PKG, "Job.Reason.Finished"), null, 0, null);
        } else {
            res = execute(0, res, startpoint, null, BaseMessages.getString(PKG, "Job.Reason.Started"));
            jerEnd = new JobEntryResult(res, startpoint.getEntry().getLogChannel().getLogChannelId(), BaseMessages.getString(PKG, "Job.Comment.JobFinished"), BaseMessages.getString(PKG, "Job.Reason.Finished"), null, 0, null);
        }
        // Save this result...
        jobTracker.addJobTracker(new JobTracker(jobMeta, jerEnd));
        log.logMinimal(BaseMessages.getString(PKG, "Job.Comment.JobFinished"));
        active.set(false);
        finished.set(true);
        return res;
    } finally {
        log.snap(Metrics.METRIC_JOB_STOP);
    }
}
Also used : JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobEntrySpecial(org.pentaho.di.job.entries.special.JobEntrySpecial) JobTracker(org.pentaho.di.core.gui.JobTracker) FileObject(org.apache.commons.vfs2.FileObject) KettleJobException(org.pentaho.di.core.exception.KettleJobException) WebResult(org.pentaho.di.www.WebResult) Result(org.pentaho.di.core.Result)

Example 3 with JobEntrySpecial

use of org.pentaho.di.job.entries.special.JobEntrySpecial in project pentaho-kettle by pentaho.

the class JobEntryCopyTest method setUp.

@Before
public void setUp() throws Exception {
    originJobEntry = new JobEntryCopy();
    copyJobEntry = new JobEntryCopy();
    originEntry = new JobEntrySpecial("EntrySpecial", false, false);
    originEntry.setChanged(false);
    originJobEntry.setEntry(originEntry);
}
Also used : JobEntrySpecial(org.pentaho.di.job.entries.special.JobEntrySpecial) Before(org.junit.Before)

Example 4 with JobEntrySpecial

use of org.pentaho.di.job.entries.special.JobEntrySpecial in project pentaho-kettle by pentaho.

the class JobEntryTransIntIT method testPDI14676.

/*
   * Tests whether the job can force a transformation to stop, when the job is asked to stop.
   * A timeout parameter is required, to avoid a failed unit test from running forever.
   */
@Test(timeout = 30000)
public void testPDI14676() throws KettleException, IOException, InterruptedException {
    String transFilename = createPDI14676Transformation();
    // Setup Job
    JobEntrySpecial startEntry = new JobEntrySpecial("Start", true, false);
    JobEntryCopy startCopy = new JobEntryCopy(startEntry);
    startCopy.setLocation(50, 50);
    startCopy.setDrawn();
    JobEntryTrans transEntry = new JobEntryTrans("PDI-13676 example");
    transEntry.setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME);
    transEntry.setFileName(transFilename);
    JobEntryCopy transCopy = new JobEntryCopy(transEntry);
    transCopy.setLocation(200, 50);
    transCopy.setDrawn();
    JobMeta jobMeta = new JobMeta();
    jobMeta.addJobEntry(startCopy);
    jobMeta.addJobEntry(transCopy);
    jobMeta.addJobHop(new JobHopMeta(startCopy, transCopy));
    // Run job
    Job jobInstance = new Job(null, jobMeta);
    jobInstance.start();
    // Allow job startup time
    while (!jobInstance.isActive()) {
        if (jobInstance.isStopped() || jobInstance.isFinished()) {
            break;
        }
        Thread.sleep(10);
    }
    // Let the job run for a short period
    Thread.sleep(300);
    assertFalse(jobInstance.isStopped());
    assertFalse(jobInstance.isFinished());
    // Tell the job to stop.
    jobInstance.stopAll();
    assertTrue(jobInstance.isStopped());
    // Allow the job's thread to stop and be cleaned up
    while (!jobInstance.isFinished() || jobInstance.isActive()) {
        Thread.sleep(10);
    }
    // Ensure that the job and the thread have both stopped
    assertTrue(jobInstance.isFinished());
    assertFalse(jobInstance.isAlive());
}
Also used : JobEntrySpecial(org.pentaho.di.job.entries.special.JobEntrySpecial) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobMeta(org.pentaho.di.job.JobMeta) JobHopMeta(org.pentaho.di.job.JobHopMeta) Job(org.pentaho.di.job.Job) Test(org.junit.Test)

Example 5 with JobEntrySpecial

use of org.pentaho.di.job.entries.special.JobEntrySpecial in project pentaho-kettle by pentaho.

the class JobMeta method createDummyEntry.

/**
 * Creates the dummy entry.
 *
 * @return the job entry copy
 */
public static final JobEntryCopy createDummyEntry() {
    JobEntrySpecial jobEntrySpecial = new JobEntrySpecial(STRING_SPECIAL_DUMMY, false, true);
    JobEntryCopy jobEntry = new JobEntryCopy();
    jobEntry.setObjectId(null);
    jobEntry.setEntry(jobEntrySpecial);
    jobEntry.setLocation(50, 50);
    jobEntry.setDrawn(false);
    jobEntry.setDescription(BaseMessages.getString(PKG, "JobMeta.DummyJobEntry.Description"));
    return jobEntry;
}
Also used : JobEntrySpecial(org.pentaho.di.job.entries.special.JobEntrySpecial) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy)

Aggregations

JobEntrySpecial (org.pentaho.di.job.entries.special.JobEntrySpecial)8 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 KettleException (org.pentaho.di.core.exception.KettleException)2 KettleStepException (org.pentaho.di.core.exception.KettleStepException)2 PluginInterface (org.pentaho.di.core.plugins.PluginInterface)2 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)2 JobHopMeta (org.pentaho.di.job.JobHopMeta)2 JobMeta (org.pentaho.di.job.JobMeta)2 JobEntryDialogInterface (org.pentaho.di.job.entry.JobEntryDialogInterface)2 JobEntryInterface (org.pentaho.di.job.entry.JobEntryInterface)2 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)2 FileObject (org.apache.commons.vfs2.FileObject)1 MessageBox (org.eclipse.swt.widgets.MessageBox)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Result (org.pentaho.di.core.Result)1 KettleJobException (org.pentaho.di.core.exception.KettleJobException)1 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)1 JobTracker (org.pentaho.di.core.gui.JobTracker)1