Search in sources :

Example 86 with PluginRegistry

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

the class ExecuteJobServlet method openRepository.

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;
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) RepositoriesMeta(org.pentaho.di.repository.RepositoriesMeta)

Example 87 with PluginRegistry

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

the class Spoon method showPluginInfo.

/**
 * Show a plugin browser
 */
public void showPluginInfo() {
    try {
        // First we collect information concerning all the plugin types...
        // 
        Map<String, RowMetaInterface> metaMap = new HashMap<>();
        Map<String, List<Object[]>> dataMap = new HashMap<>();
        PluginRegistry registry = PluginRegistry.getInstance();
        List<Class<? extends PluginTypeInterface>> pluginTypeClasses = registry.getPluginTypes();
        for (Class<? extends PluginTypeInterface> pluginTypeClass : pluginTypeClasses) {
            PluginTypeInterface pluginTypeInterface = registry.getPluginType(pluginTypeClass);
            if (pluginTypeInterface.isFragment()) {
                continue;
            }
            String subject = pluginTypeInterface.getName();
            RowBuffer pluginInformation = registry.getPluginInformation(pluginTypeClass);
            metaMap.put(subject, pluginInformation.getRowMeta());
            dataMap.put(subject, pluginInformation.getBuffer());
        }
        // Now push it all to a subject data browser...
        // 
        SubjectDataBrowserDialog dialog = new SubjectDataBrowserDialog(shell, metaMap, dataMap, "Plugin browser", "Plugin type");
        dialog.open();
    } catch (Exception e) {
        new ErrorDialog(shell, "Error", "Error listing plugins", e);
    }
}
Also used : PluginTypeInterface(org.pentaho.di.core.plugins.PluginTypeInterface) HashMap(java.util.HashMap) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowBuffer(org.pentaho.di.core.row.RowBuffer) SWTException(org.eclipse.swt.SWTException) KettleRowException(org.pentaho.di.core.exception.KettleRowException) FileSystemException(org.apache.commons.vfs2.FileSystemException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleAuthException(org.pentaho.di.core.exception.KettleAuthException) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) LifecycleException(org.pentaho.di.core.lifecycle.LifecycleException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) KettleException(org.pentaho.di.core.exception.KettleException) MalformedURLException(java.net.MalformedURLException) SubjectDataBrowserDialog(org.pentaho.di.ui.core.dialog.SubjectDataBrowserDialog) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryObject(org.pentaho.di.repository.RepositoryObject) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) FileObject(org.apache.commons.vfs2.FileObject)

Example 88 with PluginRegistry

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

the class Spoon method newStep.

/**
 * Allocate new step, optionally open and rename it.
 *
 * @param id
 *          Id of the new step
 * @param name
 *          Name of the new step
 * @param description
 *          Description of the type of step
 * @param openit
 *          Open the dialog for this step?
 * @param rename
 *          Rename this step?
 *
 * @return The newly created StepMeta object.
 */
public StepMeta newStep(TransMeta transMeta, String id, String name, String description, boolean openit, boolean rename) {
    StepMeta inf = null;
    // See if we need to rename the step to avoid doubles!
    if (rename && transMeta.findStep(name) != null) {
        int i = 2;
        String newName = name + " " + i;
        while (transMeta.findStep(newName) != null) {
            i++;
            newName = name + " " + i;
        }
        name = newName;
    }
    PluginRegistry registry = PluginRegistry.getInstance();
    PluginInterface stepPlugin = id != null ? registry.findPluginWithId(StepPluginType.class, id) : registry.findPluginWithName(StepPluginType.class, description);
    try {
        if (stepPlugin != null) {
            StepMetaInterface info = (StepMetaInterface) registry.loadClass(stepPlugin);
            info.setDefault();
            if (openit) {
                StepDialogInterface dialog = this.getStepEntryDialog(info, transMeta, name);
                if (dialog != null) {
                    name = dialog.open();
                }
            }
            inf = new StepMeta(stepPlugin.getIds()[0], name, info);
            if (name != null) {
                // OK pressed in the dialog: we have a step-name
                String newName = name;
                StepMeta stepMeta = transMeta.findStep(newName);
                int nr = 2;
                while (stepMeta != null) {
                    newName = name + " " + nr;
                    stepMeta = transMeta.findStep(newName);
                    nr++;
                }
                if (nr > 2) {
                    inf.setName(newName);
                    MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
                    // "This stepName already exists.  Spoon changed the stepName to ["+newName+"]"
                    mb.setMessage(BaseMessages.getString(PKG, "Spoon.Dialog.ChangeStepname.Message", newName));
                    mb.setText(BaseMessages.getString(PKG, "Spoon.Dialog.ChangeStepname.Title"));
                    mb.open();
                }
                // default location at (20,20)
                inf.setLocation(20, 20);
                transMeta.addStep(inf);
                addUndoNew(transMeta, new StepMeta[] { inf }, new int[] { transMeta.indexOfStep(inf) });
                // Also store it in the pluginHistory list...
                props.increasePluginHistory(stepPlugin.getIds()[0]);
                // stepHistoryChanged = true;
                refreshTree();
            } else {
                // Cancel pressed in dialog.
                return null;
            }
            setShellText();
        }
    } catch (KettleException e) {
        String filename = stepPlugin.getErrorHelpFile();
        if (!Utils.isEmpty(filename)) {
            // OK, in stead of a normal error message, we give back the
            // content of the error help file... (HTML)
            FileInputStream fis = null;
            try {
                StringBuilder content = new StringBuilder();
                fis = new FileInputStream(new File(filename));
                int ch = fis.read();
                while (ch >= 0) {
                    content.append((char) ch);
                    ch = fis.read();
                }
                ShowBrowserDialog sbd = new ShowBrowserDialog(// "Error help text"
                shell, BaseMessages.getString(PKG, "Spoon.Dialog.ErrorHelpText.Title"), content.toString());
                sbd.open();
            } catch (Exception ex) {
                new ErrorDialog(shell, // "Error showing help text"
                BaseMessages.getString(PKG, "Spoon.Dialog.ErrorShowingHelpText.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.ErrorShowingHelpText.Message"), ex);
            } finally {
                if (fis != null) {
                    try {
                        fis.close();
                    } catch (Exception ex) {
                        log.logError("Error closing plugin help file", ex);
                    }
                }
            }
        } else {
            new ErrorDialog(shell, // "I was unable to create a new step"
            BaseMessages.getString(PKG, "Spoon.Dialog.UnableCreateNewStep.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.UnableCreateNewStep.Message"), e);
        }
        return null;
    } catch (Throwable e) {
        if (!shell.isDisposed()) {
            new ErrorDialog(shell, // "Error creating step"
            BaseMessages.getString(PKG, "Spoon.Dialog.ErrorCreatingStep.Title"), BaseMessages.getString(PKG, "Spoon.Dialog.UnableCreateNewStep.Message"), e);
        }
        return null;
    }
    return inf;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) StepDialogInterface(org.pentaho.di.trans.step.StepDialogInterface) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) ShowBrowserDialog(org.pentaho.di.ui.core.dialog.ShowBrowserDialog) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StepMeta(org.pentaho.di.trans.step.StepMeta) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) FileInputStream(java.io.FileInputStream) SWTException(org.eclipse.swt.SWTException) KettleRowException(org.pentaho.di.core.exception.KettleRowException) FileSystemException(org.apache.commons.vfs2.FileSystemException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleAuthException(org.pentaho.di.core.exception.KettleAuthException) KettleRepositoryLostException(org.pentaho.di.repository.KettleRepositoryLostException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) LifecycleException(org.pentaho.di.core.lifecycle.LifecycleException) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) KettleFileException(org.pentaho.di.core.exception.KettleFileException) KettleException(org.pentaho.di.core.exception.KettleException) MalformedURLException(java.net.MalformedURLException) MessageBox(org.eclipse.swt.widgets.MessageBox) StepPluginType(org.pentaho.di.core.plugins.StepPluginType) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) LastUsedFile(org.pentaho.di.core.LastUsedFile) File(java.io.File)

Example 89 with PluginRegistry

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

the class CarteServlet method init.

@Override
public void init(ServletConfig config) throws ServletException {
    cartePluginRegistry = new ConcurrentHashMap<String, CartePluginInterface>();
    detections = Collections.synchronizedList(new ArrayList<SlaveServerDetection>());
    PluginRegistry pluginRegistry = PluginRegistry.getInstance();
    List<PluginInterface> plugins = pluginRegistry.getPlugins(CartePluginType.class);
    // Initial Registry scan
    for (PluginInterface plugin : plugins) {
        try {
            registerServlet(loadServlet(plugin));
        } catch (KettlePluginException e) {
            log.logError("Unable to instantiate plugin for use with CarteServlet " + plugin.getName());
        }
    }
    // Servlets configured in web.xml take precedence to those discovered during plugin scan
    @SuppressWarnings("unchecked") Enumeration<String> initParameterNames = config.getInitParameterNames();
    while (initParameterNames.hasMoreElements()) {
        final String paramName = initParameterNames.nextElement();
        final String className = config.getInitParameter(paramName);
        final Class<?> clazz;
        try {
            clazz = Class.forName(className);
            registerServlet((CartePluginInterface) clazz.newInstance());
        } catch (ClassNotFoundException e) {
            log.logError("Unable to find configured " + paramName + " of " + className, e);
        } catch (InstantiationException e) {
            log.logError("Unable to instantiate configured " + paramName + " of " + className, e);
        } catch (IllegalAccessException e) {
            log.logError("Unable to access configured " + paramName + " of " + className, e);
        } catch (ClassCastException e) {
            log.logError("Unable to cast configured " + paramName + " of " + className + " to " + CartePluginInterface.class, e);
        }
    }
    // Catch servlets as they become available
    pluginRegistry.addPluginListener(CartePluginType.class, new PluginTypeListener() {

        @Override
        public void pluginAdded(Object serviceObject) {
            try {
                registerServlet(loadServlet((PluginInterface) serviceObject));
            } catch (KettlePluginException e) {
                log.logError(MessageFormat.format("Unable to load plugin: {0}", serviceObject), e);
            }
        }

        @Override
        public void pluginRemoved(Object serviceObject) {
            try {
                String key = getServletKey(loadServlet((PluginInterface) serviceObject));
                cartePluginRegistry.remove(key);
            } catch (KettlePluginException e) {
                log.logError(MessageFormat.format("Unable to load plugin: {0}", serviceObject), e);
            }
        }

        @Override
        public void pluginChanged(Object serviceObject) {
            pluginAdded(serviceObject);
        }
    });
}
Also used : KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) ArrayList(java.util.ArrayList) PluginTypeListener(org.pentaho.di.core.plugins.PluginTypeListener) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry)

Example 90 with PluginRegistry

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

the class ExecuteTransServlet method openRepository.

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;
}
Also used : RepositoryMeta(org.pentaho.di.repository.RepositoryMeta) KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) RepositoriesMeta(org.pentaho.di.repository.RepositoriesMeta)

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