use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class FileNativeNodeContainerPersistor method loadNCAndWashModelSettings.
/**
* {@inheritDoc}
*/
@Override
NodeSettingsRO loadNCAndWashModelSettings(final NodeSettingsRO settingsForNode, final NodeSettingsRO modelSettings, final Map<Integer, BufferedDataTable> tblRep, final ExecutionMonitor exec, final LoadResult result) throws InvalidSettingsException, CanceledExecutionException, IOException {
final FileNodePersistor nodePersistor = createNodePersistor(settingsForNode);
nodePersistor.preLoad(m_node, result);
NodeSettingsRO washedModelSettings = modelSettings;
try {
if (modelSettings != null) {
// null if the node never had settings - no reason to load them
m_node.validateModelSettings(modelSettings);
m_node.loadModelSettingsFrom(modelSettings);
// previous versions of KNIME (2.7 and before) kept the model settings only in the node;
// NodeModel#saveSettingsTo was always called before the dialog was opened (some dialog implementations
// rely on the exact structure of the NodeSettings ... which may change between versions).
// We wash the settings through the node so that the model settings are updated (they possibly
// no longer map to the variable settings loaded further down below - if so, the inconsistency
// is warned later during configuration)
NodeSettings washedSettings = new NodeSettings("model");
m_node.saveModelSettingsTo(washedSettings);
washedModelSettings = washedSettings;
}
} catch (Exception e) {
final String error;
if (e instanceof InvalidSettingsException) {
error = "Loading model settings failed: " + e.getMessage();
} else {
error = "Caught \"" + e.getClass().getSimpleName() + "\", " + "Loading model settings failed: " + e.getMessage();
}
final LoadNodeModelSettingsFailPolicy pol = getModelSettingsFailPolicy(getMetaPersistor().getState(), nodePersistor.isInactive());
switch(pol) {
case IGNORE:
if (!(e instanceof InvalidSettingsException)) {
getLogger().coding(error, e);
}
break;
case FAIL:
result.addError(error);
m_node.createErrorMessageAndNotify(error, e);
setNeedsResetAfterLoad();
break;
case WARN:
m_node.createWarningMessageAndNotify(error, e);
result.addWarning(error);
setDirtyAfterLoad();
break;
}
}
try {
HashMap<Integer, ContainerTable> globalTableRepository = getGlobalTableRepository();
WorkflowFileStoreHandlerRepository fileStoreHandlerRepository = getFileStoreHandlerRepository();
nodePersistor.load(m_node, getParentPersistor(), exec, tblRep, globalTableRepository, fileStoreHandlerRepository, result);
} catch (final Exception e) {
String error = "Error loading node content: " + e.getMessage();
getLogger().warn(error, e);
needsResetAfterLoad();
result.addError(error);
}
if (nodePersistor.isDirtyAfterLoad()) {
setDirtyAfterLoad();
}
if (nodePersistor.needsResetAfterLoad()) {
setNeedsResetAfterLoad();
}
return washedModelSettings;
}
use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class FileNativeNodeContainerPersistor method loadSettingsForNode.
/**
* {@inheritDoc}
*/
@Override
NodeSettingsRO loadSettingsForNode(final LoadResult loadResult) throws IOException {
NodeSettingsRO nodeSettings = getNodeSettings();
if (getLoadVersion().ordinal() < LoadVersion.V280.ordinal()) {
FileNodeContainerMetaPersistor metaPersistor = getMetaPersistor();
ReferencedFile nodeFile;
try {
nodeFile = loadNodeFile(nodeSettings);
} catch (InvalidSettingsException e) {
String error = "Unable to load node settings file for node with ID suffix " + metaPersistor.getNodeIDSuffix() + " (node \"" + m_node.getName() + "\"): " + e.getMessage();
loadResult.addError(error);
getLogger().debug(error, e);
setDirtyAfterLoad();
return new NodeSettings("empty");
}
File configFile = nodeFile.getFile();
if (configFile == null || !configFile.isFile() || !configFile.canRead()) {
String error = "Unable to read node settings file for node with ID suffix " + metaPersistor.getNodeIDSuffix() + " (node \"" + m_node.getName() + "\"), file \"" + configFile + "\"";
loadResult.addError(error);
// also implies dirty
setNeedsResetAfterLoad();
return new NodeSettings("empty");
} else {
InputStream in = new FileInputStream(configFile);
try {
in = getParentPersistor().decipherInput(in);
return NodeSettings.loadFromXML(new BufferedInputStream(in));
} finally {
try {
in.close();
} catch (IOException e) {
getLogger().error("Failed to close input stream on \"" + configFile.getAbsolutePath() + "\"", e);
}
}
}
} else {
return nodeSettings;
}
}
use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class FileSingleNodeContainerPersistor method loadMemoryPolicySettings.
/**
* Load configuration of node.
*
* @param nodeSettings to load from (used in sub-classes)
* @return node config
* @throws InvalidSettingsException if that fails for any reason.
*/
MemoryPolicy loadMemoryPolicySettings(final NodeSettingsRO nodeSettings) throws InvalidSettingsException {
if (getLoadVersion().isOlderThan(LoadVersion.V210_Pre)) {
// we use the default, i.e. small data are kept in memory
if (nodeSettings.containsKey(Node.CFG_MISC_SETTINGS) && nodeSettings.getNodeSettings(Node.CFG_MISC_SETTINGS).containsKey(SingleNodeContainer.CFG_MEMORY_POLICY)) {
NodeSettingsRO sub = nodeSettings.getNodeSettings(Node.CFG_MISC_SETTINGS);
String memoryPolicy = sub.getString(SingleNodeContainer.CFG_MEMORY_POLICY, MemoryPolicy.CacheSmallInMemory.toString());
if (memoryPolicy == null) {
throw new InvalidSettingsException("Can't use null memory policy.");
}
try {
return MemoryPolicy.valueOf(memoryPolicy);
} catch (IllegalArgumentException iae) {
throw new InvalidSettingsException("Invalid memory policy: " + memoryPolicy);
}
} else {
return MemoryPolicy.CacheSmallInMemory;
}
} else {
// any version after 2.0 saves the snc settings in the settings.xml
// (previously these settings were saves as part of the node.xml)
NodeSettingsRO sub = nodeSettings.getNodeSettings(Node.CFG_MISC_SETTINGS);
String memoryPolicy = sub.getString(SingleNodeContainer.CFG_MEMORY_POLICY, MemoryPolicy.CacheSmallInMemory.toString());
if (memoryPolicy == null) {
throw new InvalidSettingsException("Can't use null memory policy.");
}
try {
return MemoryPolicy.valueOf(memoryPolicy);
} catch (IllegalArgumentException iae) {
throw new InvalidSettingsException("Invalid memory policy: " + memoryPolicy);
}
}
}
use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class FileSingleNodeContainerPersistor method loadNodeContainer.
/**
* {@inheritDoc}
*/
@Override
public void loadNodeContainer(final Map<Integer, BufferedDataTable> tblRep, final ExecutionMonitor exec, final LoadResult result) throws InvalidSettingsException, CanceledExecutionException, IOException {
final NodeSettingsRO settingsForNode = loadSettingsForNode(result);
m_sncSettings = new SingleNodeContainerSettings();
exec.checkCanceled();
try {
m_sncSettings.setMemoryPolicy(loadMemoryPolicySettings(m_nodeSettings));
} catch (InvalidSettingsException e) {
String error = "Unable to load SNC settings: " + e.getMessage();
result.addError(error);
getLogger().debug(error, e);
setDirtyAfterLoad();
return;
}
NodeSettingsRO modelSettings = null;
try {
modelSettings = loadModelSettings(settingsForNode);
} catch (InvalidSettingsException ise) {
String error = "Unable to load model settings: " + ise.getMessage();
result.addError(error);
getLogger().debug(error, ise);
setDirtyAfterLoad();
}
try {
modelSettings = loadNCAndWashModelSettings(settingsForNode, modelSettings, tblRep, exec, result);
} catch (InvalidSettingsException ise) {
String error = "Unable to load node container and wash settings: " + ise.getMessage();
result.addError(error);
getLogger().debug(error, ise);
setDirtyAfterLoad();
}
m_sncSettings.setModelSettings(modelSettings);
try {
m_sncSettings.setVariablesSettings(loadVariableSettings(settingsForNode));
} catch (InvalidSettingsException e) {
String msg = "Could load variable settings: " + e.getMessage();
result.addError(msg);
setDirtyAfterLoad();
setNeedsResetAfterLoad();
}
try {
m_flowObjects = loadFlowObjects(m_nodeSettings);
} catch (Exception e) {
m_flowObjects = Collections.emptyList();
String error = "Error loading flow variables: " + e.getMessage();
getLogger().warn(error, e);
result.addError(error);
setDirtyAfterLoad();
setNeedsResetAfterLoad();
}
exec.setProgress(1.0);
}
use of org.knime.core.node.InvalidSettingsException in project knime-core by knime.
the class FileWorkflowPersistor method loadNodeContainer.
/**
* {@inheritDoc}
*/
@Override
public void loadNodeContainer(final Map<Integer, BufferedDataTable> tblRep, final ExecutionMonitor exec, final LoadResult loadResult) throws CanceledExecutionException, IOException {
ReferencedFile workflowKNIMEFile = getWorkflowKNIMEFile();
if (workflowKNIMEFile == null || m_workflowSett == null) {
setDirtyAfterLoad();
throw new IllegalStateException("The method preLoadNodeContainer has either not been called or failed");
}
/* read nodes */
NodeSettingsRO nodes;
try {
nodes = loadSettingsForNodes(m_workflowSett);
} catch (InvalidSettingsException e) {
String error = "Can't load nodes in workflow, config not found: " + e.getMessage();
getLogger().debug(error, e);
loadResult.addError(error);
setDirtyAfterLoad();
setNeedsResetAfterLoad();
// stop loading here
return;
}
// ids of nodes that failed to load. Used to suppress superfluous errors when reading the connections
Set<Integer> failingNodeIDSet = new HashSet<Integer>();
// ids of nodes whose factory can't be loaded (e.g. node extension not installed)
Map<Integer, NodeFactoryUnknownException> missingNodeIDMap = new HashMap<Integer, NodeFactoryUnknownException>();
exec.setMessage("node information");
final ReferencedFile workflowDirRef = workflowKNIMEFile.getParent();
/* Load nodes */
for (String nodeKey : nodes.keySet()) {
exec.checkCanceled();
NodeSettingsRO nodeSetting;
try {
nodeSetting = nodes.getNodeSettings(nodeKey);
} catch (InvalidSettingsException e) {
String error = "Unable to load settings for node with internal " + "id \"" + nodeKey + "\": " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
continue;
}
if (shouldSkipThisNode(nodeSetting)) {
continue;
}
int nodeIDSuffix;
try {
nodeIDSuffix = loadNodeIDSuffix(nodeSetting);
} catch (InvalidSettingsException e) {
nodeIDSuffix = getRandomNodeID();
String error = "Unable to load node ID (internal id \"" + nodeKey + "\"), trying random number " + nodeIDSuffix + "instead: " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
}
NodeType nodeType;
try {
nodeType = loadNodeType(nodeSetting);
} catch (InvalidSettingsException e) {
String error = "Can't retrieve node type for contained node with id suffix " + nodeIDSuffix + ", attempting to read ordinary (native) node: " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
nodeType = NodeType.NativeNode;
}
NodeUIInformation nodeUIInfo = null;
String uiInfoClassName;
try {
uiInfoClassName = loadUIInfoClassName(nodeSetting);
} catch (InvalidSettingsException e) {
String error = "Unable to load UI information class name " + "to node with ID suffix " + nodeIDSuffix + ", no UI information available: " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
uiInfoClassName = null;
}
if (uiInfoClassName != null) {
try {
// load node ui info
nodeUIInfo = loadNodeUIInformation(nodeSetting);
} catch (InvalidSettingsException e) {
String error = "Unable to load UI information to " + "node with ID suffix " + nodeIDSuffix + ", no UI information available: " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
}
}
ReferencedFile nodeFile;
try {
nodeFile = loadNodeFile(nodeSetting, workflowDirRef);
} catch (InvalidSettingsException e) {
String error = "Unable to load settings for node " + "with ID suffix " + nodeIDSuffix + ": " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
failingNodeIDSet.add(nodeIDSuffix);
continue;
}
FromFileNodeContainerPersistor persistor;
switch(nodeType) {
case MetaNode:
persistor = createWorkflowPersistorLoad(nodeFile);
break;
case NativeNode:
persistor = createNativeNodeContainerPersistorLoad(nodeFile);
break;
case SubNode:
persistor = createSubNodeContainerPersistorLoad(nodeFile);
break;
default:
throw new IllegalStateException("Unknown node type: " + nodeType);
}
try {
LoadResult childResult = new LoadResult(nodeType.toString() + " with ID suffix " + nodeIDSuffix);
persistor.preLoadNodeContainer(this, nodeSetting, childResult);
loadResult.addChildError(childResult);
} catch (Throwable e) {
String error = "Unable to load node with ID suffix " + nodeIDSuffix + " into workflow, skipping it: " + e.getMessage();
String loadErrorString;
if (e instanceof NodeFactoryUnknownException) {
loadErrorString = e.getMessage();
} else {
loadErrorString = error;
}
if (e instanceof InvalidSettingsException || e instanceof IOException || e instanceof NodeFactoryUnknownException) {
getLogger().debug(error, e);
} else {
getLogger().error(error, e);
}
loadResult.addError(loadErrorString);
if (e instanceof NodeFactoryUnknownException) {
missingNodeIDMap.put(nodeIDSuffix, (NodeFactoryUnknownException) e);
// don't set dirty
} else {
setDirtyAfterLoad();
failingNodeIDSet.add(nodeIDSuffix);
// node directory is the parent of the settings.xml
m_obsoleteNodeDirectories.add(nodeFile.getParent());
continue;
}
}
NodeContainerMetaPersistor meta = persistor.getMetaPersistor();
if (m_nodeContainerLoaderMap.containsKey(nodeIDSuffix)) {
int randomID = getRandomNodeID();
setDirtyAfterLoad();
loadResult.addError("Duplicate id encountered in workflow: " + nodeIDSuffix + ", uniquifying to random id " + randomID + ", this possibly screws the connections");
nodeIDSuffix = randomID;
}
meta.setNodeIDSuffix(nodeIDSuffix);
meta.setUIInfo(nodeUIInfo);
if (persistor.isDirtyAfterLoad()) {
setDirtyAfterLoad();
}
m_nodeContainerLoaderMap.put(nodeIDSuffix, persistor);
}
/* read connections */
exec.setMessage("connection information");
NodeSettingsRO connections;
try {
connections = loadSettingsForConnections(m_workflowSett);
if (connections == null) {
connections = EMPTY_SETTINGS;
}
} catch (InvalidSettingsException e) {
String error = "Can't load workflow connections, config not found: " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
connections = EMPTY_SETTINGS;
}
for (String connectionKey : connections.keySet()) {
exec.checkCanceled();
ConnectionContainerTemplate c;
try {
c = loadConnection(connections.getNodeSettings(connectionKey));
} catch (InvalidSettingsException e) {
String error = "Can't load connection with internal ID \"" + connectionKey + "\": " + e.getMessage();
getLogger().debug(error, e);
setDirtyAfterLoad();
loadResult.addError(error);
continue;
}
int sourceIDSuffix = c.getSourceSuffix();
NodeContainerPersistor sourceNodePersistor = m_nodeContainerLoaderMap.get(sourceIDSuffix);
if (sourceNodePersistor == null && sourceIDSuffix != -1) {
setDirtyAfterLoad();
if (!failingNodeIDSet.contains(sourceIDSuffix)) {
loadResult.addError("Unable to load node connection " + c + ", source node does not exist");
}
continue;
}
fixSourcePortIfNecessary(sourceNodePersistor, c);
int destIDSuffix = c.getDestSuffix();
NodeContainerPersistor destNodePersistor = m_nodeContainerLoaderMap.get(destIDSuffix);
if (destNodePersistor == null && destIDSuffix != -1) {
setDirtyAfterLoad();
if (!failingNodeIDSet.contains(destIDSuffix)) {
loadResult.addError("Unable to load node connection " + c + ", destination node does not exist");
}
continue;
}
fixDestPortIfNecessary(destNodePersistor, c);
if (!m_connectionSet.add(c)) {
setDirtyAfterLoad();
loadResult.addError("Duplicate connection information: " + c);
}
}
for (Map.Entry<Integer, NodeFactoryUnknownException> missingNode : missingNodeIDMap.entrySet()) {
exec.checkCanceled();
int missingNodeSuffix = missingNode.getKey();
NodeAndBundleInformation nodeInfo = missingNode.getValue().getNodeAndBundleInformation();
loadResult.addMissingNode(nodeInfo);
NodeSettingsRO additionalFactorySettings = missingNode.getValue().getAdditionalFactorySettings();
ArrayList<PersistorWithPortIndex> upstreamNodes = new ArrayList<PersistorWithPortIndex>();
ArrayList<List<PersistorWithPortIndex>> downstreamNodes = new ArrayList<List<PersistorWithPortIndex>>();
for (ConnectionContainerTemplate t : m_connectionSet) {
// check upstream nodes
int sourceSuffix = t.getSourceSuffix();
int destSuffix = t.getDestSuffix();
int sourcePort = t.getSourcePort();
int destPort = t.getDestPort();
if (destSuffix == missingNodeSuffix) {
FromFileNodeContainerPersistor persistor;
if (sourceSuffix == -1) {
// connected to this metanode's input port bar
persistor = this;
} else {
persistor = m_nodeContainerLoaderMap.get(sourceSuffix);
}
ensureArrayListIndexValid(upstreamNodes, destPort);
upstreamNodes.set(destPort, new PersistorWithPortIndex(persistor, sourcePort));
}
// check downstream nodes
if (sourceSuffix == missingNodeSuffix) {
FromFileNodeContainerPersistor persistor;
if (destSuffix == -1) {
// connect to this metanode's output port bar
persistor = this;
} else {
persistor = m_nodeContainerLoaderMap.get(destSuffix);
}
ensureArrayListIndexValid(downstreamNodes, sourcePort);
List<PersistorWithPortIndex> downstreamNodesAtPort = downstreamNodes.get(sourcePort);
if (downstreamNodesAtPort == null) {
downstreamNodesAtPort = new ArrayList<PersistorWithPortIndex>();
downstreamNodes.set(sourcePort, downstreamNodesAtPort);
}
downstreamNodesAtPort.add(new PersistorWithPortIndex(persistor, destPort));
}
}
FromFileNodeContainerPersistor failingNodePersistor = m_nodeContainerLoaderMap.get(missingNodeSuffix);
failingNodePersistor.guessPortTypesFromConnectedNodes(nodeInfo, additionalFactorySettings, upstreamNodes, downstreamNodes);
}
exec.setProgress(1.0);
}
Aggregations