Search in sources :

Example 76 with NodeSettings

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

the class NodeExecutorJobManagerDialogTab method saveSettings.

/**
 * Writes the current settings of the job manager tab into the provided
 * settings object.
 *
 * @param settings the object to write settings into
 * @throws InvalidSettingsException if the settings in the pane are
 *             unacceptable
 */
public void saveSettings(final NodeContainerSettings settings) throws InvalidSettingsException {
    String selected = (String) m_jobManagerSelect.getSelectedItem();
    NodeExecutionJobManager selMgr = null;
    if (!DEFAULT_ENTRY.equals(selected)) {
        // any "real" node execution manager was selected
        selMgr = m_panels.get(selected).getFirst();
        NodeSettings panelSets = new NodeSettings("job_manager_settings");
        m_currentPanel.saveSettings(panelSets);
        selMgr.load(panelSets);
    }
    settings.setJobManager(selMgr);
}
Also used : NodeSettings(org.knime.core.node.NodeSettings)

Example 77 with NodeSettings

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

the class ObsoleteMetaNodeFileWorkflowPersistor method loadInPortsSetting.

/**
 * {@inheritDoc}
 */
@Override
protected NodeSettingsRO loadInPortsSetting(final NodeSettingsRO settings) throws InvalidSettingsException {
    NodeSettings template = new NodeSettings("inports");
    for (int i = 0; i < m_dataInNodeIDs.length; i++) {
        NodeSettingsWO sub = template.addNodeSettings("data_" + i);
        sub.addInt("index", i);
        sub.addInt("node", m_dataInNodeIDs[i]);
        sub.addString("type", "data");
    }
    return template;
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) NodeSettingsWO(org.knime.core.node.NodeSettingsWO)

Example 78 with NodeSettings

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

the class SubNodeContainer method setInPorts.

/**
 * @param portTypes Types of the new ports
 * @since 2.10
 */
public void setInPorts(final PortType[] portTypes) {
    m_inports = new NodeInPort[portTypes.length + 1];
    for (int i = 0; i < portTypes.length; i++) {
        m_inports[i + 1] = new NodeInPort(i + 1, portTypes[i]);
    }
    NodeContainer oldVNode = m_wfm.getNodeContainer(getVirtualInNodeID());
    m_inports[0] = new NodeInPort(0, FlowVariablePortObject.TYPE_OPTIONAL);
    NodeSettings settings = new NodeSettings("node settings");
    try {
        m_wfm.saveNodeSettings(oldVNode.getID(), settings);
    } catch (InvalidSettingsException e) {
    // no valid settings available, skip
    }
    m_virtualInNodeIDSuffix = m_wfm.addNode(new VirtualSubNodeInputNodeFactory(this, portTypes)).getIndex();
    NodeContainer newVNode = m_wfm.getNodeContainer(getVirtualInNodeID());
    newVNode.setUIInformation(oldVNode.getUIInformation());
    // copy settings from old to new node
    try {
        m_wfm.loadNodeSettings(newVNode.getID(), settings);
    } catch (InvalidSettingsException e) {
    // ignore
    }
    oldVNode.setDeletable(true);
    m_wfm.removeNode(oldVNode.getID());
    getInPort(0).setPortName("Variable Inport");
    newVNode.addNodeStateChangeListener(new RefreshPortNamesListener());
    refreshPortNames();
    m_wfm.setDirty();
    setDirty();
    notifyNodePropertyChangedListener(NodeProperty.MetaNodePorts);
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) VirtualSubNodeInputNodeFactory(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeFactory) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 79 with NodeSettings

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

the class SubNodeContainer method saveAsTemplate.

/**
 * {@inheritDoc}
 */
@Override
public MetaNodeTemplateInformation saveAsTemplate(final File directory, final ExecutionMonitor exec) throws IOException, CanceledExecutionException, LockFailedException, InvalidSettingsException {
    WorkflowManager tempParent = WorkflowManager.lazyInitTemplateWorkflowRoot();
    SubNodeContainer copy = null;
    ReferencedFile workflowDirRef = new ReferencedFile(directory);
    directory.mkdir();
    workflowDirRef.lock();
    try {
        WorkflowCopyContent.Builder cntBuilder = WorkflowCopyContent.builder();
        cntBuilder.setNodeIDs(getID());
        WorkflowCopyContent cnt;
        synchronized (m_nodeMutex) {
            cnt = tempParent.copyFromAndPasteHere(getParent(), cntBuilder.build());
        }
        NodeID cID = cnt.getNodeIDs()[0];
        copy = ((SubNodeContainer) tempParent.getNodeContainer(cID));
        try (WorkflowLock copyLock = copy.lock()) {
            SingleNodeContainerSettings sncSettings = copy.getSingleNodeContainerSettings().clone();
            sncSettings.setModelSettings(new NodeSettings("empty model"));
            sncSettings.setVariablesSettings(new NodeSettings("empty variables setting"));
            NodeSettings newSettings = new NodeSettings("new settings");
            sncSettings.save(newSettings);
            copy.loadSettings(newSettings);
            MetaNodeTemplateInformation template = MetaNodeTemplateInformation.createNewTemplate(SubNodeContainer.class);
            synchronized (copy.m_nodeMutex) {
                copy.setTemplateInformation(template);
                copy.setName(null);
                NodeSettings templateSettings = MetaNodeTemplateInformation.createNodeSettingsForTemplate(copy);
                templateSettings.saveToXML(new FileOutputStream(new File(workflowDirRef.getFile(), WorkflowPersistor.TEMPLATE_FILE)));
                FileSingleNodeContainerPersistor.save(copy, workflowDirRef, exec, new WorkflowSaveHelper(true, false));
            }
            return template;
        }
    } finally {
        if (copy != null) {
            tempParent.removeNode(copy.getID());
        }
        workflowDirRef.unlock();
    }
}
Also used : ReferencedFile(org.knime.core.internal.ReferencedFile) NodeSettings(org.knime.core.node.NodeSettings) FileOutputStream(java.io.FileOutputStream) ReferencedFile(org.knime.core.internal.ReferencedFile) File(java.io.File)

Example 80 with NodeSettings

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

the class SubNodeContainer method checkInOutNodesAfterLoad.

/**
 * Fixes in- and output nodes after loading (in case they don't exist or have errors).
 */
private void checkInOutNodesAfterLoad(final SubNodeContainerPersistor subNodePersistor, final LoadResult loadResult) {
    /* Fix output node */
    NodeID virtualOutID = getVirtualOutNodeID();
    // non null in case not is not present of of wrong type
    String error = null;
    // settings of previous node if present or null
    NodeSettings outputSettings = null;
    // assigned with node insertion, used for node placement
    Pair<int[], int[]> minMaxCoordinates;
    if (m_wfm.containsNodeContainer(virtualOutID)) {
        NodeContainer virtualOutNC = m_wfm.getNodeContainer(virtualOutID);
        if (virtualOutNC instanceof NativeNodeContainer) {
            NodeModel virtualOutModel = ((NativeNodeContainer) virtualOutNC).getNodeModel();
            if (!(virtualOutModel instanceof VirtualSubNodeOutputNodeModel)) {
                // this is very likely a missing node (placeholder)
                error = String.format("Virtual output node is not of expected type (expected %s, actual %s)", VirtualSubNodeOutputNodeModel.class.getName(), virtualOutModel.getClass().getName());
                try {
                    NodeSettings temp = new NodeSettings("temp");
                    m_wfm.saveNodeSettings(virtualOutID, temp);
                    outputSettings = temp;
                } catch (InvalidSettingsException ise) {
                // silently ignore; this is minor given that the node is not there.
                }
            }
        } else {
            error = String.format("Virtual output node with ID %s is not a native node", virtualOutID);
        }
    } else {
        error = String.format("Virtual output node with ID %s does not exist", virtualOutID);
    }
    if (error != null) {
        minMaxCoordinates = getMinMaxCoordinates();
        m_virtualOutNodeIDSuffix = addVirtualOutNode(Output.getPortTypesNoFlowVariablePort(m_outputs), minMaxCoordinates).getIndex();
        error = error.concat(String.format(" - creating new instance (ID %s)", m_virtualOutNodeIDSuffix));
        loadResult.addError(error);
        if (outputSettings != null) {
            try {
                m_wfm.loadNodeSettings(getVirtualOutNodeID(), outputSettings);
            } catch (InvalidSettingsException e) {
            // again, ignore as the node was missing, which is much more critical
            }
        }
    }
    /* Fix input node */
    NodeID virtualInID = getVirtualInNodeID();
    // non null in case not is not present of of wrong type
    error = null;
    // settings of previous node if present or null
    NodeSettings inputSettings = null;
    if (m_wfm.containsNodeContainer(virtualInID)) {
        NodeContainer virtualInNC = m_wfm.getNodeContainer(virtualInID);
        if (virtualInNC instanceof NativeNodeContainer) {
            NodeModel virtualInModel = ((NativeNodeContainer) virtualInNC).getNodeModel();
            if (!(virtualInModel instanceof VirtualSubNodeInputNodeModel)) {
                // this is very likely a missing node (placeholder)
                error = String.format("Virtual input node is not of expected type (expected %s, actual %s)", VirtualSubNodeInputNodeModel.class.getName(), virtualInModel.getClass().getName());
                try {
                    NodeSettings temp = new NodeSettings("temp");
                    m_wfm.saveNodeSettings(virtualInID, temp);
                    inputSettings = temp;
                } catch (InvalidSettingsException ise) {
                // silently ignore; this is minor given that the node is not there.
                }
            }
        } else {
            error = String.format("Virtual input node with ID %s is not a native node", virtualInID);
        }
    } else {
        error = String.format("Virtual input node with ID %s does not exist", virtualInID);
    }
    if (error != null) {
        minMaxCoordinates = getMinMaxCoordinates();
        // skip flow var port
        PortType[] inportTypes = new PortType[getNrInPorts() - 1];
        for (int i = 1; i < getNrInPorts(); i++) {
            inportTypes[i - 1] = getInPort(i).getPortType();
        }
        m_virtualInNodeIDSuffix = addVirtualInNode(inportTypes, minMaxCoordinates).getIndex();
        error = error.concat(String.format(" - creating new instance (ID %s)", m_virtualInNodeIDSuffix));
        loadResult.addError(error);
        if (inputSettings != null) {
            try {
                m_wfm.loadNodeSettings(getVirtualInNodeID(), inputSettings);
            } catch (InvalidSettingsException e) {
            // again, ignore as the node was missing, which is much more critical
            }
        }
    }
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) VirtualSubNodeOutputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeOutputNodeModel) VirtualSubNodeInputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeModel) NodeModel(org.knime.core.node.NodeModel) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) VirtualSubNodeInputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeInputNodeModel) VirtualSubNodeOutputNodeModel(org.knime.core.node.workflow.virtual.subnode.VirtualSubNodeOutputNodeModel) PortType(org.knime.core.node.port.PortType)

Aggregations

NodeSettings (org.knime.core.node.NodeSettings)156 File (java.io.File)58 FileOutputStream (java.io.FileOutputStream)57 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)37 GZIPOutputStream (java.util.zip.GZIPOutputStream)27 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)17 Test (org.junit.Test)16 NodeSettingsWO (org.knime.core.node.NodeSettingsWO)16 DefaultHiLiteMapper (org.knime.core.node.property.hilite.DefaultHiLiteMapper)16 IOException (java.io.IOException)14 OutputStream (java.io.OutputStream)12 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)11 BufferedOutputStream (java.io.BufferedOutputStream)9 Map (java.util.Map)8 RowKey (org.knime.core.data.RowKey)8 Config (org.knime.core.node.config.Config)8 LinkedHashMap (java.util.LinkedHashMap)7 DataTableSpec (org.knime.core.data.DataTableSpec)7 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)6 ArrayList (java.util.ArrayList)5