Search in sources :

Example 1 with WorkflowLoadHelper

use of org.knime.core.node.workflow.WorkflowLoadHelper in project knime-core by knime.

the class RepositoryFactory method loadMetaNode.

private static WorkflowManagerUI loadMetaNode(final String pluginId, final String workflowDir) {
    LOGGER.debug("found pre-installed template " + workflowDir);
    Bundle bundle = Platform.getBundle(pluginId);
    URL url = FileLocator.find(bundle, new Path(workflowDir), null);
    if (url != null) {
        try {
            File f = new File(FileLocator.toFileURL(url).getFile());
            LOGGER.debug("meta node template name: " + f.getName());
            WorkflowLoadHelper loadHelper = new WorkflowLoadHelper(true) {

                /**
                 * {@inheritDoc}
                 */
                @Override
                public String getDotKNIMEFileName() {
                    return WorkflowPersistor.WORKFLOW_FILE;
                }
            };
            // don't lock workflow dir
            FileWorkflowPersistor persistor = WorkflowManager.createLoadPersistor(f, loadHelper);
            WorkflowManager metaNode = WorkflowManager.META_NODE_ROOT.load(persistor, new ExecutionMonitor(), false).getWorkflowManager();
            return WorkflowManagerWrapper.wrap(metaNode);
        } catch (CanceledExecutionException cee) {
            LOGGER.error("Unexpected canceled execution exception", cee);
        } catch (Exception e) {
            LOGGER.error("Failed to load meta workflow repository", e);
        }
    }
    return null;
}
Also used : Path(org.eclipse.core.runtime.Path) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) Bundle(org.osgi.framework.Bundle) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) WorkflowLoadHelper(org.knime.core.node.workflow.WorkflowLoadHelper) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) File(java.io.File) URL(java.net.URL) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) FileWorkflowPersistor(org.knime.core.node.workflow.FileWorkflowPersistor)

Example 2 with WorkflowLoadHelper

use of org.knime.core.node.workflow.WorkflowLoadHelper in project knime-core by knime.

the class FileNodePersistor method load.

/**
 * Loads content into node instance.
 *
 * @param node The target node, used for meta info (#ports, e.g) and to invoke the
 *            {@link Node#load(NodePersistor, ExecutionMonitor, LoadResult)} on
 * @param parentPersistor workflow persistor for decryption
 * @param exec For progress/cancelation
 * @param loadTblRep The table repository used during load
 * @param tblRep The table repository for blob handling
 * @param fileStoreHandlerRepository ...
 * @param loadResult where to add errors to
 * @throws IOException If files can't be read
 * @throws CanceledExecutionException If canceled
 * @noreference This method is not intended to be referenced by clients.
 * @nooverride
 */
public final void load(final Node node, final WorkflowPersistor parentPersistor, final ExecutionMonitor exec, final Map<Integer, BufferedDataTable> loadTblRep, final HashMap<Integer, ContainerTable> tblRep, final WorkflowFileStoreHandlerRepository fileStoreHandlerRepository, final LoadResult loadResult) throws IOException, CanceledExecutionException {
    ExecutionMonitor loadExec = exec.createSilentSubProgress(0.6);
    ExecutionMonitor loadFileStoreExec = exec.createSilentSubProgress(0.2);
    ExecutionMonitor loadIntTblsExec = exec.createSilentSubProgress(0.1);
    ExecutionMonitor createExec = exec.createSilentSubProgress(0.1);
    exec.setMessage("settings");
    m_portObjects = new PortObject[node.getNrOutPorts()];
    m_portObjectSpecs = new PortObjectSpec[node.getNrOutPorts()];
    m_portObjectSummaries = new String[node.getNrOutPorts()];
    String nodeName = node.getName();
    // load internals
    if (m_hasContent) {
        try {
            m_nodeInternDirectory = loadNodeInternDirectory(m_settings, getNodeDirectory());
        } catch (InvalidSettingsException ise) {
            String e = "Unable to load internals directory";
            loadResult.addError(e);
            getLogger().warn(e, ise);
            setDirtyAfterLoad();
        }
    }
    WorkflowLoadHelper loadHelper = getLoadHelper();
    try {
        if (!loadHelper.isTemplateFlow()) {
            m_fileStoreHandler = loadFileStoreHandler(node, loadFileStoreExec, m_settings, fileStoreHandlerRepository);
        }
    } catch (Exception e) {
        if (!(e instanceof InvalidSettingsException) && !(e instanceof IOException)) {
            getLogger().error("Unexpected \"" + e.getClass().getSimpleName() + "\" encountered");
        }
        String err = "Unable to load file store handler for node \"" + nodeName + "\": " + e.getMessage();
        loadResult.addError(err, true);
        if (mustWarnOnDataLoadError()) {
            getLogger().warn(err, e);
        } else {
            getLogger().debug(err);
        }
        setNeedsResetAfterLoad();
    }
    loadFileStoreExec.setProgress(1.0);
    exec.setMessage("ports");
    try {
        if (!loadHelper.isTemplateFlow()) {
            loadPorts(node, loadExec, m_settings, loadTblRep, tblRep, fileStoreHandlerRepository);
        }
    } catch (Exception e) {
        if (!(e instanceof InvalidSettingsException) && !(e instanceof IOException)) {
            getLogger().error("Unexpected \"" + e.getClass().getSimpleName() + "\" encountered");
        }
        String err = "Unable to load port content for node \"" + nodeName + "\": " + e.getMessage();
        loadResult.addError(err, true);
        if (mustWarnOnDataLoadError()) {
            getLogger().warn(err, e);
        } else {
            getLogger().debug(err);
        }
        setNeedsResetAfterLoad();
    }
    loadExec.setProgress(1.0);
    try {
        if (!loadHelper.isTemplateFlow()) {
            if (getLoadVersion().isOlderThan(LoadVersion.V2100)) {
                loadInternalHeldTablesPre210(node, loadIntTblsExec, m_settings, loadTblRep, tblRep, fileStoreHandlerRepository);
            } else {
                loadInternalHeldObjects(node, loadIntTblsExec, m_settings, loadTblRep, tblRep, fileStoreHandlerRepository);
            }
        }
    } catch (Exception e) {
        if (!(e instanceof InvalidSettingsException) && !(e instanceof IOException)) {
            getLogger().error("Unexpected \"" + e.getClass().getSimpleName() + "\" encountered");
        }
        String err = "Unable to load internally held tables for node \"" + nodeName + "\": " + e.getMessage();
        loadResult.addError(err, true);
        if (mustWarnOnDataLoadError()) {
            getLogger().warn(err, e);
        } else {
            getLogger().debug(err);
        }
        setNeedsResetAfterLoad();
    }
    loadIntTblsExec.setProgress(1.0);
    exec.setMessage("Loading settings into node instance");
    node.load(this, createExec, loadResult);
    String status;
    switch(loadResult.getType()) {
        case Ok:
            status = " without errors";
            break;
        case DataLoadError:
            status = " with data errors";
            break;
        case Error:
            status = " with errors";
            break;
        case Warning:
            status = " with warnings";
            break;
        default:
            status = " with " + loadResult.getType();
    }
    String message = "Loaded node " + node + status;
    exec.setProgress(1.0, message);
}
Also used : WorkflowLoadHelper(org.knime.core.node.workflow.WorkflowLoadHelper) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Aggregations

WorkflowLoadHelper (org.knime.core.node.workflow.WorkflowLoadHelper)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 URL (java.net.URL)1 Path (org.eclipse.core.runtime.Path)1 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)1 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)1 FileWorkflowPersistor (org.knime.core.node.workflow.FileWorkflowPersistor)1 WorkflowManager (org.knime.core.node.workflow.WorkflowManager)1 Bundle (org.osgi.framework.Bundle)1