Search in sources :

Example 16 with HopException

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

the class ActionFtp method addFilenameToResultFilenames.

private void addFilenameToResultFilenames(Result result, IWorkflowEngine<WorkflowMeta> parentWorkflow, String filename) throws HopException {
    if (isAddResult) {
        FileObject targetFile = null;
        try {
            targetFile = HopVfs.getFileObject(filename);
            // Add to the result files...
            ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, targetFile, parentWorkflow.getWorkflowName(), toString());
            resultFile.setComment(BaseMessages.getString(PKG, "ActionFTP.Downloaded", serverName));
            result.getResultFiles().put(resultFile.getFile().toString(), resultFile);
            if (isDetailed()) {
                logDetailed(BaseMessages.getString(PKG, "ActionFTP.FileAddedToResult", filename));
            }
        } catch (Exception e) {
            throw new HopException(e);
        } finally {
            try {
                targetFile.close();
                targetFile = null;
            } catch (Exception e) {
            // Ignore close errors
            }
        }
    }
}
Also used : HopException(org.apache.hop.core.exception.HopException) FileObject(org.apache.commons.vfs2.FileObject) ResultFile(org.apache.hop.core.ResultFile) HopException(org.apache.hop.core.exception.HopException) HopXmlException(org.apache.hop.core.exception.HopXmlException) UnknownHostException(java.net.UnknownHostException)

Example 17 with HopException

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

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

the class PipelineMetaModifier method getTestPipeline.

public PipelineMeta getTestPipeline(ILogChannel log, IVariables variables, IHopMetadataProvider metadataProvider) throws HopException {
    // OK, so now replace an input transform with a data set attached with an Injector transform...
    // However, we don't want to have the user see this so we need to copy pipeline.pipelineMeta
    // first...
    // 
    // Clone seems to has problems so we'll take the long (XML) way around...
    // 
    InputStream stream;
    try {
        stream = new ByteArrayInputStream(pipelineMeta.getXml(variables).getBytes(Const.XML_ENCODING));
    } catch (UnsupportedEncodingException e) {
        throw new HopException("Encoding error", e);
    }
    PipelineMeta copyPipelineMeta = new PipelineMeta(stream, metadataProvider, true, variables);
    // Pass the metadata references...
    // 
    copyPipelineMeta.setMetadataProvider(pipelineMeta.getMetadataProvider());
    // 
    for (PipelineUnitTestDatabaseReplacement dbReplacement : unitTest.getDatabaseReplacements()) {
        String sourceDatabaseName = variables.resolve(dbReplacement.getOriginalDatabaseName());
        String replacementDatabaseName = variables.resolve(dbReplacement.getReplacementDatabaseName());
        DatabaseMeta sourceDatabaseMeta = copyPipelineMeta.findDatabase(sourceDatabaseName);
        DatabaseMeta replacementDatabaseMeta = copyPipelineMeta.findDatabase(replacementDatabaseName);
        if (sourceDatabaseMeta == null) {
            throw new HopException("Unable to find source database connection '" + sourceDatabaseName + "', can not be replaced");
        }
        if (replacementDatabaseMeta == null) {
            throw new HopException("Unable to find replacement database connection '" + replacementDatabaseName + "', can not be used to replace");
        }
        if (log.isDetailed()) {
            log.logDetailed("Replaced database connection '" + sourceDatabaseName + "' with connection '" + replacementDatabaseName + "'");
        }
        sourceDatabaseMeta.replaceMeta(replacementDatabaseMeta);
    }
    // Replace all transforms with an Input Data Set marker with an Injector
    // Replace all transforms with a Golden Data Set marker with a Dummy
    // Apply the tweaks to the transforms:
    // - Bypass : replace with Dummy
    // - Remove : remove transform and all connected hops.
    // 
    // Loop over the original pipeline to allow us to safely modify the copy
    // 
    List<TransformMeta> transforms = pipelineMeta.getTransforms();
    for (TransformMeta transform : transforms) {
        TransformMeta transformMeta = copyPipelineMeta.findTransform(transform.getName());
        PipelineUnitTestSetLocation inputLocation = unitTest.findInputLocation(transformMeta.getName());
        PipelineUnitTestSetLocation goldenLocation = unitTest.findGoldenLocation(transformMeta.getName());
        PipelineUnitTestTweak transformTweak = unitTest.findTweak(transformMeta.getName());
        // 
        if (inputLocation != null) {
            handleInputDataSet(log, inputLocation, unitTest, pipelineMeta, transformMeta, metadataProvider);
        }
        // 
        if (goldenLocation != null) {
            handleGoldenDataSet(log, goldenLocation, transformMeta, metadataProvider);
        }
        if (transformTweak != null && transformTweak.getTweak() != null) {
            switch(transformTweak.getTweak()) {
                case NONE:
                    break;
                case REMOVE_TRANSFORM:
                    handleTweakRemoveTransform(log, copyPipelineMeta, transformMeta);
                    break;
                case BYPASS_TRANSFORM:
                    handleTweakBypassTransform(log, transformMeta);
                    break;
                default:
                    break;
            }
        }
    }
    return copyPipelineMeta;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) HopException(org.apache.hop.core.exception.HopException) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TransformMeta(org.apache.hop.pipeline.transform.TransformMeta) UnsupportedEncodingException(java.io.UnsupportedEncodingException) DatabaseMeta(org.apache.hop.core.database.DatabaseMeta) PipelineMeta(org.apache.hop.pipeline.PipelineMeta)

Example 19 with HopException

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

the class WriteToDataSetExtensionPoint method callExtensionPoint.

@Override
public void callExtensionPoint(ILogChannel log, IVariables variables, IPipelineEngine<PipelineMeta> pipeline) throws HopException {
    final PipelineMeta pipelineMeta = pipeline.getPipelineMeta();
    boolean writeToDataSet = "Y".equalsIgnoreCase(pipeline.getVariable(DataSetConst.VAR_WRITE_TO_DATASET));
    if (!writeToDataSet) {
        return;
    }
    pipeline.addExecutionFinishedListener(engine -> {
        // Remove the flag when done.
        // We don't want to write to the data set every time we run
        // 
        pipeline.setVariable(DataSetConst.VAR_WRITE_TO_DATASET, null);
        // Prevent memory leaking as well
        // 
        WriteToDataSetExtensionPoint.transformsMap.remove(pipelineMeta.getName());
        WriteToDataSetExtensionPoint.mappingsMap.remove(pipelineMeta.getName());
        WriteToDataSetExtensionPoint.setsMap.remove(pipelineMeta.getName());
    });
    try {
        IHopMetadataProvider metadataProvider = pipelineMeta.getMetadataProvider();
        if (metadataProvider == null) {
            // Nothing to do here, we can't reference data sets.
            return;
        }
        // 
        for (final TransformMeta transformMeta : pipeline.getPipelineMeta().getTransforms()) {
            // We might want to pass the data from this transform into a data set all by itself...
            // For this we want to attach a row listener which writes the data.
            // 
            TransformMeta injectMeta = transformsMap.get(pipelineMeta.getName());
            if (injectMeta != null && injectMeta.equals(transformMeta)) {
                final List<SourceToTargetMapping> mappings = mappingsMap.get(pipelineMeta.getName());
                final DataSet dataSet = setsMap.get(pipelineMeta.getName());
                if (mappings != null && dataSet != null) {
                    passTransformRowsToDataSet(pipeline, pipelineMeta, transformMeta, mappings, dataSet);
                }
            }
        }
    } catch (Throwable e) {
        throw new HopException("Unable to pass rows to data set", e);
    }
}
Also used : DataSet(org.apache.hop.testing.DataSet) HopException(org.apache.hop.core.exception.HopException) TransformMeta(org.apache.hop.pipeline.transform.TransformMeta) IHopMetadataProvider(org.apache.hop.metadata.api.IHopMetadataProvider) SourceToTargetMapping(org.apache.hop.core.SourceToTargetMapping) PipelineMeta(org.apache.hop.pipeline.PipelineMeta)

Example 20 with HopException

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

the class EditRowsDialog method getRowForData.

private Object[] getRowForData(TableItem item, int rowNr) throws HopException {
    try {
        Object[] row = RowDataUtil.allocateRowData(rowMeta.size());
        for (int i = 0; i < rowMeta.size(); i++) {
            IValueMeta valueMeta = rowMeta.getValueMeta(i);
            IValueMeta stringValueMeta = stringRowMeta.getValueMeta(i);
            int colnr = i + 1;
            if (GuiResource.getInstance().getColorBlue().equals(item.getForeground(colnr))) {
                // <null> value
                row[i] = null;
            } else {
                String string = item.getText(colnr);
                row[i] = valueMeta.convertDataFromString(string, stringValueMeta, null, null, IValueMeta.TRIM_TYPE_NONE);
            }
        }
        return row;
    } catch (HopException e) {
        throw new HopException(BaseMessages.getString(PKG, "EditRowsDialog.Error.ErrorGettingRowForData", Integer.toString(rowNr)), e);
    }
}
Also used : IValueMeta(org.apache.hop.core.row.IValueMeta) HopException(org.apache.hop.core.exception.HopException)

Aggregations

HopException (org.apache.hop.core.exception.HopException)1038 IRowMeta (org.apache.hop.core.row.IRowMeta)289 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)197 IValueMeta (org.apache.hop.core.row.IValueMeta)177 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)152 HopTransformException (org.apache.hop.core.exception.HopTransformException)145 TransformMeta (org.apache.hop.pipeline.transform.TransformMeta)132 IVariables (org.apache.hop.core.variables.IVariables)122 FileObject (org.apache.commons.vfs2.FileObject)113 List (java.util.List)108 BaseTransformMeta (org.apache.hop.pipeline.transform.BaseTransformMeta)107 FormAttachment (org.eclipse.swt.layout.FormAttachment)103 FormData (org.eclipse.swt.layout.FormData)103 FormLayout (org.eclipse.swt.layout.FormLayout)102 BaseMessages (org.apache.hop.i18n.BaseMessages)97 SWT (org.eclipse.swt.SWT)95 IOException (java.io.IOException)91 Const (org.apache.hop.core.Const)89 BaseTransformDialog (org.apache.hop.ui.pipeline.transform.BaseTransformDialog)88 org.eclipse.swt.widgets (org.eclipse.swt.widgets)88