Search in sources :

Example 46 with StepMetaInterface

use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-kettle by pentaho.

the class TransMetaConverter method resolveStepMetaResources.

private static void resolveStepMetaResources(TransMeta transMeta) {
    for (StepMeta stepMeta : transMeta.getSteps()) {
        StepMetaInterface smi = stepMeta.getStepMetaInterface();
        if (smi instanceof ResolvableResource) {
            ResolvableResource resolvableMeta = (ResolvableResource) smi;
            resolvableMeta.resolve();
        }
    }
}
Also used : StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) ResolvableResource(org.pentaho.di.workarounds.ResolvableResource)

Example 47 with StepMetaInterface

use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-kettle by pentaho.

the class TransWebSocketEngineAdapter method getSubSteps.

@SuppressWarnings("unchecked")
private List<StepMetaDataCombi> getSubSteps(Transformation transformation, StepMetaDataCombi combi) {
    HashMap<String, Transformation> config = ((Optional<HashMap<String, Transformation>>) transformation.getConfig(TransMetaConverter.SUB_TRANSFORMATIONS_KEY)).orElse(Maps.newHashMap());
    StepMetaInterface smi = combi.stepMeta.getStepMetaInterface();
    return config.keySet().stream().filter(key -> stepHasDependency(combi, smi, key)).flatMap(key -> opsToSteps(config.get(key)).stream()).collect(Collectors.toList());
}
Also used : Transformation(org.pentaho.di.engine.api.model.Transformation) Result(org.pentaho.di.core.Result) Trans(org.pentaho.di.trans.Trans) TransMetaConverter(org.pentaho.di.trans.ael.adapters.TransMetaConverter) Arrays(java.util.Arrays) LogLevel(org.pentaho.di.engine.api.reporting.LogLevel) KettleException(org.pentaho.di.core.exception.KettleException) HashMap(java.util.HashMap) Operation(org.pentaho.di.engine.api.model.Operation) Function(java.util.function.Function) ArrayList(java.util.ArrayList) MessageEventHandler(org.pentaho.di.trans.ael.websocket.handler.MessageEventHandler) LogEntry(org.pentaho.di.engine.api.reporting.LogEntry) TransMeta(org.pentaho.di.trans.TransMeta) Collectors.toMap(java.util.stream.Collectors.toMap) Status(org.pentaho.di.engine.api.reporting.Status) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MessageEventHandlerExecutionException(org.pentaho.di.trans.ael.websocket.exception.MessageEventHandlerExecutionException) Map(java.util.Map) ExecutorService(java.util.concurrent.ExecutorService) StepInterface(org.pentaho.di.trans.step.StepInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) StopMessage(org.pentaho.di.engine.api.remote.StopMessage) ExecutionRequest(org.pentaho.di.engine.api.remote.ExecutionRequest) ResourceEntry(org.pentaho.di.resource.ResourceEntry) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) RemoteSource(org.pentaho.di.engine.api.remote.RemoteSource) CountDownLatch(java.util.concurrent.CountDownLatch) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) List(java.util.List) Principal(java.security.Principal) HandlerRegistrationException(org.pentaho.di.trans.ael.websocket.exception.HandlerRegistrationException) PDIEvent(org.pentaho.di.engine.api.events.PDIEvent) Optional(java.util.Optional) Message(org.pentaho.di.engine.api.remote.Message) ActingPrincipal(org.pentaho.di.engine.model.ActingPrincipal) RowProducer(org.pentaho.di.trans.RowProducer) Transformation(org.pentaho.di.engine.api.model.Transformation) Optional(java.util.Optional) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface)

Example 48 with StepMetaInterface

use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryTransDelegate method loadTransformation.

/**
 * Read a transformation with a certain name from a repository
 *
 * @param rep
 *          The repository to read from.
 * @param transname
 *          The name of the transformation.
 * @param repdir
 *          the path to the repository directory
 * @param monitor
 *          The progress monitor to display the progress of the file-open operation in a dialog
 * @param setInternalVariables
 *          true if you want to set the internal variables based on this transformation information
 */
public TransMeta loadTransformation(TransMeta transMeta, String transname, RepositoryDirectoryInterface repdir, ProgressMonitorListener monitor, boolean setInternalVariables) throws KettleException {
    transMeta.setRepository(repository);
    transMeta.setMetaStore(repository.metaStore);
    synchronized (repository) {
        try {
            String pathAndName = repdir.isRoot() ? repdir + transname : repdir + RepositoryDirectory.DIRECTORY_SEPARATOR + transname;
            transMeta.setName(transname);
            transMeta.setRepositoryDirectory(repdir);
            // Get the transformation id
            if (log.isDetailed()) {
                log.logDetailed(BaseMessages.getString(PKG, "TransMeta.Log.LookingForTransformation", transname, repdir.getPath()));
            }
            if (monitor != null) {
                monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.ReadingTransformationInfoTask.Title"));
            }
            transMeta.setObjectId(getTransformationID(transname, repdir.getObjectId()));
            if (monitor != null) {
                monitor.worked(1);
            }
            // If no valid id is available in the database, then give error...
            if (transMeta.getObjectId() != null) {
                ObjectId[] noteids = repository.getTransNoteIDs(transMeta.getObjectId());
                ObjectId[] stepids = repository.getStepIDs(transMeta.getObjectId());
                ObjectId[] hopids = getTransHopIDs(transMeta.getObjectId());
                int nrWork = 3 + noteids.length + stepids.length + hopids.length;
                if (monitor != null) {
                    monitor.beginTask(BaseMessages.getString(PKG, "TransMeta.Monitor.LoadingTransformationTask.Title") + pathAndName, nrWork);
                }
                if (log.isDetailed()) {
                    log.logDetailed(BaseMessages.getString(PKG, "TransMeta.Log.LoadingTransformation", transMeta.getName()));
                }
                // Load the common database connections
                if (monitor != null) {
                    monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.ReadingTheAvailableSharedObjectsTask.Title"));
                }
                try {
                    transMeta.setSharedObjects(readTransSharedObjects(transMeta));
                } catch (Exception e) {
                    log.logError(BaseMessages.getString(PKG, "TransMeta.ErrorReadingSharedObjects.Message", e.toString()));
                    log.logError(Const.getStackTracker(e));
                }
                if (monitor != null) {
                    monitor.worked(1);
                }
                // Load the notes...
                if (monitor != null) {
                    monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.ReadingNoteTask.Title"));
                }
                for (int i = 0; i < noteids.length; i++) {
                    NotePadMeta ni = repository.notePadDelegate.loadNotePadMeta(noteids[i]);
                    if (transMeta.indexOfNote(ni) < 0) {
                        transMeta.addNote(ni);
                    }
                    if (monitor != null) {
                        monitor.worked(1);
                    }
                }
                if (monitor != null) {
                    monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.ReadingStepsTask.Title"));
                }
                // read all the attributes
                repository.connectionDelegate.fillStepAttributesBuffer(transMeta.getObjectId());
                // on one go!
                for (int i = 0; i < stepids.length; i++) {
                    if (log.isDetailed()) {
                        log.logDetailed(BaseMessages.getString(PKG, "TransMeta.Log.LoadingStepWithID") + stepids[i]);
                    }
                    if (monitor != null) {
                        monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.ReadingStepTask.Title") + (i + 1) + "/" + (stepids.length));
                    }
                    StepMeta stepMeta = repository.stepDelegate.loadStepMeta(stepids[i], transMeta.getDatabases(), transMeta.getPartitionSchemas());
                    if (stepMeta.isMissing()) {
                        transMeta.addMissingTrans((MissingTrans) stepMeta.getStepMetaInterface());
                    }
                    // In this case, we just add or replace the shared steps.
                    // The repository is considered "more central"
                    transMeta.addOrReplaceStep(stepMeta);
                    if (monitor != null) {
                        monitor.worked(1);
                    }
                }
                if (monitor != null) {
                    monitor.worked(1);
                }
                // clear the buffer (should be empty anyway)
                repository.connectionDelegate.setStepAttributesBuffer(null);
                // Have all StreamValueLookups, etc. reference the correct source steps...
                for (int i = 0; i < transMeta.nrSteps(); i++) {
                    StepMetaInterface sii = transMeta.getStep(i).getStepMetaInterface();
                    sii.searchInfoAndTargetSteps(transMeta.getSteps());
                }
                if (monitor != null) {
                    monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.LoadingTransformationDetailsTask.Title"));
                }
                loadRepTrans(transMeta);
                if (monitor != null) {
                    monitor.worked(1);
                }
                if (monitor != null) {
                    monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.ReadingHopTask.Title"));
                }
                for (int i = 0; i < hopids.length; i++) {
                    TransHopMeta hi = loadTransHopMeta(hopids[i], transMeta.getSteps());
                    if (hi != null) {
                        transMeta.addTransHop(hi);
                    }
                    if (monitor != null) {
                        monitor.worked(1);
                    }
                }
                // 
                for (int i = 0; i < transMeta.nrSteps(); i++) {
                    StepPartitioningMeta stepPartitioningMeta = transMeta.getStep(i).getStepPartitioningMeta();
                    if (stepPartitioningMeta != null) {
                        stepPartitioningMeta.setPartitionSchemaAfterLoading(transMeta.getPartitionSchemas());
                    }
                }
                // 
                for (int i = 0; i < transMeta.nrSteps(); i++) {
                    transMeta.getStep(i).setClusterSchemaAfterLoading(transMeta.getClusterSchemas());
                }
                if (monitor != null) {
                    monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.ReadingTheDependenciesTask.Title"));
                }
                ObjectId[] depids = repository.getTransDependencyIDs(transMeta.getObjectId());
                for (int i = 0; i < depids.length; i++) {
                    TransDependency td = loadTransDependency(depids[i], transMeta.getDatabases());
                    transMeta.addDependency(td);
                }
                if (monitor != null) {
                    monitor.worked(1);
                }
                // Load the group attributes map
                // 
                transMeta.setAttributesMap(loadTransAttributesMap(transMeta.getObjectId()));
                // 
                for (int i = 0; i < transMeta.nrSteps(); i++) {
                    StepMeta stepMeta = transMeta.getStep(i);
                    String sourceStep = repository.getStepAttributeString(stepMeta.getObjectId(), "step_error_handling_source_step");
                    if (sourceStep != null) {
                        StepErrorMeta stepErrorMeta = repository.stepDelegate.loadStepErrorMeta(transMeta, stepMeta, transMeta.getSteps());
                        // a bit of a trick, I know.
                        stepErrorMeta.getSourceStep().setStepErrorMeta(stepErrorMeta);
                    }
                }
                // Load all the log tables for the transformation...
                // 
                RepositoryAttributeInterface attributeInterface = new KettleDatabaseRepositoryTransAttribute(repository.connectionDelegate, transMeta.getObjectId());
                for (LogTableInterface logTable : transMeta.getLogTables()) {
                    logTable.loadFromRepository(attributeInterface);
                }
                if (monitor != null) {
                    monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.SortingStepsTask.Title"));
                }
                transMeta.sortSteps();
                if (monitor != null) {
                    monitor.worked(1);
                }
                if (monitor != null) {
                    monitor.done();
                }
            } else {
                throw new KettleException(BaseMessages.getString(PKG, "TransMeta.Exception.TransformationDoesNotExist") + transMeta.getName());
            }
            if (log.isDetailed()) {
                log.logDetailed(BaseMessages.getString(PKG, "TransMeta.Log.LoadedTransformation2", transname, String.valueOf(transMeta.getRepositoryDirectory() == null)));
                log.logDetailed(BaseMessages.getString(PKG, "TransMeta.Log.LoadedTransformation", transname, transMeta.getRepositoryDirectory().getPath()));
            }
            // close prepared statements, minimize locking etc.
            // 
            repository.connectionDelegate.closeAttributeLookupPreparedStatements();
            return transMeta;
        } catch (KettleDatabaseException e) {
            log.logError(BaseMessages.getString(PKG, "TransMeta.Log.DatabaseErrorOccuredReadingTransformation") + Const.CR + e);
            throw new KettleException(BaseMessages.getString(PKG, "TransMeta.Exception.DatabaseErrorOccuredReadingTransformation"), e);
        } catch (Exception e) {
            log.logError(BaseMessages.getString(PKG, "TransMeta.Log.DatabaseErrorOccuredReadingTransformation") + Const.CR + e);
            throw new KettleException(BaseMessages.getString(PKG, "TransMeta.Exception.DatabaseErrorOccuredReadingTransformation2"), e);
        } finally {
            transMeta.initializeVariablesFrom(null);
            if (setInternalVariables) {
                transMeta.setInternalKettleVariables();
            }
        }
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) StepErrorMeta(org.pentaho.di.trans.step.StepErrorMeta) TransDependency(org.pentaho.di.trans.TransDependency) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StepPartitioningMeta(org.pentaho.di.trans.step.StepPartitioningMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) RepositoryAttributeInterface(org.pentaho.di.repository.RepositoryAttributeInterface) LogTableInterface(org.pentaho.di.core.logging.LogTableInterface) NotePadMeta(org.pentaho.di.core.NotePadMeta) TransHopMeta(org.pentaho.di.trans.TransHopMeta)

Example 49 with StepMetaInterface

use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-kettle by pentaho.

the class TransMeta method addStep.

/**
 * Add a new step to the transformation at the specified index. This method sets the step's parent transformation to
 * the this transformation, and marks that the transformations' steps have changed.
 *
 * @param p
 *          The index into the step list
 * @param stepMeta
 *          The step to be added.
 */
public void addStep(int p, StepMeta stepMeta) {
    steps.add(p, stepMeta);
    stepMeta.setParentTransMeta(this);
    changed_steps = true;
    StepMetaInterface iface = stepMeta.getStepMetaInterface();
    if (iface instanceof StepMetaChangeListenerInterface) {
        addStepChangeListener(p, (StepMetaChangeListenerInterface) stepMeta.getStepMetaInterface());
    }
    clearCaches();
}
Also used : StepMetaChangeListenerInterface(org.pentaho.di.trans.step.StepMetaChangeListenerInterface) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface)

Example 50 with StepMetaInterface

use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-kettle by pentaho.

the class RepositoryImporterTest method testImportTrans_patchTransEntries_without_variables.

@Test
public void testImportTrans_patchTransEntries_without_variables() throws KettleException {
    JobEntryInterface jobEntryInterface = createJobEntry("");
    StepMetaInterface stepMeta = createStepMeta("/userName");
    RepositoryImporter importer = createRepositoryImporter(jobEntryInterface, stepMeta, true);
    importer.setBaseDirectory(baseDirectory);
    importer.importTransformation(entityNode, feedback);
    verify((HasRepositoryDirectories) stepMeta).setDirectories(new String[] { ROOT_PATH + USER_NAME_PATH });
}
Also used : JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) Test(org.junit.Test)

Aggregations

StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)77 StepMeta (org.pentaho.di.trans.step.StepMeta)40 KettleException (org.pentaho.di.core.exception.KettleException)31 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)21 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)20 TransMeta (org.pentaho.di.trans.TransMeta)16 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)16 TableItem (org.eclipse.swt.widgets.TableItem)15 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)15 SourceToTargetMapping (org.pentaho.di.core.SourceToTargetMapping)14 Trans (org.pentaho.di.trans.Trans)14 EnterMappingDialog (org.pentaho.di.ui.core.dialog.EnterMappingDialog)14 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)12 Point (org.pentaho.di.core.gui.Point)12 TransHopMeta (org.pentaho.di.trans.TransHopMeta)11 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)11 NotePadMeta (org.pentaho.di.core.NotePadMeta)8 KettleStepException (org.pentaho.di.core.exception.KettleStepException)8 JobEntryInterface (org.pentaho.di.job.entry.JobEntryInterface)8