Java Code Examples for org.pentaho.di.trans.Trans#execute()

The following examples show how to use org.pentaho.di.trans.Trans#execute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransformationResource.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@GET
@Path( "/start/{id : .+}" )
@Produces( { MediaType.APPLICATION_JSON } )
public TransformationStatus startTransformation( @PathParam( "id" ) String id ) {
  Trans trans = CarteResource.getTransformation( id );
  try {
    // Discard old log lines from old transformation runs
    //
    KettleLogStore.discardLines( trans.getLogChannelId(), true );

    String carteObjectId = UUID.randomUUID().toString();
    SimpleLoggingObject servletLoggingObject =
      new SimpleLoggingObject( getClass().getName(), LoggingObjectType.CARTE, null );
    servletLoggingObject.setContainerObjectId( carteObjectId );
    servletLoggingObject.setLogLevel( trans.getLogLevel() );
    trans.setParent( servletLoggingObject );
    trans.execute( null );
  } catch ( KettleException e ) {
    e.printStackTrace();
  }
  return getTransformationStatus( id );
}
 
Example 2
Source File: JPanelTransformation.java    From nordpos with GNU General Public License v3.0 5 votes vote down vote up
public Trans runTransformationFromResource(String resource, List<TransVariable> listVaribale) {
    try {
        // load latest revision of the transformation
        // The TransMeta object is the programmatic representation of a transformation definition.
        TransMeta transMeta = new TransMeta(getClass().getResourceAsStream(resource), null, false, null, null);

        // Creating a transformation object which is the programmatic representation of a transformation 
        // A transformation object can be executed, report success, etc.
        Trans transformation = new Trans(transMeta);
        if (listVaribale != null) {
            for (TransVariable variable : listVaribale) {
                transformation.setVariable(variable.getName(), variable.getValue());
            }
        }

        // adjust the log level
        transformation.setLogLevel(LogLevel.BASIC);

        // starting the transformation, which will execute asynchronously
        transformation.execute(null);

        // waiting for the transformation to finish
        transformation.waitUntilFinished();

        return transformation;
    } catch (KettleException ex) {
        MessageInf msg = new MessageInf(MessageInf.SGN_WARNING, AppLocal.getIntString("message.syncerror"), ex);
        msg.show(this);
        return null;
    }
}
 
Example 3
Source File: MetricsIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testTransformation() throws Exception {

  TransMeta transMeta = new TransMeta( "src/it/resources/metrics/simple-test.ktr" );
  transMeta.setGatheringMetrics( true );
  Trans trans = new Trans( transMeta );
  trans.setGatheringMetrics( true );
  trans.execute( null );
  trans.waitUntilFinished();

  LogChannelInterface log = trans.getLogChannel();

  Queue<MetricsSnapshotInterface> snapshotList =
    MetricsRegistry.getInstance().getSnapshotList( log.getLogChannelId() );
  assertTrue( snapshotList.size() >= 4 );

  List<MetricsDuration> durationList =
    MetricsUtil.getDuration( log.getLogChannelId(), Metrics.METRIC_TRANSFORMATION_EXECUTION_START );
  assertEquals( 1, durationList.size() );
  MetricsDuration duration = durationList.get( 0 );
  assertTrue( duration.getDuration() >= 20 && duration.getDuration() <= 5000 );
  assertEquals( Long.valueOf( 1L ), duration.getCount() );

  // Get all durations...
  //
  // durationList = MetricsUtil.getDurations(trans.getLogChannelId());

}
 
Example 4
Source File: SafeStopTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void testDownStreamStepsFinishProcessing() throws KettleException {
  String path = getClass().getResource( "/safe-stop-gen-rows.ktr" ).getPath();
  TransMeta transMeta = new TransMeta( path, new Variables() );
  Trans trans = new Trans( transMeta );
  trans.execute( new String[] {} );
  trans.safeStop();
  trans.waitUntilFinished();
  assertEquals( trans.getSteps().get( 0 ).step.getLinesWritten(), trans.getSteps().get( 2 ).step.getLinesRead() );
}
 
Example 5
Source File: CombinationLookupIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Test case for Combination lookup/update.
 */
public void testCombinationLookup() throws Exception {
  //
  // Create a new transformation...
  //
  TransMeta transMeta = new TransMeta();
  transMeta.setName( "transname" );

  // Add the database connections
  for ( int i = 0; i < databasesXML.length; i++ ) {
    DatabaseMeta databaseMeta = new DatabaseMeta( databasesXML[i] );
    transMeta.addDatabase( databaseMeta );
  }

  DatabaseMeta lookupDBInfo = transMeta.findDatabase( "lookup" );

  // Execute our setup SQLs in the database.
  Database lookupDatabase = new Database( transMeta, lookupDBInfo );
  lookupDatabase.connect();
  createTables( lookupDatabase );
  createData( lookupDatabase );

  PluginRegistry registry = PluginRegistry.getInstance();

  //
  // create the source step...
  //
  String fromstepname = "read from [" + source_table + "]";
  TableInputMeta tii = new TableInputMeta();
  tii.setDatabaseMeta( transMeta.findDatabase( "lookup" ) );
  String selectSQL = "SELECT " + Const.CR;
  selectSQL += "DLR_CD, DLR_NM, DLR_DESC ";
  selectSQL += "FROM " + source_table + " ORDER BY ORDNO;";
  tii.setSQL( selectSQL );

  String fromstepid = registry.getPluginId( StepPluginType.class, tii );
  StepMeta fromstep = new StepMeta( fromstepid, fromstepname, tii );
  fromstep.setLocation( 150, 100 );
  fromstep.setDraw( true );
  fromstep.setDescription( "Reads information from table ["
    + source_table + "] on database [" + lookupDBInfo + "]" );
  transMeta.addStep( fromstep );

  //
  // create the combination lookup/update step...
  //
  String lookupstepname = "lookup from [lookup]";
  CombinationLookupMeta clm = new CombinationLookupMeta();
  String[] lookupKey = { "DLR_CD" };
  clm.setTablename( target_table );
  clm.setKeyField( lookupKey );
  clm.setKeyLookup( lookupKey );
  clm.setTechnicalKeyField( "ID" );
  clm.setTechKeyCreation( CombinationLookupMeta.CREATION_METHOD_TABLEMAX );
  clm.setDatabaseMeta( lookupDBInfo );

  String lookupstepid = registry.getPluginId( StepPluginType.class, clm );
  StepMeta lookupstep = new StepMeta( lookupstepid, lookupstepname, clm );
  lookupstep.setDescription( "Looks up information from table [lookup] on database [" + lookupDBInfo + "]" );
  transMeta.addStep( lookupstep );

  TransHopMeta hi = new TransHopMeta( fromstep, lookupstep );
  transMeta.addTransHop( hi );

  // Now execute the transformation...
  Trans trans = new Trans( transMeta );
  trans.execute( null );

  trans.waitUntilFinished();

  checkResults( lookupDatabase );
}
 
Example 6
Source File: MetricsIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Test
public void testDatabaseGetRow() throws Exception {

  MetricsRegistry metricsRegistry = MetricsRegistry.getInstance();

  TransMeta insertTransMeta = new TransMeta( "src/it/resources/metrics/insert-data.ktr" );
  Trans insertTrans = new Trans( insertTransMeta );
  insertTrans.setGatheringMetrics( true );
  insertTrans.execute( null );
  insertTrans.waitUntilFinished();

  LogChannelInterface log = insertTrans.getLogChannel();
  Queue<MetricsSnapshotInterface> snapshotList = metricsRegistry.getSnapshotList( log.getLogChannelId() );
  assertTrue( snapshotList.size() >= 4 );

  TransMeta readTransMeta = new TransMeta( "src/it/resources/metrics/read-data.ktr" );
  Trans readTrans = new Trans( readTransMeta );
  readTrans.setGatheringMetrics( true );
  readTrans.execute( null );
  readTrans.waitUntilFinished();

  log = readTrans.getLogChannel();
  snapshotList = metricsRegistry.getSnapshotList( log.getLogChannelId() );
  assertTrue( snapshotList.size() >= 4 );

  Long rowCount = MetricsUtil.getResult( Metrics.METRIC_DATABASE_GET_ROW_COUNT );
  assertNotNull( rowCount );
  assertEquals( Long.valueOf( 1001 ), rowCount );

  Long sumTime = MetricsUtil.getResult( Metrics.METRIC_DATABASE_GET_ROW_SUM_TIME );
  assertNotNull( sumTime );
  assertTrue( sumTime > 0 );

  Long minTime = MetricsUtil.getResult( Metrics.METRIC_DATABASE_GET_ROW_MIN_TIME );
  assertNotNull( minTime );
  assertTrue( minTime < sumTime );

  Long maxTime = MetricsUtil.getResult( Metrics.METRIC_DATABASE_GET_ROW_MAX_TIME );
  assertNotNull( maxTime );
  assertTrue( maxTime >= minTime );
}
 
Example 7
Source File: StartTransServlet.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
protected void executeTrans( Trans trans ) throws KettleException {
  trans.execute( null );
}