use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.
the class TransformationHasTransLogConfiguredImportRuleIT method testRule.
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());
}
use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.
the class KettleEnvironmentIT method lifecycleListenerEnvironmentInitCallback.
/**
* Validate that a LifecycleListener's environment init callback is called when the Kettle Environment is initialized.
*/
@Test
public void lifecycleListenerEnvironmentInitCallback() throws Exception {
resetKettleEnvironmentInitializationFlag();
assertFalse("This test only works if the Kettle Environment is not yet initialized", KettleEnvironment.isInitialized());
System.setProperty(Const.KETTLE_PLUGIN_CLASSES, MockLifecycleListener.class.getName());
KettleEnvironment.init();
PluginInterface pi = PluginRegistry.getInstance().findPluginWithId(KettleLifecyclePluginType.class, pluginId);
MockLifecycleListener l = (MockLifecycleListener) PluginRegistry.getInstance().loadClass(pi, KettleLifecycleListener.class);
assertNotNull("Test plugin not registered properly", l);
assertTrue(environmentInitCalled.get());
}
use of org.pentaho.di.core.plugins.PluginInterface 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();
}
use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.
the class Spoon method addCoreObjectsTree.
public void addCoreObjectsTree() {
// Now create a new expand bar inside that item
// We're going to put the core object in there
//
coreObjectsTree = new Tree(variableComposite, SWT.V_SCROLL | SWT.SINGLE);
props.setLook(coreObjectsTree);
coreObjectsTree.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent event) {
//
if (props.getAutoCollapseCoreObjectsTree()) {
TreeItem[] selection = coreObjectsTree.getSelection();
if (selection.length == 1) {
// expand if clicked on the the top level entry only...
//
TreeItem top = selection[0];
while (top.getParentItem() != null) {
top = top.getParentItem();
}
if (top == selection[0]) {
boolean expanded = top.getExpanded();
for (TreeItem item : coreObjectsTree.getItems()) {
item.setExpanded(false);
}
top.setExpanded(!expanded);
}
}
}
}
});
coreObjectsTree.addTreeListener(new TreeAdapter() {
@Override
public void treeExpanded(TreeEvent treeEvent) {
if (props.getAutoCollapseCoreObjectsTree()) {
TreeItem treeItem = (TreeItem) treeEvent.item;
/*
* Trick for WSWT on Windows systems: a SelectionEvent is called after the TreeEvent if setSelection() is not
* used here. Otherwise the first item in the list is selected as default and collapsed again but wrong, see
* PDI-1480
*/
coreObjectsTree.setSelection(treeItem);
//
for (TreeItem item : coreObjectsTree.getItems()) {
if (item != treeItem) {
item.setExpanded(false);
} else {
treeItem.setExpanded(true);
}
}
}
}
});
coreObjectsTree.addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent move) {
// don't show tooltips in the tree if the option is not set
if (!getProperties().showToolTips()) {
return;
}
toolTip.hide();
TreeItem item = searchMouseOverTreeItem(coreObjectsTree.getItems(), move.x, move.y);
if (item != null) {
String name = item.getText();
String tip = coreStepToolTipMap.get(name);
if (tip != null) {
PluginInterface plugin = PluginRegistry.getInstance().findPluginWithName(StepPluginType.class, name);
if (plugin != null) {
Image image = GUIResource.getInstance().getImagesSteps().get(plugin.getIds()[0]).getAsBitmapForSize(display, ConstUI.ICON_SIZE, ConstUI.ICON_SIZE);
if (image == null) {
toolTip.hide();
}
toolTip.setImage(image);
toolTip.setText(name + Const.CR + Const.CR + tip);
toolTip.setBackgroundColor(GUIResource.getInstance().getColor(255, 254, 225));
toolTip.setForegroundColor(GUIResource.getInstance().getColor(0, 0, 0));
toolTip.show(new org.eclipse.swt.graphics.Point(move.x + 10, move.y + 10));
}
}
tip = coreJobToolTipMap.get(name);
if (tip != null) {
PluginInterface plugin = PluginRegistry.getInstance().findPluginWithName(JobEntryPluginType.class, name);
if (plugin != null) {
Image image = GUIResource.getInstance().getImagesJobentries().get(plugin.getIds()[0]).getAsBitmapForSize(display, ConstUI.ICON_SIZE, ConstUI.ICON_SIZE);
toolTip.setImage(image);
toolTip.setText(name + Const.CR + Const.CR + tip);
toolTip.setBackgroundColor(GUIResource.getInstance().getColor(255, 254, 225));
toolTip.setForegroundColor(GUIResource.getInstance().getColor(0, 0, 0));
toolTip.show(new org.eclipse.swt.graphics.Point(move.x + 10, move.y + 10));
}
}
}
}
});
addDragSourceToTree(coreObjectsTree);
addDefaultKeyListeners(coreObjectsTree);
coreObjectsTree.addMouseListener(new MouseAdapter() {
@Override
public void mouseDoubleClick(MouseEvent event) {
boolean shift = (event.stateMask & SWT.SHIFT) != 0;
doubleClickedInTree(coreObjectsTree, shift);
}
});
toolTip = new DefaultToolTip(variableComposite, ToolTip.RECREATE, true);
toolTip.setRespectMonitorBounds(true);
toolTip.setRespectDisplayBounds(true);
toolTip.setPopupDelay(350);
toolTip.setHideDelay(5000);
toolTip.setShift(new org.eclipse.swt.graphics.Point(ConstUI.TOOLTIP_OFFSET, ConstUI.TOOLTIP_OFFSET));
}
use of org.pentaho.di.core.plugins.PluginInterface in project pentaho-kettle by pentaho.
the class Spoon method doubleClickedInTree.
/**
* Reaction to double click
*/
private void doubleClickedInTree(Tree tree, boolean shift) {
TreeSelection[] objects = getTreeObjects(tree);
if (objects.length != 1) {
// not yet supported, we can do this later when the OSX bug
return;
// goes away
}
TreeSelection object = objects[0];
final Object selection = object.getSelection();
final Object parent = object.getParent();
if (selection instanceof Class<?>) {
if (selection.equals(TransMeta.class)) {
newTransFile();
}
if (selection.equals(JobMeta.class)) {
newJobFile();
}
if (selection.equals(TransHopMeta.class)) {
newHop((TransMeta) parent);
}
if (selection.equals(DatabaseMeta.class)) {
delegates.db.newConnection();
}
if (selection.equals(PartitionSchema.class)) {
newPartitioningSchema((TransMeta) parent);
}
if (selection.equals(ClusterSchema.class)) {
newClusteringSchema((TransMeta) parent);
}
if (selection.equals(SlaveServer.class)) {
newSlaveServer((HasSlaveServersInterface) parent);
}
} else {
if (selection instanceof TransMeta) {
TransGraph.editProperties((TransMeta) selection, this, rep, true);
}
if (selection instanceof JobMeta) {
JobGraph.editProperties((JobMeta) selection, this, rep, true);
}
if (selection instanceof PluginInterface) {
PluginInterface plugin = (PluginInterface) selection;
if (plugin.getPluginType().equals(StepPluginType.class)) {
TransGraph transGraph = getActiveTransGraph();
if (transGraph != null) {
transGraph.addStepToChain(plugin, shift);
}
}
if (plugin.getPluginType().equals(JobEntryPluginType.class)) {
JobGraph jobGraph = getActiveJobGraph();
if (jobGraph != null) {
jobGraph.addJobEntryToChain(object.getItemText(), shift);
}
}
}
if (selection instanceof DatabaseMeta) {
DatabaseMeta database = (DatabaseMeta) selection;
delegates.db.editConnection(database);
}
if (selection instanceof StepMeta) {
StepMeta step = (StepMeta) selection;
delegates.steps.editStep((TransMeta) parent, step);
sharedObjectSyncUtil.synchronizeSteps(step);
}
if (selection instanceof JobEntryCopy) {
editJobEntry((JobMeta) parent, (JobEntryCopy) selection);
}
if (selection instanceof TransHopMeta) {
editHop((TransMeta) parent, (TransHopMeta) selection);
}
if (selection instanceof PartitionSchema) {
editPartitionSchema((TransMeta) parent, (PartitionSchema) selection);
}
if (selection instanceof ClusterSchema) {
delegates.clusters.editClusterSchema((TransMeta) parent, (ClusterSchema) selection);
}
if (selection instanceof SlaveServer) {
editSlaveServer((SlaveServer) selection);
}
editSelectionTreeExtension(selection);
}
}
Aggregations