Search in sources :

Example 56 with PluginInterface

use of org.pentaho.di.core.plugins.PluginInterface 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 57 with PluginInterface

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

the class StepPartitioningMeta method getMethod.

public static final String getMethod(String name) {
    if (Utils.isEmpty(name)) {
        return methodCodes[PARTITIONING_METHOD_NONE];
    }
    for (int i = 0; i < methodDescriptions.length; i++) {
        if (methodDescriptions[i].equalsIgnoreCase(name)) {
            return methodCodes[i];
        }
    }
    for (int i = 0; i < methodCodes.length; i++) {
        if (methodCodes[i].equalsIgnoreCase(name)) {
            return methodCodes[i];
        }
    }
    PluginRegistry registry = PluginRegistry.getInstance();
    PluginInterface plugin = registry.findPluginWithName(PartitionerPluginType.class, name);
    if (plugin != null) {
        return name;
    }
    plugin = registry.findPluginWithId(PartitionerPluginType.class, name);
    if (plugin != null) {
        return name;
    }
    return methodCodes[PARTITIONING_METHOD_NONE];
}
Also used : PartitionerPluginType(org.pentaho.di.core.plugins.PartitionerPluginType) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface)

Example 58 with PluginInterface

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

the class Database method connectUsingClass.

/**
 * Connect using the correct classname
 *
 * @param classname for example "org.gjt.mm.mysql.Driver"
 * @return true if the connect was successful, false if something went wrong.
 */
private void connectUsingClass(String classname, String partitionId) throws KettleDatabaseException {
    // Install and load the jdbc Driver
    PluginInterface plugin = PluginRegistry.getInstance().getPlugin(DatabasePluginType.class, databaseMeta.getDatabaseInterface());
    try {
        synchronized (java.sql.DriverManager.class) {
            ClassLoader classLoader = PluginRegistry.getInstance().getClassLoader(plugin);
            Class<?> driverClass = classLoader.loadClass(classname);
            // Only need DelegatingDriver for drivers not from our classloader
            if (driverClass.getClassLoader() != this.getClass().getClassLoader()) {
                String pluginId = PluginRegistry.getInstance().getPluginId(DatabasePluginType.class, databaseMeta.getDatabaseInterface());
                Set<String> registeredDriversFromPlugin = registeredDrivers.get(pluginId);
                if (registeredDriversFromPlugin == null) {
                    registeredDriversFromPlugin = new HashSet<String>();
                    registeredDrivers.put(pluginId, registeredDriversFromPlugin);
                }
                // Prevent registering multiple delegating drivers for same class, plugin
                if (!registeredDriversFromPlugin.contains(driverClass.getCanonicalName())) {
                    DriverManager.registerDriver(new DelegatingDriver((Driver) driverClass.newInstance()));
                    registeredDriversFromPlugin.add(driverClass.getCanonicalName());
                }
            } else {
                // Trigger static register block in driver class
                Class.forName(classname);
            }
        }
    } catch (NoClassDefFoundError e) {
        throw new KettleDatabaseException(BaseMessages.getString(PKG, "Database.Exception.UnableToFindClassMissingDriver", classname, plugin.getName()), e);
    } catch (ClassNotFoundException e) {
        throw new KettleDatabaseException(BaseMessages.getString(PKG, "Database.Exception.UnableToFindClassMissingDriver", classname, plugin.getName()), e);
    } catch (Exception e) {
        throw new KettleDatabaseException("Exception while loading class", e);
    }
    try {
        String url;
        if (databaseMeta.isPartitioned() && !Utils.isEmpty(partitionId)) {
            url = environmentSubstitute(databaseMeta.getURL(partitionId));
        } else {
            url = environmentSubstitute(databaseMeta.getURL());
        }
        String clusterUsername = null;
        String clusterPassword = null;
        if (databaseMeta.isPartitioned() && !Utils.isEmpty(partitionId)) {
            // Get the cluster information...
            PartitionDatabaseMeta partition = databaseMeta.getPartitionMeta(partitionId);
            if (partition != null) {
                clusterUsername = partition.getUsername();
                clusterPassword = Encr.decryptPasswordOptionallyEncrypted(partition.getPassword());
            }
        }
        String username;
        String password;
        if (!Utils.isEmpty(clusterUsername)) {
            username = clusterUsername;
            password = clusterPassword;
        } else {
            username = environmentSubstitute(databaseMeta.getUsername());
            password = Encr.decryptPasswordOptionallyEncrypted(environmentSubstitute(databaseMeta.getPassword()));
        }
        Properties properties = databaseMeta.getConnectionProperties();
        if (databaseMeta.supportsOptionsInURL()) {
            if (!Utils.isEmpty(username) || !Utils.isEmpty(password)) {
                // Allow for empty username with given password, in this case username must be given with one space
                properties.put("user", Const.NVL(username, " "));
                properties.put("password", Const.NVL(password, ""));
                if (databaseMeta.getDatabaseInterface() instanceof MSSQLServerNativeDatabaseMeta) {
                    // Handle MSSQL Instance name. Would rather this was handled in the dialect
                    // but cannot (without refactor) get to variablespace for variable substitution from
                    // a BaseDatabaseMeta subclass.
                    String instance = environmentSubstitute(databaseMeta.getSQLServerInstance());
                    if (!Utils.isEmpty(instance)) {
                        url += ";instanceName=" + instance;
                    }
                }
                connection = DriverManager.getConnection(url, properties);
            } else {
                // Perhaps the username is in the URL or no username is required...
                connection = DriverManager.getConnection(url, properties);
            }
        } else {
            if (!Utils.isEmpty(username)) {
                properties.put("user", username);
            }
            if (!Utils.isEmpty(password)) {
                properties.put("password", password);
            }
            connection = DriverManager.getConnection(url, properties);
        }
    } catch (SQLException e) {
        throw new KettleDatabaseException("Error connecting to database: (using class " + classname + ")", e);
    } catch (Throwable e) {
        throw new KettleDatabaseException("Error connecting to database: (using class " + classname + ")", e);
    }
}
Also used : SQLException(java.sql.SQLException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) Driver(java.sql.Driver) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Properties(java.util.Properties) KettleValueException(org.pentaho.di.core.exception.KettleValueException) BatchUpdateException(java.sql.BatchUpdateException) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) SQLException(java.sql.SQLException) KettleDatabaseBatchException(org.pentaho.di.core.exception.KettleDatabaseBatchException) DriverManager(java.sql.DriverManager)

Example 59 with PluginInterface

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

the class DatabaseMeta method getDatabaseFactory.

public DatabaseFactoryInterface getDatabaseFactory() throws Exception {
    PluginRegistry registry = PluginRegistry.getInstance();
    PluginInterface plugin = registry.getPlugin(DatabasePluginType.class, databaseInterface.getPluginId());
    if (plugin == null) {
        throw new KettleDatabaseException("database type with plugin id [" + databaseInterface.getPluginId() + "] couldn't be found!");
    }
    ClassLoader loader = registry.getClassLoader(plugin);
    Class<?> clazz = Class.forName(databaseInterface.getDatabaseFactoryName(), true, loader);
    return (DatabaseFactoryInterface) clazz.newInstance();
}
Also used : KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface)

Example 60 with PluginInterface

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

the class ValueMetaFactory method getValueMetaNames.

public static String[] getValueMetaNames() {
    List<String> strings = new ArrayList<String>();
    List<PluginInterface> plugins = pluginRegistry.getPlugins(ValueMetaPluginType.class);
    for (PluginInterface plugin : plugins) {
        int id = Integer.valueOf(plugin.getIds()[0]);
        if (id > 0 && id != ValueMetaInterface.TYPE_SERIALIZABLE) {
            strings.add(plugin.getName());
        }
    }
    return strings.toArray(new String[strings.size()]);
}
Also used : PluginInterface(org.pentaho.di.core.plugins.PluginInterface) ArrayList(java.util.ArrayList)

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