Search in sources :

Example 96 with NodeSettings

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

the class PolyRegLearnerNodeModel method saveInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    if (m_viewData != null) {
        // Is this necessary?
        NodeSettings internals = new NodeSettings("internals");
        internals.addDoubleArray("betas", m_viewData.betas);
        internals.addStringArray("columnNames", m_viewData.columnNames);
        internals.addDouble("squaredError", m_viewData.squaredError);
        internals.addDouble("adjustedSquaredError", m_viewData.m_adjustedR2);
        internals.addDoubleArray("meanValues", m_viewData.meanValues);
        internals.addDoubleArray("stdErrors", m_viewData.m_stdErrs);
        internals.addDoubleArray("tValues", m_viewData.m_tValues);
        internals.addDoubleArray("pValues", m_viewData.m_pValues);
        internals.saveToXML(new BufferedOutputStream(new FileOutputStream(new File(nodeInternDir, "internals.xml"))));
        File dataFile = new File(nodeInternDir, "data.zip");
        DataContainer.writeToZip(m_viewData.getRowContainer(), dataFile, exec);
    }
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File)

Example 97 with NodeSettings

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

the class ClusterNodeModel method saveInternals.

/**
 * {@inheritDoc}
 */
@Override
protected void saveInternals(final File internDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
    NodeSettings internalSettings = new NodeSettings("kMeans");
    internalSettings.addInt(CFG_DIMENSION, m_dimension);
    internalSettings.addInt(CFG_IGNORED_COLS, m_nrIgnoredColumns);
    internalSettings.addIntArray(CFG_COVERAGE, m_viewData.clusterCoverage());
    for (int i = 0; i < m_nrOfClusters.getIntValue(); i++) {
        internalSettings.addDoubleArray(CFG_CLUSTER + i, m_viewData.clusters()[i]);
    }
    internalSettings.addStringArray(CFG_FEATURE_NAMES, m_viewData.featureNames());
    if (m_enableHilite.getBooleanValue()) {
        NodeSettingsWO mapSet = internalSettings.addNodeSettings(CFG_HILITEMAPPING);
        ((DefaultHiLiteMapper) m_translator.getMapper()).save(mapSet);
    }
    File f = new File(internDir, SETTINGS_FILE_NAME);
    FileOutputStream out = new FileOutputStream(f);
    internalSettings.saveToXML(out);
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) FileOutputStream(java.io.FileOutputStream) DefaultHiLiteMapper(org.knime.core.node.property.hilite.DefaultHiLiteMapper) File(java.io.File)

Example 98 with NodeSettings

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

the class WorkflowManager method updateNodeTemplateLinkInternal.

/**
 * Actual implementation to #updateMetaNodeLink. It updates a single metanode, which must be a linked metanode. It
 * does not keep any backups and doesn't have a rollback.
 */
private NodeContainerTemplate updateNodeTemplateLinkInternal(final NodeID id, final ExecutionMonitor exec, final WorkflowLoadHelper loadHelper, final Map<URI, NodeContainerTemplate> visitedTemplateMap, final NodeContainerTemplateLinkUpdateResult loadRes) throws Exception {
    final NodeContainerTemplate newLinkMN;
    final NodeContainer oldLinkMN = m_workflow.getNode(id);
    NodeContainerTemplate tnc = (NodeContainerTemplate) oldLinkMN;
    MetaNodeTemplateInformation templInfo = tnc.getTemplateInformation();
    assert templInfo.getRole().equals(Role.Link);
    URI sourceURI = templInfo.getSourceURI();
    NodeContainerTemplate tempLink = visitedTemplateMap.get(sourceURI);
    if (tempLink == null) {
        try {
            tempLink = loadMetaNodeTemplate(tnc, loadHelper, loadRes);
            visitedTemplateMap.put(sourceURI, tempLink);
        } catch (IOException e) {
            String error = "Failed to update metanode reference: " + e.getMessage();
            LOGGER.error(error, e);
            loadRes.addError(error);
            return null;
        } catch (UnsupportedWorkflowVersionException e) {
            String error = "Unsupported version in metanode template " + e.getMessage();
            LOGGER.error(error, e);
            loadRes.addError(error);
            return null;
        }
    }
    try (WorkflowLock lock = lock()) {
        // current settings, re-apply after update
        NodeSettings ncSettings = new NodeSettings("metanode_settings");
        try {
            saveNodeSettings(id, ncSettings);
        } catch (InvalidSettingsException e1) {
            String error = "Unable to store metanode settings: " + e1.getMessage();
            LOGGER.warn(error, e1);
            loadRes.addError(error);
        }
        NodeAnnotationData oldAnnoData = oldLinkMN.getNodeAnnotation().getData();
        NodeUIInformation oldUI = oldLinkMN.getUIInformation();
        NodeUIInformation newUI = oldUI != null ? NodeUIInformation.builder(oldUI).build() : null;
        // keep old in/out connections to later relink them
        Set<ConnectionContainer> inConns = getIncomingConnectionsFor(id);
        Set<ConnectionContainer> outConns = getOutgoingConnectionsFor(id);
        removeNode(id);
        WorkflowCopyContent pasteResult = copyFromAndPasteHere(tempLink.getParent(), WorkflowCopyContent.builder().setNodeID(tempLink.getID(), id.getIndex(), newUI).build());
        newLinkMN = getNodeContainer(pasteResult.getNodeIDs()[0], NodeContainerTemplate.class, true);
        if (oldAnnoData != null && !oldAnnoData.isDefault()) {
            ((NodeContainer) newLinkMN).getNodeAnnotation().getData().copyFrom(oldAnnoData, true);
        }
        loadRes.setNCTemplate(newLinkMN);
        try {
            loadNodeSettings(loadRes.getNCTemplate().getID(), ncSettings);
        } catch (InvalidSettingsException e) {
            String error = "Can't apply previous settigs to new metanode link: " + e.getMessage();
            LOGGER.warn(error, e);
            loadRes.addError(error);
        }
        for (ConnectionContainer cc : inConns) {
            NodeID s = cc.getSource();
            int sourcePort = cc.getSourcePort();
            int destPort = cc.getDestPort();
            if (!canAddConnection(s, sourcePort, id, destPort)) {
                loadRes.addWarning("Could not restore connection between \"" + getNodeContainer(s).getNameWithID() + "\" and metanode template");
            } else {
                ConnectionContainer c = addConnection(s, sourcePort, id, destPort);
                c.setDeletable(cc.isDeletable());
                ConnectionUIInformation uiInfo = cc.getUIInfo();
                c.setUIInfo(uiInfo != null ? ConnectionUIInformation.builder(uiInfo).build() : null);
            }
        }
        for (ConnectionContainer cc : outConns) {
            int sourcePort = cc.getSourcePort();
            int destPort = cc.getDestPort();
            NodeID des = cc.getDest();
            if (!canAddConnection(id, sourcePort, des, destPort)) {
                loadRes.addError("Could not restore connection between metanode template and \"" + getNodeContainer(des).getNameWithID() + "\"");
            } else {
                ConnectionContainer c = addConnection(id, sourcePort, des, destPort);
                c.setDeletable(cc.isDeletable());
                ConnectionUIInformation uiInfo = cc.getUIInfo();
                c.setUIInfo(uiInfo != null ? ConnectionUIInformation.builder(uiInfo).build() : null);
            }
        }
        return newLinkMN;
    }
}
Also used : IOException(java.io.IOException) URI(java.net.URI) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) NodeSettings(org.knime.core.node.NodeSettings) InvalidSettingsException(org.knime.core.node.InvalidSettingsException)

Example 99 with NodeSettings

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

the class WorkflowManager method saveAsTemplate.

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

Example 100 with NodeSettings

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

the class WorkflowManager method loadSettings.

/**
 * {@inheritDoc}
 */
@Override
void loadSettings(final NodeSettingsRO settings) throws InvalidSettingsException {
    super.loadSettings(settings);
    NodeSettingsRO modelSettings = settings.getNodeSettings("model");
    Map<NodeID, QuickFormInputNode> nodes = findNodes(QuickFormInputNode.class, false);
    for (Entry<NodeID, QuickFormInputNode> entry : nodes.entrySet()) {
        NodeID id = entry.getKey();
        String nodeID = Integer.toString(id.getIndex());
        if (modelSettings.containsKey(nodeID)) {
            NodeSettingsRO conf = modelSettings.getNodeSettings(nodeID);
            QuickFormInputNode qfin = entry.getValue();
            NodeSettingsWO oldSettings = new NodeSettings(nodeID);
            qfin.getConfiguration().getValueConfiguration().saveValue(oldSettings);
            if (!conf.equals(oldSettings)) {
                // FIXME: likely not here but in the WFM...
                // not needed (actually nodes not work) because WFM itself
                // was reset completely if any one of the settings change.
                // SingleNodeContainer snc = (SingleNodeContainer)this.getNodeContainer(id);
                // snc.reset();
                @SuppressWarnings("unchecked") AbstractQuickFormConfiguration<AbstractQuickFormValueInConfiguration> config = (AbstractQuickFormConfiguration<AbstractQuickFormValueInConfiguration>) qfin.getConfiguration();
                if (config != null) {
                    config.getValueConfiguration().loadValueInModel(conf);
                    saveNodeSettingsToDefault(id);
                }
            // see above: not needed
            // this.configureNodeAndSuccessors(id, true);
            }
        }
    }
}
Also used : AbstractQuickFormValueInConfiguration(org.knime.core.quickform.AbstractQuickFormValueInConfiguration) AbstractQuickFormConfiguration(org.knime.core.quickform.AbstractQuickFormConfiguration) NodeSettings(org.knime.core.node.NodeSettings) NodeSettingsWO(org.knime.core.node.NodeSettingsWO) NodeSettingsRO(org.knime.core.node.NodeSettingsRO) QuickFormInputNode(org.knime.core.quickform.in.QuickFormInputNode)

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