use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.
the class WorkflowManager method continueExecutionOnLoad.
/**
* @param nc The node container
* @param persistor The persistor
* @return true if load and execution was successful, false otherwise
* @throws InvalidSettingsException If the settings are invalid
* @throws NodeExecutionJobReconnectException If continuing the execution does fail
*/
boolean continueExecutionOnLoad(final NodeContainer nc, final NodeContainerPersistor persistor) throws InvalidSettingsException, NodeExecutionJobReconnectException {
NodeContainerMetaPersistor metaPers = persistor.getMetaPersistor();
NodeSettingsRO execJobSettings = metaPers.getExecutionJobSettings();
NodeOutPort[] ports = assemblePredecessorOutPorts(nc.getID());
PortObject[] inData = new PortObject[ports.length];
boolean allDataAvailable = true;
for (int i = 0; i < ports.length; i++) {
if (ports[i] != null) {
inData[i] = ports[i].getPortObject();
// if connected but no data, set to false
if (inData[i] == null) {
allDataAvailable = false;
}
} else if (!nc.getInPort(i).getPortType().isOptional()) {
// unconnected non-optional port ... abort
allDataAvailable = false;
}
}
if (allDataAvailable && nc.getInternalState().equals(EXECUTINGREMOTELY)) {
nc.continueExecutionOnLoad(inData, execJobSettings);
return true;
}
return false;
}
use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.
the class WorkflowManager method loadContent.
/**
* {@inheritDoc}
*/
@Override
WorkflowCopyContent loadContent(final NodeContainerPersistor nodePersistor, final Map<Integer, BufferedDataTable> tblRep, final FlowObjectStack ignoredStack, final ExecutionMonitor exec, final LoadResult loadResult, final boolean preserveNodeMessage) throws CanceledExecutionException {
exec.checkCanceled();
if (!(nodePersistor instanceof WorkflowPersistor)) {
throw new IllegalStateException("Expected " + WorkflowPersistor.class.getSimpleName() + " persistor object, got " + nodePersistor.getClass().getSimpleName());
}
WorkflowPersistor persistor = (WorkflowPersistor) nodePersistor;
assert this != ROOT || persistor.getConnectionSet().isEmpty() : "ROOT workflow has no connections: " + persistor.getConnectionSet();
LinkedHashMap<NodeID, NodeContainerPersistor> persistorMap = new LinkedHashMap<NodeID, NodeContainerPersistor>();
Map<Integer, ? extends NodeContainerPersistor> nodeLoaderMap = persistor.getNodeLoaderMap();
exec.setMessage("annotations");
List<WorkflowAnnotation> annos = persistor.getWorkflowAnnotations();
for (WorkflowAnnotation w : annos) {
addWorkflowAnnotationInternal(w);
}
exec.setMessage("node & connection information");
Map<Integer, NodeID> translationMap = loadNodesAndConnections(nodeLoaderMap, persistor.getConnectionSet(), loadResult);
for (Map.Entry<Integer, NodeID> e : translationMap.entrySet()) {
NodeID id = e.getValue();
NodeContainerPersistor p = nodeLoaderMap.get(e.getKey());
assert p != null : "Deficient translation map";
persistorMap.put(id, p);
}
persistor.postLoad(this, loadResult);
try {
postLoad(persistorMap, tblRep, persistor.mustWarnOnDataLoadError(), exec, loadResult, preserveNodeMessage);
} catch (CanceledExecutionException cee) {
for (NodeID insertedNodeID : translationMap.values()) {
removeNode(insertedNodeID);
}
throw cee;
}
NodeSettingsRO wizardState = persistor.getWizardExecutionControllerState();
if (wizardState != null) {
try {
m_executionController = new WizardExecutionController(this, wizardState);
} catch (InvalidSettingsException e1) {
String msg = "Failed to restore wizard controller from file: " + e1.getMessage();
LOGGER.debug(msg, e1);
loadResult.addError(msg);
}
}
// of the workflow can't be properly read from the workflow.knime)
if (persistor.needsResetAfterLoad() || persistor.isDirtyAfterLoad()) {
setDirty();
}
ReferencedFile ncDirectory = getNodeContainerDirectory();
if (ncDirectory != null) {
ncDirectory.getDeletedNodesFileLocations().addAll(persistor.getObsoleteNodeDirectories());
}
ReferencedFile autoSaveDirectory = getAutoSaveDirectory();
if (autoSaveDirectory != null) {
autoSaveDirectory.getDeletedNodesFileLocations().addAll(persistor.getObsoleteNodeDirectories());
}
Collection<NodeID> resultColl = persistorMap.keySet();
NodeID[] newIDs = resultColl.toArray(new NodeID[resultColl.size()]);
WorkflowAnnotation[] newAnnotations = annos.toArray(new WorkflowAnnotation[annos.size()]);
addConnectionsFromTemplates(persistor.getAdditionalConnectionSet(), loadResult, translationMap, false);
WorkflowCopyContent.Builder result = WorkflowCopyContent.builder();
result.setAnnotationIDs(getWorkflowAnnotationIDs(newAnnotations));
result.setNodeIDs(newIDs);
return result.build();
}
use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.
the class AbstractPortObjectRepositoryNodeModel method loadInternals.
@Override
protected void loadInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
File f = new File(nodeInternDir, INTERNALS_FILE_PORT_OBJECT_IDS);
if (f.exists()) {
try (InputStream in = new GZIPInputStream(new BufferedInputStream(new FileInputStream(f)))) {
NodeSettingsRO settings = NodeSettings.loadFromXML(in);
if (settings.containsKey(CFG_PORT_OBJECT_IDS)) {
m_portObjectIds.clear();
m_portObjects.clear();
addPortObjectIds(settings.getStringArray(CFG_PORT_OBJECT_IDS));
addToPortObjectRepository();
}
} catch (InvalidSettingsException ise) {
throw new IOException("Unable to read port object ids", ise);
}
}
}
use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.
the class SubNodeContainer method performValidateSettings.
/**
* {@inheritDoc}
*/
@SuppressWarnings("rawtypes")
@Override
void performValidateSettings(final NodeSettingsRO modelSettings) throws InvalidSettingsException {
Map<NodeID, DialogNode> nodes = m_wfm.findNodes(DialogNode.class, false);
for (Map.Entry<NodeID, DialogNode> entry : nodes.entrySet()) {
NodeID id = entry.getKey();
DialogNode node = entry.getValue();
String parameterName = getDialogNodeParameterName(node, id);
if (modelSettings.containsKey(parameterName)) {
NodeSettingsRO conf = modelSettings.getNodeSettings(parameterName);
NodeContext.pushContext(m_wfm.getNodeContainer(id));
try {
final DialogNodeValue validationDialogValue = node.createEmptyDialogValue();
validationDialogValue.loadFromNodeSettings(conf);
node.validateDialogValue(validationDialogValue);
} catch (InvalidSettingsException ise) {
throw ise;
} catch (Throwable e) {
LOGGER.coding("Settings validation threw \"" + e.getClass().getSimpleName() + "\": " + e.getMessage(), e);
throw new InvalidSettingsException(e.getMessage(), e);
} finally {
NodeContext.removeLastContext();
}
}
}
}
use of org.knime.core.node.NodeSettingsRO in project knime-core by knime.
the class SubNodeContainer method performLoadContent.
/**
* {@inheritDoc}
*/
@Override
WorkflowCopyContent performLoadContent(final SingleNodeContainerPersistor nodePersistor, final Map<Integer, BufferedDataTable> tblRep, final FlowObjectStack inStack, final ExecutionMonitor exec, final LoadResult loadResult, final boolean preserveNodeMessage) throws CanceledExecutionException {
SubNodeContainerPersistor subNodePersistor = (SubNodeContainerPersistor) nodePersistor;
WorkflowPersistor workflowPersistor = subNodePersistor.getWorkflowPersistor();
// TODO pass in a filter input stack
m_wfm.loadContent(workflowPersistor, tblRep, inStack, exec, loadResult, preserveNodeMessage);
if (workflowPersistor.isDirtyAfterLoad() || m_wfm.isDirty()) {
setDirty();
}
InternalNodeContainerState loadState = nodePersistor.getMetaPersistor().getState();
if (!m_wfm.getInternalState().equals(loadState)) {
// can happen for workflows that were exported without data;
// the same check is done by the caller (WorkflowManager#postLoad) and handled appropriately
setInternalState(m_wfm.getInternalState(), false);
}
NodeSettingsRO modelSettings = subNodePersistor.getSNCSettings().getModelSettings();
if (modelSettings != null) {
try {
loadModelSettingsIntoDialogNodes(modelSettings, false);
} catch (InvalidSettingsException e) {
final String msg = "Could not load Component configuration into dialog-nodes: " + e.getMessage();
LOGGER.error(msg, e);
loadResult.addError(msg);
setDirty();
}
}
checkInOutNodesAfterLoad(subNodePersistor, loadResult);
loadLegacyPortNamesAndDescriptionsFromInOutNodes();
// put data input output node if it was executed;
final NativeNodeContainer virtualOutNode = getVirtualOutNode();
LoadVersion l = nodePersistor instanceof FileSingleNodeContainerPersistor ? ((FileSingleNodeContainerPersistor) nodePersistor).getLoadVersion() : LoadVersion.V3010;
if (l.isOlderThan(LoadVersion.V3010) && virtualOutNode.getInternalState().isExecuted()) {
VirtualSubNodeOutputNodeModel outNodeModel = getVirtualOutNodeModel();
PortObject[] outputData = new PortObject[virtualOutNode.getNrInPorts()];
m_wfm.assembleInputData(getVirtualOutNodeID(), outputData);
outNodeModel.postLoadExecute(ArrayUtils.removeAll(outputData, 0));
// allow node to receive the internal held objects so that the next save operation also persists the
// array of internal held objects - otherwise we get strange errors with nodes saved in 2.x, then loaded
// and saved in 3.1+ (and converted ... although unmodified)
getVirtualOutNode().getNode().assignInternalHeldObjects(outputData, null, getVirtualOutNode().createExecutionContext(), new PortObject[0]);
}
setVirtualOutputIntoOutport(m_wfm.getInternalState());
m_wfmStateChangeListener = createAndAddStateListener();
m_wfmListener = createAndAddWorkflowListener();
getInPort(0).setPortName("Variable Inport");
getOutPort(0).setPortName("Variable Outport");
getVirtualInNode().addNodeStateChangeListener(new RefreshPortNamesListener());
getVirtualOutNode().addNodeStateChangeListener(new RefreshPortNamesListener());
refreshPortNames();
return null;
}
Aggregations