@ -98,14 +98,16 @@ public class DagHelper {
List < TaskNode > childNodeList = new ArrayList < > ( ) ;
List < TaskNode > childNodeList = new ArrayList < > ( ) ;
if ( startNode = = null ) {
if ( startNode = = null ) {
logger . error ( "start node name [{}] is not in task node list [{}] " ,
logger . error ( "start node name [{}] is not in task node list [{}] " ,
startNodeName ,
startNodeName ,
taskNodeList
taskNodeList
) ;
) ;
continue ;
continue ;
} else if ( TaskDependType . TASK_POST = = taskDependType ) {
} else if ( TaskDependType . TASK_POST = = taskDependType ) {
childNodeList = getFlowNodeListPost ( startNode , taskNodeList ) ;
List < String > visitedNodeNameList = new ArrayList < > ( ) ;
childNodeList = getFlowNodeListPost ( startNode , taskNodeList , visitedNodeNameList ) ;
} else if ( TaskDependType . TASK_PRE = = taskDependType ) {
} else if ( TaskDependType . TASK_PRE = = taskDependType ) {
childNodeList = getFlowNodeListPre ( startNode , recoveryNodeNameList , taskNodeList ) ;
List < String > visitedNodeNameList = new ArrayList < > ( ) ;
childNodeList = getFlowNodeListPre ( startNode , recoveryNodeNameList , taskNodeList , visitedNodeNameList ) ;
} else {
} else {
childNodeList . add ( startNode ) ;
childNodeList . add ( startNode ) ;
}
}
@ -128,14 +130,19 @@ public class DagHelper {
* @param taskNodeList taskNodeList
* @param taskNodeList taskNodeList
* @return task node list
* @return task node list
* /
* /
private static List < TaskNode > getFlowNodeListPost ( TaskNode startNode , List < TaskNode > taskNodeList ) {
private static List < TaskNode > getFlowNodeListPost ( TaskNode startNode , List < TaskNode > taskNodeList , List < String > visitedNodeNameList ) {
List < TaskNode > resultList = new ArrayList < > ( ) ;
List < TaskNode > resultList = new ArrayList < > ( ) ;
for ( TaskNode taskNode : taskNodeList ) {
for ( TaskNode taskNode : taskNodeList ) {
List < String > depList = taskNode . getDepList ( ) ;
List < String > depList = taskNode . getDepList ( ) ;
if ( null ! = depList & & null ! = startNode & & depList . contains ( startNode . getName ( ) ) ) {
if ( null ! = depList & & null ! = startNode & & depList . contains ( startNode . getName ( ) ) & & ! visitedNodeNameList . contains ( taskNode . getName ( ) ) ) {
resultList . addAll ( getFlowNodeListPost ( taskNode , taskNodeList ) ) ;
resultList . addAll ( getFlowNodeListPost ( taskNode , taskNodeList , visitedNodeNameList ) ) ;
}
}
}
}
// why add (startNode != null) condition? for SonarCloud Quality Gate passed
if ( null ! = startNode ) {
visitedNodeNameList . add ( startNode . getName ( ) ) ;
}
resultList . add ( startNode ) ;
resultList . add ( startNode ) ;
return resultList ;
return resultList ;
}
}
@ -148,7 +155,7 @@ public class DagHelper {
* @param taskNodeList taskNodeList
* @param taskNodeList taskNodeList
* @return task node list
* @return task node list
* /
* /
private static List < TaskNode > getFlowNodeListPre ( TaskNode startNode , List < String > recoveryNodeNameList , List < TaskNode > taskNodeList ) {
private static List < TaskNode > getFlowNodeListPre ( TaskNode startNode , List < String > recoveryNodeNameList , List < TaskNode > taskNodeList , List < String > visitedNodeNameList ) {
List < TaskNode > resultList = new ArrayList < > ( ) ;
List < TaskNode > resultList = new ArrayList < > ( ) ;
@ -158,16 +165,23 @@ public class DagHelper {
resultList . add ( startNode ) ;
resultList . add ( startNode ) ;
}
}
if ( CollectionUtils . isEmpty ( depList ) ) {
if ( CollectionUtils . isEmpty ( depList ) ) {
if ( null ! = startNode ) {
visitedNodeNameList . add ( startNode . getName ( ) ) ;
}
return resultList ;
return resultList ;
}
}
for ( String depNodeName : depList ) {
for ( String depNodeName : depList ) {
TaskNode start = findNodeByName ( taskNodeList , depNodeName ) ;
TaskNode start = findNodeByName ( taskNodeList , depNodeName ) ;
if ( recoveryNodeNameList . contains ( depNodeName ) ) {
if ( recoveryNodeNameList . contains ( depNodeName ) ) {
resultList . add ( start ) ;
resultList . add ( start ) ;
} else {
} else if ( ! visitedNodeNameList . contains ( depNodeName ) ) {
resultList . addAll ( getFlowNodeListPre ( start , recoveryNodeNameList , taskNodeList ) ) ;
resultList . addAll ( getFlowNodeListPre ( start , recoveryNodeNameList , taskNodeList , visitedNodeNameList ) ) ;
}
}
}
}
// why add (startNode != null) condition? for SonarCloud Quality Gate passed
if ( null ! = startNode ) {
visitedNodeNameList . add ( startNode . getName ( ) ) ;
}
return resultList ;
return resultList ;
}
}
@ -369,7 +383,7 @@ public class DagHelper {
* /
* /
public static boolean haveConditionsAfterNode ( String parentNodeName ,
public static boolean haveConditionsAfterNode ( String parentNodeName ,
DAG < String , TaskNode , TaskNodeRelation > dag
DAG < String , TaskNode , TaskNodeRelation > dag
) {
) {
boolean result = false ;
boolean result = false ;
Set < String > subsequentNodes = dag . getSubsequentNodes ( parentNodeName ) ;
Set < String > subsequentNodes = dag . getSubsequentNodes ( parentNodeName ) ;
if ( CollectionUtils . isEmpty ( subsequentNodes ) ) {
if ( CollectionUtils . isEmpty ( subsequentNodes ) ) {