Search in sources :

Example 81 with PluginRegistry

use of org.pentaho.di.core.plugins.PluginRegistry in project pentaho-kettle by pentaho.

the class ExecSQLRowIT method testExecSQLRow1.

/**
 * Basic Test case for Exec SQL Row. This tests a commit size of zero (i.e. autocommit)
 */
@Test
public void testExecSQLRow1() 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"));
    // use Autocommit
    execsqlmeta.setCommitSize(0);
    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);
}
Also used : RowProducer(org.pentaho.di.trans.RowProducer) RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) InjectorMeta(org.pentaho.di.trans.steps.injector.InjectorMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) StepInterface(org.pentaho.di.trans.step.StepInterface) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Trans(org.pentaho.di.trans.Trans) Test(org.junit.Test)

Example 82 with PluginRegistry

use of org.pentaho.di.core.plugins.PluginRegistry in project pentaho-kettle by pentaho.

the class ExecSQLRowIT method testExecSQLRow3.

/**
 * 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);
}
Also used : RowProducer(org.pentaho.di.trans.RowProducer) RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) InjectorMeta(org.pentaho.di.trans.steps.injector.InjectorMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) StepInterface(org.pentaho.di.trans.step.StepInterface) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Trans(org.pentaho.di.trans.Trans) Test(org.junit.Test)

Example 83 with PluginRegistry

use of org.pentaho.di.core.plugins.PluginRegistry in project pentaho-kettle by pentaho.

the class FilterRowsIT method testFilterConditionRefersToNonExistingFields.

@Test
public void testFilterConditionRefersToNonExistingFields() throws Exception {
    KettleEnvironment.init();
    // Create a new transformation...
    TransMeta transMeta = new TransMeta();
    transMeta.setName("filterrowstest");
    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 filter rows step
    String filterStepName = "filter rows step";
    FilterRowsMeta frm = new FilterRowsMeta();
    Condition condition = new Condition();
    String nonExistingFieldName = "non-existing-field";
    condition.setLeftValuename(nonExistingFieldName);
    // IS NOT
    condition.setFunction(8);
    condition.setRightValuename(null);
    condition.setOperator(0);
    frm.setCondition(condition);
    String filterRowsStepPid = registry.getPluginId(StepPluginType.class, frm);
    StepMeta filterRowsStep = new StepMeta(filterRowsStepPid, filterStepName, frm);
    transMeta.addStep(filterRowsStep);
    TransHopMeta hi = new TransHopMeta(injectorStep, filterRowsStep);
    transMeta.addTransHop(hi);
    // Now execute the transformation
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    RowProducer rp = trans.addRowProducer(injectorStepname, 0);
    // add rows
    List<RowMetaAndData> inputList = createIntegerData();
    for (RowMetaAndData rm : inputList) {
        rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();
    trans.startThreads();
    trans.waitUntilFinished();
    // expect errors
    assertEquals(1, trans.getErrors());
}
Also used : Condition(org.pentaho.di.core.Condition) RowProducer(org.pentaho.di.trans.RowProducer) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransMeta(org.pentaho.di.trans.TransMeta) InjectorMeta(org.pentaho.di.trans.steps.injector.InjectorMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Trans(org.pentaho.di.trans.Trans) Test(org.junit.Test)

Example 84 with PluginRegistry

use of org.pentaho.di.core.plugins.PluginRegistry in project pentaho-kettle by pentaho.

the class GPLoadIT method createTransformationMeta.

/**
 * 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;
}
Also used : PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransMeta(org.pentaho.di.trans.TransMeta) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) KettleException(org.pentaho.di.core.exception.KettleException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 85 with PluginRegistry

use of org.pentaho.di.core.plugins.PluginRegistry in project pentaho-kettle by pentaho.

the class WebServer method startServer.

public void startServer() throws Exception {
    server = new Server();
    List<String> roles = new ArrayList<String>();
    roles.add(Constraint.ANY_ROLE);
    // Set up the security handler, optionally with JAAS
    // 
    ConstraintSecurityHandler securityHandler = new ConstraintSecurityHandler();
    if (System.getProperty("loginmodulename") != null && System.getProperty("java.security.auth.login.config") != null) {
        JAASLoginService jaasLoginService = new JAASLoginService("Kettle");
        jaasLoginService.setLoginModuleName(System.getProperty("loginmodulename"));
        securityHandler.setLoginService(jaasLoginService);
    } else {
        roles.add("default");
        HashLoginService hashLoginService;
        SlaveServer slaveServer = transformationMap.getSlaveServerConfig().getSlaveServer();
        if (!Utils.isEmpty(slaveServer.getPassword())) {
            hashLoginService = new HashLoginService("Kettle");
            hashLoginService.putUser(slaveServer.getUsername(), new Password(slaveServer.getPassword()), new String[] { "default" });
        } else {
            // See if there is a kettle.pwd file in the KETTLE_HOME directory:
            if (Utils.isEmpty(passwordFile)) {
                File homePwdFile = new File(Const.getKettleCartePasswordFile());
                if (homePwdFile.exists()) {
                    passwordFile = Const.getKettleCartePasswordFile();
                } else {
                    passwordFile = Const.getKettleLocalCartePasswordFile();
                }
            }
            hashLoginService = new HashLoginService("Kettle", passwordFile) {

                @Override
                public synchronized UserIdentity putUser(String userName, Credential credential, String[] roles) {
                    List<String> newRoles = new ArrayList<String>();
                    newRoles.add("default");
                    Collections.addAll(newRoles, roles);
                    return super.putUser(userName, credential, newRoles.toArray(new String[newRoles.size()]));
                }
            };
        }
        securityHandler.setLoginService(hashLoginService);
    }
    Constraint constraint = new Constraint();
    constraint.setName(Constraint.__BASIC_AUTH);
    constraint.setRoles(roles.toArray(new String[roles.size()]));
    constraint.setAuthenticate(true);
    ConstraintMapping constraintMapping = new ConstraintMapping();
    constraintMapping.setConstraint(constraint);
    constraintMapping.setPathSpec("/*");
    securityHandler.setConstraintMappings(new ConstraintMapping[] { constraintMapping });
    // Add all the servlets defined in kettle-servlets.xml ...
    // 
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    // Root
    // 
    ServletContextHandler root = new ServletContextHandler(contexts, GetRootServlet.CONTEXT_PATH, ServletContextHandler.SESSIONS);
    GetRootServlet rootServlet = new GetRootServlet();
    rootServlet.setJettyMode(true);
    root.addServlet(new ServletHolder(rootServlet), "/*");
    PluginRegistry pluginRegistry = PluginRegistry.getInstance();
    List<PluginInterface> plugins = pluginRegistry.getPlugins(CartePluginType.class);
    for (PluginInterface plugin : plugins) {
        CartePluginInterface servlet = pluginRegistry.loadClass(plugin, CartePluginInterface.class);
        servlet.setup(transformationMap, jobMap, socketRepository, detections);
        servlet.setJettyMode(true);
        ServletContextHandler servletContext = new ServletContextHandler(contexts, getContextPath(servlet), ServletContextHandler.SESSIONS);
        ServletHolder servletHolder = new ServletHolder((Servlet) servlet);
        servletContext.addServlet(servletHolder, "/*");
    }
    // setup jersey (REST)
    ServletHolder jerseyServletHolder = new ServletHolder(ServletContainer.class);
    jerseyServletHolder.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
    jerseyServletHolder.setInitParameter("com.sun.jersey.config.property.packages", "org.pentaho.di.www.jaxrs");
    root.addServlet(jerseyServletHolder, "/api/*");
    // setup static resource serving
    // ResourceHandler mobileResourceHandler = new ResourceHandler();
    // mobileResourceHandler.setWelcomeFiles(new String[]{"index.html"});
    // mobileResourceHandler.setResourceBase(getClass().getClassLoader().
    // getResource("org/pentaho/di/www/mobile").toExternalForm());
    // Context mobileContext = new Context(contexts, "/mobile", Context.SESSIONS);
    // mobileContext.setHandler(mobileResourceHandler);
    // Allow png files to be shown for transformations and jobs...
    // 
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setResourceBase("temp");
    // add all handlers/contexts to server
    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { contexts, resourceHandler });
    securityHandler.setHandler(handlers);
    server.setHandler(securityHandler);
    // Start execution
    createListeners();
    server.start();
}
Also used : HandlerList(org.eclipse.jetty.server.handler.HandlerList) Server(org.eclipse.jetty.server.Server) SlaveServer(org.pentaho.di.cluster.SlaveServer) Constraint(org.eclipse.jetty.util.security.Constraint) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ArrayList(java.util.ArrayList) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler) SlaveServer(org.pentaho.di.cluster.SlaveServer) HashLoginService(org.eclipse.jetty.security.HashLoginService) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) ArrayList(java.util.ArrayList) HandlerList(org.eclipse.jetty.server.handler.HandlerList) List(java.util.List) Password(org.eclipse.jetty.util.security.Password) Credential(org.eclipse.jetty.util.security.Credential) ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) UserIdentity(org.eclipse.jetty.server.UserIdentity) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) JAASLoginService(org.eclipse.jetty.plus.jaas.JAASLoginService) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) File(java.io.File)

Aggregations

PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)154 StepMeta (org.pentaho.di.trans.step.StepMeta)103 TransMeta (org.pentaho.di.trans.TransMeta)101 Trans (org.pentaho.di.trans.Trans)82 TransHopMeta (org.pentaho.di.trans.TransHopMeta)77 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)74 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)71 StepInterface (org.pentaho.di.trans.step.StepInterface)69 RowStepCollector (org.pentaho.di.trans.RowStepCollector)67 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)54 InjectorMeta (org.pentaho.di.trans.steps.injector.InjectorMeta)52 RowProducer (org.pentaho.di.trans.RowProducer)47 PluginInterface (org.pentaho.di.core.plugins.PluginInterface)46 Test (org.junit.Test)33 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)26 KettleException (org.pentaho.di.core.exception.KettleException)26 ArrayList (java.util.ArrayList)14 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)13 Before (org.junit.Before)11 HashMap (java.util.HashMap)7