Skip to content

Commit 416e0df

Browse files
committed
Merge branch 'dev-1.21.0' into dev-1.21.0-hadoop3
2 parents 130e0c6 + 24193ad commit 416e0df

3 files changed

Lines changed: 30 additions & 21 deletions

File tree

dss-orchestrator/orchestrators/dss-workflow/dss-flow-execution-server/src/main/scala/com/webank/wedatasphere/dss/flow/execution/entrance/node/BranchNodeRunner.scala

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,18 @@ class BranchNodeRunner(flow: Workflow) extends NodeRunner with Logging {
134134
}
135135
}
136136
rules.iterator.map { rule =>
137-
val matched = BranchExpressionUtils.evaluateCondition(rule.condition, context)
138-
val selectedTargetName = if (matched) rule.targetName else rule.onFailureTarget
139-
logInfo(s"Branch node ${node.getName} rule evaluated: ${rule.condition}, matched=$matched, selectedTarget=${selectedTargetName.getOrElse("")}")
140-
selectedTargetName.flatMap { targetName =>
141-
val target = matchEdge(targetName)
142-
logInfo(s"Branch node ${node.getName} target lookup: ${targetName}, found=${target.isDefined}")
143-
target
137+
if (!BranchExpressionUtils.isStrictConditionSyntaxValid(rule.condition)) {
138+
logInfo(s"Branch node ${node.getName} skip invalid rule condition: ${rule.condition}")
139+
None
140+
} else {
141+
val matched = BranchExpressionUtils.evaluateCondition(rule.condition, context)
142+
val selectedTargetName = if (matched) rule.targetName else rule.onFailureTarget
143+
logInfo(s"Branch node ${node.getName} rule evaluated: ${rule.condition}, matched=$matched, selectedTarget=${selectedTargetName.getOrElse("")}")
144+
selectedTargetName.flatMap { targetName =>
145+
val target = matchEdge(targetName)
146+
logInfo(s"Branch node ${node.getName} target lookup: ${targetName}, found=${target.isDefined}")
147+
target
148+
}
144149
}
145150
}.find(_.isDefined).flatten
146151
}

dss-orchestrator/orchestrators/dss-workflow/dss-flow-execution-server/src/main/scala/com/webank/wedatasphere/dss/flow/execution/entrance/utils/BranchExpressionUtils.scala

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,20 +146,11 @@ object BranchExpressionUtils extends Logging {
146146

147147
def evaluateCondition(condition: String, context: Map[String, String]): Boolean = {
148148
val normalized = Option(condition).map(_.trim).getOrElse("")
149-
if (normalized.isEmpty) {
149+
if (!isStrictConditionSyntaxValid(normalized)) {
150150
false
151151
} else {
152-
if (normalized.startsWith("${") && normalized.endsWith("}")) {
153-
warn(s"Invalid branch condition syntax, wrapper `$${...}` is not allowed: $condition")
154-
return false
155-
}
156152
val expr = normalized
157-
if (isUnsupportedDefaultKeyword(expr)) return false
158153
val operators = Seq("==", "!=", ">=", "<=", ">", "<")
159-
if (!operators.exists(expr.contains)) {
160-
warn(s"Invalid branch condition syntax, explicit comparison is required: $condition")
161-
return false
162-
}
163154
operators.collectFirst {
164155
case operator if expr.contains(operator) =>
165156
val parts = expr.split(java.util.regex.Pattern.quote(operator), 2).map(_.trim)
@@ -181,6 +172,21 @@ object BranchExpressionUtils extends Logging {
181172
}
182173
}
183174

175+
private val StrictConditionPattern = "^[A-Za-z0-9_.-]+\s*(==|!=|>=|<=|>|<)\s*([A-Za-z0-9_.-]+|\"[^\"]*\"|'[^']*')$".r
176+
177+
def isStrictConditionSyntaxValid(condition: String): Boolean = {
178+
val normalized = Option(condition).map(_.trim).getOrElse("")
179+
if (normalized.isEmpty || isUnsupportedDefaultKeyword(normalized)) {
180+
false
181+
} else {
182+
val valid = StrictConditionPattern.pattern.matcher(normalized).matches()
183+
if (!valid) {
184+
warn(s"Invalid branch condition syntax, explicit comparison expression is required: $condition")
185+
}
186+
valid
187+
}
188+
}
189+
184190
private def stripExpressionWrapper(expression: String): String = {
185191
if (expression.startsWith("${") && expression.endsWith("}")) {
186192
expression.substring(2, expression.length - 1).trim

dss-orchestrator/orchestrators/dss-workflow/dss-workflow-server/src/main/java/com/webank/wedatasphere/dss/workflow/service/impl/DSSFlowServiceImpl.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ public class DSSFlowServiceImpl implements DSSFlowService {
173173
private static final String nodeUIViewIdKey = "viewId";
174174

175175
private static final Pattern pattern = Pattern.compile("^[a-zA-Z][a-zA-Z0-9_-]*$");
176+
private static final Pattern STRICT_BRANCH_CONDITION_PATTERN = Pattern.compile("^[A-Za-z0-9_.-]+\\s*(==|!=|>=|<=|>|<)\\s*([A-Za-z0-9_.-]+|\\"[^\\"]*\\"|'[^']*')$");
176177
private static final String BRANCH_NODE_TYPE = "workflow.branch";
177178

178179
protected Sender getOrchestratorSender() {
@@ -650,10 +651,7 @@ private boolean isStrictBranchCondition(String condition) {
650651
return false;
651652
}
652653
String expr = condition.trim();
653-
if (expr.startsWith("${") && expr.endsWith("}")) {
654-
return false;
655-
}
656-
return expr.contains("==") || expr.contains("!=") || expr.contains(">=") || expr.contains("<=") || expr.contains(">") || expr.contains("<");
654+
return STRICT_BRANCH_CONDITION_PATTERN.matcher(expr).matches();
657655
}
658656

659657
private boolean isUnsupportedDefaultKeyword(String condition) {

0 commit comments

Comments
 (0)