简体   繁体   中英

Sample program for transformation and job in pentaho kettle-spoon using Java (eclipse)

Hi i am very new to pentaho kettle-spoon. I want a sample program which takes input from .csv file and push into database and after certain time like 2:30 am a job will run and few records from that database(sql developer) in csv format will emailed to user. I am using Java to call the transformation like:

public static void main(String[] args) {
    try {
            KettleEnvironment.init();
            TransMeta metaData = new TransMeta("hello.ktr");
            Trans trans = new Trans( metaData );
            trans.execute( null );
            trans.waitUntilFinished();
            if ( trans.getErrors() > 0 ) {
                System.out.print( "Error Executing transformation" );
            }
    } 
    catch( KettleException e ) {
            e.printStackTrace();
    }
}

Here I have created HelloWorld(hello.ktr) program in Spoon and called it in java code. I want to do similar. Making transformation and job in spoon and calling in my java code. kindly help me out with it.

Why don't you schedule the program to run at 2:30AM using crontab? In lunux, create a script called whatever you want eg start.sh and add the following script code:

#!/bin/bash
30 2 * * * /root/transScript.sh /dev/null 2>&1 | mail -s "Cronjob ouput" saket@gmail.com

Then create another script maybe called transScript like /root/transScript.sh and add the following in script to run the transformation using pan. pan is the tool that runs kettle transformations via the command line. For running kettle jobs via command line, you have to use kitchen.

$ cat pdi.sh
#!/bin/bash
/opt/data-integration/pan.sh -file=/Users/saket/Transformations/hello.ktr 
/level:Basic

Then all you have to do is run this command to begin the scheduled task:

crontab start.sh

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM