mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(sfn): accept a decimal ToleratedFailurePercentage at execution (#7297)
* fix(sfn): accept a decimal ToleratedFailurePercentage at execution ToleratedFailurePercentage is a number from 0 to 100, not an integer. Create-time validation already treats it that way, so a definition declaring 100.0 or 12.5 was accepted by CreateStateMachine and then failed every execution of its Distributed Map with States.Runtime "ToleratedFailurePercentage must resolve to an integer of 0 or more". The execution path now resolves the percentage as a decimal, through its literal, its Path or a JSONata expression, rejects values outside 0 to 100, and absorbs floor(itemCount * percentage / 100) failed items. DescribeMapRun reports the declared value unrounded. ToleratedFailureCount is unchanged and stays an integer. * fix(sfn): accept a decimal ToleratedFailurePercentage only as a literal The guide asks for "a value between zero and 100" for the literal, but says the Path "must resolve to a positive integer between 0 and 100 at runtime" and a JSONata expression must evaluate to an integer. The Path and JSONata forms keep main's integer check, and the shared resolveMapField refactor is reverted with them.
This commit is contained in:
1 parent
cd6e516929
commit
7abba35051
4 files changed
+204
-11
No files matched your search
@@ -87,7 +87,9 @@ import jakarta.ws.rs.core.Response;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.math.RoundingMode;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
@@ -3673,12 +3675,14 @@ public class AslExecutor {
|
||||
? resolveToleranceField(stateDef, "ToleratedFailureCount", Integer.MAX_VALUE, mapInput,
|
||||
jsonata, context, variables)
|
||||
: 0;
|
||||
int percentage = hasPercentage
|
||||
? resolveToleranceField(stateDef, "ToleratedFailurePercentage", 100, mapInput, jsonata,
|
||||
context, variables)
|
||||
: 0;
|
||||
BigDecimal percentage = hasPercentage
|
||||
? resolveTolerancePercentage(stateDef, mapInput, jsonata, context, variables)
|
||||
: BigDecimal.ZERO;
|
||||
|
||||
int fromPercentage = (int) ((long) itemCount * percentage / 100);
|
||||
// The run fails once the failed share exceeds the percentage, so the absorbed count is the
|
||||
// floor of itemCount * percentage / 100. BigDecimal keeps a decimal percentage exact.
|
||||
int fromPercentage = BigDecimal.valueOf(itemCount).multiply(percentage)
|
||||
.divide(BigDecimal.valueOf(100), 0, RoundingMode.FLOOR).intValue();
|
||||
int threshold;
|
||||
if (hasCount && hasPercentage) {
|
||||
threshold = Math.min(count, fromPercentage);
|
||||
@@ -3687,7 +3691,28 @@ public class AslExecutor {
|
||||
} else {
|
||||
threshold = fromPercentage;
|
||||
}
|
||||
return new ToleratedFailures(true, count, percentage, threshold);
|
||||
return new ToleratedFailures(true, count, percentage.doubleValue(), threshold);
|
||||
}
|
||||
|
||||
/**
|
||||
* The guide asks for "a value between zero and 100" when ToleratedFailurePercentage is a literal, and
|
||||
* DescribeMapRun models it as a float, so a literal may be a decimal such as {@code 100.0} or
|
||||
* {@code 12.5}. Its Path must resolve to an integer and its JSONata expression must evaluate to one, so
|
||||
* those forms keep the integer check.
|
||||
*/
|
||||
private BigDecimal resolveTolerancePercentage(JsonNode stateDef, JsonNode mapInput, boolean jsonata,
|
||||
JsonNode context, ObjectNode variables) {
|
||||
String field = "ToleratedFailurePercentage";
|
||||
JsonNode literal = stateDef.get(field);
|
||||
if (stateDef.has(field + "Path") || literal == null || !literal.isNumber()) {
|
||||
return BigDecimal.valueOf(resolveToleranceField(stateDef, field, 100, mapInput, jsonata, context,
|
||||
variables));
|
||||
}
|
||||
BigDecimal value = literal.decimalValue();
|
||||
if (value.signum() < 0 || value.compareTo(BigDecimal.valueOf(100)) > 0) {
|
||||
throw new FailStateException("States.Runtime", field + " must be a number between 0 and 100", field);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
/** A tolerance is a percentage or a count, so it shares the Map integer resolver and adds a ceiling. */
|
||||
|
||||
Reference in new issue
Block a user