kettle 程序调用执行ktr转换示例代码
package com.***.dci;
import java.io.File;
import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry;
import org.logicalcobwebs.proxool.admin.servlet.AdminServlet; import org.pentaho.di.core.exception.KettleException; import org.pentaho.di.core.util.EnvUtil; import org.pentaho.di.trans.StepLoader; import org.pentaho.di.trans.Trans; import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.trans.performance.StepPerformanceSnapShot;
public class Test { /**
* @param args * @throws IOException */
public static void main(String[] args) throws IOException { // 解释
runTransformation(\ }
public static void runTransformation(String filename) throws IOException { try {
//初始化任务 StepLoader.init(); EnvUtil.environmentInit();
TransMeta transMeta = new TransMeta(filename); transMeta.setCapturingStepPerformanceSnapShots(true); Trans trans = new Trans(transMeta); trans.setMonitored(true); trans.setInitializing(true); trans.setPreparing(true); trans.setRunning(true); trans.setSafeModeEnabled(true);
trans.execute(null); // You can pass arguments instead of null.
//放入一个MAP存储结果 HashMap map = new HashMap(); trans.setStepPerformanceSnapShots(map); while (!trans.isFinished()) {
if (trans.getStepPerformanceSnapShots() != null&& trans.getStepPerformanceSnapShots().size() > 0) {
//得到所有步骤
Map
//输出动态监控情况
Iterator it = SnapShots.entrySet().iterator(); String oneTimeOneStepInfo = \ String ontTimeAllStepInfo = \ while(it.hasNext())
{
Entry en = (Entry)it.next(); //步骤当前情况
ArrayList SnapShotList = (ArrayList) en.getValue(); if (SnapShotList != null && SnapShotList.size() > 0) {
StepPerformanceSnapShot SnapShot = (StepPerformanceSnapShot) SnapShotList.get(SnapShotList.size() - 1);
oneTimeOneStepInfo = ( \ +\
+ \ + \ + \ + \ + \ + \ + \ + \ + \
+ \ + \ + \ + \ + \ + \ + \ + \ + \
ontTimeAllStepInfo+=oneTimeOneStepInfo; }
System.out.println(ontTimeAllStepInfo+\ } } }
System.out.println(\
} catch (KettleException e) {
// TODO Put your exception-handling code here. System.out.println(e); } } }