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);
}
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);
}
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());
}
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;
}
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();
}
Aggregations