Search in sources :

Example 1 with HopPluginException

use of org.apache.hop.core.exception.HopPluginException 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 HopPluginException

use of org.apache.hop.core.exception.HopPluginException in project hop by apache.

the class CypherMeta method getFields.

@Override
public void getFields(IRowMeta rowMeta, String name, IRowMeta[] info, TransformMeta nextStep, IVariables space, IHopMetadataProvider metadataProvider) throws HopTransformException {
    if (usingUnwind) {
        // Unwind only outputs results, not input
        // 
        rowMeta.clear();
    }
    if (returningGraph) {
        // We send out a single Graph value per input row
        // 
        IValueMeta valueMetaGraph = new ValueMetaGraph(Const.NVL(returnGraphField, "graph"));
        valueMetaGraph.setOrigin(name);
        rowMeta.addValueMeta(valueMetaGraph);
    } else {
        // 
        for (ReturnValue returnValue : returnValues) {
            try {
                int type = ValueMetaFactory.getIdForValueMeta(returnValue.getType());
                IValueMeta valueMeta = ValueMetaFactory.createValueMeta(returnValue.getName(), type);
                valueMeta.setOrigin(name);
                rowMeta.addValueMeta(valueMeta);
            } catch (HopPluginException e) {
                throw new HopTransformException("Unknown data type '" + returnValue.getType() + "' for value named '" + returnValue.getName() + "'");
            }
        }
    }
}
Also used : IValueMeta(org.apache.hop.core.row.IValueMeta) ValueMetaGraph(org.apache.hop.neo4j.core.value.ValueMetaGraph) HopPluginException(org.apache.hop.core.exception.HopPluginException) HopTransformException(org.apache.hop.core.exception.HopTransformException)

Example 3 with HopPluginException

use of org.apache.hop.core.exception.HopPluginException in project hop by apache.

the class PipelineExecutorMeta method addFieldToRow.

protected void addFieldToRow(IRowMeta row, String fieldName, int type, int length, int precision) throws HopTransformException {
    if (!Utils.isEmpty(fieldName)) {
        try {
            IValueMeta value = ValueMetaFactory.createValueMeta(fieldName, type, length, precision);
            value.setOrigin(getParentTransformMeta().getName());
            row.addValueMeta(value);
        } catch (HopPluginException e) {
            throw new HopTransformException(BaseMessages.getString(PKG, "PipelineExecutorMeta.ValueMetaInterfaceCreation", fieldName), e);
        }
    }
}
Also used : IValueMeta(org.apache.hop.core.row.IValueMeta) HopPluginException(org.apache.hop.core.exception.HopPluginException) HopTransformException(org.apache.hop.core.exception.HopTransformException)

Example 4 with HopPluginException

use of org.apache.hop.core.exception.HopPluginException in project hop by apache.

the class RowsFromResultMeta method getFields.

@Override
public void getFields(IRowMeta r, String origin, IRowMeta[] info, TransformMeta nextTransform, IVariables variables, IHopMetadataProvider metadataProvider) throws HopTransformException {
    for (int i = 0; i < this.fieldname.length; i++) {
        IValueMeta v;
        try {
            v = ValueMetaFactory.createValueMeta(fieldname[i], type[i], length[i], precision[i]);
            v.setOrigin(origin);
            r.addValueMeta(v);
        } catch (HopPluginException e) {
            throw new HopTransformException(e);
        }
    }
}
Also used : IValueMeta(org.apache.hop.core.row.IValueMeta) HopPluginException(org.apache.hop.core.exception.HopPluginException) HopTransformException(org.apache.hop.core.exception.HopTransformException)

Example 5 with HopPluginException

use of org.apache.hop.core.exception.HopPluginException in project hop by apache.

the class WorkflowRunConfigurationMetadataObjectFactory method createObject.

@Override
public Object createObject(String id, Object parentObject) throws HopException {
    PluginRegistry registry = PluginRegistry.getInstance();
    IPlugin plugin = registry.findPluginWithId(WorkflowEnginePluginType.class, id);
    if (plugin == null) {
        throw new HopException("Unable to find the plugin in the context of a pipeline engine plugin for id: " + id);
    }
    try {
        // We don't return the engine but the corresponding engine configuration
        // 
        IWorkflowEngine engine = registry.loadClass(plugin, IWorkflowEngine.class);
        IWorkflowEngineRunConfiguration engineRunConfiguration = engine.createDefaultWorkflowEngineRunConfiguration();
        engineRunConfiguration.setEnginePluginId(plugin.getIds()[0]);
        engineRunConfiguration.setEnginePluginName(plugin.getName());
        if (parentObject != null && (parentObject instanceof IVariables)) {
            engineRunConfiguration.initializeFrom((IVariables) parentObject);
        }
        return engineRunConfiguration;
    } catch (HopPluginException e) {
        throw new HopException("Unable to load the workflow engine plugin class with plugin id: " + id, e);
    }
}
Also used : IWorkflowEngine(org.apache.hop.workflow.engine.IWorkflowEngine) HopException(org.apache.hop.core.exception.HopException) IVariables(org.apache.hop.core.variables.IVariables) PluginRegistry(org.apache.hop.core.plugins.PluginRegistry) HopPluginException(org.apache.hop.core.exception.HopPluginException) IPlugin(org.apache.hop.core.plugins.IPlugin)

Aggregations

HopPluginException (org.apache.hop.core.exception.HopPluginException)38 IValueMeta (org.apache.hop.core.row.IValueMeta)17 HopTransformException (org.apache.hop.core.exception.HopTransformException)10 IPlugin (org.apache.hop.core.plugins.IPlugin)9 IRowMeta (org.apache.hop.core.row.IRowMeta)9 HopException (org.apache.hop.core.exception.HopException)7 PluginRegistry (org.apache.hop.core.plugins.PluginRegistry)7 RowMeta (org.apache.hop.core.row.RowMeta)7 ValueMetaNone (org.apache.hop.core.row.value.ValueMetaNone)5 ValueMetaString (org.apache.hop.core.row.value.ValueMetaString)4 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)3 Annotation (java.lang.annotation.Annotation)3 ArrayList (java.util.ArrayList)3 HopPluginClassMapException (org.apache.hop.core.exception.HopPluginClassMapException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Method (java.lang.reflect.Method)2 FileObject (org.apache.commons.vfs2.FileObject)2 GuiAction (org.apache.hop.core.gui.plugin.action.GuiAction)2