Example code of Ktr conversion executed by kettle program call

Source: Internet
Author: User
Package Com. ***. DCI;

ImportJava. Io. file;
ImportJava. Io. filenotfoundexception;
ImportJava. Io. fileoutputstream;
ImportJava. Io. filewriter;
ImportJava. Io. ioexception;
ImportJava. util. arraylist;
ImportJava. util. date;
ImportJava. util. hashmap;
ImportJava. util. iterator;
ImportJava. util. List;
ImportJava. util. Map;
ImportJava. util. Map. entry;

ImportOrg. logicalcobwebs. proxool. admin. servlet. adminservlet;
ImportOrg. pentaho. Di. Core. Exception. kettleexception;
ImportOrg. pentaho. Di. Core. util. envutil;
ImportOrg. pentaho. Di. Trans. steploader;
ImportOrg. pentaho. Di. Trans. Trans;
ImportOrg. pentaho. Di. Trans. transmeta;
ImportOrg. pentaho. Di. Trans. performance. stepperformancesnapshot;

Public ClassTest {

/**
* @ Param ARGs
* @ throws ioexception
*/
Public static void main (string [] ARGs) throws ioexception {
// explanation
runtransformation (" C:/SS. ktr ");
}

Public Static VoidRuntransformation (string filename)ThrowsIoexception {
Try{

// Initialize a task
Steploader. INIT ();
Envutil. environmentinit ();
Transmeta = New Transmeta (filename );
Transmeta. setcapturingstepperformancesnapshots ( True );
Trans trans = New Trans (transmeta );
Trans. setmonitored ( True );
Trans. setinitializing (True );
Trans. setpreparing ( True );
Trans. setrunning ( True );
Trans. setsafemodeenabled ( True );
Trans.exe cute ( Null ); // You can pass arguments instead of null.

// Store results in a map
Hashmap map = New Hashmap ();
Trans. setstepperformancesnapshots (MAP );
While (! Trans. isfinished ()){

If (Trans. getstepperformancesnapshots ()! = Null & Amp; Trans. getstepperformancesnapshots (). Size ()> 0 ){

// Get all steps
Map <string, list <stepperformancesnapshot> snapshots = trans. getstepperformancesnapshots ();

// Output dynamic monitoring
Iterator it = snapshots. entryset (). iterator ();
String onetimeonestepinfo = "";
String onttimeallstepinfo = "";
While (It. hasnext ())
{
Entry en = (entry) it. Next ();
// Current steps
Arraylist snapshotlist = (arraylist) en. getvalue ();
If (Snapshotlist! = Null & Snapshotlist. Size ()> 0 ){

Stepperformancesnapshot snapshot = (stepperformancesnapshot) snapshotlist. Get (snapshotlist. Size ()-1 );

Onetimeonestepinfo = ("stepname:" + snapshot. getstepname () + ";"
+ "Errors:" + snapshot. geterrors () + ";"
+ "Inputbuffersize:" + snapshot. getinputbuffersize () + ";"
+ "Linesinput:" + snapshot. getlinesinput () + ";"
+ "Linesoutput:" + snapshot. getlinesoutput () + ";"
+ "Linesread:" + snapshot. getlinesread () + ";"
+ "Linesrejected:" + snapshot. getlinesrejected () + ";"
+ "Linesupdated:" + snapshot. getlinesupdated () + ";"
+ "Lineswritten:" + snapshot. getlineswritten () + ";"
+ "Outputbuffersize:" + snapshot. getoutputbuffersize () + ";"
+ "Stepcopy:" + snapshot. getstepcopy () + ";"
+ "Timedifference:" + snapshot. gettimedifference () + ";"
+ "Totalerrors:" + snapshot. gettotalerrors () + ";"
+ "Totallinesinput:" + snapshot. gettotallinesinput () + ";"
+ "Totallinesoutput:" + snapshot. gettotallinesoutput () + ";"
+ "Totallinesread:" + snapshot. gettotallinesread () + ";"
+ "Totallinesrejected:" + snapshot. gettotallinesrejected () + ";"
+ "Totallinesupdated:" + snapshot. gettotallinesupdated () + ";"
+ "Totallineswritten:" + snapshot. gettotallineswritten () + ";"
+ "Date:" + snapshot. getdate () + "\ n ");

Onttimeallstepinfo + = onetimeonestepinfo;

}
System. Out. println (onttimeallstepinfo + "\ n ");
}


}
}

System. Out. println ("End ............");

}Catch(Kettleexception e ){
//Todo put your exception-handling code here.
System. Out. println (E );
}
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.