use of org.knime.core.node.workflow.NodeExecutionJobManager in project knime-core by knime.
the class WorkflowEditor method updateJobManagerDisplay.
private void updateJobManagerDisplay() {
NodeExecutionJobManager jobManager = m_manager.findJobManager();
URL url;
if (jobManager instanceof AbstractNodeExecutionJobManager) {
url = ((AbstractNodeExecutionJobManager) jobManager).getIconForWorkflow();
} else {
url = null;
}
Image image;
if (url != null) {
image = ImageRepository.getUnscaledImage(url);
} else {
image = null;
}
WorkflowFigure workflowFigure = ((WorkflowRootEditPart) getViewer().getRootEditPart().getContents()).getFigure();
workflowFigure.setJobManagerFigure(image);
}
use of org.knime.core.node.workflow.NodeExecutionJobManager in project knime-core by knime.
the class NodeExecutionJobManagerPool method merge.
/**
* Get the common settings for a set of job managers.
* Used from {@link WorkflowManager#getCommonSettings(org.knime.core.node.workflow.NodeID...)}.
* @param jobManagers ...
* @return ...
* @since 2.7
*/
public static NodeContainerSettings merge(final NodeExecutionJobManager[] jobManagers) {
String factoryID = null;
NodeSettings mgrSettings = null;
boolean isFirst = true;
for (NodeExecutionJobManager jobManager : jobManagers) {
String curFactoryID;
NodeSettings curMgrSettings;
if (jobManager == null) {
curFactoryID = null;
curMgrSettings = null;
} else {
curFactoryID = jobManager.getID();
NodeSettings temp = new NodeSettings(CFG_JOB_MANAGER_SETTINGS);
jobManager.save(temp);
curMgrSettings = temp;
}
if (isFirst) {
isFirst = false;
factoryID = curFactoryID;
mgrSettings = curMgrSettings;
} else if (ConvenienceMethods.areEqual(factoryID, curFactoryID)) {
if (!ConvenienceMethods.areEqual(mgrSettings, curMgrSettings)) {
mgrSettings = null;
}
} else {
// different job managers
// unassigned
curFactoryID = null;
}
}
if (factoryID == null) {
return null;
}
NodeExecutionJobManagerFactory jobManagerFactory = getJobManagerFactory(factoryID);
assert jobManagerFactory != null : "Factory ID " + factoryID + " unknown although job manager present";
NodeExecutionJobManager instance = jobManagerFactory.getInstance();
if (mgrSettings != null) {
try {
instance.load(mgrSettings);
} catch (InvalidSettingsException e) {
LOGGER.error("Settings could not be applied to job manager although " + "they retrieved from another identical instance.", e);
}
}
NodeContainerSettings result = new NodeContainerSettings();
result.setJobManager(instance);
return result;
}
use of org.knime.core.node.workflow.NodeExecutionJobManager in project knime-core by knime.
the class SandboxedNodeCreator method createSandbox.
/**
* Creates that temporary mini workflow that is executed remotely on the cluster/stream executor.
* The returned value should be {@link SandboxedNode#close()} when done (using try-with-resources). After this
* method is called no other set-method should be called.
*
* @param exec for progress/cancelation
* @return the index of the node that represents this node (the node to execute) in the temporary mini workflow
* @throws InvalidSettingsException
* @throws IOException
* @throws CanceledExecutionException
* @throws LockFailedException
* @throws InterruptedException
*/
public SandboxedNode createSandbox(final ExecutionMonitor exec) throws InvalidSettingsException, IOException, CanceledExecutionException, LockFailedException, InterruptedException {
exec.setMessage("Creating virtual workflow");
final WorkflowManager parent = m_nc.getParent();
// derive workflow context via NodeContext as the parent could only a be a metanode in a metanode...
final WorkflowContext origContext = NodeContext.getContext().getWorkflowManager().getContext();
WorkflowContext.Factory ctxFactory;
// (specifically reading knime://knime.workflow files)
if (!m_copyDataIntoNewContext) {
ctxFactory = origContext.createCopy();
if (m_localWorkflowDir != null) {
ctxFactory.setOriginalLocation(origContext.getCurrentLocation()).setCurrentLocation(m_localWorkflowDir);
}
} else if (m_localWorkflowDir != null) {
ctxFactory = new WorkflowContext.Factory(m_localWorkflowDir);
} else {
ctxFactory = new WorkflowContext.Factory(FileUtil.createTempDir("sandbox-" + m_nc.getNameWithID()));
}
// We have to use the same location for the temporary files
ctxFactory.setTempLocation(origContext.getTempLocation());
origContext.getMountpointURI().ifPresent(u -> ctxFactory.setMountpointURI(u));
WorkflowCreationHelper creationHelper = new WorkflowCreationHelper();
creationHelper.setWorkflowContext(ctxFactory.createContext());
if (!m_copyDataIntoNewContext) {
creationHelper.setWorkflowDataRepository(parent.getWorkflowDataRepository());
}
WorkflowManager tempWFM = m_rootWFM.createAndAddProject("Sandbox Exec on " + m_nc.getNameWithID(), creationHelper);
// Add the workflow variables
List<FlowVariable> workflowVariables = parent.getProjectWFM().getWorkflowVariables();
tempWFM.addWorkflowVariables(true, workflowVariables.toArray(new FlowVariable[workflowVariables.size()]));
// update credentials store of the workflow
CredentialsStore cs = tempWFM.getCredentialsStore();
workflowVariables.stream().filter(f -> f.getType().equals(FlowVariable.Type.CREDENTIALS)).filter(f -> !cs.contains(f.getName())).forEach(cs::addFromFlowVariable);
final int inCnt = m_inData.length;
// port object IDs in static port object map, one entry for
// each connected input (no value for unconnected optional inputs)
List<UUID> portObjectRepositoryIDs = new ArrayList<>(inCnt);
try {
NodeID[] ins = new NodeID[inCnt];
for (int i = 0; i < inCnt; i++) {
final PortObject in = m_inData[i];
final NodeInPort inPort = m_nc.getInPort(i);
final PortType portType = inPort.getPortType();
if (in == null) {
// unconnected optional input
CheckUtils.checkState(portType.isOptional(), "No data at port %d, although port is mandatory (port type %s)", i, portType.getName());
continue;
}
List<FlowVariable> flowVars = getFlowVariablesOnPort(i);
UUID portObjectRepositoryID = PortObjectRepository.add(in);
PortObjectIDSettings settings = new PortObjectIDSettings();
settings.setId(portObjectRepositoryID);
settings.setCopyData(m_copyDataIntoNewContext);
settings.setFlowVariables(flowVars);
portObjectRepositoryIDs.add(portObjectRepositoryID);
boolean isTable = BufferedDataTable.TYPE.equals(portType);
NodeID inID = tempWFM.createAndAddNode(isTable ? TABLE_READ_NODE_FACTORY : OBJECT_READ_NODE_FACTORY);
NodeSettings s = new NodeSettings("temp_data_in");
tempWFM.saveNodeSettings(inID, s);
PortObjectInNodeModel.setInputNodeSettings(s, settings);
// update credentials store of the workflow
flowVars.stream().filter(f -> f.getType().equals(FlowVariable.Type.CREDENTIALS)).filter(f -> !cs.contains(f.getName())).forEach(cs::addFromFlowVariable);
tempWFM.loadNodeSettings(inID, s);
ins[i] = inID;
}
// execute inPort object nodes to store the input data in them
if (ins.length > 0 && !tempWFM.executeAllAndWaitUntilDoneInterruptibly()) {
String error = "Unable to execute virtual workflow, status sent to log facilities";
LOGGER.debug(error + ":");
LOGGER.debug(tempWFM.toString());
throw new RuntimeException(error);
}
// add the target node to the workflow
WorkflowCopyContent.Builder content = WorkflowCopyContent.builder();
content.setNodeIDs(m_nc.getID());
final NodeID targetNodeID = tempWFM.copyFromAndPasteHere(parent, content.build()).getNodeIDs()[0];
NodeContainer targetNode = tempWFM.getNodeContainer(targetNodeID);
// connect target node to inPort object nodes, skipping unconnected (optional) inputs
IntStream.range(0, inCnt).filter(i -> ins[i] != null).forEach(i -> tempWFM.addConnection(ins[i], 1, targetNodeID, i));
if (m_forwardConnectionProgressEvents) {
setupConnectionProgressEventListeners(m_nc, targetNode);
}
// copy the existing tables into the (meta) node (e.g. an executed file reader that's necessary
// for other nodes to execute)
exec.setMessage("Copying tables into temp flow");
NodeContainerExecutionResult origResult = m_nc.createExecutionResult(exec);
ExecutionMonitor copyExec = exec.createSubProgress(0.0);
copyExistingTablesIntoSandboxContainer(origResult, m_nc, targetNode, copyExec, m_copyDataIntoNewContext);
CopyContentIntoTempFlowNodeExecutionJobManager copyDataIntoTmpFlow = new CopyContentIntoTempFlowNodeExecutionJobManager(origResult);
NodeExecutionJobManager oldJobManager = targetNode.getJobManager();
tempWFM.setJobManager(targetNodeID, copyDataIntoTmpFlow);
tempWFM.executeAllAndWaitUntilDoneInterruptibly();
tempWFM.setJobManager(targetNodeID, oldJobManager);
// do not use the cluster executor on the cluster...
tempWFM.setJobManager(targetNodeID, NodeExecutionJobManagerPool.getDefaultJobManagerFactory().getInstance());
if (!m_copyDataIntoNewContext) {
copyFileStoreHandlerReference(targetNode, parent, false);
}
// save workflow in the local job dir
if (m_localWorkflowDir != null) {
tempWFM.save(m_localWorkflowDir, exec, true);
deepCopyFilesInWorkflowDir(m_nc, tempWFM);
}
return new SandboxedNode(tempWFM, targetNodeID);
} finally {
portObjectRepositoryIDs.stream().forEach(PortObjectRepository::remove);
}
}
use of org.knime.core.node.workflow.NodeExecutionJobManager in project knime-core by knime.
the class NodeContainerEditPart method updateJobManagerIcon.
private void updateJobManagerIcon() {
NodeContainerUI nc = getNodeContainer();
NodeExecutionJobManager jobManager = nc.getJobManager();
URL iconURL;
if (jobManager != null) {
iconURL = jobManager.getIcon();
} else {
NodeExecutionJobManager parentJobManager = nc.findJobManager();
if (parentJobManager instanceof AbstractNodeExecutionJobManager) {
if (Wrapper.wraps(nc, NodeContainer.class)) {
iconURL = ((AbstractNodeExecutionJobManager) parentJobManager).getIconForChild(Wrapper.unwrapNC(nc));
} else {
iconURL = null;
}
} else {
iconURL = null;
}
}
Image icon = null;
if (iconURL != null) {
icon = ImageDescriptor.createFromURL(iconURL).createImage();
}
((NodeContainerFigure) getFigure()).setJobExecutorIcon(icon);
}
use of org.knime.core.node.workflow.NodeExecutionJobManager in project knime-core by knime.
the class NodeExecutionJobManagerPool method load.
/**
* Restores a job manager given the parameters contained in the argument
* settings.
*
* @param sncSettings To load from.
* @return A customized job manager or the default one if no settings were
* stored.
* @throws InvalidSettingsException If that fails.
*/
public static NodeExecutionJobManager load(final NodeSettingsRO sncSettings) throws InvalidSettingsException {
String jobManagerID = sncSettings.getString(CFG_JOB_MANAGER_FACTORY_ID);
NodeExecutionJobManagerFactory reference = getJobManagerFactory(jobManagerID);
if (reference == null) {
throw new InvalidSettingsException("Unknown job manager factory id \"" + jobManagerID + "\" (job manager factory possibly not installed?)");
}
NodeSettingsRO sub = sncSettings.getNodeSettings(CFG_JOB_MANAGER_SETTINGS);
NodeExecutionJobManager jobManager = reference.getInstance();
jobManager.load(sub);
return jobManager;
}
Aggregations