Hitachi Vantara Pentaho Community Forums
Results 1 to 6 of 6

Thread: Executing a Job from Java code

  1. #1
    Join Date
    Jul 2007
    Posts
    1,013

    Default Executing a Job from Java code

    I have successfully executed a transformation from Java code this way:

    Code:
    StepLoader.init();
                
                EnvUtil.environmentInit();
                
                TransMeta transMeta = new TransMeta(filename);
                transMeta.setVariable("testvar", "testvalue");
                
                Trans trans = new Trans(transMeta);
                
                trans.execute(null);
    
                trans.waitUntilFinished();
                if ( trans.getErrors() > 0 )
                {
                  throw new RuntimeException( "There were errors during transformation execution." );
                }
    Now I would like to run a Job which simply executes that transformation. I'm trying this, which is either fundamentally wrong or needs something else:

    Code:
        JobEntryLoader.init();
                StepLoader.init();
                EnvUtil.environmentInit();
    
                Job job = new Job(LogWriter.getInstance(), filename, "", null);
                job.setVariable("testvar", "testvalue");
                job.execute();
                
                if ( job.getErrors() > 0 )
                {
                    throw new RuntimeException( "There were errors during job execution." );
                }
                }
    Any help would be greatly appreciated.

    Cheers!

  2. #2
    Join Date
    Jul 2007
    Posts
    1,013

    Default

    Well, I found the Kitchen source code and was able to extract the parts I needed from it. This is what I'm running now:

    Code:
                JobEntryLoader.init();
                StepLoader.init();
                StepLoader stepLoader = StepLoader.getInstance();
                LogWriter log = LogWriter.getInstance(LogWriter.LOG_LEVEL_BASIC);
                
                JobMeta jobMeta = new JobMeta(log, filename, null, null);
                Job job = new Job(log, stepLoader, null, jobMeta);
                job.setVariable("testvar", "testvalue");
                
                job.initializeVariablesFrom(null);
                job.getJobMeta().setInternalKettleVariables(job);
                
                job.execute();
                job.waitUntilFinished();
                
                if ( job.getErrors() > 0 )
                {
                    throw new RuntimeException( "There were errors during job execution." );
                }
    It's more than likely improvable, so any comments are welcome.

    Cheers!

  3. #3
    Join Date
    May 2006
    Posts
    4,882

    Default

    That's pretty much it

    Regards,
    Sven

  4. #4
    Join Date
    Dec 2010
    Posts
    8

    Default

    I want to get Transformation id used in a Job. All i need to know which transfomation in repository is used in a Job.
    Could anyone share the code as per PDI 4 Java API.

  5. #5
    Join Date
    Nov 1999
    Posts
    9,729

    Default

    It's been answered quite a few times so we started to put together some wiki pages on the subject:

    http://wiki.pentaho.com/display/EAI/The+PDI+SDK

    As for your different subject (don't hijack threads please!) you can examine the "log channel" log table after the execution of the job.
    Last edited by MattCasters; 03-28-2011 at 04:17 PM.

  6. #6
    Join Date
    Dec 2010
    Posts
    8

    Smile Thanks Matt once again

    Recently I upgraded PDI Kettle to 4.1.0.

    I got solution from the link provided by you.

    Also i found important things to learn from Pentaho Kettle Solutions which i recently purchased and started reading.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.