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