使用java创建job(kettle)

搬运原地址

/**
* This method generates a job definition from scratch. 
* 
* It demonstrates the following:
* 
* - Creating a new job
* - Creating and connecting job entries
* 
* @return the generated job definition
*/
public JobMeta generateJob() {

try {
System.out.println("Generating a job definition");


// create empty transformation definition
JobMeta jobMeta = new JobMeta();
jobMeta.setName("Generated Demo Job");


// ------------------------------------------------------------------------------------ 
// Create start entry and put it into the job
// ------------------------------------------------------------------------------------
System.out.println("- Adding Start Entry");

// Create and configure start entry
JobEntrySpecial start = new JobEntrySpecial();
start.setName("START");
start.setStart(true);

// wrap into JobEntryCopy object, which holds generic job entry information
JobEntryCopy startEntry = new JobEntryCopy(start);

// place it on Spoon canvas properly
startEntry.setDrawn(true);
startEntry.setLocation(100, 100);

jobMeta.addJobEntry(startEntry);

// ------------------------------------------------------------------------------------ 
// Create "write to log" entry and put it into the job
// ------------------------------------------------------------------------------------
System.out.println("- Adding Write To Log Entry");

// Create and configure entry
JobEntryWriteToLog writeToLog = new JobEntryWriteToLog();
writeToLog.setName("Output PDI Stats");
writeToLog.setLogLevel(LogLevel.MINIMAL);
writeToLog.setLogSubject("Logging PDI Build Information:");
writeToLog.setLogMessage("Version: ${Internal.Kettle.Version}\n" +
"Build Date: ${Internal.Kettle.Build.Date}");

// wrap into JobEntryCopy object, which holds generic job entry information
JobEntryCopy writeToLogEntry = new JobEntryCopy(writeToLog);

// place it on Spoon canvas properly
writeToLogEntry.setDrawn(true);
writeToLogEntry.setLocation(200, 100);

jobMeta.addJobEntry(writeToLogEntry); 

// connect start entry to logging entry using simple hop
jobMeta.addJobHop(new JobHopMeta(startEntry, writeToLogEntry));

// ------------------------------------------------------------------------------------ 
// Create "success" entry and put it into the job
// ------------------------------------------------------------------------------------
System.out.println("- Adding Success Entry");

// crate and configure entry
JobEntrySuccess success = new JobEntrySuccess();
success.setName("Success");

// wrap into JobEntryCopy object, which holds generic job entry information
JobEntryCopy successEntry = new JobEntryCopy(success);

// place it on Spoon canvas properly
successEntry.setDrawn(true);
successEntry.setLocation(400, 100);

jobMeta.addJobEntry(successEntry); 

// connect logging entry to success entry on TRUE evaluation 
JobHopMeta greenHop = new JobHopMeta(writeToLogEntry, successEntry);
greenHop.setEvaluation(true);
jobMeta.addJobHop(greenHop);

// ------------------------------------------------------------------------------------ 
// Create "abort" entry and put it into the job
// ------------------------------------------------------------------------------------
System.out.println("- Adding Abort Entry");

// crate and configure entry
JobEntryAbort abort = new JobEntryAbort();
abort.setName("Abort Job");

// wrap into JobEntryCopy object, which holds generic job entry information
JobEntryCopy abortEntry = new JobEntryCopy(abort);

// place it on Spoon canvas properly
abortEntry.setDrawn(true);
abortEntry.setLocation(400, 300);

jobMeta.addJobEntry(abortEntry); 

// connect logging entry to abort entry on TRUE evaluation 
JobHopMeta redHop = new JobHopMeta(writeToLogEntry, abortEntry);
redHop.setEvaluation(true);
jobMeta.addJobHop(redHop);


return jobMeta;


} catch (Exception e) {


// something went wrong, just log and return
e.printStackTrace();
return null;
}


}

 

posted @ 2017-11-07 15:27  衰草寒烟  阅读(4539)  评论(0编辑  收藏  举报