Search in sources :

Example 26 with StepMetaInterface

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

the class RunTransServletTest method testFinishProcessingTransWithServletOutputSteps.

@Test
public void testFinishProcessingTransWithServletOutputSteps() throws Exception {
    StepMetaDataCombi stepMetaDataCombi = new StepMetaDataCombi();
    StepMetaInterface stepMeta = mock(StepMetaInterface.class);
    when(stepMeta.passDataToServletOutput()).thenReturn(true);
    stepMetaDataCombi.meta = stepMeta;
    stepList.add(stepMetaDataCombi);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            Thread.currentThread().sleep(2000);
            return null;
        }
    }).when(trans).waitUntilFinished();
    runTransServlet.finishProcessing(trans, out);
    assertTrue(outData.toString().isEmpty());
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) Test(org.junit.Test)

Example 27 with StepMetaInterface

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

the class MappingIT method testInfoStreams_with_main_data_path.

/**
 * Tests that an input step that is a main data path is not flagged as an info stream
 */
public void testInfoStreams_with_main_data_path() throws Exception {
    KettleEnvironment.init();
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // Create a new transformation with a row generator that feeds a Mapping (Sub-Transformation) Step
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("Mapping Info Test");
    StepMeta rowGenerator = buildRowGeneratorStep(registry, "Generate Rows");
    transMeta.addStep(rowGenerator);
    StepMeta rowGeneratorMain = buildRowGeneratorStep(registry, "Generate Rows Main");
    transMeta.addStep(rowGeneratorMain);
    String mappingName = "mapping";
    MappingMeta mappingMeta = new MappingMeta();
    mappingMeta.setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME);
    mappingMeta.setFileName("test/org/pentaho/di/trans/steps/mapping/subtrans.ktr");
    List<MappingIODefinition> inputMappings = new ArrayList<MappingIODefinition>();
    String mappingInputStepName = "input";
    inputMappings.add(createMappingDef(rowGenerator.getName(), mappingInputStepName, "string", "a"));
    // Create the main data path mapping
    MappingIODefinition mainMappingDef = createMappingDef(rowGeneratorMain.getName(), mappingInputStepName, "string", "a");
    mainMappingDef.setMainDataPath(true);
    inputMappings.add(mainMappingDef);
    mappingMeta.setInputMappings(inputMappings);
    String mappingPid = registry.getPluginId(StepPluginType.class, mappingMeta);
    StepMeta mapping = new StepMeta(mappingPid, mappingName, mappingMeta);
    transMeta.addStep(mapping);
    TransHopMeta hopGeneratorToMapping = new TransHopMeta(rowGenerator, mapping);
    transMeta.addTransHop(hopGeneratorToMapping);
    hopGeneratorToMapping = new TransHopMeta(rowGeneratorMain, mapping);
    transMeta.addTransHop(hopGeneratorToMapping);
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    // (Copied from TransMeta.loadXML())
    for (int i = 0; i < transMeta.nrSteps(); i++) {
        StepMeta stepMeta = transMeta.getStep(i);
        StepMetaInterface sii = stepMeta.getStepMetaInterface();
        if (sii != null) {
            sii.searchInfoAndTargetSteps(transMeta.getSteps());
        }
    }
    // Verify the transformation was configured properly
    assertEquals("Transformation not initialized properly", 3, transMeta.nrSteps());
    StepMeta meta = transMeta.getStep(2);
    assertTrue("Transformation not initialized properly", meta.getStepMetaInterface() instanceof MappingMeta);
    MappingMeta loadedMappingMeta = (MappingMeta) meta.getStepMetaInterface();
    assertEquals("Expected a two input mapping definition", 2, loadedMappingMeta.getInputMappings().size());
    StepIOMetaInterface ioMeta = loadedMappingMeta.getStepIOMeta();
    assertEquals("Expected a single Info Stream", 1, ioMeta.getInfoStreams().size());
    assertEquals("Expected a single Info Step", 1, loadedMappingMeta.getInfoSteps().length);
}
Also used : TransMeta(org.pentaho.di.trans.TransMeta) ArrayList(java.util.ArrayList) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Trans(org.pentaho.di.trans.Trans)

Example 28 with StepMetaInterface

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

the class MappingIT method testInfoStreams_single.

/**
 * Tests that info steps are correctly identified via StepMetaInterface.getStepIOMeta()
 */
public void testInfoStreams_single() throws Exception {
    KettleEnvironment.init();
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // Create a new transformation with a row generator that feeds a Mapping (Sub-Transformation) Step
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("Mapping Info Test");
    StepMeta rowGenerator = buildRowGeneratorStep(registry, "Generate Rows");
    transMeta.addStep(rowGenerator);
    String mappingName = "mapping";
    MappingMeta mappingMeta = new MappingMeta();
    mappingMeta.setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME);
    mappingMeta.setFileName("test/org/pentaho/di/trans/steps/mapping/subtrans.ktr");
    String mappingInputStepName = "input";
    mappingMeta.setInputMappings(Collections.singletonList(createMappingDef(rowGenerator.getName(), mappingInputStepName, "string", "a")));
    String mappingPid = registry.getPluginId(StepPluginType.class, mappingMeta);
    StepMeta mapping = new StepMeta(mappingPid, mappingName, mappingMeta);
    transMeta.addStep(mapping);
    TransHopMeta hopGeneratorToMapping = new TransHopMeta(rowGenerator, mapping);
    transMeta.addTransHop(hopGeneratorToMapping);
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    // (Copied from TransMeta.loadXML())
    for (int i = 0; i < transMeta.nrSteps(); i++) {
        StepMeta stepMeta = transMeta.getStep(i);
        StepMetaInterface sii = stepMeta.getStepMetaInterface();
        if (sii != null) {
            sii.searchInfoAndTargetSteps(transMeta.getSteps());
        }
    }
    // Verify the transformation was configured properly
    assertEquals("Transformation not initialized properly", 2, transMeta.nrSteps());
    StepMeta meta = transMeta.getStep(1);
    assertTrue("Transformation not initialized properly", meta.getStepMetaInterface() instanceof MappingMeta);
    MappingMeta loadedMappingMeta = (MappingMeta) meta.getStepMetaInterface();
    assertEquals("Expected a single input mapping definition", 1, loadedMappingMeta.getInputMappings().size());
    StepIOMetaInterface ioMeta = loadedMappingMeta.getStepIOMeta();
    assertEquals("Expected a single Info Stream", 1, ioMeta.getInfoStreams().size());
    assertEquals("Expected a single Info Step", 1, loadedMappingMeta.getInfoSteps().length);
    // Verify the transformation can be executed
    StepInterface si = trans.getStepInterface(mappingName, 0);
    RowStepCollector rc = new RowStepCollector();
    si.addRowListener(rc);
    trans.startThreads();
    trans.waitUntilFinished();
    assertEquals(1, rc.getRowsRead().size());
    assertEquals(1, rc.getRowsWritten().size());
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Trans(org.pentaho.di.trans.Trans)

Example 29 with StepMetaInterface

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

the class BaseStreamStep method init.

public boolean init(StepMetaInterface stepMetaInterface, StepDataInterface stepDataInterface) {
    Preconditions.checkNotNull(stepMetaInterface);
    stepMeta = (BaseStreamStepMeta) stepMetaInterface;
    stepMeta.setParentStepMeta(getStepMeta());
    stepMeta.setFileName(stepMeta.getTransformationPath());
    boolean superInit = super.init(stepMetaInterface, stepDataInterface);
    try {
        TransMeta transMeta = TransExecutorMeta.loadMappingMeta(stepMeta, getTransMeta().getRepository(), getTransMeta().getMetaStore(), getParentVariableSpace());
        subtransExecutor = new SubtransExecutor(getStepname(), getTrans(), transMeta, true, new TransExecutorParameters(), environmentSubstitute(stepMeta.getSubStep()));
    } catch (KettleException e) {
        log.logError(e.getLocalizedMessage(), e);
        return false;
    }
    List<CheckResultInterface> remarks = new ArrayList<>();
    stepMeta.check(remarks, getTransMeta(), stepMeta.getParentStepMeta(), // these parameters are not used inside the method
    null, // these parameters are not used inside the method
    null, // these parameters are not used inside the method
    null, // these parameters are not used inside the method
    null, variables, getRepository(), getMetaStore());
    boolean errorsPresent = remarks.stream().filter(result -> result.getType() == CheckResultInterface.TYPE_RESULT_ERROR).peek(result -> logError(result.getText())).count() > 0;
    if (errorsPresent) {
        return false;
    }
    return superInit;
}
Also used : Result(org.pentaho.di.core.Result) Trans(org.pentaho.di.trans.Trans) StepDataInterface(org.pentaho.di.trans.step.StepDataInterface) CheckResultInterface(org.pentaho.di.core.CheckResultInterface) StreamWindow(org.pentaho.di.trans.streaming.api.StreamWindow) KettleException(org.pentaho.di.core.exception.KettleException) TransExecutorMeta(org.pentaho.di.trans.steps.transexecutor.TransExecutorMeta) ArrayList(java.util.ArrayList) TransMeta(org.pentaho.di.trans.TransMeta) StepStatus(org.pentaho.di.trans.step.StepStatus) BaseMessages(org.pentaho.di.i18n.BaseMessages) StepMeta(org.pentaho.di.trans.step.StepMeta) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) Collection(java.util.Collection) Throwables(com.google.common.base.Throwables) StreamSource(org.pentaho.di.trans.streaming.api.StreamSource) BaseStep(org.pentaho.di.trans.step.BaseStep) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) List(java.util.List) SubtransExecutor(org.pentaho.di.trans.SubtransExecutor) KettleStepException(org.pentaho.di.core.exception.KettleStepException) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) TransExecutorParameters(org.pentaho.di.trans.steps.transexecutor.TransExecutorParameters) Collections(java.util.Collections) KettleException(org.pentaho.di.core.exception.KettleException) SubtransExecutor(org.pentaho.di.trans.SubtransExecutor) TransMeta(org.pentaho.di.trans.TransMeta) ArrayList(java.util.ArrayList) TransExecutorParameters(org.pentaho.di.trans.steps.transexecutor.TransExecutorParameters) CheckResultInterface(org.pentaho.di.core.CheckResultInterface)

Example 30 with StepMetaInterface

use of org.pentaho.di.trans.step.StepMetaInterface 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)

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