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

1.3k views Asked by At

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.

1

There are 1 answers

3
The Georgia On

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

#!/bin/bash
30 2 * * * /root/transScript.sh /dev/null 2>&1 | mail -s "Cronjob ouput" [email protected]

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