Search in sources :

Example 31 with CanceledExecutionException

use of org.knime.core.node.CanceledExecutionException in project knime-core by knime.

the class CellSplitterNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
    String errMsg = m_settings.getStatus(inSpecs[0]);
    if (errMsg != null) {
        throw new InvalidSettingsException(errMsg);
    }
    // Guessing is done in the execute method
    if (!m_settings.isGuessNumOfCols()) {
        try {
            m_settings = CellSplitterCellFactory.createNewColumnTypes(null, m_settings, null);
        } catch (CanceledExecutionException cee) {
        // can't happen
        }
    }
    DataTableSpec outSpec = null;
    if ((inSpecs[0] != null) && (((!m_settings.isGuessNumOfCols()) && m_settings.isOutputAsCols()) || !m_settings.isOutputAsCols())) {
        // if we are supposed to guess we don't know the num of cols here
        outSpec = createColumnRearranger(inSpecs[0]).createSpec();
    }
    return new DataTableSpec[] { outSpec };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException)

Example 32 with CanceledExecutionException

use of org.knime.core.node.CanceledExecutionException in project knime-core by knime.

the class RowFilterIterator method getNextMatch.

/*
     * returns the next row that is supposed to be returned or null if it met
     * the end of it before.
     */
private DataRow getNextMatch() {
    while (true) {
        try {
            m_exec.checkCanceled();
        } catch (CanceledExecutionException cee) {
            throw new RuntimeCanceledExecutionException(cee);
        }
        // we must not cause any trouble.
        if (!m_orig.hasNext()) {
            return null;
        }
        m_exec.setProgress(m_rowNumber / (double) m_totalCountInOrig);
        DataRow next = m_orig.next();
        if (m_includeRest) {
            m_rowNumber++;
            return next;
        } else {
            // consult the filter whether to include this row
            try {
                if (m_filter.matches(next, m_rowNumber)) {
                    return next;
                }
            // else fall through and get the next row from the orig
            // table.
            } catch (EndOfTableException eote) {
                // filter: there are now more matching rows. Reached our
                // EOT.
                m_nextRow = null;
                return null;
            } catch (IncludeFromNowOn ifno) {
                // filter: include all rows from now on
                m_includeRest = true;
                return next;
            } finally {
                m_rowNumber++;
            }
        }
    }
}
Also used : CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IncludeFromNowOn(org.knime.base.node.preproc.filter.row.rowfilter.IncludeFromNowOn) EndOfTableException(org.knime.base.node.preproc.filter.row.rowfilter.EndOfTableException) DataRow(org.knime.core.data.DataRow)

Example 33 with CanceledExecutionException

use of org.knime.core.node.CanceledExecutionException in project knime-core by knime.

the class BoxPlotNodeModel method loadInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    try {
        File f = new File(nodeInternDir, FILE_NAME);
        FileInputStream fis = new FileInputStream(f);
        NodeSettingsRO settings = NodeSettings.loadFromXML(fis);
        m_statistics = new LinkedHashMap<DataColumnSpec, double[]>();
        m_mildOutliers = new LinkedHashMap<String, Map<Double, Set<RowKey>>>();
        m_extremeOutliers = new LinkedHashMap<String, Map<Double, Set<RowKey>>>();
        int nrOfCols = settings.getInt(CFG_NR_COLS);
        for (int i = 0; i < nrOfCols; i++) {
            NodeSettings subSetting = (NodeSettings) settings.getConfig(CFG_COL + i);
            DataColumnSpec spec = DataColumnSpec.load(subSetting);
            double[] stats = settings.getDoubleArray(CFG_STATS + spec.getName());
            m_statistics.put(spec, stats);
            loadOutliers(settings, spec);
        }
        File data = new File(nodeInternDir, ARRAY_FILE);
        ContainerTable table = DataContainer.readFromZip(data);
        m_array = new DefaultDataArray(table, 1, 2, exec);
    } catch (Exception e) {
        LOGGER.warn(e);
        throw new IOException(e.getMessage());
    }
}
Also used : RowKey(org.knime.core.data.RowKey) DefaultDataArray(org.knime.base.node.util.DefaultDataArray) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ContainerTable(org.knime.core.data.container.ContainerTable) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException) NodeSettings(org.knime.core.node.NodeSettings) DataColumnSpec(org.knime.core.data.DataColumnSpec) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 34 with CanceledExecutionException

use of org.knime.core.node.CanceledExecutionException in project knime-core by knime.

the class ReadTableNodeModel method extractTable.

/**
 * @param exec
 * @return
 * @throws IOException
 * @throws InvalidSettingsException
 */
private ContainerTable extractTable(final ExecutionContext exec) throws IOException, InvalidSettingsException {
    try (InputStream inputStream = openInputStream()) {
        // possibly re-assigned
        InputStream in = inputStream;
        long sizeInBytes;
        String loc = m_fileName.getStringValue();
        try {
            try {
                URL url = new URL(loc);
                sizeInBytes = FileUtil.getFileFromURL(url).length();
            } catch (MalformedURLException mue) {
                File file = new File(loc);
                if (file.exists()) {
                    sizeInBytes = file.length();
                } else {
                    sizeInBytes = 0L;
                }
            }
        } catch (Exception e) {
            // ignore, no progress
            sizeInBytes = 0L;
        }
        final long sizeFinal = sizeInBytes;
        if (sizeFinal > 0) {
            CountingInputStream bcs = new CountingInputStream(in) {

                @Override
                protected synchronized void afterRead(final int n) {
                    super.afterRead(n);
                    final long byteCount = getByteCount();
                    exec.setProgress((double) byteCount / sizeFinal, () -> FileUtils.byteCountToDisplaySize(byteCount));
                    try {
                        exec.checkCanceled();
                    } catch (CanceledExecutionException e) {
                        throw new RuntimeException("canceled");
                    }
                }
            };
            in = bcs;
        }
        return DataContainer.readFromStream(in);
    } finally {
        exec.setProgress(1.0);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) BufferedInputStream(java.io.BufferedInputStream) ZipInputStream(java.util.zip.ZipInputStream) CountingInputStream(org.apache.commons.io.input.CountingInputStream) NonClosableInputStream(org.knime.core.data.util.NonClosableInputStream) InputStream(java.io.InputStream) CountingInputStream(org.apache.commons.io.input.CountingInputStream) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) File(java.io.File) URL(java.net.URL) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Example 35 with CanceledExecutionException

use of org.knime.core.node.CanceledExecutionException in project knime-core by knime.

the class WorkflowManager method updateMetaNodeLinkWithCache.

/**
 * Implementation of {@link #updateMetaNodeLink(NodeID, ExecutionMonitor, WorkflowLoadHelper)} with an extra cache
 * argument.
 *
 * @param visitedTemplateMap The map to avoid loading duplicate
 */
private NodeContainerTemplateLinkUpdateResult updateMetaNodeLinkWithCache(final NodeID id, final ExecutionMonitor exec, final WorkflowLoadHelper loadHelper, final Map<URI, NodeContainerTemplate> visitedTemplateMap) throws CanceledExecutionException {
    final NodeContainerTemplateLinkUpdateResult loadRes = new NodeContainerTemplateLinkUpdateResult("Update node link \"" + getNameWithID() + "\"");
    NodeContainer nc = getNodeContainer(id);
    if (!(nc instanceof NodeContainerTemplate)) {
        throw new IllegalArgumentException("Node \"" + nc.getNameWithID() + "\" is not a template node (can't update link)");
    }
    NodeContainerTemplate tnc = (NodeContainerTemplate) nc;
    final MetaNodeTemplateInformation tempInfo = tnc.getTemplateInformation();
    if (!tempInfo.getRole().equals(Role.Link)) {
        loadRes.addError("Node \"" + getNameWithID() + "\" is not a template node link");
        return loadRes;
    }
    try (WorkflowLock lock = lock()) {
        boolean needsUpdate;
        try {
            needsUpdate = checkUpdateMetaNodeLinkWithCache(id, loadHelper, loadRes, visitedTemplateMap, false);
        } catch (IOException e2) {
            String msg = "Unable to check node update for " + tnc.getNameWithID() + ": " + e2.getMessage();
            LOGGER.error(msg, e2);
            loadRes.addError(msg);
            return loadRes;
        }
        WorkflowCopyContent.Builder oldContent = WorkflowCopyContent.builder();
        oldContent.setNodeIDs(id);
        oldContent.setIncludeInOutConnections(true);
        WorkflowPersistor copy = copy(true, oldContent.build());
        NodeContainerTemplate updatedTemplate = null;
        try {
            NodeContainerTemplate recursionManager;
            if (needsUpdate) {
                updatedTemplate = updateNodeTemplateLinkInternal(id, exec, loadHelper, visitedTemplateMap, loadRes);
                recursionManager = updatedTemplate;
            } else {
                // didn't update so this will be its own reference
                loadRes.setNCTemplate(tnc);
                recursionManager = tnc;
            }
            recursionManager.updateMetaNodeLinkInternalRecursively(exec, loadHelper, visitedTemplateMap, loadRes);
        } catch (Exception e) {
            String error = e.getClass().getSimpleName() + " while loading template: " + e.getMessage();
            LOGGER.error(error, e);
            loadRes.addError(error);
            if (updatedTemplate != null) {
                removeNode(updatedTemplate.getID());
            }
            paste(copy);
            return loadRes;
        }
        loadRes.setUndoPersistor(copy);
        return loadRes;
    }
}
Also used : IOException(java.io.IOException) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) CoreException(org.eclipse.core.runtime.CoreException) LockFailedException(org.knime.core.util.LockFailedException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NotConfigurableException(org.knime.core.node.NotConfigurableException) IOException(java.io.IOException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) URISyntaxException(java.net.URISyntaxException) NodeContainerTemplateLinkUpdateResult(org.knime.core.node.workflow.WorkflowPersistor.NodeContainerTemplateLinkUpdateResult)

Aggregations

CanceledExecutionException (org.knime.core.node.CanceledExecutionException)82 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)34 IOException (java.io.IOException)32 File (java.io.File)21 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)21 DataRow (org.knime.core.data.DataRow)20 DataTableSpec (org.knime.core.data.DataTableSpec)20 BufferedDataTable (org.knime.core.node.BufferedDataTable)20 DataCell (org.knime.core.data.DataCell)19 ArrayList (java.util.ArrayList)11 DataColumnSpec (org.knime.core.data.DataColumnSpec)11 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)10 LinkedHashMap (java.util.LinkedHashMap)9 ExecutionException (java.util.concurrent.ExecutionException)9 DefaultRow (org.knime.core.data.def.DefaultRow)9 RowKey (org.knime.core.data.RowKey)8 BufferedWriter (java.io.BufferedWriter)7 FileInputStream (java.io.FileInputStream)7 Map (java.util.Map)7 Future (java.util.concurrent.Future)7