Search in sources :

Example 46 with PluginInterface

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());
}
Also used : TransformationHasTransLogConfiguredImportRule(org.pentaho.di.imp.rules.TransformationHasTransLogConfiguredImportRule) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) TransMeta(org.pentaho.di.trans.TransMeta) TransLogTable(org.pentaho.di.core.logging.TransLogTable) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta)

Example 47 with PluginInterface

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());
}
Also used : PluginInterface(org.pentaho.di.core.plugins.PluginInterface) KettleLifecycleListener(org.pentaho.di.core.lifecycle.KettleLifecycleListener) Test(org.junit.Test)

Example 48 with PluginInterface

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

Example 49 with PluginInterface

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));
}
Also used : MouseEvent(org.eclipse.swt.events.MouseEvent) DefaultToolTip(org.eclipse.jface.window.DefaultToolTip) TreeItem(org.eclipse.swt.widgets.TreeItem) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) MouseAdapter(org.eclipse.swt.events.MouseAdapter) TreeAdapter(org.eclipse.swt.events.TreeAdapter) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) Image(org.eclipse.swt.graphics.Image) JobEntryPluginType(org.pentaho.di.core.plugins.JobEntryPluginType) TreeEvent(org.eclipse.swt.events.TreeEvent) MouseMoveListener(org.eclipse.swt.events.MouseMoveListener) StepPluginType(org.pentaho.di.core.plugins.StepPluginType) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Tree(org.eclipse.swt.widgets.Tree)

Example 50 with PluginInterface

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);
    }
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) PartitionSchema(org.pentaho.di.partition.PartitionSchema) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) TransMeta(org.pentaho.di.trans.TransMeta) TransGraph(org.pentaho.di.ui.spoon.trans.TransGraph) SlaveServer(org.pentaho.di.cluster.SlaveServer) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) JobGraph(org.pentaho.di.ui.spoon.job.JobGraph) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) RepositoryObject(org.pentaho.di.repository.RepositoryObject) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) FileObject(org.apache.commons.vfs2.FileObject) TransHopMeta(org.pentaho.di.trans.TransHopMeta) ClusterSchema(org.pentaho.di.cluster.ClusterSchema)

Aggregations

PluginInterface (org.pentaho.di.core.plugins.PluginInterface)99 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)45 KettleException (org.pentaho.di.core.exception.KettleException)24 ArrayList (java.util.ArrayList)17 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)14 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)12 TransMeta (org.pentaho.di.trans.TransMeta)11 StepMeta (org.pentaho.di.trans.step.StepMeta)11 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)10 Test (org.junit.Test)9 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)9 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)8 Point (org.pentaho.di.core.gui.Point)8 JobMeta (org.pentaho.di.job.JobMeta)8 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)7 TransHopMeta (org.pentaho.di.trans.TransHopMeta)7 TreeItem (org.eclipse.swt.widgets.TreeItem)6 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)6 LongObjectId (org.pentaho.di.repository.LongObjectId)6 ObjectId (org.pentaho.di.repository.ObjectId)6