Thursday, March 7, 2013

Pentaho Kettle (PDI): Get Pan and Kitchen Exit Code

Various monitoring applications require the exit code/status of a process as an input.

A simple example (test1.sh):

#!/bin/bash
echo "Hi"
exit $?

Let’s run it:
$ ./test1.sh
Let’s check the exit status (of the last command) which can be accessed via $?:
$ echo $?
0

Let’s take a look at how we can get the exit status from Pan and Kitchen:

For demonstration purposes we create a very simple dummy transformation which just outputs some data to the log:
Now create a shell file:
#!/bin/bash
/opt/pentaho/pdi/pdi-ce-4.4.0-stable/pan.sh -file='/home/dsteiner/Dropbox/pentaho/Examples/PDI/exit_code/tr_dummy.ktr' -Level=Basic > /home/dsteiner/Dropbox/pentaho/Examples/PDI/exit_code/err.log
echo $?

Note the echo $? in the last line which will return the exit status. This is for demonstration purposes here only. Normally you would use exit $? instead.

On Windows use instead:
echo %ERRORLEVEL%

Now lets run the shell script:
The exit status tells us that the transformation was executed successfully.

Next we will introduce an error into the transformation. I just add a formula step with a wrong formula:
We run the shell script again and this time we get a return code other than 0:
Any return code other than 0 means it is an error.

Please find below an overview of all the return codes (src1, src2):

Error Code
Description
0
The job ran without a problem
1
Errors occurred during processing
2
An unexpected error occurred during loading / running of the job / transformation, an error in the XML format, reading the file, problems with the repository connection, ...
3
unable to connect to a database, open a file or other initialization error.
7
The job / transformation couldn't be loaded from XML or the Repository
8
Error loading job entries or steps or plugins (error in loading one of the plugins mostly).one of the plugins in the plugins/ folder is not written correctly or is incompatible. You should never see this anymore though. If you do it's going to be an installation problem with Kettle.
9
Command line usage printing

3 comments:

  1. Hi, this does not work for me. Even if the ktr fails - like if DB password is wrong, have an Abort step or if the target table name is given wrong, always pan.sh returns 0. Any help is greatly appreciated.

    ReplyDelete
    Replies
    1. I think you need to update your Kitchen.bat or Pan.bat files. Add echo %ERRORLEVEL% as last line of those files. Then it would return proper error codes. Atleast it worked for me :)

      Delete
    2. EXIT /B %ERRORLEVEL% at the end of kitchen or pan batch file

      Delete