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