Java Code Examples for org.pentaho.di.core.plugins.PluginRegistry#getInstance()

The following examples show how to use org.pentaho.di.core.plugins.PluginRegistry#getInstance() . 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: RestorePDIEnvironment.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
void cleanUp() {
    KettleClientEnvironment.reset();
    PluginRegistry.getInstance().reset();
    MetricsRegistry.getInstance().reset();
    ExtensionPointMap.getInstance().reset();
    if ( KettleLogStore.isInitialized() ) {
      KettleLogStore.getInstance().reset();
    }
    KettleLogStore.setLogChannelInterfaceFactory( new LogChannelFactory() );
    if ( Props.isInitialized() ) {
      Props.getInstance().reset();
    }
    KettleVFS.getInstance().reset();
    XMLHandlerCache.getInstance().clear();
    ValueMetaFactory.pluginRegistry = PluginRegistry.getInstance();
    // under no circumstance reset the LoggingRegistry
//    LoggingRegistry.getInstance().reset();
  }
 
Example 2
Source File: GPLoadIT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a transformation with a row generator step and hopped to a GPLoadStep with the passed name.
 * 
 * @param gpLoadStepname
 *          The name of the GPLoad step.
 * 
 * @throws KettleException
 */
public TransMeta createTransformationMeta( String gpLoadStepname ) throws Exception {

  // Create a new transformation...
  TransMeta transMeta = new TransMeta();
  transMeta.setName( "row generatortest" );

  // Add a database connection to the trans meta
  transMeta.addDatabase( new DatabaseMeta( GREENPLUM_DATABASE_CONNECTION ) );

  // get a reference to the plugin registry
  PluginRegistry registry = PluginRegistry.getInstance();
  if ( registry == null ) {
    throw new Exception( "Plugin registry is null.  Make sure that the Kettle environment was initialized." );
  }

  // create the GPLoad step
  GPLoadMeta gpLoadMeta = new GPLoadMeta();
  String dummyPid = registry.getPluginId( StepPluginType.class, gpLoadMeta );
  StepMeta gpLoadStepMeta = new StepMeta( dummyPid, gpLoadStepname, gpLoadMeta );
  transMeta.addStep( gpLoadStepMeta );

  return transMeta;
}
 
Example 3
Source File: ImportRules.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void loadXML( Node rulesNode ) throws KettleException {
  List<Node> ruleNodes = XMLHandler.getNodes( rulesNode, BaseImportRule.XML_TAG );
  for ( Node ruleNode : ruleNodes ) {
    String id = XMLHandler.getTagValue( ruleNode, "id" );

    PluginRegistry registry = PluginRegistry.getInstance();

    PluginInterface plugin = registry.findPluginWithId( ImportRulePluginType.class, id );
    if ( plugin == null ) {
      throw new KettleException( "The import rule of type '"
        + id + "' could not be found in the plugin registry." );
    }
    ImportRuleInterface rule = (ImportRuleInterface) registry.loadClass( plugin );

    rule.loadXML( ruleNode );

    getRules().add( rule );
  }
}
 
Example 4
Source File: CsvInput1IT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Test case for Get XML Data step, very simple example.
 *
 * @throws Exception
 *           Upon any exception
 */
@Test
public void testCSVInput1() throws Exception {
  KettleEnvironment.init();

  //
  // Create a new transformation...
  //
  TransMeta transMeta = new TransMeta();
  transMeta.setName( "csvinput1" );

  PluginRegistry registry = PluginRegistry.getInstance();

  String fileName = writeInputFile();

  StepMeta injectorStep = createInjectorStep( transMeta, registry );
  StepMeta csvInputStep = createCsvInputStep( transMeta, registry, "\"", true );

  createAndTestTrans(
    registry, transMeta, injectorStep, csvInputStep, fileName, createTextFileInputFields().length );
}
 
Example 5
Source File: StepPartitioningMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void createPartitioner( String method ) throws KettlePluginException {
  methodType = getMethodType( method );
  switch ( methodType ) {
    case PARTITIONING_METHOD_SPECIAL: {
      PluginRegistry registry = PluginRegistry.getInstance();
      PluginInterface plugin = registry.findPluginWithId( PartitionerPluginType.class, method );
      partitioner = (Partitioner) registry.loadClass( plugin );
      partitioner.setId( plugin.getIds()[0] );
      break;
    }
    case PARTITIONING_METHOD_NONE:
    default:
      partitioner = null;
  }
  if ( partitioner != null ) {
    partitioner.setMeta( this );
  }
}
 
Example 6
Source File: ExecuteJobServlet.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
Repository openRepository( String repositoryName, String user, String pass ) throws KettleException {

  if ( Utils.isEmpty( repositoryName ) ) {
    return null;
  }

  RepositoriesMeta repositoriesMeta = new RepositoriesMeta();
  repositoriesMeta.readData();
  RepositoryMeta repositoryMeta = repositoriesMeta.findRepository( repositoryName );
  if ( repositoryMeta == null ) {
    String message = BaseMessages.getString( PKG, "ExecuteJobServlet.Error.UnableToFindRepository", repositoryName );
    throw new KettleRepositoryNotFoundException( message );
  }
  PluginRegistry registry = PluginRegistry.getInstance();
  Repository repository = registry.loadClass( RepositoryPluginType.class, repositoryMeta, Repository.class );
  repository.init( repositoryMeta );
  repository.connect( user, pass );
  return repository;
}
 
Example 7
Source File: ExecuteTransServlet.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private Repository openRepository( String repositoryName, String user, String pass ) throws KettleException {

    if ( Utils.isEmpty( repositoryName ) ) {
      return null;
    }

    RepositoriesMeta repositoriesMeta = new RepositoriesMeta();
    repositoriesMeta.readData();
    RepositoryMeta repositoryMeta = repositoriesMeta.findRepository( repositoryName );
    if ( repositoryMeta == null ) {
      throw new KettleException( "Unable to find repository: " + repositoryName );
    }
    PluginRegistry registry = PluginRegistry.getInstance();
    Repository repository = registry.loadClass( RepositoryPluginType.class, repositoryMeta, Repository.class );
    repository.init( repositoryMeta );
    repository.connect( user, pass );
    return repository;
  }
 
Example 8
Source File: StringEvaluatorIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void loadValueMetaPlugins() {
  // Need to load the ValueMeta plugins
  PluginRegistry registry = PluginRegistry.getInstance();
  assertNotNull( "Registry singleton was not found!", registry );

  // Register a new plugin type...
  //
  PluginRegistry.addPluginType( ValueMetaPluginType.getInstance() );

  // Plugin Registry should initialize without exception
  Exception initException = null;
  try {
    PluginRegistry.init();
  } catch ( Exception e ) {
    initException = e;
  }
  assertNull( initException );

  // There will always be a PluginRegistryPluginType, so see if we enough plugin types here.
  //
  List<Class<? extends PluginTypeInterface>> pluginTypes = registry.getPluginTypes();
  assertTrue( "At least two plugin types expected in the registry", pluginTypes.size() > 1 );

  // ... and have at least 1 ValueMetaPlugin
  List<PluginInterface> valueMetaPlugins = registry.getPlugins( ValueMetaPluginType.class );
  assertTrue( "Size of plugins list expected to be >1", valueMetaPlugins.size() > 1 );
}
 
Example 9
Source File: StepMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void setDeprecationAndSuggestedStep() {
  PluginRegistry registry = PluginRegistry.getInstance();
  final List<PluginInterface> deprecatedSteps = registry.getPluginsByCategory( StepPluginType.class,
    BaseMessages.getString( PKG, "BaseStep.Category.Deprecated" ) );
  for ( PluginInterface p : deprecatedSteps ) {
    String[] ids = p.getIds();
    if ( !ArrayUtils.isEmpty( ids ) && ids[0].equals( this.stepid ) ) {
      this.isDeprecated = true;
      this.suggestion = registry.findPluginWithId( StepPluginType.class, this.stepid ) != null
        ? registry.findPluginWithId( StepPluginType.class, this.stepid ).getSuggestion() : "";
      break;
    }
  }
}
 
Example 10
Source File: InsertUpdateMetaTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  TransMeta transMeta = new TransMeta();
  transMeta.setName( "delete1" );

  Map<String, String> vars = new HashMap<String, String>();
  vars.put( "max.sz", "10" );
  transMeta.injectVariables( vars );

  umi = new InsertUpdateMeta();
  ud = new InsertUpdateData();

  PluginRegistry plugReg = PluginRegistry.getInstance();
  String deletePid = plugReg.getPluginId( StepPluginType.class, umi );

  stepMeta = new StepMeta( deletePid, "delete", umi );
  Trans trans = new Trans( transMeta );
  transMeta.addStep( stepMeta );
  upd = new InsertUpdate( stepMeta, ud, 1, transMeta, trans );
  upd.copyVariablesFrom( transMeta );

  mockHelper =
    new StepMockHelper<>( "insertUpdate", InsertUpdateMeta.class, InsertUpdateData.class );
  Mockito.when( mockHelper.logChannelInterfaceFactory.create( Mockito.any(), Mockito.any( LoggingObjectInterface.class ) ) )
    .thenReturn( mockHelper.logChannelInterface );
  Mockito.when( mockHelper.stepMeta.getStepMetaInterface() ).thenReturn( new InsertUpdateMeta() );
}
 
Example 11
Source File: KettleDatabaseRepositoryCreationHelper.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public KettleDatabaseRepositoryCreationHelper( KettleDatabaseRepository repository ) {
  this.repository = repository;
  this.databaseMeta = this.repository.getDatabaseMeta();
  this.database = this.repository.getDatabase();

  this.log = repository.getLog();
  this.pluginRegistry = PluginRegistry.getInstance();
}
 
Example 12
Source File: SpoonJobDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public JobEntryDialogInterface getJobEntryDialog( JobEntryInterface jobEntryInterface, JobMeta jobMeta ) {
  Class<?>[] paramClasses = new Class<?>[] { Shell.class, JobEntryInterface.class, Repository.class, JobMeta.class };
  Object[] paramArgs = new Object[] { spoon.getShell(), jobEntryInterface, spoon.getRepository(), jobMeta };

  PluginRegistry registry = PluginRegistry.getInstance();
  PluginInterface plugin = registry.getPlugin( JobEntryPluginType.class, jobEntryInterface );
  String dialogClassName = plugin.getClassMap().get( JobEntryDialogInterface.class );
  if ( dialogClassName == null ) {
    // try the deprecated way
    log.logDebug( "Use of JobEntryInterface#getDialogClassName is deprecated, use PluginDialog annotation instead." );
    dialogClassName = jobEntryInterface.getDialogClassName();
  }

  try {
    Class<JobEntryDialogInterface> dialogClass = registry.getClass( plugin, dialogClassName );
    Constructor<JobEntryDialogInterface> dialogConstructor = dialogClass.getConstructor( paramClasses );
    JobEntryDialogInterface entryDialogInterface = dialogConstructor.newInstance( paramArgs );
    entryDialogInterface.setMetaStore( spoon.getMetaStore() );
    return entryDialogInterface;
  } catch ( Throwable t ) {
    t.printStackTrace();
    String errorTitle = BaseMessages.getString( PKG, "Spoon.Dialog.ErrorCreatingJobDialog.Title" );
    String errorMsg = BaseMessages.getString( PKG, "Spoon.Dialog.ErrorCreatingJobEntryDialog.Message", dialogClassName );
    spoon.getLog().logError( spoon.toString(), errorMsg );
    new ErrorDialog( spoon.getShell(), errorTitle, errorMsg, t );
    return null;
  }
}
 
Example 13
Source File: SlaveServerConfig.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void openRepository( String repositoryId ) throws KettleException {
  try {

    RepositoriesMeta repositoriesMeta = new RepositoriesMeta();
    repositoriesMeta.readData();
    repositoryMeta = repositoriesMeta.findRepository( repositoryId );
    if ( repositoryMeta == null ) {
      throw new KettleException( "Unable to find repository: " + repositoryId );
    }
    PluginRegistry registry = PluginRegistry.getInstance();
    repository = registry.loadClass( RepositoryPluginType.class, repositoryMeta, Repository.class );
    repository.init( repositoryMeta );
    repository.connect( repositoryUsername, repositoryPassword );

    // Add the repository MetaStore to the delegation as well.
    // Set this one as active with the highest priority
    //
    if ( repository.getMetaStore() != null ) {
      metaStore.addMetaStore( 0, repository.getMetaStore() );
      metaStore.setActiveMetaStoreName( repository.getMetaStore().getName() );
    }

    LogChannel.GENERAL.logBasic( "Connected to repository '" + repository.getName() + "'" );

  } catch ( Exception e ) {
    throw new KettleException( "Unable to open repository connection", e );
  }
}
 
Example 14
Source File: ParameterSimpleTransIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Test case for parameters using a simple transformation. Check whether parameters override variables.
 *
 * @throws Exception
 *           exception on any problem.
 */
public void testParameterSimpleTrans5() throws Exception {
  KettleEnvironment.init();

  //
  // Create a new transformation...
  //
  TransMeta transMeta = new TransMeta();
  transMeta.setName( "parameter_simple_trans4" );

  PluginRegistry registry = PluginRegistry.getInstance();

  //
  // create a get variables step...
  //
  String getVariablesStepname = "get variables step";
  GetVariableMeta gvm = new GetVariableMeta();

  // Set the information of the get variables step.
  String getVariablesPid = registry.getPluginId( StepPluginType.class, gvm );
  StepMeta getVariablesStep = new StepMeta( getVariablesPid, getVariablesStepname, gvm );
  transMeta.addStep( getVariablesStep );

  //
  // Generate 1 row
  //
  String[] fieldName = { "PARAM1", "PARAM2" };
  String[] varName = { "${Param1}", "%%PARAM2%%" };
  int[] fieldType = { ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING };
  int[] length = { -1, -1 };
  int[] precision = { -1, -1 };
  String[] format = { "", "" };
  String[] currency = { "", "" };
  String[] decimal = { "", "" };
  String[] grouping = { "", "" };
  int[] trimType = { ValueMetaInterface.TRIM_TYPE_NONE, ValueMetaInterface.TRIM_TYPE_NONE };

  FieldDefinition[] fields = new FieldDefinition[fieldName.length];
  for ( int i = 0; i < fields.length; i++ ) {
    FieldDefinition field = new FieldDefinition();
    field.setFieldName( fieldName[i] );
    field.setVariableString( varName[i] );
    field.setFieldType( fieldType[i] );
    field.setFieldLength( length[i] );
    field.setFieldPrecision( precision[i] );
    field.setFieldFormat( format[i] );
    field.setCurrency( currency[i] );
    field.setDecimal( decimal[i] );
    field.setGroup( grouping[i] );
    field.setTrimType( trimType[i] );
    fields[i] = field;
  }
  gvm.setFieldDefinitions( fields );

  //
  // Create a dummy step 1
  //
  String dummyStepname1 = "dummy step 1";
  DummyTransMeta dm1 = new DummyTransMeta();

  String dummyPid1 = registry.getPluginId( StepPluginType.class, dm1 );
  StepMeta dummyStep1 = new StepMeta( dummyPid1, dummyStepname1, dm1 );
  transMeta.addStep( dummyStep1 );

  TransHopMeta hi1 = new TransHopMeta( getVariablesStep, dummyStep1 );
  transMeta.addTransHop( hi1 );

  // Now execute the transformation...
  Trans trans = new Trans( transMeta );
  trans.addParameterDefinition( "Param1", "default1", "Parameter 1" );
  trans.addParameterDefinition( "PARAM2", "", "Parameter 2" );
  trans.setParameterValue( "PARAM2", "PARAMVALUE2" );

  // See whether this variable overrides the parameter... it should NOT. Param1
  // is defined but not set, so defaults should kick in.
  trans.setVariable( "Param1", "Variable1" );

  trans.prepareExecution( null );

  StepInterface si = trans.getStepInterface( dummyStepname1, 0 );
  RowStepCollector endRc = new RowStepCollector();
  si.addRowListener( endRc );

  trans.startThreads();

  trans.waitUntilFinished();

  // Now check whether the output is still as we expect.
  List<RowMetaAndData> goldenImageRows = createResultData5();
  List<RowMetaAndData> resultRows1 = endRc.getRowsWritten();
  checkRows( resultRows1, goldenImageRows );
}
 
Example 15
Source File: TableOutputIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Test case for normal table output case.
 */
@SuppressWarnings( "deprecation" )
public void testTableOutputNormal() throws Exception {
  KettleEnvironment.init();

  //
  // Create a new transformation...
  //
  TransMeta transMeta = new TransMeta();
  transMeta.setName( "table output normal test" );

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

  DatabaseMeta dbInfo = transMeta.findDatabase( "db" );

  // Execute our setup SQLs in the database.
  Database database = new Database( transMeta, dbInfo );
  database.connect();
  createTable( database, target_table, createSourceRowMetaInterface1() );

  PluginRegistry registry = PluginRegistry.getInstance();

  //
  // create an injector step...
  //
  String injectorStepname = "injector step";
  InjectorMeta im = new InjectorMeta();

  // Set the information of the injector.
  String injectorPid = registry.getPluginId( StepPluginType.class, im );
  StepMeta injectorStep = new StepMeta( injectorPid, injectorStepname, im );
  transMeta.addStep( injectorStep );

  //
  // create the source step...
  //
  String outputname = "output to [" + target_table + "]";
  TableOutputMeta tom = new TableOutputMeta();
  tom.setDatabaseMeta( transMeta.findDatabase( "db" ) );
  tom.setTablename( target_table );

  String fromid = registry.getPluginId( StepPluginType.class, tom );
  StepMeta fromstep = new StepMeta( fromid, outputname, tom );
  fromstep.setDescription( "write data to table [" + target_table + "] on database [" + dbInfo + "]" );
  transMeta.addStep( fromstep );

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

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

  trans.prepareExecution( null );

  StepInterface si = trans.getStepInterface( outputname, 0 );
  RowStepCollector rc = new RowStepCollector();
  si.addRowListener( rc );

  RowProducer rp = trans.addRowProducer( injectorStepname, 0 );
  trans.startThreads();

  // add rows
  List<RowMetaAndData> inputList = createNormalDataRows();
  for ( RowMetaAndData rm : inputList ) {
    rp.putRow( rm.getRowMeta(), rm.getData() );
  }
  rp.finished();

  trans.waitUntilFinished();

  List<RowMetaAndData> resultRows = rc.getRowsWritten();
  List<RowMetaAndData> goldRows = createNormalDataRows();
  checkRows( goldRows, resultRows );
  checkResultsNormal( database );
}
 
Example 16
Source File: TransformationHasTransLogConfiguredImportRuleIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void testRule() throws Exception {

    TransMeta transMeta = new TransMeta();
    DatabaseMeta logDbMeta =
      new DatabaseMeta( "LOGDB", "MYSQL", "JDBC", "localhost", "test", "3306", "foo", "bar" );
    transMeta.addDatabase( logDbMeta );
    TransLogTable logTable = transMeta.getTransLogTable();

    PluginRegistry registry = PluginRegistry.getInstance();

    PluginInterface plugin =
      registry.findPluginWithId( ImportRulePluginType.class, "TransformationHasTransLogConfigured" );
    assertNotNull(
      "The 'transformation has trans log table configured' rule could not be found in the plugin registry!",
      plugin );

    TransformationHasTransLogConfiguredImportRule rule =
      (TransformationHasTransLogConfiguredImportRule) registry.loadClass( plugin );
    assertNotNull(
      "The 'transformation has trans log table configured' class could not be loaded by the plugin registry!",
      plugin );

    rule.setEnabled( true );

    List<ImportValidationFeedback> feedback = rule.verifyRule( transMeta );
    assertTrue( "We didn't get any feedback from the 'transformation has trans log table configured'", !feedback
      .isEmpty() );
    assertTrue(
      "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR );

    logTable.setTableName( "SCHEMA" );
    logTable.setTableName( "LOGTABLE" );
    logTable.setConnectionName( logDbMeta.getName() );
    feedback = rule.verifyRule( transMeta );
    assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() );
    assertTrue(
      "An approval ruling was expected",
      feedback.get( 0 ).getResultType() == ImportValidationResultType.APPROVAL );

    // Make the rules stricter!
    //
    rule.setTableName( "SCHEMA" );
    rule.setTableName( "LOGTABLE" );
    rule.setConnectionName( logDbMeta.getName() );
    feedback = rule.verifyRule( transMeta );
    assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() );
    assertTrue(
      "An approval ruling was expected",
      feedback.get( 0 ).getResultType() == ImportValidationResultType.APPROVAL );

    // Break the rule
    //
    rule.setSchemaName( "INCORRECT_SCHEMA" );
    rule.setTableName( "LOGTABLE" );
    rule.setConnectionName( logDbMeta.getName() );
    feedback = rule.verifyRule( transMeta );
    assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() );
    assertTrue(
      "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR );

    rule.setSchemaName( "SCHEMA" );
    rule.setTableName( "INCORRECT_LOGTABLE" );
    rule.setConnectionName( logDbMeta.getName() );
    feedback = rule.verifyRule( transMeta );
    assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() );
    assertTrue(
      "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR );

    rule.setSchemaName( "SCHEMA" );
    rule.setTableName( "LOGTABLE" );
    rule.setConnectionName( "INCORRECT_DATABASE" );
    feedback = rule.verifyRule( transMeta );
    assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() );
    assertTrue(
      "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR );

    // No feedback expected!
    //
    rule.setEnabled( false );

    feedback = rule.verifyRule( transMeta );
    assertTrue( "We didn't expect any feedback from the 'transformation has trans "
      + "log table configured' since the rule is not enabled", feedback.isEmpty() );
  }
 
Example 17
Source File: ExecSQLRowIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Basic Test case for Exec SQL Row. This tests a commit size of two (i.e. not autocommit and not the input row size)
 */
@Test
public void testExecSQLRow3() throws Exception {
  KettleEnvironment.init();

  //
  // 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 dbInfo = transMeta.findDatabase( "db" );
  PluginRegistry registry = PluginRegistry.getInstance();

  //
  // create an injector step...
  //
  String injectorStepname = "injector step";
  InjectorMeta im = new InjectorMeta();

  // Set the information of the injector.

  String injectorPid = registry.getPluginId( StepPluginType.class, im );
  StepMeta injectorStep = new StepMeta( injectorPid, injectorStepname, im );
  transMeta.addStep( injectorStep );

  //
  // create the Exec SQL Row step...
  //
  String stepName = "delete from [" + execsqlrow_testtable + "]";
  ExecSQLRowMeta execsqlmeta = new ExecSQLRowMeta();
  execsqlmeta.setDatabaseMeta( transMeta.findDatabase( "db" ) );
  execsqlmeta.setCommitSize( 2 );
  execsqlmeta.setSqlFieldName( "SQL" );

  String execSqlRowId = registry.getPluginId( StepPluginType.class, execsqlmeta );
  StepMeta execSqlRowStep = new StepMeta( execSqlRowId, stepName, execsqlmeta );
  execSqlRowStep.setDescription( "Deletes information from table ["
    + execsqlrow_testtable + "] on database [" + dbInfo + "]" );
  transMeta.addStep( execSqlRowStep );

  TransHopMeta hi = new TransHopMeta( injectorStep, execSqlRowStep );
  transMeta.addTransHop( hi );

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

  trans.prepareExecution( null );

  StepInterface si = trans.getStepInterface( stepName, 0 );
  RowStepCollector rc = new RowStepCollector();
  si.addRowListener( rc );

  RowProducer rp = trans.addRowProducer( injectorStepname, 0 );
  trans.startThreads();

  // add rows
  List<RowMetaAndData> inputList = createDataRows();
  for ( RowMetaAndData rm : inputList ) {
    rp.putRow( rm.getRowMeta(), rm.getData() );
  }
  rp.finished();

  trans.waitUntilFinished();

  List<RowMetaAndData> resultRows = rc.getRowsWritten();
  List<RowMetaAndData> goldRows = createResultDataRows();
  checkRows( goldRows, resultRows );
}
 
Example 18
Source File: OptimizationLevelIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Creates the transformation needed to test the java script step with an optimization level set.
 *
 * @param optimizationLevel
 * @return
 * @throws KettleException
 */
private List<CheckResultInterface> testOptimizationLevel( String optimizationLevel ) throws KettleException {

  KettleEnvironment.init();

  // Create a new transformation...
  TransMeta transMeta = new TransMeta();
  transMeta.setName( "Test optimization level exception handling" );

  PluginRegistry registry = PluginRegistry.getInstance();

  // create an injector step.../
  String injectorStepname = "injector step";
  InjectorMeta im = new InjectorMeta();

  // Set the information of the injector.
  String injectorPid = registry.getPluginId( StepPluginType.class, im );
  StepMeta injectorStep = new StepMeta( injectorPid, injectorStepname, im );
  transMeta.addStep( injectorStep );

  // Create a javascript step
  String javaScriptStepname = "javascript step";

  // Create the meta and populate
  ScriptValuesMetaMod scriptValuesMetaMod = new ScriptValuesMetaMod();
  ScriptValuesScript[] js =
    new ScriptValuesScript[] { new ScriptValuesScript(
      ScriptValuesScript.TRANSFORM_SCRIPT, "script", "var str = string;\n" + "var bool = LuhnCheck(str);" ) };
  scriptValuesMetaMod.setJSScripts( js );
  scriptValuesMetaMod.setFieldname( new String[] { "bool" } );
  scriptValuesMetaMod.setRename( new String[] { "" } );
  scriptValuesMetaMod.setType( new int[] { ValueMetaInterface.TYPE_BOOLEAN } );
  scriptValuesMetaMod.setLength( new int[] { -1 } );
  scriptValuesMetaMod.setPrecision( new int[] { -1 } );
  scriptValuesMetaMod.setReplace( new boolean[] { false } );
  scriptValuesMetaMod.setCompatible( false );
  scriptValuesMetaMod.setOptimizationLevel( optimizationLevel );

  // Create the step meta
  String javaScriptStepPid = registry.getPluginId( StepPluginType.class, scriptValuesMetaMod );
  StepMeta javaScriptStep = new StepMeta( javaScriptStepPid, javaScriptStepname, scriptValuesMetaMod );

  // Create a dummy step
  String dummyStepname = "dummy step";
  DummyTransMeta dm = new DummyTransMeta();
  String dummyPid = registry.getPluginId( StepPluginType.class, dm );
  StepMeta dummyStep = new StepMeta( dummyPid, dummyStepname, dm );
  transMeta.addStep( dummyStep );

  // hop the steps that were created
  TransHopMeta hi2 = new TransHopMeta( javaScriptStep, dummyStep );
  transMeta.addTransHop( hi2 );

  // We use an existing test that creates data: we'll use that data here
  JavaScriptSpecialIT javaScriptSpecialTest = new JavaScriptSpecialIT();
  List<RowMetaAndData> inputList = javaScriptSpecialTest.createData1();
  // RowMetaInterface rowMetaInterface = null;

  // This is the collection of error messages that may be generated
  // and other things that the check method will need
  List<CheckResultInterface> remarks = new ArrayList<CheckResultInterface>();
  String[] input = new String[] { injectorStepname };
  String[] output = new String[] {};

  // We get the row meta and data....
  Iterator<RowMetaAndData> it = inputList.iterator();
  if ( it.hasNext() ) {
    RowMetaAndData rowMetaAndData = it.next();

    // .... and then call the scriptValuesMetaMod's check method
    scriptValuesMetaMod.check(
      remarks, transMeta, javaScriptStep, rowMetaAndData.getRowMeta(), input, output, null, transMeta, null,
      null );
  } else {
    fail( "No data in the inputList" );
  }

  // we then return the remarks made by scriptValuesMetaMod.check(....);
  return remarks;
}
 
Example 19
Source File: BaseSerializingMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private StepMetaInterface getNewMeta() throws KettleException {
  PluginRegistry pluginRegistry = PluginRegistry.getInstance();
  String id = pluginRegistry.getPluginId( StepPluginType.class, this );
  PluginInterface plugin = pluginRegistry.getPlugin( StepPluginType.class, id );
  return (StepMetaInterface) pluginRegistry.loadClass( plugin );
}
 
Example 20
Source File: TextFileOutputIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Tests the normal output capability of the TextFileOutput step
 *
 * @throws Exception
 */
@Test
public void testTextFileOutput6() throws Exception {
  KettleEnvironment.init();

  // Create a new transformation...
  //
  TransMeta transMeta = new TransMeta();
  transMeta.setName( "testTextFileOutput6" );
  PluginRegistry registry = PluginRegistry.getInstance();

  // create an injector step
  String injectorStepName = "injector step";
  StepMeta injectorStep = TestUtilities.createInjectorStep( injectorStepName, registry );
  transMeta.addStep( injectorStep );

  // create a row generator step
  StepMeta rowGeneratorStep = createRowGeneratorStep( "Create rows for testTextFileOutput5", registry );
  transMeta.addStep( rowGeneratorStep );

  // create a TransHopMeta for injector and add it to the transMeta
  TransHopMeta hop_injectory_rowGenerator = new TransHopMeta( injectorStep, rowGeneratorStep );
  transMeta.addTransHop( hop_injectory_rowGenerator );

  // create the text file output step with no compression
  // but first lets get a filename
  String textFileName = "testTextFileOutput6";
  String textFileOutputStepName = "text file output step";
  StepMeta textFileOutputStep =
    createTextFileOutputStep( textFileOutputStepName, textFileName, "None", registry );
  transMeta.addStep( textFileOutputStep );

  // create a TransHopMeta for textFileOutputStep and add it to the transMeta
  TransHopMeta hop_RowGenerator_outputTextFile = new TransHopMeta( rowGeneratorStep, textFileOutputStep );
  transMeta.addTransHop( hop_RowGenerator_outputTextFile );

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

  // Create a row collector and add it to the dummy step interface
  StepInterface dummyStepInterface = trans.getStepInterface( textFileOutputStepName, 0 );
  RowStepCollector dummyRowCollector = new RowStepCollector();
  dummyStepInterface.addRowListener( dummyRowCollector );

  trans.startThreads();
  trans.waitUntilFinished();

  // Compare the results
  List<RowMetaAndData> resultRows = dummyRowCollector.getRowsWritten();
  Object[][] rows = new Object[10][3];
  File f = new File( textFileName + "." + EXTENSION );
  f.deleteOnExit();
  try {
    FileInputStream fin = new FileInputStream( f );
    InputStreamReader xover = new InputStreamReader( fin );
    BufferedReader input = new BufferedReader( xover );

    readData1Rows( rows, input );

    fin.close();

  } catch ( IOException e ) {
    fail( e.getLocalizedMessage() );
  }

  List<RowMetaAndData> outFileRows = createResultDataFromObjects( rows );

  try {
    TestUtilities.checkRows( resultRows, outFileRows );
  } catch ( TestFailedException tfe ) {
    fail( tfe.getMessage() );
  }
}