use of org.knime.core.node.workflow.WorkflowPersistor.WorkflowLoadResult in project knime-core by knime.
the class LoadWorkflowRunnable method run.
/**
* {@inheritDoc}
*/
@Override
public void run(final IProgressMonitor pm) {
// indicates whether to create an empty workflow
// this is done if the file is empty
boolean createEmptyWorkflow = false;
// name of workflow will be null (uses directory name then)
String name = null;
m_throwable = null;
try {
// create progress monitor
ProgressHandler progressHandler = new ProgressHandler(pm, 101, "Loading workflow...");
final CheckCancelNodeProgressMonitor progressMonitor = new CheckCancelNodeProgressMonitor(pm);
progressMonitor.addProgressListener(progressHandler);
File workflowDirectory = m_workflowFile.getParentFile();
Display d = Display.getDefault();
GUIWorkflowLoadHelper loadHelper = new GUIWorkflowLoadHelper(d, workflowDirectory.getName(), m_mountpointURI, workflowDirectory, m_mountpointRoot);
final WorkflowLoadResult result = WorkflowManager.loadProject(workflowDirectory, new ExecutionMonitor(progressMonitor), loadHelper);
final WorkflowManager wm = result.getWorkflowManager();
m_editor.setWorkflowManager(wm);
pm.subTask("Finished.");
pm.done();
if (wm.isDirty()) {
m_editor.markDirty();
}
final IStatus status = createStatus(result, !result.getGUIMustReportDataLoadErrors());
String message;
switch(status.getSeverity()) {
case IStatus.OK:
message = "No problems during load.";
break;
case IStatus.WARNING:
message = "Warnings during load";
logPreseveLineBreaks("Warnings during load: " + result.getFilteredError("", LoadResultEntryType.Warning), false);
break;
default:
message = "Errors during load";
logPreseveLineBreaks("Errors during load: " + result.getFilteredError("", LoadResultEntryType.Warning), true);
}
if (!status.isOK()) {
showLoadErrorDialog(result, status, message);
}
final List<NodeID> linkedMNs = wm.getLinkedMetaNodes(true);
if (!linkedMNs.isEmpty()) {
final WorkflowEditor editor = m_editor;
m_editor.addAfterOpenRunnable(new Runnable() {
@Override
public void run() {
postLoadCheckForMetaNodeUpdates(editor, wm, linkedMNs);
}
});
}
} catch (FileNotFoundException fnfe) {
m_throwable = fnfe;
LOGGER.fatal("File not found", fnfe);
} catch (IOException ioe) {
m_throwable = ioe;
if (m_workflowFile.length() == 0) {
LOGGER.info("New workflow created.");
// this is the only place to set this flag to true: we have an
// empty workflow file, i.e. a new project was created
// bugfix 1555: if an exception is thrown DO NOT create empty
// workflow
createEmptyWorkflow = true;
} else {
LOGGER.error("Could not load workflow from: " + m_workflowFile.getName(), ioe);
}
} catch (InvalidSettingsException ise) {
LOGGER.error("Could not load workflow from: " + m_workflowFile.getName(), ise);
m_throwable = ise;
} catch (UnsupportedWorkflowVersionException uve) {
m_loadingCanceledMessage = INCOMPATIBLE_VERSION_MSG;
LOGGER.info(m_loadingCanceledMessage, uve);
m_editor.setWorkflowManager(null);
} catch (CanceledExecutionException cee) {
m_loadingCanceledMessage = "Canceled loading workflow: " + m_workflowFile.getParentFile().getName();
LOGGER.info(m_loadingCanceledMessage, cee);
m_editor.setWorkflowManager(null);
} catch (LockFailedException lfe) {
StringBuilder error = new StringBuilder();
error.append("Unable to load workflow \"");
error.append(m_workflowFile.getParentFile().getName());
if (m_workflowFile.getParentFile().exists()) {
error.append("\"\nIt is in use by another user/instance.");
} else {
error.append("\"\nLocation does not exist.");
}
m_loadingCanceledMessage = error.toString();
LOGGER.info(m_loadingCanceledMessage, lfe);
m_editor.setWorkflowManager(null);
} catch (Throwable e) {
m_throwable = e;
LOGGER.error("Workflow could not be loaded. " + e.getMessage(), e);
m_editor.setWorkflowManager(null);
} finally {
// (empty workflow file)
if (createEmptyWorkflow) {
WorkflowCreationHelper creationHelper = new WorkflowCreationHelper();
WorkflowContext.Factory fac = new WorkflowContext.Factory(m_workflowFile.getParentFile());
fac.setMountpointRoot(m_mountpointRoot);
fac.setMountpointURI(m_mountpointURI);
creationHelper.setWorkflowContext(fac.createContext());
m_editor.setWorkflowManager(WorkflowManager.ROOT.createAndAddProject(name, creationHelper));
// save empty project immediately
// bugfix 1341 -> see WorkflowEditor line 1294
// (resource delta visitor movedTo)
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
m_editor.doSave(new NullProgressMonitor());
}
});
m_editor.setIsDirty(false);
}
// IMPORTANT: Remove the reference to the file and the
// editor!!! Otherwise the memory cannot be freed later
m_editor = null;
m_workflowFile = null;
m_mountpointRoot = null;
}
}
use of org.knime.core.node.workflow.WorkflowPersistor.WorkflowLoadResult in project knime-core by knime.
the class BugAP5712_CloseWhileStreaming method initWorkflowFromTemp.
private WorkflowLoadResult initWorkflowFromTemp() throws Exception {
// will save the workflow in one of the test ...don't write SVN folder
WorkflowLoadResult loadResult = loadWorkflow(m_workflowDir, new ExecutionMonitor());
setManager(loadResult.getWorkflowManager());
NodeID baseID = getManager().getID();
m_tableView_4 = new NodeID(baseID, 4);
m_streamSubnode_5 = new NodeID(baseID, 5);
return loadResult;
}
use of org.knime.core.node.workflow.WorkflowPersistor.WorkflowLoadResult in project knime-core by knime.
the class BugAP6262_FileStoresInPortObjectCell method testExecuteAfterPartialSave.
@Test(timeout = 300000L)
public void testExecuteAfterPartialSave() throws Exception {
WorkflowManager manager = getManager();
checkState(manager, IDLE);
executeAllAndWait();
checkState(manager, EXECUTED);
manager.save(m_workflowDir, new ExecutionMonitor(), true);
closeWorkflow();
assertNull(getManager());
WorkflowLoadResult loadResult = initWorkflowFromTemp();
manager = getManager();
assertFalse("should not have errors", loadResult.hasErrors());
checkState(manager, EXECUTED);
reset(m_predictorLoopStart_11);
checkState(manager, IDLE);
executeAllAndWait();
checkState(manager, EXECUTED);
}
use of org.knime.core.node.workflow.WorkflowPersistor.WorkflowLoadResult in project knime-core by knime.
the class BugAP7982_FutureKNIMEVersion_AllCompatible method loadWorkflow.
/**
* Load workflow, expect no errors.
*/
@Test
public void loadWorkflow() 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) {
throw new AssertionFailedError("Not to be called - workflow is expected to be compatible");
}
});
setManager(loadWorkflow.getWorkflowManager());
assertThat("Expected to loaded without errors", loadWorkflow.getType(), is(LoadResultEntryType.Ok));
assertThat("Workflow version incorrect", getManager().getLoadVersion(), is(LoadVersion.V280));
}
use of org.knime.core.node.workflow.WorkflowPersistor.WorkflowLoadResult in project knime-core by knime.
the class NodeContextTest method setupClass.
/**
* Unpack and load testflow.
*
* @throws Exception if an error occurs
*/
@BeforeClass
public static void setupClass() throws Exception {
File workflowZip = findInPlugin("/files/NodeContextTestflow.zip");
File tmpDir = FileUtil.createTempDir("NodeContextTest");
tmpDir.deleteOnExit();
FileUtil.unzip(workflowZip, tmpDir);
File workflowDir = tmpDir.listFiles()[0];
WorkflowLoadResult res = WorkflowManager.loadProject(workflowDir, new ExecutionMonitor(), new WorkflowLoadHelper(workflowDir));
if (res.hasErrors()) {
throw new IOException("Error while loading workflow: " + res.getMessage());
}
wfm = res.getWorkflowManager();
executorService = Executors.newSingleThreadExecutor();
}
Aggregations