simple_statelang_with_loop.json 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. {
  2. "Name": "simpleLoopTestStateMachine",
  3. "Comment": "带循环参数的测试状态机定义",
  4. "StartState": "FirstState",
  5. "Version": "0.0.1",
  6. "States": {
  7. "FirstState": {
  8. "Type": "ServiceTask",
  9. "ServiceName": "demoService",
  10. "ServiceMethod": "foo",
  11. "CompensateState": "CompensateFirstState",
  12. "Loop": {
  13. "Parallel": 3,
  14. "Collection": "$.[collection]",
  15. "ElementVariableName": "element",
  16. "ElementIndexName": "loopCounter",
  17. "CompletionCondition": "[nrOfCompletedInstances] == ([collection].size()-4)"
  18. },
  19. "Input": [
  20. {
  21. "loopCounter": "$.[loopCounter]",
  22. "element": "$.[element]",
  23. "throwException": "$.[fooThrowException]"
  24. }
  25. ],
  26. "Output": {
  27. "fooResult": "$.#root"
  28. },
  29. "Next": "ChoiceState"
  30. },
  31. "ChoiceState":{
  32. "Type": "Choice",
  33. "Choices":[
  34. {
  35. "Expression": "[loopResult].?[#this[fooResult] == null].size() == 0 && [a] == 1",
  36. "Next":"SecondState"
  37. },
  38. {
  39. "Expression": "[loopResult].?[#this[fooResult] == null].size() == 0 && [a] == 2",
  40. "Next":"CallSubStateMachine"
  41. }
  42. ],
  43. "Default":"Fail"
  44. },
  45. "SecondState": {
  46. "Type": "ServiceTask",
  47. "ServiceName": "demoService",
  48. "ServiceMethod": "bar",
  49. "CompensateState": "CompensateSecondState",
  50. "Loop": {
  51. "Parallel": 3,
  52. "Collection": "$.[collection]",
  53. "ElementVariableName": "element",
  54. "CompletionCondition": "[nrOfCompletedInstances] / [nrOfInstances] >= 0.4",
  55. "ElementIndexName": "loopCounter"
  56. },
  57. "Input": [
  58. {
  59. "loopCounter": "$.[loopCounter]",
  60. "loopElement": "$.[element]",
  61. "throwException": "$.[barThrowException]"
  62. }
  63. ],
  64. "Catch": [
  65. {
  66. "Exceptions": [
  67. "io.seata.saga.engine.mock.DemoException"
  68. ],
  69. "Next": "CompensationTriggerTest"
  70. }
  71. ]
  72. },
  73. "CallSubStateMachine": {
  74. "Type": "SubStateMachine",
  75. "StateMachineName": "simpleCompensationStateMachine",
  76. "Loop": {
  77. "Parallel": 3,
  78. "Collection": "$.[collection]",
  79. "ElementVariableName": "element",
  80. "CompletionCondition": "[nrOfCompletedInstances] / [nrOfInstances] >= 0.4",
  81. "ElementIndexName": "loopCounter"
  82. },
  83. "Input": [
  84. {
  85. "a": 1,
  86. "collection": "$.[collection]",
  87. "loopCounter": "$.[loopCounter]",
  88. "element": "$.[element]",
  89. "barThrowException": "$.[barThrowException]",
  90. "fooThrowException": "$.[fooThrowException]",
  91. "compensateFooThrowException": "$.[compensateFooThrowException]"
  92. }
  93. ],
  94. "Output": {
  95. "fooResult": "$.#root"
  96. },
  97. "Next": "Succeed"
  98. },
  99. "CompensateFirstState": {
  100. "Type": "ServiceTask",
  101. "ServiceName": "demoService",
  102. "ServiceMethod": "compensateFoo",
  103. "Input": [
  104. {
  105. "compensateFooInput": "$.[fooResult]",
  106. "throwException": "$.[compensateFooThrowException]",
  107. "loopCounter": "$.[loopCounter]",
  108. "element": "$.[element]"
  109. }
  110. ]
  111. },
  112. "CompensateSecondState": {
  113. "Type": "ServiceTask",
  114. "ServiceName": "demoService",
  115. "ServiceMethod": "compensateBar",
  116. "Input": [
  117. {
  118. "compensateBarInput": "$.[barResult]",
  119. "loopCounter": "$.[loopCounter]",
  120. "loopElement": "$.[element]"
  121. }
  122. ]
  123. },
  124. "CompensationTriggerTest": {
  125. "Type": "CompensationTrigger",
  126. "Next": "Fail"
  127. },
  128. "Succeed": {
  129. "Type":"Succeed"
  130. },
  131. "Fail": {
  132. "Type":"Fail",
  133. "ErrorCode": "NOT_FOUND",
  134. "Message": "not found"
  135. }
  136. }
  137. }