Search in sources :

Example 26 with StepMetaDataCombi

use of org.pentaho.di.trans.step.StepMetaDataCombi in project pdi-dataservice-server-plugin by pentaho.

the class CachedServiceTest method testReplayFullCache.

@Test
public void testReplayFullCache() throws Exception {
    DataServiceExecutor executor = dataServiceExecutor(BASE_QUERY);
    CachedService cachedService = CachedService.complete(testData);
    RowProducer rowProducer = genTrans.addRowProducer(INJECTOR_STEP, 0);
    // Activate cachedServiceLoader
    Executor mockExecutor = mock(Executor.class);
    final CachedServiceLoader cachedServiceLoader = new CachedServiceLoader(cachedService, mockExecutor);
    ListenableFuture<Integer> replay = cachedServiceLoader.replay(executor);
    ArgumentCaptor<Runnable> replayRunnable = ArgumentCaptor.forClass(Runnable.class);
    verify(mockExecutor).execute(replayRunnable.capture());
    stepMetaDataCombi.step = inputStep;
    stepMetaDataCombi.meta = inputStepMetaInterface;
    stepMetaDataCombi.data = inputStepDataInterface;
    List<StepMetaDataCombi> stepMetaDataCombis = new ArrayList<>();
    stepMetaDataCombis.add(stepMetaDataCombi);
    when(serviceTrans.getSteps()).thenReturn(stepMetaDataCombis);
    // Simulate executing data service
    executor.executeListeners(DataServiceExecutor.ExecutionPoint.READY);
    executor.executeListeners(DataServiceExecutor.ExecutionPoint.START);
    // Verify that serviceTrans never started, genTrans is accepting rows
    verify(serviceTrans).stopAll();
    verify(inputStep).setOutputDone();
    verify(inputStep).dispose(inputStepMetaInterface, inputStepDataInterface);
    verify(inputStep).markStop();
    verify(serviceTrans, never()).startThreads();
    verify(genTrans).startThreads();
    when(rowProducer.putRowWait(any(RowMetaInterface.class), any(Object[].class), anyInt(), any(TimeUnit.class))).then(new Answer<Boolean>() {

        int calls = 0;

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            // Simulate full row set on tenth call
            return ++calls != 10;
        }
    });
    when(genTrans.isRunning()).thenReturn(true);
    // Run cache loader (would be asynchronous)
    replayRunnable.getValue().run();
    assertThat(replay.get(1, TimeUnit.SECONDS), equalTo(testData.size()));
    InOrder rowsProduced = inOrder(rowProducer);
    for (int i = 0; i < testData.size(); i++) {
        RowMetaAndData metaAndData = testData.get(i);
        // Tenth row was called twice, since row set was full
        Object[] data = metaAndData.getData();
        rowsProduced.verify(rowProducer, times(i == 9 ? 2 : 1)).putRowWait(eq(metaAndData.getRowMeta()), and(eq(data), AdditionalMatchers.not(same(data))), anyInt(), any(TimeUnit.class));
    }
    rowsProduced.verify(rowProducer).finished();
    rowsProduced.verifyNoMoreInteractions();
}
Also used : RowProducer(org.pentaho.di.trans.RowProducer) InOrder(org.mockito.InOrder) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) Executor(java.util.concurrent.Executor) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) InvocationOnMock(org.mockito.invocation.InvocationOnMock) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.Test)

Example 27 with StepMetaDataCombi

use of org.pentaho.di.trans.step.StepMetaDataCombi in project pentaho-metaverse by pentaho.

the class StepExternalResourceConsumerListener method callExtensionPoint.

/**
 * This method is called by the Kettle code when a step is about to start
 *
 * @param log    the logging channel to log debugging information to
 * @param object The subject object that is passed to the plugin code
 * @throws org.pentaho.di.core.exception.KettleException In case the plugin decides that an error has occurred
 *                                                       and the parent process should stop.
 */
@Override
public void callExtensionPoint(LogChannelInterface log, Object object) throws KettleException {
    if (stepConsumerProvider == null) {
        stepConsumerProvider = (IStepExternalResourceConsumerProvider) MetaverseBeanUtil.getInstance().get("IStepExternalResourceConsumerProvider");
    }
    StepMetaDataCombi stepCombi = (StepMetaDataCombi) object;
    if (stepCombi != null) {
        StepMetaInterface meta = stepCombi.meta;
        StepInterface step = stepCombi.step;
        if (meta != null) {
            Class<?> metaClass = meta.getClass();
            if (BaseStepMeta.class.isAssignableFrom(metaClass)) {
                if (stepConsumerProvider != null) {
                    // Put the class into a collection and get the consumers that can process this class
                    Set<Class<?>> metaClassSet = new HashSet<Class<?>>(1);
                    metaClassSet.add(metaClass);
                    List<IStepExternalResourceConsumer> stepConsumers = stepConsumerProvider.getExternalResourceConsumers(metaClassSet);
                    if (stepConsumers != null) {
                        for (IStepExternalResourceConsumer stepConsumer : stepConsumers) {
                            // We might know enough at this point, so call the consumer
                            Collection<IExternalResourceInfo> resources = stepConsumer.getResourcesFromMeta(meta);
                            addExternalResources(resources, step);
                            // Add a RowListener if the step is data-driven
                            if (stepConsumer.isDataDriven(meta)) {
                                stepCombi.step.addRowListener(new StepExternalConsumerRowListener(stepConsumer, step));
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) IExternalResourceInfo(org.pentaho.metaverse.api.model.IExternalResourceInfo) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) IStepExternalResourceConsumer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer) HashSet(java.util.HashSet)

Example 28 with StepMetaDataCombi

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

the class Validator method init.

public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
    meta = (ValidatorMeta) smi;
    data = (ValidatorData) sdi;
    if (super.init(smi, sdi)) {
        // initialize steps by names
        List<StepMeta> steps = new ArrayList<>();
        List<StepMetaDataCombi> transSteps = getTrans().getSteps();
        if (transSteps != null) {
            for (StepMetaDataCombi s : transSteps) {
                steps.add(s.stepMeta);
            }
        }
        meta.searchInfoAndTargetSteps(steps);
        // initialize arrays of validation data
        data.constantsMeta = new ValueMetaInterface[meta.getValidations().size()];
        data.minimumValueAsString = new String[meta.getValidations().size()];
        data.maximumValueAsString = new String[meta.getValidations().size()];
        data.fieldsMinimumLengthAsInt = new int[meta.getValidations().size()];
        data.fieldsMaximumLengthAsInt = new int[meta.getValidations().size()];
        data.minimumValue = new Object[meta.getValidations().size()];
        data.maximumValue = new Object[meta.getValidations().size()];
        data.listValues = new Object[meta.getValidations().size()][];
        data.errorCode = new String[meta.getValidations().size()];
        data.errorDescription = new String[meta.getValidations().size()];
        data.conversionMask = new String[meta.getValidations().size()];
        data.decimalSymbol = new String[meta.getValidations().size()];
        data.groupingSymbol = new String[meta.getValidations().size()];
        data.maximumLength = new String[meta.getValidations().size()];
        data.minimumLength = new String[meta.getValidations().size()];
        data.startString = new String[meta.getValidations().size()];
        data.endString = new String[meta.getValidations().size()];
        data.startStringNotAllowed = new String[meta.getValidations().size()];
        data.endStringNotAllowed = new String[meta.getValidations().size()];
        data.regularExpression = new String[meta.getValidations().size()];
        data.regularExpressionNotAllowed = new String[meta.getValidations().size()];
        data.patternExpected = new Pattern[meta.getValidations().size()];
        data.patternDisallowed = new Pattern[meta.getValidations().size()];
        for (int i = 0; i < meta.getValidations().size(); i++) {
            Validation field = meta.getValidations().get(i);
            try {
                data.constantsMeta[i] = createValueMeta(field.getFieldName(), field.getDataType());
                data.constantsMeta[i].setConversionMask(field.getConversionMask());
                data.constantsMeta[i].setDecimalSymbol(field.getDecimalSymbol());
                data.constantsMeta[i].setGroupingSymbol(field.getGroupingSymbol());
                data.errorCode[i] = environmentSubstitute(Const.NVL(field.getErrorCode(), ""));
                data.errorDescription[i] = environmentSubstitute(Const.NVL(field.getErrorDescription(), ""));
                data.conversionMask[i] = environmentSubstitute(Const.NVL(field.getConversionMask(), ""));
                data.decimalSymbol[i] = environmentSubstitute(Const.NVL(field.getDecimalSymbol(), ""));
                data.groupingSymbol[i] = environmentSubstitute(Const.NVL(field.getGroupingSymbol(), ""));
                data.maximumLength[i] = environmentSubstitute(Const.NVL(field.getMaximumLength(), ""));
                data.minimumLength[i] = environmentSubstitute(Const.NVL(field.getMinimumLength(), ""));
                data.maximumValueAsString[i] = environmentSubstitute(Const.NVL(field.getMaximumValue(), ""));
                data.minimumValueAsString[i] = environmentSubstitute(Const.NVL(field.getMinimumValue(), ""));
                data.startString[i] = environmentSubstitute(Const.NVL(field.getStartString(), ""));
                data.endString[i] = environmentSubstitute(Const.NVL(field.getEndString(), ""));
                data.startStringNotAllowed[i] = environmentSubstitute(Const.NVL(field.getStartStringNotAllowed(), ""));
                data.endStringNotAllowed[i] = environmentSubstitute(Const.NVL(field.getEndStringNotAllowed(), ""));
                data.regularExpression[i] = environmentSubstitute(Const.NVL(field.getRegularExpression(), ""));
                data.regularExpressionNotAllowed[i] = environmentSubstitute(Const.NVL(field.getRegularExpressionNotAllowed(), ""));
                ValueMetaInterface stringMeta = cloneValueMeta(data.constantsMeta[i], ValueMetaInterface.TYPE_STRING);
                data.minimumValue[i] = Utils.isEmpty(data.minimumValueAsString[i]) ? null : data.constantsMeta[i].convertData(stringMeta, data.minimumValueAsString[i]);
                data.maximumValue[i] = Utils.isEmpty(data.maximumValueAsString[i]) ? null : data.constantsMeta[i].convertData(stringMeta, data.maximumValueAsString[i]);
                try {
                    data.fieldsMinimumLengthAsInt[i] = Integer.valueOf(Const.NVL(data.minimumLength[i], "-1"));
                } catch (NumberFormatException nfe) {
                    throw new KettleValueException("Caught a number format exception converting minimum length with value " + data.minimumLength[i] + " to an int.", nfe);
                }
                try {
                    data.fieldsMaximumLengthAsInt[i] = Integer.valueOf(Const.NVL(data.maximumLength[i], "-1"));
                } catch (NumberFormatException nfe) {
                    throw new KettleValueException("Caught a number format exception converting minimum length with value " + data.maximumLength[i] + " to an int.", nfe);
                }
                int listSize = field.getAllowedValues() != null ? field.getAllowedValues().length : 0;
                data.listValues[i] = new Object[listSize];
                for (int s = 0; s < listSize; s++) {
                    data.listValues[i][s] = Utils.isEmpty(field.getAllowedValues()[s]) ? null : data.constantsMeta[i].convertData(stringMeta, environmentSubstitute(field.getAllowedValues()[s]));
                }
            } catch (KettleException e) {
                if (field.getDataType() == ValueMetaInterface.TYPE_NONE) {
                    logError(BaseMessages.getString(PKG, "Validator.Exception.SpecifyDataType"), e);
                } else {
                    logError(BaseMessages.getString(PKG, "Validator.Exception.DataConversionErrorEncountered"), e);
                }
                return false;
            }
            if (!Utils.isEmpty(data.regularExpression[i])) {
                data.patternExpected[i] = Pattern.compile(data.regularExpression[i]);
            }
            if (!Utils.isEmpty(data.regularExpressionNotAllowed[i])) {
                data.patternDisallowed[i] = Pattern.compile(data.regularExpressionNotAllowed[i]);
            }
        }
        return true;
    }
    return false;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ArrayList(java.util.ArrayList) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) KettleValueException(org.pentaho.di.core.exception.KettleValueException) StepMeta(org.pentaho.di.trans.step.StepMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 29 with StepMetaDataCombi

use of org.pentaho.di.trans.step.StepMetaDataCombi 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 30 with StepMetaDataCombi

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

the class SingleThreadedTransExecutor method dispose.

public void dispose() throws KettleException {
    // 
    for (StepMetaDataCombi combi : trans.getSteps()) {
        combi.step.setOutputDone();
    }
    // 
    for (StepMetaDataCombi combi : steps) {
        combi.step.dispose(combi.meta, combi.data);
        combi.step.markStop();
    }
}
Also used : StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi)

Aggregations

StepMetaDataCombi (org.pentaho.di.trans.step.StepMetaDataCombi)55 StepInterface (org.pentaho.di.trans.step.StepInterface)21 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)18 Test (org.junit.Test)13 KettleException (org.pentaho.di.core.exception.KettleException)10 ArrayList (java.util.ArrayList)8 StepMeta (org.pentaho.di.trans.step.StepMeta)8 Trans (org.pentaho.di.trans.Trans)7 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)6 KettleValueException (org.pentaho.di.core.exception.KettleValueException)6 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)6 StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)6 RowSet (org.pentaho.di.core.RowSet)5 UnknownParamException (org.pentaho.di.core.parameters.UnknownParamException)5 TransMeta (org.pentaho.di.trans.TransMeta)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Before (org.junit.Before)4 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)4 KettleFileException (org.pentaho.di.core.exception.KettleFileException)4