Hitachi Vantara Pentaho Community Forums
Results 1 to 2 of 2

Thread: Kettle API running a job.

  1. #1

    Default Kettle API running a job.

    Here's what I want to do. I want to run a job, without neccesarily giving a full path to the job, but rather, giving the name of the repository and the name of the job. THe reason for this is as follows: I am dealing with multiople installs of pentaho in multiple environments, the repo and job names are the same, but the locations on the file system may not b, I want this solution I am building to be flexible. Basically I have some code, but I am having an issue getting it to do what I want, I have an exception no matter what I try. I think my issue is in obtaining a RepositoryDirectoryInterface, but I'm not sure if that is even neccesary. My code is as follows:

    Code:
    import
    org.pentaho.di.core.KettleEnvironment;
    import
    org.pentaho.di.core.plugins.PluginRegistry;
    import
    org.pentaho.di.core.plugins.RepositoryPluginType;
    import
    org.pentaho.di.job.Job;
    import
    org.pentaho.di.job.JobMeta;
    import
    org.pentaho.di.repository.ObjectId;
    import
    org.pentaho.di.repository.RepositoriesMeta;
    import
    org.pentaho.di.repository.Repository;
    import
    org.pentaho.di.repository.RepositoryDirectoryInterface;
    import
    org.pentaho.di.repository.RepositoryMeta;
    import
    org.pentaho.di.repository.filerep.KettleFileRepository;
    public
    class ExecuteJob {publicstaticvoid main(String[] args) throws Exception{String repoName = "test_repo";String user = "admin";String pass = "";//not going to use filename//String filename = args[0];
    KettleEnvironment.createKettleHome();KettleEnvironment.init();RepositoriesMeta reposMeta =
    new RepositoriesMeta();reposMeta.readData();
    PluginRegistry registry = PluginRegistry.getInstance();
    Repository repo = registry.loadClass(RepositoryPluginTypeclass,repoMeta,Repository.class
    );
    repo.connect(user, pass);
    /////////////////////////////////////////////////RepositoryDirectoryInterface rdi = repo.
    ObjectId jobID = repo.getJobId("test_job", null);
    //CANT BE NULL THROWS EXCEPTION, WHAT DO I NEED HERE??
    ///////////////////////////////////////////////////JobMeta jobMeta = repo.loadJob(jobID,
    null);Job job = new Job(null, jobMeta);job.start();job.waitUntilFinished();if(job.getErrors()!=0){System.out.println("Error encountered!");}if(repo.isConnected()){repo.disconnect();}}
    }




    THe code didn't paste over too well, but it is readable. The part where I have the //////// comments is where the issue is. Please explain to me how to generate that class I am getting an exception, but I think I don't even need it. Is there a better way to do this??

    Any help is HUGELY appreciated. Thanks in advance.

    Edit: How do I make the code box bigger so it is easier to read?

  2. #2

    Default

    I know this is possible because I can, from the command line call kettle.bat with arguments of repo,user, pass, job, etc. What do I have to use, and why can't I find it anywhere. I've read the appropriate section in ch 22 of Pentaho Kettle Solutions, and it gives an incomplete example for setting this up if you have a filename. However, I am trying to make due without the filename, and since I can do it from the command line, which ultimately just calls something in the .jars I know it is possible. The javadoc for the classes involved are very bad. There is no description of what most methods do, only argument and return types. This leaves me clueless, as I know what none of these methods truly do. SHould I really need to read through tons of source code to call a job? Why am I forced to piece together lots of nonsense, surely somone has done this and has a solution.

Tags for this Thread

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.