use of com.flink.platform.common.graph.DAG in project flink-platform-backend by itinycheng.
the class JobFlowDagHelper method isPreconditionSatisfied.
public static boolean isPreconditionSatisfied(JobVertex toVertex, DAG<Long, JobVertex, JobEdge> dag) {
Collection<JobVertex> preVertices = dag.getPreVertices(toVertex);
if (CollectionUtils.isEmpty(preVertices)) {
return true;
}
ExecutionCondition precondition = toVertex.getPrecondition();
if (precondition == AND) {
return preVertices.stream().allMatch(fromVertex -> fromVertex.getJobRunStatus() == dag.getEdge(fromVertex, toVertex).getExpectStatus());
} else if (precondition == OR) {
return preVertices.stream().anyMatch(fromVertex -> fromVertex.getJobRunStatus() == dag.getEdge(fromVertex, toVertex).getExpectStatus());
} else {
throw new IllegalStateException("Can't handle precondition status: " + precondition);
}
}
use of com.flink.platform.common.graph.DAG in project flink-platform-backend by itinycheng.
the class JobFlowDagHelper method getNextExecutableVertices.
private static Set<JobVertex> getNextExecutableVertices(Collection<JobVertex> fromVertices, DAG<Long, JobVertex, JobEdge> dag) {
// Get the edges whose status matched his formVertex's status.
Set<JobEdge> statusMatchedEdgeSet = fromVertices.stream().flatMap(fromVertex -> dag.getEdgesFromVertex(fromVertex).stream().map(edge -> edge.unwrap(JobEdge.class)).filter(edge -> edge.getExpectStatus() == fromVertex.getJobRunStatus())).collect(toSet());
// Get the executable vertices.
Set<JobVertex> executableToVertices = statusMatchedEdgeSet.stream().map(edge -> dag.getVertex(edge.getToVId())).filter(toVertex -> isPreconditionSatisfied(toVertex, dag)).collect(toSet());
// If toVertex is executed, use it as fromVertex to find the next executable vertex.
Set<JobVertex> executedVertices = new HashSet<>();
Set<JobVertex> unExecutedVertices = new HashSet<>();
for (JobVertex executableToVertex : executableToVertices) {
if (executableToVertex.getJobRunStatus() != null) {
executedVertices.add(executableToVertex);
} else {
unExecutedVertices.add(executableToVertex);
}
}
if (CollectionUtils.isNotEmpty(executedVertices)) {
unExecutedVertices.addAll(getNextExecutableVertices(executedVertices, dag));
}
return unExecutedVertices;
}
Aggregations