Skip to content

Instantly share code, notes, and snippets.

@amusarra
Created June 7, 2011 10:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amusarra/1011985 to your computer and use it in GitHub Desktop.
Save amusarra/1011985 to your computer and use it in GitHub Desktop.
Classe Java per l’esecuzione di un Job Kettle.
package it.dontesta.lab.jobs.kettle;
import org.pentaho.di.core.KettleEnvironment;
import org.pentaho.di.core.logging.LogChannel;
import org.pentaho.di.core.logging.LogChannelInterface;
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.RepositoriesMeta;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.repository.RepositoryDirectoryInterface;
import org.pentaho.di.repository.RepositoryMeta;
/**
* @author amusarra
*/
public class ExecuteGenericJob {
public static final String STRING_LOG = "ExecuteGenericJob";
public static void main(String[] args) throws Exception {
LogChannelInterface log = new LogChannel(STRING_LOG);
String filename = args[0];
KettleEnvironment.init();
RepositoriesMeta repositoriesMeta = new RepositoriesMeta();
repositoriesMeta.readData();
RepositoryMeta repositoryMeta = repositoriesMeta.findRepository("1");
PluginRegistry registry = PluginRegistry.getInstance();
Repository repository = registry.loadClass(RepositoryPluginType.class,
repositoryMeta, Repository.class);
log.logBasic("Repository Description: "
+ repositoryMeta.getDescription());
repository.init(repositoryMeta);
repository.connect("admin", "admin");
RepositoryDirectoryInterface directory = repository
.loadRepositoryDirectoryTree();
directory = directory.findDirectory("ShirusKettleDirectory");
JobMeta jobMeta = new JobMeta();
jobMeta = repository.loadJob(filename, directory, null, null);
log.logBasic("JobMeta Description: " + jobMeta.getDescription());
log.logBasic("JobMeta Version: " + jobMeta.getJobversion());
log.logBasic("JobMeta Modify Date: " + jobMeta.getModifiedDate());
log.logBasic("JobMeta Id: " + jobMeta.getObjectId().getId());
Job job = new Job(repository, jobMeta);
log.logBasic("Job Name: " + job.getJobname());
job.start();
job.waitUntilFinished();
if (job.getErrors() != 0) {
log.logError("Job Error: " + job.getErrors());
log.logError("Error encountered!");
}
}
}
INFO 06-02 19:05:02,864 - Using "/var/folders/Ze/ZeZnC-m0GParEA44C74AVk+++TI/-Tmp-/vfs_cache" as temporary files store.
INFO 06-02 19:05:04,034 - RepositoriesMeta - Reading repositories XML file: /Users/amusarra/.kettle/repositories.xml
INFO 06-02 19:05:04,141 - ExecuteGenericJob - Repository Description: kettle-amusarra-repository
Exception in thread "main" org.pentaho.di.core.exception.KettleException:
Error connecting to the repository!
Error occured while trying to connect to the database
INFO 06-02 20:25:53,130 - Using "/var/folders/Ze/ZeZnC-m0GParEA44C74AVk+++TI/-Tmp-/vfs_cache" as temporary files store.
INFO 06-02 20:25:54,036 - RepositoriesMeta - Reading repositories XML file: /Users/amusarra/.kettle/repositories.xml
INFO 06-02 20:25:54,111 - ExecuteGenericJob - Repository Description: kettle-amusarra-repository
INFO 06-02 20:26:14,612 - ExecuteGenericJob - JobMeta Description: Job che esegue la trasformazione per l'integrazione del Codice Fiscale
INFO 06-02 20:26:14,612 - ExecuteGenericJob - JobMeta Version: 1.0
INFO 06-02 20:26:14,612 - ExecuteGenericJob - JobMeta Modify Date: 2011-01-31 15:51:54.0
INFO 06-02 20:26:14,612 - ExecuteGenericJob - JobMeta Id: 2
INFO 06-02 20:26:14,617 - ExecuteGenericJob - Job Name: ExecuteCalculateCodiceFiscale
INFO 06-02 20:26:14,618 - ExecuteCalculateCodiceFiscale - Inizio dell'esecuzione del job
INFO 06-02 20:26:14,622 - ExecuteCalculateCodiceFiscale - Inizio entry [ImportPerson_CalculateCodiceFiscale]
INFO 06-02 20:26:14,624 - ImportPerson_CalculateCodiceFiscale - Caricamento della trasformazione dal repository [ImportPerson_CalculateCodiceFiscale] nella cartella [/ShirusKettleDirectory]
INFO 06-02 20:26:16,051 - ExecuteCalculateCodiceFiscale - Inizio entry [Mail Success]
INFO 06-02 20:26:16,166 - Mail Success - Added file '///Users/amusarra/Progetti/PentahoKettleAPI/KettleAPI-4.1.1/ImportPerson_CalculateCodiceFiscale.log' to the mail message.
INFO 06-02 20:26:16,401 - ExecuteCalculateCodiceFiscale - Terminata jobentry [Mail Success] (risultato=[true])
INFO 06-02 20:26:16,402 - ExecuteCalculateCodiceFiscale - Terminata jobentry [ImportPerson_CalculateCodiceFiscale] (risultato=[true])
INFO 06-02 20:26:16,402 - ExecuteCalculateCodiceFiscale - L'esecuzione del job è terminata
<repositories>
<connection>
<name>Kettle Repository on shirus-pentaho-suite-00</name>
<server>shirus-pentaho-suite-00.lab.roma.dontesta.it</server>
<type>MYSQL</type>
<access>Native</access>
<database>kettle_4_1_repository</database>
<port>3306</port>
<username>kettle</username>
<password>Encrypted 2be98afc86aa7f2e4cb79a575ca86a3df</password>
<servername/>
</connection>
<repository>
<id>KettleDatabaseRepository</id>
<name>1</name>
<description>kettle-amusarra-repository</description>
<connection>Kettle Repository on shirus-pentaho-suite-00</connection>
</repository>
</repositories>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment