Search in sources :

Example 76 with JobMeta

use of org.pentaho.di.job.JobMeta 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 77 with JobMeta

use of org.pentaho.di.job.JobMeta in project pentaho-kettle by pentaho.

the class KettleFileRepositoryIT method verifyJobSamples.

private void verifyJobSamples(RepositoryDirectoryInterface samplesDirectory) throws Exception {
    FileObject jobSamplesFolder = KettleVFS.getFileObject("samples/jobs/");
    FileObject[] files = jobSamplesFolder.findFiles(new FileSelector() {

        @Override
        public boolean traverseDescendents(FileSelectInfo arg0) throws Exception {
            return true;
        }

        @Override
        public boolean includeFile(FileSelectInfo info) throws Exception {
            return info.getFile().getName().getExtension().equalsIgnoreCase("kjb");
        }
    });
    List<FileObject> filesList = Arrays.asList(files);
    Collections.sort(filesList, new Comparator<FileObject>() {

        @Override
        public int compare(FileObject o1, FileObject o2) {
            return o1.getName().getPath().compareTo(o2.getName().getPath());
        }
    });
    for (FileObject file : filesList) {
        String jobFilename = file.getName().getPath();
        System.out.println("Storing/Loading/validating job '" + jobFilename + "'");
        // Load the JobMeta object...
        // 
        JobMeta jobMeta = new JobMeta(jobFilename, repository);
        jobMeta.setFilename(null);
        // The name is sometimes empty in the file, duplicates are present too...
        // Replaces slashes and the like as well...
        // 
        jobMeta.setName(Const.createName(file.getName().getBaseName()));
        jobMeta.setName(jobMeta.getName().replace('/', '-'));
        if (Utils.isEmpty(jobMeta.getName())) {
            jobMeta.setName(Const.createName(file.getName().getBaseName()));
        }
        if (jobMeta.getName().contains("/")) {
            jobMeta.setName(jobMeta.getName().replace('/', '-'));
        }
        // Save it in the repository in the samples folder
        // 
        jobMeta.setRepositoryDirectory(samplesDirectory);
        repository.save(jobMeta, "unit testing");
        assertNotNull(jobMeta.getObjectId());
        // Load it back up again...
        // 
        JobMeta repJobMeta = repository.loadJob(jobMeta.getObjectId(), null);
        String oneXml = repJobMeta.getXML();
        // Save & load it again
        // 
        repository.save(jobMeta, "unit testing");
        repJobMeta = repository.loadJob(jobMeta.getObjectId(), null);
        String twoXml = repJobMeta.getXML();
        // The XML needs to be identical after loading
        // 
        // storeFile(oneXml, "/tmp/one.ktr");
        // storeFile(twoXml, "/tmp/two.ktr");
        // 
        assertEquals(oneXml, twoXml);
    }
    // Verify the number of stored files, see if we can find them all again.
    // 
    System.out.println("Stored " + files.length + " job samples in folder " + samplesDirectory.getPath());
    String[] jobNames = repository.getJobNames(samplesDirectory.getObjectId(), false);
    assertEquals(files.length, jobNames.length);
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) FileSelector(org.apache.commons.vfs2.FileSelector) FileObject(org.apache.commons.vfs2.FileObject) FileSelectInfo(org.apache.commons.vfs2.FileSelectInfo) KettleException(org.pentaho.di.core.exception.KettleException)

Example 78 with JobMeta

use of org.pentaho.di.job.JobMeta in project pentaho-kettle by pentaho.

the class RunConfigurationDelegate method updateLoadedJobs.

protected void updateLoadedJobs(String key, RunConfiguration runConfig) {
    for (JobMeta job : spoonSupplier.get().getLoadedJobs()) {
        for (int i = 0; i < job.nrJobEntries(); i++) {
            JobEntryInterface entry = job.getJobEntry(i).getEntry();
            if (entry instanceof JobEntryTrans) {
                JobEntryTrans jet = (JobEntryTrans) entry;
                if (jet.getRunConfiguration().equals(key)) {
                    try {
                        ExtensionPointHandler.callExtensionPoint(job.getLogChannel(), KettleExtensionPoint.JobEntryTransSave.id, new Object[] { job, runConfig.getName() });
                    } catch (KettleException e) {
                        spoonSupplier.get().getLog().logBasic("Unable to set run configuration in job " + job.getName());
                    }
                    jet.setRunConfiguration(runConfig.getName());
                    jet.setRemoteSlaveServerName(((DefaultRunConfiguration) runConfig).getServer());
                    jet.setLoggingRemoteWork(((DefaultRunConfiguration) runConfig).isLogRemoteExecutionLocally());
                    jet.setChanged();
                }
            }
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) JobEntryTrans(org.pentaho.di.job.entries.trans.JobEntryTrans) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint)

Example 79 with JobMeta

use of org.pentaho.di.job.JobMeta in project pentaho-kettle by pentaho.

the class RunConfigurationDelegateTest method testUpdateLoadedJobs_PDI16777.

@Test
public void testUpdateLoadedJobs_PDI16777() {
    JobEntryTrans trans = new JobEntryTrans();
    trans.setRunConfiguration("key");
    JobMeta meta = new JobMeta();
    meta.addJobEntry(new JobEntryCopy(trans));
    JobMeta[] jobs = new JobMeta[] { meta };
    doReturn(jobs).when(spoon).getLoadedJobs();
    DefaultRunConfiguration config = new DefaultRunConfiguration();
    config.setName("Test");
    config.setServer("localhost");
    delegate.updateLoadedJobs("key", config);
    assertEquals("Test", trans.getRunConfiguration());
    assertEquals("localhost", trans.getRemoteSlaveServerName());
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobEntryTrans(org.pentaho.di.job.entries.trans.JobEntryTrans) DefaultRunConfiguration(org.pentaho.di.engine.configuration.impl.pentaho.DefaultRunConfiguration) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 80 with JobMeta

use of org.pentaho.di.job.JobMeta in project pentaho-kettle by pentaho.

the class RunConfigurationImportExtensionPoint method createSlaveServerRunConfigurations.

private List<RunConfiguration> createSlaveServerRunConfigurations(List<String> existingConfigurationNames, AbstractMeta abstractMeta) {
    List<RunConfiguration> runConfigurations = new ArrayList<>();
    if (abstractMeta instanceof JobMeta) {
        JobMeta jobMeta = (JobMeta) abstractMeta;
        Map<String, List<JobEntryTrans>> slaveServerGroups = jobMeta.getJobCopies().stream().map(JobEntryCopy::getEntry).filter(entry -> entry instanceof JobEntryTrans).map(entry -> (JobEntryTrans) entry).filter(entry -> Utils.isEmpty(entry.getRunConfiguration())).filter(entry -> !Utils.isEmpty(entry.getRemoteSlaveServerName())).collect(Collectors.groupingBy(JobEntryTrans::getRemoteSlaveServerName));
        slaveServerGroups.forEach((remoteServerName, entries) -> {
            String runConfigurationName = createRunConfigurationName(existingConfigurationNames, remoteServerName);
            DefaultRunConfiguration runConfiguration = createRunConfiguration(runConfigurationName, remoteServerName);
            runConfigurations.add(runConfiguration);
            entries.forEach(e -> e.setRunConfiguration(runConfiguration.getName()));
        });
    }
    return runConfigurations;
}
Also used : RunConfiguration(org.pentaho.di.engine.configuration.api.RunConfiguration) DefaultRunConfiguration(org.pentaho.di.engine.configuration.impl.pentaho.DefaultRunConfiguration) EmbeddedMetaStore(org.pentaho.di.core.attributes.metastore.EmbeddedMetaStore) KettleException(org.pentaho.di.core.exception.KettleException) JobMeta(org.pentaho.di.job.JobMeta) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Utils(org.pentaho.di.core.util.Utils) AbstractMeta(org.pentaho.di.base.AbstractMeta) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) RunConfigurationManager(org.pentaho.di.engine.configuration.impl.RunConfigurationManager) List(java.util.List) EmbeddedRunConfigurationManager(org.pentaho.di.engine.configuration.impl.EmbeddedRunConfigurationManager) DefaultRunConfigurationProvider(org.pentaho.di.engine.configuration.impl.pentaho.DefaultRunConfigurationProvider) Map(java.util.Map) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ExtensionPointInterface(org.pentaho.di.core.extension.ExtensionPointInterface) JobEntryTrans(org.pentaho.di.job.entries.trans.JobEntryTrans) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) Comparator(java.util.Comparator) ExtensionPoint(org.pentaho.di.core.extension.ExtensionPoint) JobMeta(org.pentaho.di.job.JobMeta) RunConfiguration(org.pentaho.di.engine.configuration.api.RunConfiguration) DefaultRunConfiguration(org.pentaho.di.engine.configuration.impl.pentaho.DefaultRunConfiguration) JobEntryTrans(org.pentaho.di.job.entries.trans.JobEntryTrans) ArrayList(java.util.ArrayList) DefaultRunConfiguration(org.pentaho.di.engine.configuration.impl.pentaho.DefaultRunConfiguration) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

JobMeta (org.pentaho.di.job.JobMeta)254 Test (org.junit.Test)88 TransMeta (org.pentaho.di.trans.TransMeta)69 KettleException (org.pentaho.di.core.exception.KettleException)62 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)48 Job (org.pentaho.di.job.Job)45 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)27 Repository (org.pentaho.di.repository.Repository)25 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)25 Point (org.pentaho.di.core.gui.Point)24 ArrayList (java.util.ArrayList)23 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)22 SlaveServer (org.pentaho.di.cluster.SlaveServer)17 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)17 FileObject (org.apache.commons.vfs2.FileObject)16 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)16 LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)15 SimpleLoggingObject (org.pentaho.di.core.logging.SimpleLoggingObject)15 PrintWriter (java.io.PrintWriter)12 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)12