Search in sources :

Example 1 with LocalPipelineEngine

use of org.apache.hop.pipeline.engines.local.LocalPipelineEngine in project hop by apache.

the class InjectDataSetIntoTransformExtensionPoint method callExtensionPoint.

@Override
public void callExtensionPoint(ILogChannel log, IVariables variables, final IPipelineEngine<PipelineMeta> pipeline) throws HopException {
    if (!(pipeline instanceof LocalPipelineEngine)) {
        throw new HopPluginException("Unit tests can only run using a local pipeline engine type");
    }
    final PipelineMeta pipelineMeta = pipeline.getPipelineMeta();
    boolean dataSetEnabled = "Y".equalsIgnoreCase(pipeline.getVariable(DataSetConst.VAR_RUN_UNIT_TEST));
    if (log.isDetailed()) {
        log.logDetailed("Data Set enabled? " + dataSetEnabled);
    }
    if (!dataSetEnabled) {
        return;
    }
    String unitTestName = pipeline.getVariable(DataSetConst.VAR_UNIT_TEST_NAME);
    if (log.isDetailed()) {
        log.logDetailed("Unit test name: " + unitTestName);
    }
    try {
        IHopMetadataProvider metadataProvider = pipelineMeta.getMetadataProvider();
        // 
        if (StringUtil.isEmpty(unitTestName)) {
            return;
        }
        PipelineUnitTest unitTest = metadataProvider.getSerializer(PipelineUnitTest.class).load(unitTestName);
        if (unitTest == null) {
            if (log.isDetailed()) {
                log.logDetailed("Unit test '" + unitTestName + "' could not be found");
            }
            return;
        }
        // 
        for (final TransformMeta transformMeta : pipeline.getPipelineMeta().getTransforms()) {
            String transformName = transformMeta.getName();
            PipelineUnitTestSetLocation inputLocation = unitTest.findInputLocation(transformName);
            if (inputLocation != null && StringUtils.isNotEmpty(inputLocation.getDataSetName())) {
                String inputDataSetName = inputLocation.getDataSetName();
                log.logDetailed("Data Set location found for transform '" + transformName + "' and data set  " + inputDataSetName);
                // We need to inject data from the data set with the specified name into the transform
                // 
                injectDataSetIntoTransform((LocalPipelineEngine) pipeline, inputDataSetName, metadataProvider, transformMeta, inputLocation);
            }
            // How about capturing rows for golden data review?
            // 
            PipelineUnitTestSetLocation goldenLocation = unitTest.findGoldenLocation(transformName);
            if (goldenLocation != null) {
                String goldenDataSetName = goldenLocation.getDataSetName();
                if (!StringUtil.isEmpty(goldenDataSetName)) {
                    log.logDetailed("Capturing rows for validation at pipeline end, transform='" + transformMeta.getName() + "', golden set '" + goldenDataSetName);
                    final RowCollection rowCollection = new RowCollection();
                    // Create a row collection map if it's missing...
                    // 
                    @SuppressWarnings("unchecked") Map<String, RowCollection> collectionMap = (Map<String, RowCollection>) pipeline.getExtensionDataMap().get(DataSetConst.ROW_COLLECTION_MAP);
                    if (collectionMap == null) {
                        collectionMap = new HashMap<>();
                        pipeline.getExtensionDataMap().put(DataSetConst.ROW_COLLECTION_MAP, collectionMap);
                    }
                    // Keep the map for safe keeping...
                    // 
                    collectionMap.put(transformMeta.getName(), rowCollection);
                    // We'll capture the rows from this one and then evaluate them after execution...
                    // 
                    IEngineComponent component = pipeline.findComponent(transformMeta.getName(), 0);
                    component.addRowListener(new RowAdapter() {

                        @Override
                        public void rowReadEvent(IRowMeta rowMeta, Object[] row) throws HopTransformException {
                            if (rowCollection.getRowMeta() == null) {
                                rowCollection.setRowMeta(rowMeta);
                            }
                            rowCollection.getRows().add(row);
                        }
                    });
                }
            }
        }
    } catch (Throwable e) {
        throw new HopException("Unable to inject data set rows", e);
    }
}
Also used : PipelineUnitTestSetLocation(org.apache.hop.testing.PipelineUnitTestSetLocation) HopException(org.apache.hop.core.exception.HopException) IRowMeta(org.apache.hop.core.row.IRowMeta) HopPluginException(org.apache.hop.core.exception.HopPluginException) HopTransformException(org.apache.hop.core.exception.HopTransformException) IEngineComponent(org.apache.hop.pipeline.engine.IEngineComponent) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) LocalPipelineEngine(org.apache.hop.pipeline.engines.local.LocalPipelineEngine) RowAdapter(org.apache.hop.pipeline.transform.RowAdapter) TransformMeta(org.apache.hop.pipeline.transform.TransformMeta) IHopMetadataProvider(org.apache.hop.metadata.api.IHopMetadataProvider) PipelineUnitTest(org.apache.hop.testing.PipelineUnitTest) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with LocalPipelineEngine

use of org.apache.hop.pipeline.engines.local.LocalPipelineEngine in project hop by apache.

the class ScriptValueAddFunctions_SetVariableScopeTest method createPipeline.

private Pipeline createPipeline() {
    Pipeline pipeline = new LocalPipelineEngine();
    pipeline.setLogChannel(log);
    pipeline = spy(pipeline);
    return pipeline;
}
Also used : LocalPipelineEngine(org.apache.hop.pipeline.engines.local.LocalPipelineEngine) Pipeline(org.apache.hop.pipeline.Pipeline)

Example 3 with LocalPipelineEngine

use of org.apache.hop.pipeline.engines.local.LocalPipelineEngine in project hop by apache.

the class BaseParsingTest method beforeCommon.

/**
 * Initialize transform info. Method is final against redefine in descendants.
 */
@Before
public final void beforeCommon() throws Exception {
    HopEnvironment.init();
    PluginRegistry.addPluginType(CompressionPluginType.getInstance());
    PluginRegistry.init();
    transformMeta = new TransformMeta();
    transformMeta.setName("test");
    pipeline = new LocalPipelineEngine();
    pipeline.setLogChannel(log);
    pipeline.setRunning(true);
    pipelineMeta = new PipelineMeta() {

        @Override
        public TransformMeta findTransform(String name) {
            return transformMeta;
        }
    };
    fs = VFS.getManager();
    inPrefix = '/' + this.getClass().getPackage().getName().replace('.', '/') + "/files/";
}
Also used : LocalPipelineEngine(org.apache.hop.pipeline.engines.local.LocalPipelineEngine) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) Before(org.junit.Before)

Example 4 with LocalPipelineEngine

use of org.apache.hop.pipeline.engines.local.LocalPipelineEngine in project hop by apache.

the class PGBulkLoaderMetaTest method setUp.

@Before
public void setUp() {
    PipelineMeta pipelineMeta = new PipelineMeta();
    pipelineMeta.setName("loader");
    lm = new PGBulkLoaderMeta();
    ld = new PGBulkLoaderData();
    PluginRegistry plugReg = PluginRegistry.getInstance();
    String loaderPid = plugReg.getPluginId(TransformPluginType.class, lm);
    transformMeta = new TransformMeta(loaderPid, "loader", lm);
    Pipeline pipeline = new LocalPipelineEngine(pipelineMeta);
    pipelineMeta.addTransform(transformMeta);
    loader = new PGBulkLoader(transformMeta, lm, ld, 1, pipelineMeta, pipeline);
}
Also used : LocalPipelineEngine(org.apache.hop.pipeline.engines.local.LocalPipelineEngine) PluginRegistry(org.apache.hop.core.plugins.PluginRegistry) TransformMeta(org.apache.hop.pipeline.transform.TransformMeta) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) Pipeline(org.apache.hop.pipeline.Pipeline) Before(org.junit.Before)

Example 5 with LocalPipelineEngine

use of org.apache.hop.pipeline.engines.local.LocalPipelineEngine in project hop by apache.

the class PipelineDataProbeXp method executeProbingPipeline.

/**
 * Execute a probing pipeline for the current pipeline. Add a listener to the transform copies.
 * Send the data to the PipelineDataProbe transform(s) in the probing pipeline
 *
 * @param pipelineProbe
 * @param dataProbeLocation
 * @param loggingPipelineFilename The pipeline to start for the location
 * @param pipeline The parent pipeline to listen to
 * @param variables
 * @throws HopException
 */
private synchronized void executeProbingPipeline(PipelineProbe pipelineProbe, DataProbeLocation dataProbeLocation, String loggingPipelineFilename, IPipelineEngine<PipelineMeta> pipeline, IVariables variables) throws HopException {
    PipelineMeta probingPipelineMeta = new PipelineMeta(loggingPipelineFilename, pipeline.getMetadataProvider(), true, variables);
    // Create a local pipeline engine...
    // 
    LocalPipelineEngine probingPipeline = new LocalPipelineEngine(probingPipelineMeta, variables, pipeline);
    // Flag it as a probing and logging pipeline so we don't try to probe or log ourselves...
    // 
    probingPipeline.getExtensionDataMap().put(PIPELINE_DATA_PROBE_FLAG, "Y");
    probingPipeline.getExtensionDataMap().put(PipelineStartLoggingXp.PIPELINE_LOGGING_FLAG, "Y");
    // Only log errors
    // 
    probingPipeline.setLogLevel(LogLevel.ERROR);
    probingPipeline.prepareExecution();
    List<IEngineComponent> componentCopies = pipeline.getComponentCopies(dataProbeLocation.getSourceTransformName());
    for (IEngineComponent componentCopy : componentCopies) {
        // 
        for (TransformMetaDataCombi combi : probingPipeline.getTransforms()) {
            if (combi.transform instanceof PipelineDataProbe) {
                // Give the transform a bit more information to work with...
                // 
                PipelineDataProbe pipelineDataProbe = (PipelineDataProbe) combi.transform;
                pipelineDataProbe.setSourcePipelineName(pipeline.getPipelineMeta().getName());
                pipelineDataProbe.setSourceTransformLogChannelId(pipeline.getLogChannelId());
                pipelineDataProbe.setSourceTransformName(componentCopy.getName());
                pipelineDataProbe.setSourceTransformCopy(componentCopy.getCopyNr());
                try {
                    final RowProducer rowProducer = probingPipeline.addRowProducer(combi.transformName, combi.copy);
                    // For every copy of the component, add an input row set to the parent pipeline...
                    // 
                    componentCopy.addRowListener(new RowAdapter() {

                        @Override
                        public void rowWrittenEvent(IRowMeta rowMeta, Object[] row) throws HopTransformException {
                            // Pass this row to the row producer...
                            // 
                            rowProducer.putRow(rowMeta, row);
                        }
                    });
                    // If the pipeline we're the transform is and we can safely stop streaming...
                    // 
                    pipeline.addExecutionFinishedListener(pe -> rowProducer.finished());
                } catch (HopException e) {
                    throw new HopTransformException("Error adding row producer to transform '" + combi.transformName + "'", e);
                }
            }
        }
    }
    // Execute the logging pipeline to save the logging information
    // 
    probingPipeline.startThreads();
    // We'll not wait around until this is finished...
    // The pipeline should stop automatically when the parent does
    // 
    pipeline.addExecutionStoppedListener(e -> probingPipeline.stopAll());
}
Also used : RowProducer(org.apache.hop.pipeline.RowProducer) HopException(org.apache.hop.core.exception.HopException) IRowMeta(org.apache.hop.core.row.IRowMeta) HopTransformException(org.apache.hop.core.exception.HopTransformException) IEngineComponent(org.apache.hop.pipeline.engine.IEngineComponent) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) LocalPipelineEngine(org.apache.hop.pipeline.engines.local.LocalPipelineEngine) RowAdapter(org.apache.hop.pipeline.transform.RowAdapter) FileObject(org.apache.commons.vfs2.FileObject) PipelineDataProbe(org.apache.hop.reflection.probe.transform.PipelineDataProbe) TransformMetaDataCombi(org.apache.hop.pipeline.transform.TransformMetaDataCombi)

Aggregations

LocalPipelineEngine (org.apache.hop.pipeline.engines.local.LocalPipelineEngine)54 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)42 TransformMeta (org.apache.hop.pipeline.transform.TransformMeta)24 Pipeline (org.apache.hop.pipeline.Pipeline)23 Before (org.junit.Before)15 HopException (org.apache.hop.core.exception.HopException)13 Test (org.junit.Test)10 PluginRegistry (org.apache.hop.core.plugins.PluginRegistry)9 ValueMetaString (org.apache.hop.core.row.value.ValueMetaString)9 HopTransformException (org.apache.hop.core.exception.HopTransformException)8 IRowMeta (org.apache.hop.core.row.IRowMeta)8 RowProducer (org.apache.hop.pipeline.RowProducer)7 ITransform (org.apache.hop.pipeline.transform.ITransform)7 ITransformMeta (org.apache.hop.pipeline.transform.ITransformMeta)7 ArrayList (java.util.ArrayList)6 IVariables (org.apache.hop.core.variables.IVariables)6 PipelineHopMeta (org.apache.hop.pipeline.PipelineHopMeta)6 RowAdapter (org.apache.hop.pipeline.transform.RowAdapter)6 RowMetaAndData (org.apache.hop.core.RowMetaAndData)5 InjectorMeta (org.apache.hop.pipeline.transforms.injector.InjectorMeta)5