-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
StepFunctions: Add Support for MaxConcurrencyPath (#10705)
- Loading branch information
Showing
17 changed files
with
2,777 additions
and
2,006 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,899 changes: 955 additions & 944 deletions
1,899
localstack/services/stepfunctions/asl/antlr/runtime/ASLLexer.py
Large diffs are not rendered by default.
Oops, something went wrong.
2,150 changes: 1,113 additions & 1,037 deletions
2,150
localstack/services/stepfunctions/asl/antlr/runtime/ASLParser.py
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 75 additions & 5 deletions
80
...k/services/stepfunctions/asl/component/state/state_execution/state_map/max_concurrency.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,80 @@ | ||
import abc | ||
from typing import Final | ||
|
||
from localstack.services.stepfunctions.asl.component.component import Component | ||
from localstack.aws.api.stepfunctions import ExecutionFailedEventDetails, HistoryEventType | ||
from localstack.services.stepfunctions.asl.component.common.error_name.failure_event import ( | ||
FailureEvent, | ||
FailureEventException, | ||
) | ||
from localstack.services.stepfunctions.asl.component.common.error_name.states_error_name import ( | ||
StatesErrorName, | ||
) | ||
from localstack.services.stepfunctions.asl.component.common.error_name.states_error_name_type import ( | ||
StatesErrorNameType, | ||
) | ||
from localstack.services.stepfunctions.asl.component.eval_component import EvalComponent | ||
from localstack.services.stepfunctions.asl.eval.environment import Environment | ||
from localstack.services.stepfunctions.asl.eval.event.event_detail import EventDetails | ||
from localstack.services.stepfunctions.asl.utils.encoding import to_json_str | ||
from localstack.services.stepfunctions.asl.utils.json_path import JSONPathUtils | ||
|
||
DEFAULT_MAX_CONCURRENCY_VALUE: Final[int] = 0 # No limit. | ||
|
||
class MaxConcurrency(Component): | ||
DEFAULT: Final[int] = 0 # No limit. | ||
|
||
def __init__(self, num: int = DEFAULT): | ||
self.num: Final[int] = num | ||
class MaxConcurrencyDecl(EvalComponent, abc.ABC): | ||
@abc.abstractmethod | ||
def _eval_max_concurrency(self, env: Environment) -> int: ... | ||
|
||
def _eval_body(self, env: Environment) -> None: | ||
max_concurrency_value = self._eval_max_concurrency(env=env) | ||
env.stack.append(max_concurrency_value) | ||
|
||
|
||
class MaxConcurrency(MaxConcurrencyDecl): | ||
max_concurrency_value: Final[int] | ||
|
||
def __init__(self, num: int = DEFAULT_MAX_CONCURRENCY_VALUE): | ||
super().__init__() | ||
self.max_concurrency_value = num | ||
|
||
def _eval_max_concurrency(self, env: Environment) -> int: | ||
return self.max_concurrency_value | ||
|
||
|
||
class MaxConcurrencyPath(MaxConcurrency): | ||
max_concurrency_path: Final[str] | ||
|
||
def __init__(self, max_concurrency_path: str): | ||
super().__init__() | ||
self.max_concurrency_path = max_concurrency_path | ||
|
||
def _eval_max_concurrency(self, env: Environment) -> int: | ||
inp = env.stack[-1] | ||
max_concurrency_value = JSONPathUtils.extract_json(self.max_concurrency_path, inp) | ||
|
||
error_cause = None | ||
if not isinstance(max_concurrency_value, int): | ||
value_str = ( | ||
to_json_str(max_concurrency_value) | ||
if not isinstance(max_concurrency_value, str) | ||
else max_concurrency_value | ||
) | ||
error_cause = f'The MaxConcurrencyPath field refers to value "{value_str}" which is not a valid integer: {self.max_concurrency_path}' | ||
elif max_concurrency_value < 0: | ||
error_cause = f"Expected non-negative integer for MaxConcurrency, got '{max_concurrency_value}' instead." | ||
|
||
if error_cause is not None: | ||
raise FailureEventException( | ||
failure_event=FailureEvent( | ||
env=env, | ||
error_name=StatesErrorName(typ=StatesErrorNameType.StatesRuntime), | ||
event_type=HistoryEventType.ExecutionFailed, | ||
event_details=EventDetails( | ||
executionFailedEventDetails=ExecutionFailedEventDetails( | ||
error=StatesErrorNameType.StatesRuntime.to_name(), cause=error_cause | ||
) | ||
), | ||
) | ||
) | ||
|
||
return max_concurrency_value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...s/aws/services/stepfunctions/templates/scenarios/statemachines/max_concurrency_path.json5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"Comment": "MAX_CONCURRENCY_PATH", | ||
"StartAt": "MapState", | ||
"States": { | ||
"MapState": { | ||
"Type": "Map", | ||
"ItemsPath": "$.Values", | ||
"MaxConcurrencyPath": "$.MaxConcurrencyValue", | ||
"ItemProcessor": { | ||
"ProcessorConfig": { | ||
"Mode": "INLINE" | ||
}, | ||
"StartAt": "HandleItem", | ||
"States": { | ||
"HandleItem": { | ||
"Type": "Pass", | ||
"End": true | ||
} | ||
} | ||
}, | ||
"Next": "Final", | ||
}, | ||
"Final": { | ||
"Type": "Pass", | ||
"End": true | ||
} | ||
} | ||
} |
Oops, something went wrong.