2016-06-30 2 views
0

ケトルの.ktrファイルに含まれているすべての手順をJavaで調べる必要があります。ケトル(ペンタホPDI):どのように仕事のすべてのステップを訪問する

私は

KettleEnvironment.init(); 
JobMeta jobMeta = new JobMeta("file.kjb", null); 
Job job = new Job(null, jobMeta); 

ではなくJobを使用してもJobMetaだが、基本的な手順にジョブを訪問するための任意の方法を提供するように見えます。

+0

私の側からの野生の推測:

package testTransformationsInJob; import java.util.List; import org.pentaho.di.core.KettleEnvironment; import org.pentaho.di.core.exception.KettleException; import org.pentaho.di.job.DelegationListener; import org.pentaho.di.job.Job; import org.pentaho.di.job.JobExecutionConfiguration; import org.pentaho.di.job.JobMeta; import org.pentaho.di.trans.Trans; import org.pentaho.di.trans.TransExecutionConfiguration; import org.pentaho.di.trans.TransListener; import org.pentaho.di.trans.step.StepMetaDataCombi; import org.pentaho.di.trans.step.StepInterface; public class MainClass { public MainClass() { // TODO Auto-generated constructor stub } private static class MyTransListener implements TransListener { @Override public void transActive(Trans arg0) { // TODO Auto-generated method stub } @Override public void transFinished(Trans arg0) throws KettleException { // TODO Auto-generated method stub } @Override public void transStarted(Trans delegatedTrans) throws KettleException { List<StepMetaDataCombi> stepCombis = delegatedTrans.getSteps(); if(stepCombis == null) { return; } for(StepMetaDataCombi stepCombi: stepCombis) { StepInterface step = stepCombi.step; // // Do some useful work here. // System.out.println("\t" + step.getStepname()); } } } private static class MyDelegationListener implements DelegationListener { private TransListener transListener; MyDelegationListener(TransListener transListener) { this.transListener = transListener; } @Override public void jobDelegationStarted(Job delegatedJob, JobExecutionConfiguration jobExecutionConfiguration) { // TODO Auto-generated method stub } @Override public void transformationDelegationStarted(Trans delegatedTrans, TransExecutionConfiguration transExecutionConfiguratioStep) { System.out.println("transformationDelegationStarted"); System.out.println(delegatedTrans.getName()); // transformationDelegationStarted() is called after Trans object is constructed // but before it is executed. // However, we can't access steps at this point using delegatedTrans.getSteps() // since steps are constructed somewhere in execute method. // However, we can add TransListener here, which will be able to iterate steps. delegatedTrans.addTransListener(this.transListener); } } public static void main(String[] args) throws KettleException { KettleEnvironment.init(); JobMeta jobMeta = new JobMeta("d:\\test_job.kjb", null); Job job = new Job(null, jobMeta); // Here I add a DelegationListener, which will add a TransListener to every Trans in job. // Not sure though if using DelegationListener is a right way to access Transformation Job Entries // Maybe there is a more elegant way to do it. MyTransListener myTransListener = new MyTransListener(); DelegationListener delegationListener = new MyDelegationListener(myTransListener); job.addDelegationListener(delegationListener); job.start(); job.waitUntilFinished(); } } 

そして、ここでは、私が手に出力されますが、 'org.pentaho.diをチェックしています.job.DelegationListener'インターフェース? transformDelegationStarted(Trans、TransExecutionConfiguration)メソッドは、Transが作成された後、実行される前に呼び出されます。あなたはそれを実装して仕事に加えることができます。 – user4637357

+0

ありがとうございます。新しいDelegationAdapter()public void transformDelegationStarted(Trans trans、TransExecutionConfiguration transExecutionConfiguration){// ...} 'が呼び出されることはありません。 – Claudio

答えて

0

だから、私はDelegationListenerTransListenerの組み合わせでそれをやっていましたが、ここにDelegationListenerが必要かどうかはわかりません。たぶん、変換ジョブ・エントリにTransListenersを追加するための別の方法があります:

2016/07/07 09:47:37 - test_job - Start of job execution 
2016/07/07 09:47:37 - test_job - Starting entry [Transformation] 
2016/07/07 09:47:37 - Transformation - Loading transformation from XML file [file:///d://test.ktr] 
transformationDelegationStarted 
test 
2016/07/07 09:47:37 - test - Dispatching started for transformation [test] 
    Detect empty stream 
    User Defined Java Class 
2016/07/07 09:47:37 - Detect empty stream.0 - Finished processing (I=0, O=0, R=0, W=1, U=0, E=0) 
2016/07/07 09:47:38 - User Defined Java Class.0 - Finished processing (I=0, O=0, R=1, W=1, U=0, E=0) 
2016/07/07 09:47:38 - test_job - Finished job entry [Transformation] (result=[true]) 
2016/07/07 09:47:38 - test_job - Job execution finished 
関連する問題