Search in sources :

Example 6 with WorkflowLoadResult

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

the class BugAP7982_FutureKNIMEVersion_FutureVersion method loadWorkflowTry.

/**
 * Load workflow, expect no errors.
 */
@Test
public void loadWorkflowTry() throws Exception {
    WorkflowLoadResult loadWorkflow = loadWorkflow(true);
    setManager(loadWorkflow.getWorkflowManager());
    assertThat("Expected to loaded without errors", loadWorkflow.getType(), is(LoadResultEntryType.Ok));
    assertThat("Workflow version incorrect", getManager().getLoadVersion(), is(LoadVersion.FUTURE));
}
Also used : WorkflowLoadResult(org.knime.core.node.workflow.WorkflowPersistor.WorkflowLoadResult) Test(org.junit.Test)

Example 7 with WorkflowLoadResult

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

the class BugAP7982_FutureKNIMEVersion_FutureVersion method loadWorkflow.

private WorkflowLoadResult loadWorkflow(final boolean tryToLoadInsteadOfFail) throws Exception {
    File wkfDir = getDefaultWorkflowDirectory();
    WorkflowLoadResult loadWorkflow = loadWorkflow(wkfDir, new ExecutionMonitor(), new WorkflowLoadHelper(wkfDir) {

        @Override
        public UnknownKNIMEVersionLoadPolicy getUnknownKNIMEVersionLoadPolicy(final LoadVersion workflowKNIMEVersion, final Version createdByKNIMEVersion, final boolean isNightlyBuild) {
            assertThat("Unexpected KNIME version in file", workflowKNIMEVersion, is(LoadVersion.FUTURE));
            assertThat("Nightly flag wrong", isNightlyBuild, is(m_isExpectNightly));
            if (tryToLoadInsteadOfFail) {
                return UnknownKNIMEVersionLoadPolicy.Try;
            } else {
                return UnknownKNIMEVersionLoadPolicy.Abort;
            }
        }
    });
    return loadWorkflow;
}
Also used : LoadVersion(org.knime.core.node.workflow.FileWorkflowPersistor.LoadVersion) Version(org.knime.core.util.Version) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) LoadVersion(org.knime.core.node.workflow.FileWorkflowPersistor.LoadVersion) File(java.io.File) WorkflowLoadResult(org.knime.core.node.workflow.WorkflowPersistor.WorkflowLoadResult)

Example 8 with WorkflowLoadResult

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

the class Bug6729_InvalidConfigOnInactiveNodes method init.

private void init() throws Exception {
    WorkflowLoadResult loadResult = loadWorkflow(m_workflowDirTemp, new ExecutionMonitor(), new WorkflowLoadHelper(m_workflowDirTemp));
    assertThat("Expected non-error/non-warning load result: " + loadResult.getMessage(), loadResult.getType(), is(LoadResultEntryType.Ok));
    final WorkflowManager workflowManager = loadResult.getWorkflowManager();
    setManager(workflowManager);
    NodeID baseID = workflowManager.getID();
    m_fileReader2 = new NodeID(baseID, 2);
}
Also used : ExecutionMonitor(org.knime.core.node.ExecutionMonitor) WorkflowLoadResult(org.knime.core.node.workflow.WorkflowPersistor.WorkflowLoadResult)

Example 9 with WorkflowLoadResult

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

the class BatchExecutor method loadWorkflow.

/**
 * Loads a single workflow.
 *
 * @param config the workflow configuration
 * @return the workflow manager representing the loaded workflow
 * @throws IOException if an I/O error occurs while loading the workflow
 * @throws InvalidSettingsException if some node or workflow settings are invalid
 * @throws CanceledExecutionException if loading the workflow is canceled by the user (should not happen in batch
 *             mode)
 * @throws UnsupportedWorkflowVersionException if the workflow version is not supported
 * @throws LockFailedException if the workflow cannot be locked
 * @throws IllegalOptionException if a node option is invalid
 * @since 2.7
 */
protected WorkflowManager loadWorkflow(final WorkflowConfiguration config) throws IOException, InvalidSettingsException, CanceledExecutionException, UnsupportedWorkflowVersionException, LockFailedException, IllegalOptionException {
    if (config.inputWorkflow.isFile()) {
        File dir = FileUtil.createTempDir("BatchExecutorInput");
        FileUtil.unzip(config.inputWorkflow, dir);
        config.workflowLocation = dir;
    } else {
        config.workflowLocation = config.inputWorkflow;
    }
    // exported to a zip using the wizard)
    if (!new File(config.workflowLocation, WorkflowPersistor.WORKFLOW_FILE).exists()) {
        File[] children = config.workflowLocation.listFiles();
        if (children.length == 0) {
            throw new IOException("No workflow directory at " + config.workflowLocation);
        } else {
            config.workflowLocation = config.workflowLocation.listFiles()[0];
        }
    }
    BatchExecWorkflowLoadHelper batchLH = new BatchExecWorkflowLoadHelper(config.credentials, config.workflowLocation);
    WorkflowLoadResult loadResult = WorkflowManager.loadProject(config.workflowLocation, new ExecutionMonitor(), batchLH);
    WorkflowManager wfm = loadResult.getWorkflowManager();
    if (config.failOnLoadError && loadResult.hasErrors()) {
        if (wfm != null) {
            wfm.getParent().removeProject(wfm.getID());
        }
        LOGGER.error(loadResult.getFilteredError("", LoadResultEntryType.Error));
        throw new IOException("Error(s) during workflow loading. Check log file for details.");
    }
    BatchExecWorkflowTemplateLoadHelper batchTemplateLH = new BatchExecWorkflowTemplateLoadHelper(batchLH);
    if (config.updateMetanodeLinks) {
        LOGGER.debug("Checking for metanode link updates...");
        try {
            wfm.updateMetaNodeLinks(batchTemplateLH, config.failOnLoadError, new ExecutionMonitor());
        } catch (IOException ex) {
            wfm.getParent().removeProject(wfm.getID());
            throw ex;
        }
        LOGGER.debug("Checking for metanode link updates... done");
    }
    if (!config.flowVariables.isEmpty()) {
        applyWorkflowVariables(wfm, config.reset, config.flowVariables);
    }
    if (config.reset) {
        wfm.resetAndConfigureAll();
        LOGGER.debug("Workflow reset done.");
    }
    try {
        setNodeOptions(config.nodeOptions, wfm);
    } catch (IllegalOptionException ex) {
        wfm.getParent().removeProject(wfm.getID());
        throw ex;
    } catch (InvalidSettingsException ex) {
        wfm.getParent().removeProject(wfm.getID());
        throw ex;
    }
    return wfm;
}
Also used : InvalidSettingsException(org.knime.core.node.InvalidSettingsException) IOException(java.io.IOException) ExecutionMonitor(org.knime.core.node.ExecutionMonitor) File(java.io.File) WorkflowLoadResult(org.knime.core.node.workflow.WorkflowPersistor.WorkflowLoadResult)

Example 10 with WorkflowLoadResult

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

the class WorkflowManager method load.

/**
 * Loads the content of the argument persistor into this node.
 *
 * @param persistor The persistor containing the node(s) to be loaded as children to this node.
 * @param exec For progress/cancellation (currently not supported)
 * @param keepNodeMessages Whether to keep the messages that are associated with the nodes in the loaded workflow
 *            (mostly false but true when remotely computed results are loaded).
 * @return A workflow load result, which also contains the loaded node(s).
 * @throws IOException If errors reading the "important" files fails due to I/O problems (file not present, e.g.)
 * @throws InvalidSettingsException If parsing the "important" files fails.
 * @throws CanceledExecutionException If canceled.
 * @throws UnsupportedWorkflowVersionException If the version of the workflow is unknown (future version)
 */
public WorkflowLoadResult load(final FileWorkflowPersistor persistor, final ExecutionMonitor exec, final boolean keepNodeMessages) throws IOException, InvalidSettingsException, CanceledExecutionException, UnsupportedWorkflowVersionException {
    final ReferencedFile refDirectory = persistor.getMetaPersistor().getNodeContainerDirectory();
    final File directory = refDirectory.getFile();
    final WorkflowLoadResult result = new WorkflowLoadResult(directory.getName());
    load(persistor, result, exec, keepNodeMessages);
    final WorkflowManager manager = result.getWorkflowManager();
    if (!directory.canWrite()) {
        result.addWarning("Workflow directory \"" + directory.getName() + "\" is read-only; saving a modified workflow " + "will not be possible");
        manager.m_isWorkflowDirectoryReadonly = true;
    }
    boolean fixDataLoadProblems = false;
    // check for it and silently overwrite the workflow
    switch(result.getType()) {
        case DataLoadError:
            if (!persistor.mustWarnOnDataLoadError() && !manager.m_isWorkflowDirectoryReadonly) {
                LOGGER.debug("Workflow was apparently ex/imported without " + "data, silently fixing states and writing changes");
                try {
                    manager.save(directory, new ExecutionMonitor(), true);
                    fixDataLoadProblems = true;
                } catch (Throwable t) {
                    LOGGER.warn("Failed in an attempt to write workflow to file (workflow was ex/imported " + "without data; could not write the \"corrected\" flow.)", t);
                }
            }
            break;
        default:
    }
    StringBuilder message = new StringBuilder("Loaded workflow from \"");
    message.append(directory.getAbsolutePath()).append("\" ");
    switch(result.getType()) {
        case Ok:
            message.append(" with no errors");
            break;
        case Warning:
            message.append(" with warnings");
            break;
        case DataLoadError:
            message.append(" with errors during data load. ");
            if (fixDataLoadProblems) {
                message.append("Problems were fixed and (silently) saved.");
            } else {
                message.append("Problems were fixed but not saved!");
            }
            break;
        case Error:
            message.append(" with errors");
            break;
        default:
            message.append("with ").append(result.getType());
    }
    LOGGER.debug(message.toString());
    return result;
}
Also used : ExecutionMonitor(org.knime.core.node.ExecutionMonitor) ReferencedFile(org.knime.core.internal.ReferencedFile) ReferencedFile(org.knime.core.internal.ReferencedFile) File(java.io.File) WorkflowLoadResult(org.knime.core.node.workflow.WorkflowPersistor.WorkflowLoadResult)

Aggregations

WorkflowLoadResult (org.knime.core.node.workflow.WorkflowPersistor.WorkflowLoadResult)17 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)15 File (java.io.File)6 Test (org.junit.Test)6 IOException (java.io.IOException)4 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 LoadVersion (org.knime.core.node.workflow.FileWorkflowPersistor.LoadVersion)2 Version (org.knime.core.util.Version)2 FileNotFoundException (java.io.FileNotFoundException)1 ReentrantLock (java.util.concurrent.locks.ReentrantLock)1 AssertionFailedError (junit.framework.AssertionFailedError)1 IStatus (org.eclipse.core.runtime.IStatus)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1 Display (org.eclipse.swt.widgets.Display)1 BeforeClass (org.junit.BeforeClass)1 ReferencedFile (org.knime.core.internal.ReferencedFile)1 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)1 NodeID (org.knime.core.node.workflow.NodeID)1 UnsupportedWorkflowVersionException (org.knime.core.node.workflow.UnsupportedWorkflowVersionException)1 WorkflowContext (org.knime.core.node.workflow.WorkflowContext)1