Search in sources :

Example 86 with NodeSettingsRO

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;
}
Also used : NodeSettingsRO(org.knime.core.node.NodeSettingsRO) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) PortObject(org.knime.core.node.port.PortObject) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint)

Example 87 with NodeSettingsRO

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();
}
Also used : ReferencedFile(org.knime.core.internal.ReferencedFile) LinkedHashMap(java.util.LinkedHashMap) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 88 with NodeSettingsRO

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);
        }
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 89 with NodeSettingsRO

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();
            }
        }
    }
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) DialogNode(org.knime.core.node.dialog.DialogNode) DialogNodeValue(org.knime.core.node.dialog.DialogNodeValue) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Example 90 with NodeSettingsRO

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;
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) LoadVersion(org.knime.core.util.LoadVersion) VirtualSubNodeOutputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeOutputNodeModel) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) PortObject(org.knime.core.node.port.PortObject)

Aggregations

NodeSettingsRO (org.knime.core.node.NodeSettingsRO)208 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)125 File (java.io.File)49 FileInputStream (java.io.FileInputStream)47 IOException (java.io.IOException)43 InputStream (java.io.InputStream)22 LinkedHashMap (java.util.LinkedHashMap)20 NodeSettings (org.knime.core.node.NodeSettings)20 BufferedInputStream (java.io.BufferedInputStream)19 ArrayList (java.util.ArrayList)16 GZIPInputStream (java.util.zip.GZIPInputStream)15 DataTableSpec (org.knime.core.data.DataTableSpec)14 Map (java.util.Map)11 ReferencedFile (org.knime.core.internal.ReferencedFile)11 BufferedDataTable (org.knime.core.node.BufferedDataTable)10 HashMap (java.util.HashMap)9 DataColumnSpec (org.knime.core.data.DataColumnSpec)9 RowKey (org.knime.core.data.RowKey)9 DataType (org.knime.core.data.DataType)8 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)8