use of org.knime.core.node.workflow.InternalNodeContainerState.CONFIGURED in project knime-core by knime.
the class WorkflowManager method computeNewState.
/**
* Derives state of this WFM by inspecting all nodes and computing the corresponding state.
*
* @return the state of the wfm derived from the state of its contained nodes.
*/
InternalNodeContainerState computeNewState() {
assert m_workflowLock.isHeldByCurrentThread();
final Collection<NodeContainer> nodeValues = m_workflow.getNodeValues();
// getting the state from a contained node/workflow will lock that instance, which is expensive (AP-10548)
if (!nodeValues.isEmpty() && //
nodeValues.stream().allMatch(nc -> nc instanceof NodeContainerParent && ((NodeContainerParent) nc).isProject())) {
return IDLE;
}
int[] nrNodesInState = new int[InternalNodeContainerState.values().length];
int nrNodes = 0;
boolean internalNodeHasError = false;
for (NodeContainer ncIt : nodeValues) {
nrNodesInState[ncIt.getInternalState().ordinal()]++;
nrNodes++;
if ((ncIt.getNodeMessage() != null) && (ncIt.getNodeMessage().getMessageType().equals(NodeMessage.Type.ERROR))) {
internalNodeHasError = true;
}
}
// set summarization message if any of the internal nodes has an error
if (internalNodeHasError) {
String summary = getNodeErrorSummary().orElse("An internal error occurred.");
setNodeMessage(new NodeMessage(NodeMessage.Type.ERROR, summary));
} else {
setNodeMessage(NodeMessage.NONE);
}
//
assert nrNodes == m_workflow.getNrNodes();
InternalNodeContainerState newState = IDLE;
// check if all outports are connected
boolean allOutPortsConnected = getNrOutPorts() == m_workflow.getConnectionsByDest(this.getID()).size();
// check if we have complete Objects on outports
boolean allPopulated = false;
// ...and at the same time find the "smallest" common state of all inports (useful when all internal nodes
// are green but we have through connections)!
InternalNodeContainerState inportState = EXECUTED;
if (allOutPortsConnected) {
allPopulated = true;
for (int i = 0; i < getNrOutPorts(); i++) {
NodeOutPort nop = getOutPort(i).getUnderlyingPort();
if (nop == null) {
allPopulated = false;
inportState = IDLE;
} else if (nop.getPortObject() == null) {
allPopulated = false;
switch(nop.getNodeState()) {
case IDLE:
case UNCONFIGURED_MARKEDFOREXEC:
inportState = IDLE;
break;
default:
inportState = CONFIGURED;
}
}
}
}
if (nrNodes == 0) {
// special case: zero nodes!
if (allOutPortsConnected) {
newState = allPopulated ? EXECUTED : CONFIGURED;
} else {
newState = IDLE;
}
} else if (nrNodesInState[EXECUTED.ordinal()] == nrNodes) {
// are connected and contain their portobjects.
if (allPopulated) {
// all nodes in WFM done and all ports populated!
newState = EXECUTED;
} else {
// all executed but some through connections with non-EXECUTED state!
newState = inportState;
}
} else if (nrNodesInState[CONFIGURED.ordinal()] == nrNodes) {
// all (>=1) configured
if (allOutPortsConnected) {
newState = CONFIGURED;
} else {
newState = IDLE;
}
} else if (nrNodesInState[EXECUTED.ordinal()] + nrNodesInState[CONFIGURED.ordinal()] == nrNodes) {
newState = CONFIGURED;
} else if (nrNodesInState[EXECUTING.ordinal()] >= 1) {
newState = EXECUTING;
} else if (nrNodesInState[EXECUTINGREMOTELY.ordinal()] >= 1) {
newState = EXECUTINGREMOTELY;
} else if (nrNodesInState[PREEXECUTE.ordinal()] >= 1) {
newState = EXECUTING;
} else if (nrNodesInState[POSTEXECUTE.ordinal()] >= 1) {
newState = EXECUTING;
} else if (nrNodesInState[CONFIGURED_QUEUED.ordinal()] >= 1) {
newState = EXECUTING;
} else if (nrNodesInState[EXECUTED_QUEUED.ordinal()] >= 1) {
newState = EXECUTING;
} else if (nrNodesInState[UNCONFIGURED_MARKEDFOREXEC.ordinal()] >= 1) {
newState = UNCONFIGURED_MARKEDFOREXEC;
} else if (nrNodesInState[CONFIGURED_MARKEDFOREXEC.ordinal()] + nrNodesInState[EXECUTED_MARKEDFOREXEC.ordinal()] >= 1) {
newState = CONFIGURED_MARKEDFOREXEC;
}
return newState;
}
Aggregations