Search in sources :

Example 91 with PluginRegistry

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

the class SlaveServerConfig method openRepository.

private void openRepository(String repositoryId) throws KettleException {
    try {
        RepositoriesMeta repositoriesMeta = new RepositoriesMeta();
        repositoriesMeta.readData();
        repositoryMeta = repositoriesMeta.findRepository(repositoryId);
        if (repositoryMeta == null) {
            throw new KettleException("Unable to find repository: " + repositoryId);
        }
        PluginRegistry registry = PluginRegistry.getInstance();
        repository = registry.loadClass(RepositoryPluginType.class, repositoryMeta, Repository.class);
        repository.init(repositoryMeta);
        repository.connect(repositoryUsername, repositoryPassword);
        // 
        if (repository.getMetaStore() != null) {
            metaStore.addMetaStore(0, repository.getMetaStore());
            metaStore.setActiveMetaStoreName(repository.getMetaStore().getName());
        }
        LogChannel.GENERAL.logBasic("Connected to repository '" + repository.getName() + "'");
    } catch (Exception e) {
        throw new KettleException("Unable to open repository connection", e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) Repository(org.pentaho.di.repository.Repository) RepositoryPluginType(org.pentaho.di.core.plugins.RepositoryPluginType) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) RepositoriesMeta(org.pentaho.di.repository.RepositoriesMeta) KettleException(org.pentaho.di.core.exception.KettleException) SocketException(java.net.SocketException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException)

Example 92 with PluginRegistry

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

the class TransProfileFactory method generateTransformation.

public TransMeta generateTransformation(LoggingObjectInterface parentLoggingInterface) throws KettleException {
    PluginRegistry registry = PluginRegistry.getInstance();
    // Get the list of fields from the table...
    // 
    tableLayout = getTableFields(parentLoggingInterface);
    // Now start building the transformation...
    // 
    TransMeta transMeta = new TransMeta(databaseMeta);
    transMeta.addDatabase(databaseMeta);
    // Create a step to read the content of the table
    // Read the data from the database table...
    // For now we read it all, later we add options to only read the first X rows
    // 
    TableInputMeta readMeta = new TableInputMeta();
    readMeta.setSQL("SELECT * FROM " + schemaTable);
    readMeta.setDatabaseMeta(databaseMeta);
    StepMeta read = new StepMeta(registry.getPluginId(StepPluginType.class, readMeta), "Read data", readMeta);
    read.setLocation(50, 50);
    read.setDraw(true);
    transMeta.addStep(read);
    // Grab the data types too
    // 
    // Now calculate the requested statistics for all fields...
    // TODO: create configuration possibility
    // For now, just do : min, max, sum, count, avg, std dev. (7)
    // 
    int[] numericCalculations = new int[] { GroupByMeta.TYPE_GROUP_MIN, GroupByMeta.TYPE_GROUP_MAX, GroupByMeta.TYPE_GROUP_SUM, GroupByMeta.TYPE_GROUP_COUNT_ALL, GroupByMeta.TYPE_GROUP_AVERAGE, GroupByMeta.TYPE_GROUP_STANDARD_DEVIATION };
    int[] stringCalculations = new int[] { GroupByMeta.TYPE_GROUP_MIN, GroupByMeta.TYPE_GROUP_MAX, GroupByMeta.TYPE_GROUP_COUNT_ALL };
    int[] dateCalculations = new int[] { GroupByMeta.TYPE_GROUP_MIN, GroupByMeta.TYPE_GROUP_MAX, GroupByMeta.TYPE_GROUP_COUNT_ALL };
    int[] booleanCalculations = new int[] { GroupByMeta.TYPE_GROUP_MIN, GroupByMeta.TYPE_GROUP_MAX, GroupByMeta.TYPE_GROUP_COUNT_ALL };
    // Run it through the "group by" step without a grouping.
    // Later, we can use the UnivariateStats plugin/step perhaps.
    // 
    GroupByMeta statsMeta = new GroupByMeta();
    int nrNumeric = 0;
    int nrDates = 0;
    int nrStrings = 0;
    int nrBooleans = 0;
    for (ValueMetaInterface valueMeta : tableLayout.getValueMetaList()) {
        if (valueMeta.isNumeric()) {
            nrNumeric++;
        }
        if (valueMeta.isDate()) {
            nrDates++;
        }
        if (valueMeta.isString()) {
            nrStrings++;
        }
        if (valueMeta.isBoolean()) {
            nrBooleans++;
        }
    }
    int nrCalculations = nrNumeric * numericCalculations.length + nrDates * dateCalculations.length + nrStrings * stringCalculations.length + nrBooleans * booleanCalculations.length;
    statsMeta.allocate(0, nrCalculations);
    int calcIndex = 0;
    for (int i = 0; i < tableLayout.size(); i++) {
        ValueMetaInterface valueMeta = tableLayout.getValueMeta(i);
        // 
        if (valueMeta.isNumeric()) {
            // CHECKSTYLE:LineLength:OFF
            for (int c = 0; c < numericCalculations.length; c++) {
                statsMeta.getAggregateField()[calcIndex] = valueMeta.getName() + "(" + GroupByMeta.getTypeDesc(numericCalculations[c]) + ")";
                statsMeta.getSubjectField()[calcIndex] = valueMeta.getName();
                statsMeta.getAggregateType()[calcIndex] = numericCalculations[c];
                calcIndex++;
            }
        }
        // 
        if (valueMeta.isString()) {
            // CHECKSTYLE:LineLength:OFF
            for (int c = 0; c < stringCalculations.length; c++) {
                statsMeta.getAggregateField()[calcIndex] = valueMeta.getName() + "(" + GroupByMeta.getTypeDesc(stringCalculations[c]) + ")";
                statsMeta.getSubjectField()[calcIndex] = valueMeta.getName();
                statsMeta.getAggregateType()[calcIndex] = stringCalculations[c];
                calcIndex++;
            }
        }
        // 
        if (valueMeta.isDate()) {
            for (int c = 0; c < dateCalculations.length; c++) {
                statsMeta.getAggregateField()[calcIndex] = valueMeta.getName() + "(" + GroupByMeta.getTypeDesc(dateCalculations[c]) + ")";
                statsMeta.getSubjectField()[calcIndex] = valueMeta.getName();
                statsMeta.getAggregateType()[calcIndex] = dateCalculations[c];
                calcIndex++;
            }
        }
        // 
        if (valueMeta.isBoolean()) {
            for (int c = 0; c < booleanCalculations.length; c++) {
                statsMeta.getAggregateField()[calcIndex] = valueMeta.getName() + "(" + GroupByMeta.getTypeDesc(booleanCalculations[c]) + ")";
                statsMeta.getSubjectField()[calcIndex] = valueMeta.getName();
                statsMeta.getAggregateType()[calcIndex] = booleanCalculations[c];
                calcIndex++;
            }
        }
    }
    StepMeta calc = new StepMeta(registry.getPluginId(StepPluginType.class, statsMeta), "Calc", statsMeta);
    calc.setLocation(250, 50);
    calc.setDraw(true);
    transMeta.addStep(calc);
    TransHopMeta hop = new TransHopMeta(read, calc);
    transMeta.addTransHop(hop);
    DummyTransMeta dummyMeta = new DummyTransMeta();
    StepMeta result = new StepMeta(registry.getPluginId(StepPluginType.class, dummyMeta), RESULT_STEP_NAME, dummyMeta);
    result.setLocation(450, 50);
    result.setDraw(true);
    transMeta.addStep(result);
    TransHopMeta hop2 = new TransHopMeta(calc, result);
    transMeta.addTransHop(hop2);
    return transMeta;
}
Also used : GroupByMeta(org.pentaho.di.trans.steps.groupby.GroupByMeta) StepPluginType(org.pentaho.di.core.plugins.StepPluginType) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) TableInputMeta(org.pentaho.di.trans.steps.tableinput.TableInputMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)

Example 93 with PluginRegistry

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

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

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

the class ExtensionPointMap method reInitialize.

/**
 * Reinitialize the extension point plugins map
 */
public void reInitialize() {
    lock.writeLock().lock();
    try {
        extensionPointPluginMap = HashBasedTable.create();
        final PluginRegistry registry = PluginRegistry.getInstance();
        List<PluginInterface> extensionPointPlugins = registry.getPlugins(ExtensionPointPluginType.class);
        for (PluginInterface extensionPointPlugin : extensionPointPlugins) {
            addExtensionPoint(extensionPointPlugin);
        }
    } finally {
        lock.writeLock().unlock();
    }
}
Also used : PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface)

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