Search in sources :

Example 1 with TransExecutorParameters

use of org.pentaho.di.trans.steps.transexecutor.TransExecutorParameters in project pentaho-kettle by pentaho.

the class TransExecutorDialog method collectInformation.

private void collectInformation() {
    // The parameters...
    // 
    TransExecutorParameters parameters = transExecutorMeta.getParameters();
    int nrLines = wTransExecutorParameters.nrNonEmpty();
    String[] variables = new String[nrLines];
    String[] fields = new String[nrLines];
    String[] input = new String[nrLines];
    parameters.setVariable(variables);
    parameters.setField(fields);
    parameters.setInput(input);
    for (int i = 0; i < nrLines; i++) {
        TableItem item = wTransExecutorParameters.getNonEmpty(i);
        variables[i] = item.getText(1);
        fields[i] = item.getText(2);
        input[i] = item.getText(3);
    }
    parameters.setInheritingAllVariables(wInheritAll.getSelection());
    // The group definition
    // 
    transExecutorMeta.setGroupSize(wGroupSize.getText());
    transExecutorMeta.setGroupField(wGroupField.getText());
    transExecutorMeta.setGroupTime(wGroupTime.getText());
    transExecutorMeta.setExecutionResultTargetStep(wExecutionResultTarget.getText());
    transExecutorMeta.setExecutionResultTargetStepMeta(transMeta.findStep(wExecutionResultTarget.getText()));
    transExecutorMeta.setExecutionTimeField(tiExecutionTimeField.getText(FIELD_NAME));
    transExecutorMeta.setExecutionResultField(tiExecutionResultField.getText(FIELD_NAME));
    transExecutorMeta.setExecutionNrErrorsField(tiExecutionNrErrorsField.getText(FIELD_NAME));
    transExecutorMeta.setExecutionLinesReadField(tiExecutionLinesReadField.getText(FIELD_NAME));
    transExecutorMeta.setExecutionLinesWrittenField(tiExecutionLinesWrittenField.getText(FIELD_NAME));
    transExecutorMeta.setExecutionLinesInputField(tiExecutionLinesInputField.getText(FIELD_NAME));
    transExecutorMeta.setExecutionLinesOutputField(tiExecutionLinesOutputField.getText(FIELD_NAME));
    transExecutorMeta.setExecutionLinesRejectedField(tiExecutionLinesRejectedField.getText(FIELD_NAME));
    transExecutorMeta.setExecutionLinesUpdatedField(tiExecutionLinesUpdatedField.getText(FIELD_NAME));
    transExecutorMeta.setExecutionLinesDeletedField(tiExecutionLinesDeletedField.getText(FIELD_NAME));
    transExecutorMeta.setExecutionFilesRetrievedField(tiExecutionFilesRetrievedField.getText(FIELD_NAME));
    transExecutorMeta.setExecutionExitStatusField(tiExecutionExitStatusField.getText(FIELD_NAME));
    transExecutorMeta.setExecutionLogTextField(tiExecutionLogTextField.getText(FIELD_NAME));
    transExecutorMeta.setExecutionLogChannelIdField(tiExecutionLogChannelIdField.getText(FIELD_NAME));
    transExecutorMeta.setResultFilesTargetStep(wResultFilesTarget.getText());
    transExecutorMeta.setResultFilesTargetStepMeta(transMeta.findStep(wResultFilesTarget.getText()));
    transExecutorMeta.setResultFilesFileNameField(wResultFileNameField.getText());
    if (!Utils.isEmpty(executorOutputStep)) {
        transExecutorMeta.setExecutorsOutputStep(executorOutputStep);
        transExecutorMeta.setExecutorsOutputStepMeta(transMeta.findStep(executorOutputStep));
    }
    // Result row info
    // 
    transExecutorMeta.setOutputRowsSourceStep(wOutputRowsSource.getText());
    transExecutorMeta.setOutputRowsSourceStepMeta(transMeta.findStep(wOutputRowsSource.getText()));
    int nrFields = wOutputFields.nrNonEmpty();
    transExecutorMeta.setOutputRowsField(new String[nrFields]);
    transExecutorMeta.setOutputRowsType(new int[nrFields]);
    transExecutorMeta.setOutputRowsLength(new int[nrFields]);
    transExecutorMeta.setOutputRowsPrecision(new int[nrFields]);
    // CHECKSTYLE:Indentation:OFF
    for (int i = 0; i < nrFields; i++) {
        TableItem item = wOutputFields.getNonEmpty(i);
        transExecutorMeta.getOutputRowsField()[i] = item.getText(1);
        transExecutorMeta.getOutputRowsType()[i] = ValueMetaFactory.getIdForValueMeta(item.getText(2));
        transExecutorMeta.getOutputRowsLength()[i] = Const.toInt(item.getText(3), -1);
        transExecutorMeta.getOutputRowsPrecision()[i] = Const.toInt(item.getText(4), -1);
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) TransExecutorParameters(org.pentaho.di.trans.steps.transexecutor.TransExecutorParameters)

Example 2 with TransExecutorParameters

use of org.pentaho.di.trans.steps.transexecutor.TransExecutorParameters in project pentaho-kettle by pentaho.

the class SubtransExecutorTest method stopsAll.

@Test
public void stopsAll() throws KettleException {
    TransMeta parentMeta = new TransMeta(this.getClass().getResource("subtrans-executor-parent.ktr").getPath(), new Variables());
    TransMeta subMeta = new TransMeta(this.getClass().getResource("subtrans-executor-sub.ktr").getPath(), new Variables());
    LoggingObjectInterface loggingObject = new LoggingObject("anything");
    Trans parentTrans = new Trans(parentMeta, loggingObject);
    SubtransExecutor subtransExecutor = new SubtransExecutor("subtransname", parentTrans, subMeta, true, new TransExecutorParameters(), "");
    subtransExecutor.running = Mockito.spy(subtransExecutor.running);
    RowMetaInterface rowMeta = parentMeta.getStepFields("Data Grid");
    List<RowMetaAndData> rows = Arrays.asList(new RowMetaAndData(rowMeta, "Pentaho", 1L), new RowMetaAndData(rowMeta, "Pentaho", 2L), new RowMetaAndData(rowMeta, "Pentaho", 3L), new RowMetaAndData(rowMeta, "Pentaho", 4L));
    subtransExecutor.execute(rows);
    verify(subtransExecutor.running).add(any());
    subtransExecutor.stop();
    assertTrue(subtransExecutor.running.isEmpty());
}
Also used : Variables(org.pentaho.di.core.variables.Variables) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) LoggingObject(org.pentaho.di.core.logging.LoggingObject) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) TransExecutorParameters(org.pentaho.di.trans.steps.transexecutor.TransExecutorParameters) Test(org.junit.Test)

Example 3 with TransExecutorParameters

use of org.pentaho.di.trans.steps.transexecutor.TransExecutorParameters 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 4 with TransExecutorParameters

use of org.pentaho.di.trans.steps.transexecutor.TransExecutorParameters in project pentaho-kettle by pentaho.

the class SubtransExecutorTest method testRunsATrans.

@Test
public void testRunsATrans() throws Exception {
    TransMeta parentMeta = new TransMeta(this.getClass().getResource("subtrans-executor-parent.ktr").getPath(), new Variables());
    TransMeta subMeta = new TransMeta(this.getClass().getResource("subtrans-executor-sub.ktr").getPath(), new Variables());
    LoggingObjectInterface loggingObject = new LoggingObject("anything");
    Trans parentTrans = spy(new Trans(parentMeta, loggingObject));
    SubtransExecutor subtransExecutor = new SubtransExecutor("subtransname", parentTrans, subMeta, true, new TransExecutorParameters(), "Group By");
    RowMetaInterface rowMeta = parentMeta.getStepFields("Data Grid");
    List<RowMetaAndData> rows = Arrays.asList(new RowMetaAndData(rowMeta, "Pentaho", 1L), new RowMetaAndData(rowMeta, "Pentaho", 2L), new RowMetaAndData(rowMeta, "Pentaho", 3L), new RowMetaAndData(rowMeta, "Pentaho", 4L));
    Optional<Result> optionalResult = subtransExecutor.execute(rows);
    assertEquals(1, optionalResult.orElseThrow(AssertionError::new).getRows().size());
    verify(this.logChannel).logBasic(Const.CR + "------------> Linenr 1------------------------------" + Const.CR + "name = Pentaho" + Const.CR + "sum = 10" + Const.CR + Const.CR + "====================");
    Map<String, StepStatus> statuses = subtransExecutor.getStatuses();
    assertEquals(3, statuses.size());
    List<StepStatus> statusList = new ArrayList<>(statuses.values());
    assertEquals("Get rows from result", statusList.get(0).getStepname());
    assertEquals("Group by", statusList.get(1).getStepname());
    assertEquals("Write to log", statusList.get(2).getStepname());
    for (Map.Entry<String, StepStatus> entry : statuses.entrySet()) {
        StepStatus statusSpy = spy(entry.getValue());
        statuses.put(entry.getKey(), statusSpy);
    }
    subtransExecutor.execute(rows);
    for (Map.Entry<String, StepStatus> entry : statuses.entrySet()) {
        verify(entry.getValue()).updateAll(any());
    }
    verify(parentTrans, atLeastOnce()).addActiveSubTransformation(eq("subtransname"), any(Trans.class));
}
Also used : ArrayList(java.util.ArrayList) LoggingObject(org.pentaho.di.core.logging.LoggingObject) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepStatus(org.pentaho.di.trans.step.StepStatus) Result(org.pentaho.di.core.Result) Variables(org.pentaho.di.core.variables.Variables) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) TransExecutorParameters(org.pentaho.di.trans.steps.transexecutor.TransExecutorParameters) Map(java.util.Map) Test(org.junit.Test)

Example 5 with TransExecutorParameters

use of org.pentaho.di.trans.steps.transexecutor.TransExecutorParameters in project pentaho-kettle by pentaho.

the class SubtransExecutorTest method doesNotExecuteWhenStopped.

@Test
public void doesNotExecuteWhenStopped() throws KettleException {
    TransMeta parentMeta = new TransMeta(this.getClass().getResource("subtrans-executor-parent.ktr").getPath(), new Variables());
    TransMeta subMeta = new TransMeta(this.getClass().getResource("subtrans-executor-sub.ktr").getPath(), new Variables());
    LoggingObjectInterface loggingObject = new LoggingObject("anything");
    Trans parentTrans = new Trans(parentMeta, loggingObject);
    SubtransExecutor subtransExecutor = new SubtransExecutor("subtransname", parentTrans, subMeta, true, new TransExecutorParameters(), "");
    RowMetaInterface rowMeta = parentMeta.getStepFields("Data Grid");
    List<RowMetaAndData> rows = Arrays.asList(new RowMetaAndData(rowMeta, "Pentaho", 1L), new RowMetaAndData(rowMeta, "Pentaho", 2L), new RowMetaAndData(rowMeta, "Pentaho", 3L), new RowMetaAndData(rowMeta, "Pentaho", 4L));
    subtransExecutor.stop();
    subtransExecutor.execute(rows);
    verify(this.logChannel, never()).logBasic("\n" + "------------> Linenr 1------------------------------\n" + "name = Pentaho\n" + "sum = 10\n" + "\n" + "====================");
}
Also used : Variables(org.pentaho.di.core.variables.Variables) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) LoggingObject(org.pentaho.di.core.logging.LoggingObject) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) TransExecutorParameters(org.pentaho.di.trans.steps.transexecutor.TransExecutorParameters) Test(org.junit.Test)

Aggregations

TransExecutorParameters (org.pentaho.di.trans.steps.transexecutor.TransExecutorParameters)6 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)4 Test (org.junit.Test)3 LoggingObject (org.pentaho.di.core.logging.LoggingObject)3 LoggingObjectInterface (org.pentaho.di.core.logging.LoggingObjectInterface)3 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)3 Variables (org.pentaho.di.core.variables.Variables)3 ArrayList (java.util.ArrayList)2 TableItem (org.eclipse.swt.widgets.TableItem)2 Result (org.pentaho.di.core.Result)2 StepStatus (org.pentaho.di.trans.step.StepStatus)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions (com.google.common.base.Preconditions)1 Throwables (com.google.common.base.Throwables)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 CTabItem (org.eclipse.swt.custom.CTabItem)1 ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1