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 };
}
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++;
}
}
}
}
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());
}
}
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);
}
}
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;
}
}
Aggregations