Search in sources :

Example 1 with DAG

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);
    }
}
Also used : DAG(com.flink.platform.common.graph.DAG) ABNORMAL(com.flink.platform.common.enums.ExecutionStatus.ABNORMAL) Collection(java.util.Collection) Set(java.util.Set) JobVertex(com.flink.platform.common.model.JobVertex) ExecutionCondition(com.flink.platform.common.enums.ExecutionCondition) CollectionUtils(org.apache.commons.collections4.CollectionUtils) RUNNING(com.flink.platform.common.enums.ExecutionStatus.RUNNING) HashSet(java.util.HashSet) Objects(java.util.Objects) ERROR(com.flink.platform.common.enums.ExecutionStatus.ERROR) AND(com.flink.platform.common.enums.ExecutionCondition.AND) ExecutionStatus(com.flink.platform.common.enums.ExecutionStatus) OR(com.flink.platform.common.enums.ExecutionCondition.OR) KILLED(com.flink.platform.common.enums.ExecutionStatus.KILLED) FAILURE(com.flink.platform.common.enums.ExecutionStatus.FAILURE) SUCCESS(com.flink.platform.common.enums.ExecutionStatus.SUCCESS) JobFlowDag(com.flink.platform.dao.entity.JobFlowDag) SUBMITTED(com.flink.platform.common.enums.ExecutionStatus.SUBMITTED) Nonnull(javax.annotation.Nonnull) NOT_EXIST(com.flink.platform.common.enums.ExecutionStatus.NOT_EXIST) JobEdge(com.flink.platform.common.model.JobEdge) Collectors.toSet(java.util.stream.Collectors.toSet) JobVertex(com.flink.platform.common.model.JobVertex) ExecutionCondition(com.flink.platform.common.enums.ExecutionCondition)

Example 2 with DAG

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;
}
Also used : DAG(com.flink.platform.common.graph.DAG) ABNORMAL(com.flink.platform.common.enums.ExecutionStatus.ABNORMAL) Collection(java.util.Collection) Set(java.util.Set) JobVertex(com.flink.platform.common.model.JobVertex) ExecutionCondition(com.flink.platform.common.enums.ExecutionCondition) CollectionUtils(org.apache.commons.collections4.CollectionUtils) RUNNING(com.flink.platform.common.enums.ExecutionStatus.RUNNING) HashSet(java.util.HashSet) Objects(java.util.Objects) ERROR(com.flink.platform.common.enums.ExecutionStatus.ERROR) AND(com.flink.platform.common.enums.ExecutionCondition.AND) ExecutionStatus(com.flink.platform.common.enums.ExecutionStatus) OR(com.flink.platform.common.enums.ExecutionCondition.OR) KILLED(com.flink.platform.common.enums.ExecutionStatus.KILLED) FAILURE(com.flink.platform.common.enums.ExecutionStatus.FAILURE) SUCCESS(com.flink.platform.common.enums.ExecutionStatus.SUCCESS) JobFlowDag(com.flink.platform.dao.entity.JobFlowDag) SUBMITTED(com.flink.platform.common.enums.ExecutionStatus.SUBMITTED) Nonnull(javax.annotation.Nonnull) NOT_EXIST(com.flink.platform.common.enums.ExecutionStatus.NOT_EXIST) JobEdge(com.flink.platform.common.model.JobEdge) Collectors.toSet(java.util.stream.Collectors.toSet) JobVertex(com.flink.platform.common.model.JobVertex) JobEdge(com.flink.platform.common.model.JobEdge) HashSet(java.util.HashSet)

Aggregations

ExecutionCondition (com.flink.platform.common.enums.ExecutionCondition)2 AND (com.flink.platform.common.enums.ExecutionCondition.AND)2 OR (com.flink.platform.common.enums.ExecutionCondition.OR)2 ExecutionStatus (com.flink.platform.common.enums.ExecutionStatus)2 ABNORMAL (com.flink.platform.common.enums.ExecutionStatus.ABNORMAL)2 ERROR (com.flink.platform.common.enums.ExecutionStatus.ERROR)2 FAILURE (com.flink.platform.common.enums.ExecutionStatus.FAILURE)2 KILLED (com.flink.platform.common.enums.ExecutionStatus.KILLED)2 NOT_EXIST (com.flink.platform.common.enums.ExecutionStatus.NOT_EXIST)2 RUNNING (com.flink.platform.common.enums.ExecutionStatus.RUNNING)2 SUBMITTED (com.flink.platform.common.enums.ExecutionStatus.SUBMITTED)2 SUCCESS (com.flink.platform.common.enums.ExecutionStatus.SUCCESS)2 DAG (com.flink.platform.common.graph.DAG)2 JobEdge (com.flink.platform.common.model.JobEdge)2 JobVertex (com.flink.platform.common.model.JobVertex)2 JobFlowDag (com.flink.platform.dao.entity.JobFlowDag)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 Objects (java.util.Objects)2 Set (java.util.Set)2