You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@seata.apache.org by "xjlgod (via GitHub)" <gi...@apache.org> on 2024/01/22 14:33:40 UTC

[PR] feature: add serverice task parse in statelang [incubator-seata-go]

xjlgod opened a new pull request, #650:
URL: https://github.com/apache/incubator-seata-go/pull/650

   <!--  Thanks for sending a pull request! 
   -->
   
   **What this PR does**:
   
   This PR involves the serverice task parse in statelang module. At the same time, the parse of other models related to servicetask is also implemented.
   
   **Which issue(s) this PR fixes**:
   <!--
   *Automatically closes linked issue when PR is merged.
   Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
   _If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
   -->
   Fixes #https://github.com/apache/incubator-seata-go/issues/636
   
   **Special notes for your reviewer**:
   There are still some parse functions that have not been implemented in statelang refer to seata-java.
   **Does this PR introduce a user-facing change?**:
   <!--
   If no, just write "NONE" in the release-note block below.
   If yes, a release note is required:
   Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
   -->
   ```release-note
   no change
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@seata.apache.org
For additional commands, e-mail: dev-help@seata.apache.org


Re: [PR] feature: add serverice task parse in statelang [incubator-seata-go]

Posted by "xjlgod (via GitHub)" <gi...@apache.org>.
xjlgod commented on code in PR #650:
URL: https://github.com/apache/incubator-seata-go/pull/650#discussion_r1464991919


##########
pkg/saga/statemachine/statelang/parser/statemachine_parser.go:
##########
@@ -52,22 +41,118 @@ func (b BaseStateParser) GetString(stateName string, stateMap map[string]interfa
 	return valueAsString, nil
 }
 
-func (b BaseStateParser) GetSlice(stateName string, stateMap map[string]interface{}, key string) ([]interface{}, error) {
+func (b BaseStateParser) GetStringOrDefault(stateMap map[string]interface{}, key string, defaultValue string) string {
 	value := stateMap[key]
+	if value == nil {
+		return defaultValue
+	}
+
+	valueAsString, ok := value.(string)
+	if !ok {

Review Comment:
   I throw err in all methods now.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@seata.apache.org
For additional commands, e-mail: dev-help@seata.apache.org


Re: [PR] feature: add serverice task parse in statelang [incubator-seata-go]

Posted by "xjlgod (via GitHub)" <gi...@apache.org>.
xjlgod commented on code in PR #650:
URL: https://github.com/apache/incubator-seata-go/pull/650#discussion_r1464990990


##########
pkg/saga/statemachine/statelang/parser/statemachine_json_parser_test.go:
##########
@@ -11,3 +11,11 @@ func TestParseChoice(t *testing.T) {
 		t.Error("parse fail: " + err.Error())
 	}
 }
+
+func TestParseServiceTask(t *testing.T) {
+	content := "{\n    \"Name\": \"StateMachineNewDesigner\",\n    \"Comment\": \"This state machine is modeled by designer tools.\",\n    \"Version\": \"0.0.1\",\n    \"style\": {\n        \"bounds\": {\n            \"x\": 200,\n            \"y\": 200,\n            \"width\": 36,\n            \"height\": 36\n        }\n    },\n    \"States\": {\n        \"ServiceTask-a9h2o51\": {\n            \"style\": {\n                \"bounds\": {\n                    \"x\": 300,\n                    \"y\": 178,\n                    \"width\": 100,\n                    \"height\": 80\n                }\n            },\n            \"Name\": \"ServiceTask-a9h2o51\",\n            \"IsForCompensation\": false,\n            \"Input\": [\n                {}\n            ],\n            \"Output\": {},\n            \"Status\": {},\n            \"Retry\": [],\n            \"ServiceName\": \"\",\n            \"ServiceMethod\": \"\",\n            \"Type\": \"ServiceTask\",\n            \"Next\": \"Choice-
 4ajl8nt\",\n            \"edge\": {\n                \"Choice-4ajl8nt\": {\n                    \"style\": {\n                        \"waypoints\": [\n                            {\n                                \"original\": {\n                                    \"x\": 400,\n                                    \"y\": 218\n                                },\n                                \"x\": 400,\n                                \"y\": 218\n                            },\n                            {\n                                \"x\": 435,\n                                \"y\": 218\n                            },\n                            {\n                                \"original\": {\n                                    \"x\": 455,\n                                    \"y\": 218\n                                },\n                                \"x\": 455,\n                                \"y\": 218\n                            }\n                        ],
 \n                        \"source\": \"ServiceTask-a9h2o51\",\n                        \"target\": \"Choice-4ajl8nt\"\n                    },\n                    \"Type\": \"Transition\"\n                }\n            },\n            \"CompensateState\": \"CompensateFirstState\"\n        },\n        \"Choice-4ajl8nt\": {\n            \"style\": {\n                \"bounds\": {\n                    \"x\": 455,\n                    \"y\": 193,\n                    \"width\": 50,\n                    \"height\": 50\n                }\n            },\n            \"Name\": \"Choice-4ajl8nt\",\n            \"Type\": \"Choice\",\n            \"Choices\": [\n                {\n                    \"Expression\": \"\",\n                    \"Next\": \"SubStateMachine-cauj9uy\"\n                },\n                {\n                    \"Expression\": \"\",\n                    \"Next\": \"ServiceTask-vdij28l\"\n                }\n            ],\n            \"Default\": \"SubStateMachin
 e-cauj9uy\",\n            \"edge\": {\n                \"SubStateMachine-cauj9uy\": {\n                    \"style\": {\n                        \"waypoints\": [\n                            {\n                                \"original\": {\n                                    \"x\": 505,\n                                    \"y\": 218\n                                },\n                                \"x\": 505,\n                                \"y\": 218\n                            },\n                            {\n                                \"x\": 530,\n                                \"y\": 218\n                            },\n                            {\n                                \"original\": {\n                                    \"x\": 550,\n                                    \"y\": 218\n                                },\n                                \"x\": 550,\n                                \"y\": 218\n                            }\n               
          ],\n                        \"source\": \"Choice-4ajl8nt\",\n                        \"target\": \"SubStateMachine-cauj9uy\"\n                    },\n                    \"Type\": \"ChoiceEntry\"\n                },\n                \"ServiceTask-vdij28l\": {\n                    \"style\": {\n                        \"waypoints\": [\n                            {\n                                \"original\": {\n                                    \"x\": 480,\n                                    \"y\": 243\n                                },\n                                \"x\": 480,\n                                \"y\": 243\n                            },\n                            {\n                                \"x\": 600,\n                                \"y\": 290\n                            },\n                            {\n                                \"original\": {\n                                    \"x\": 600,\n                                    
 \"y\": 310\n                                },\n                                \"x\": 600,\n                                \"y\": 310\n                            }\n                        ],\n                        \"source\": \"Choice-4ajl8nt\",\n                        \"target\": \"ServiceTask-vdij28l\"\n                    },\n                    \"Type\": \"ChoiceEntry\"\n                }\n            }\n        },\n        \"CompensateFirstState\": {\n            \"style\": {\n                \"bounds\": {\n                    \"x\": 300,\n                    \"y\": 310,\n                    \"width\": 100,\n                    \"height\": 80\n                }\n            },\n            \"Name\": \"CompensateFirstState\",\n            \"IsForCompensation\": true,\n            \"Input\": [\n                {}\n            ],\n            \"Output\": {},\n            \"Status\": {},\n            \"Retry\": [],\n            \"ServiceName\": \"\",\n            \"ServiceMe
 thod\": \"\",\n            \"Type\": \"ServiceTask\"\n        },\n        \"SubStateMachine-cauj9uy\": {\n            \"style\": {\n                \"bounds\": {\n                    \"x\": 550,\n                    \"y\": 178,\n                    \"width\": 100,\n                    \"height\": 80\n                }\n            },\n            \"Name\": \"SubStateMachine-cauj9uy\",\n            \"IsForCompensation\": false,\n            \"Input\": [\n                {}\n            ],\n            \"Output\": {},\n            \"Status\": {},\n            \"Retry\": [],\n            \"StateMachineName\": \"\",\n            \"Type\": \"SubStateMachine\",\n            \"Next\": \"Succeed-5x3z98u\",\n            \"edge\": {\n                \"Succeed-5x3z98u\": {\n                    \"style\": {\n                        \"waypoints\": [\n                            {\n                                \"original\": {\n                                    \"x\": 650,\n                  
                   \"y\": 218\n                                },\n                                \"x\": 650,\n                                \"y\": 218\n                            },\n                            {\n                                \"x\": 702,\n                                \"y\": 218\n                            },\n                            {\n                                \"original\": {\n                                    \"x\": 722,\n                                    \"y\": 218\n                                },\n                                \"x\": 722,\n                                \"y\": 218\n                            }\n                        ],\n                        \"source\": \"SubStateMachine-cauj9uy\",\n                        \"target\": \"Succeed-5x3z98u\"\n                    },\n                    \"Type\": \"Transition\"\n                }\n            }\n        },\n        \"ServiceTask-vdij28l\": {\n            \"style\":
  {\n                \"bounds\": {\n                    \"x\": 550,\n                    \"y\": 310,\n                    \"width\": 100,\n                    \"height\": 80\n                }\n            },\n            \"Name\": \"ServiceTask-vdij28l\",\n            \"IsForCompensation\": false,\n            \"Input\": [\n                {}\n            ],\n            \"Output\": {},\n            \"Status\": {},\n            \"Retry\": [],\n            \"ServiceName\": \"\",\n            \"ServiceMethod\": \"\",\n            \"Catch\": [\n                {\n                    \"Exceptions\": [],\n                    \"Next\": \"CompensationTrigger-uldp2ou\"\n                }\n            ],\n            \"Type\": \"ServiceTask\",\n            \"catch\": {\n                \"style\": {\n                    \"bounds\": {\n                        \"x\": 632,\n                        \"y\": 372,\n                        \"width\": 36,\n                        \"height\": 36\n      
               }\n                },\n                \"edge\": {\n                    \"CompensationTrigger-uldp2ou\": {\n                        \"style\": {\n                            \"waypoints\": [\n                                {\n                                    \"original\": {\n                                        \"x\": 668,\n                                        \"y\": 390\n                                    },\n                                    \"x\": 668,\n                                    \"y\": 390\n                                },\n                                {\n                                    \"x\": 702,\n                                    \"y\": 390\n                                },\n                                {\n                                    \"original\": {\n                                        \"x\": 722,\n                                        \"y\": 390\n                                    },\n                        
             \"x\": 722,\n                                    \"y\": 390\n                                }\n                            ],\n                            \"source\": \"ServiceTask-vdij28l\",\n                            \"target\": \"CompensationTrigger-uldp2ou\"\n                        },\n                        \"Type\": \"ExceptionMatch\"\n                    }\n                }\n            },\n            \"Next\": \"Succeed-5x3z98u\",\n            \"edge\": {\n                \"Succeed-5x3z98u\": {\n                    \"style\": {\n                        \"waypoints\": [\n                            {\n                                \"original\": {\n                                    \"x\": 600,\n                                    \"y\": 310\n                                },\n                                \"x\": 600,\n                                \"y\": 310\n                            },\n                            {\n                            
     \"x\": 740,\n                                \"y\": 256\n                            },\n                            {\n                                \"original\": {\n                                    \"x\": 740,\n                                    \"y\": 236\n                                },\n                                \"x\": 740,\n                                \"y\": 236\n                            }\n                        ],\n                        \"source\": \"ServiceTask-vdij28l\",\n                        \"target\": \"Succeed-5x3z98u\"\n                    },\n                    \"Type\": \"Transition\"\n                }\n            }\n        },\n        \"Succeed-5x3z98u\": {\n            \"style\": {\n                \"bounds\": {\n                    \"x\": 722,\n                    \"y\": 200,\n                    \"width\": 36,\n                    \"height\": 36\n                }\n            },\n            \"Name\": \"Succeed-5x3z98u\",\n  
           \"Type\": \"Succeed\"\n        },\n        \"CompensationTrigger-uldp2ou\": {\n            \"style\": {\n                \"bounds\": {\n                    \"x\": 722,\n                    \"y\": 372,\n                    \"width\": 36,\n                    \"height\": 36\n                }\n            },\n            \"Name\": \"CompensationTrigger-uldp2ou\",\n            \"Type\": \"CompensationTrigger\",\n            \"Next\": \"Fail-9roxcv5\",\n            \"edge\": {\n                \"Fail-9roxcv5\": {\n                    \"style\": {\n                        \"waypoints\": [\n                            {\n                                \"original\": {\n                                    \"x\": 758,\n                                    \"y\": 390\n                                },\n                                \"x\": 758,\n                                \"y\": 390\n                            },\n                            {\n                              
   \"x\": 792,\n                                \"y\": 390\n                            },\n                            {\n                                \"original\": {\n                                    \"x\": 812,\n                                    \"y\": 390\n                                },\n                                \"x\": 812,\n                                \"y\": 390\n                            }\n                        ],\n                        \"source\": \"CompensationTrigger-uldp2ou\",\n                        \"target\": \"Fail-9roxcv5\"\n                    },\n                    \"Type\": \"Transition\"\n                }\n            }\n        },\n        \"Fail-9roxcv5\": {\n            \"style\": {\n                \"bounds\": {\n                    \"x\": 812,\n                    \"y\": 372,\n                    \"width\": 36,\n                    \"height\": 36\n                }\n            },\n            \"Name\": \"Fail-9roxcv5\",\n     
        \"ErrorCode\": \"\",\n            \"Message\": \"\",\n            \"Type\": \"Fail\"\n        }\n    },\n    \"StartState\": \"ServiceTask-a9h2o51\",\n    \"edge\": {\n        \"style\": {\n            \"waypoints\": [\n                {\n                    \"original\": {\n                        \"x\": 236,\n                        \"y\": 218\n                    },\n                    \"x\": 236,\n                    \"y\": 218\n                },\n                {\n                    \"x\": 280,\n                    \"y\": 218\n                },\n                {\n                    \"original\": {\n                        \"x\": 300,\n                        \"y\": 218\n                    },\n                    \"x\": 300,\n                    \"y\": 218\n                }\n            ],\n            \"target\": \"ServiceTask-a9h2o51\"\n        },\n        \"Type\": \"Transition\"\n    }\n}"

Review Comment:
   Ok, I had put json files in testdata dir.



##########
pkg/saga/statemachine/statelang/parser/compensation_trigger_state_parser.go:
##########
@@ -0,0 +1,31 @@
+package parser
+
+import (
+	"github.com/seata/seata-go/pkg/saga/statemachine/constant"
+	"github.com/seata/seata-go/pkg/saga/statemachine/statelang"
+	"github.com/seata/seata-go/pkg/saga/statemachine/statelang/state"
+)
+
+type CompensationTriggerStateParser struct {
+	BaseStateParser

Review Comment:
   I have modified them all as pointer embedding.



##########
pkg/saga/statemachine/statelang/state/sub_state_machine.go:
##########
@@ -0,0 +1,70 @@
+package state
+
+import (
+	"github.com/google/uuid"
+	"github.com/seata/seata-go/pkg/saga/statemachine/constant"
+	"strconv"
+)
+
+type SubStateMachine interface {
+	TaskState
+
+	StateMachineName() string
+
+	CompensateStateImpl() TaskState
+}
+
+type SubStateMachineImpl struct {
+	*ServiceTaskStateImpl
+	stateMachineName string
+	compensateState  TaskState
+}
+
+func NewSubStateMachineImpl() *SubStateMachineImpl {
+	return &SubStateMachineImpl{
+		ServiceTaskStateImpl: NewServiceTaskStateImpl(),
+	}
+}
+
+func (s *SubStateMachineImpl) StateMachineName() string {
+	return s.stateMachineName
+}
+
+func (s *SubStateMachineImpl) SetStateMachineName(stateMachineName string) {
+	s.stateMachineName = stateMachineName
+}
+
+func (s *SubStateMachineImpl) CompensateStateImpl() TaskState {
+	return s.compensateState
+}
+
+func (s *SubStateMachineImpl) SetCompensateStateImpl(compensateState TaskState) {
+	s.compensateState = compensateState
+}
+
+type CompensateSubStateMachineState interface {
+	ServiceTaskState
+}
+
+type CompensateSubStateMachineStateImpl struct {
+	*ServiceTaskStateImpl
+	hashcode string
+}
+
+func NewCompensateSubStateMachineStateImpl() *CompensateSubStateMachineStateImpl {
+	uuid := uuid.New()
+	c := &CompensateSubStateMachineStateImpl{
+		ServiceTaskStateImpl: NewServiceTaskStateImpl(),
+		hashcode:             strconv.Itoa(int(uuid.ID())),

Review Comment:
   Ok.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@seata.apache.org
For additional commands, e-mail: dev-help@seata.apache.org


Re: [PR] feature: add serverice task parse in statelang [incubator-seata-go]

Posted by "ptyin (via GitHub)" <gi...@apache.org>.
ptyin commented on PR #650:
URL: https://github.com/apache/incubator-seata-go/pull/650#issuecomment-1909232911

   LGTM


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@seata.apache.org
For additional commands, e-mail: dev-help@seata.apache.org


Re: [PR] feature: add serverice task parse in statelang [incubator-seata-go]

Posted by "wt-better (via GitHub)" <gi...@apache.org>.
wt-better merged PR #650:
URL: https://github.com/apache/incubator-seata-go/pull/650


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@seata.apache.org
For additional commands, e-mail: dev-help@seata.apache.org


Re: [PR] feature: add serverice task parse in statelang [incubator-seata-go]

Posted by "ptyin (via GitHub)" <gi...@apache.org>.
ptyin commented on code in PR #650:
URL: https://github.com/apache/incubator-seata-go/pull/650#discussion_r1462869840


##########
pkg/saga/statemachine/statelang/parser/compensation_trigger_state_parser.go:
##########
@@ -0,0 +1,31 @@
+package parser
+
+import (
+	"github.com/seata/seata-go/pkg/saga/statemachine/constant"
+	"github.com/seata/seata-go/pkg/saga/statemachine/statelang"
+	"github.com/seata/seata-go/pkg/saga/statemachine/statelang/state"
+)
+
+type CompensationTriggerStateParser struct {
+	BaseStateParser

Review Comment:
   I found `BaseStateParser` are sometimes used as pointer embedding, and sometimes value embedding. Is there any special consideration?



##########
pkg/saga/statemachine/statelang/state/sub_state_machine.go:
##########
@@ -0,0 +1,70 @@
+package state
+
+import (
+	"github.com/google/uuid"
+	"github.com/seata/seata-go/pkg/saga/statemachine/constant"
+	"strconv"
+)
+
+type SubStateMachine interface {
+	TaskState
+
+	StateMachineName() string
+
+	CompensateStateImpl() TaskState
+}
+
+type SubStateMachineImpl struct {
+	*ServiceTaskStateImpl
+	stateMachineName string
+	compensateState  TaskState
+}
+
+func NewSubStateMachineImpl() *SubStateMachineImpl {
+	return &SubStateMachineImpl{
+		ServiceTaskStateImpl: NewServiceTaskStateImpl(),
+	}
+}
+
+func (s *SubStateMachineImpl) StateMachineName() string {
+	return s.stateMachineName
+}
+
+func (s *SubStateMachineImpl) SetStateMachineName(stateMachineName string) {
+	s.stateMachineName = stateMachineName
+}
+
+func (s *SubStateMachineImpl) CompensateStateImpl() TaskState {
+	return s.compensateState
+}
+
+func (s *SubStateMachineImpl) SetCompensateStateImpl(compensateState TaskState) {
+	s.compensateState = compensateState
+}
+
+type CompensateSubStateMachineState interface {
+	ServiceTaskState
+}
+
+type CompensateSubStateMachineStateImpl struct {
+	*ServiceTaskStateImpl
+	hashcode string
+}
+
+func NewCompensateSubStateMachineStateImpl() *CompensateSubStateMachineStateImpl {
+	uuid := uuid.New()
+	c := &CompensateSubStateMachineStateImpl{
+		ServiceTaskStateImpl: NewServiceTaskStateImpl(),
+		hashcode:             strconv.Itoa(int(uuid.ID())),

Review Comment:
   `uuid.String()` is more appropriate



##########
pkg/saga/statemachine/statelang/parser/statemachine_json_parser_test.go:
##########
@@ -11,3 +11,11 @@ func TestParseChoice(t *testing.T) {
 		t.Error("parse fail: " + err.Error())
 	}
 }
+
+func TestParseServiceTask(t *testing.T) {
+	content := "{\n    \"Name\": \"StateMachineNewDesigner\",\n    \"Comment\": \"This state machine is modeled by designer tools.\",\n    \"Version\": \"0.0.1\",\n    \"style\": {\n        \"bounds\": {\n            \"x\": 200,\n            \"y\": 200,\n            \"width\": 36,\n            \"height\": 36\n        }\n    },\n    \"States\": {\n        \"ServiceTask-a9h2o51\": {\n            \"style\": {\n                \"bounds\": {\n                    \"x\": 300,\n                    \"y\": 178,\n                    \"width\": 100,\n                    \"height\": 80\n                }\n            },\n            \"Name\": \"ServiceTask-a9h2o51\",\n            \"IsForCompensation\": false,\n            \"Input\": [\n                {}\n            ],\n            \"Output\": {},\n            \"Status\": {},\n            \"Retry\": [],\n            \"ServiceName\": \"\",\n            \"ServiceMethod\": \"\",\n            \"Type\": \"ServiceTask\",\n            \"Next\": \"Choice-
 4ajl8nt\",\n            \"edge\": {\n                \"Choice-4ajl8nt\": {\n                    \"style\": {\n                        \"waypoints\": [\n                            {\n                                \"original\": {\n                                    \"x\": 400,\n                                    \"y\": 218\n                                },\n                                \"x\": 400,\n                                \"y\": 218\n                            },\n                            {\n                                \"x\": 435,\n                                \"y\": 218\n                            },\n                            {\n                                \"original\": {\n                                    \"x\": 455,\n                                    \"y\": 218\n                                },\n                                \"x\": 455,\n                                \"y\": 218\n                            }\n                        ],
 \n                        \"source\": \"ServiceTask-a9h2o51\",\n                        \"target\": \"Choice-4ajl8nt\"\n                    },\n                    \"Type\": \"Transition\"\n                }\n            },\n            \"CompensateState\": \"CompensateFirstState\"\n        },\n        \"Choice-4ajl8nt\": {\n            \"style\": {\n                \"bounds\": {\n                    \"x\": 455,\n                    \"y\": 193,\n                    \"width\": 50,\n                    \"height\": 50\n                }\n            },\n            \"Name\": \"Choice-4ajl8nt\",\n            \"Type\": \"Choice\",\n            \"Choices\": [\n                {\n                    \"Expression\": \"\",\n                    \"Next\": \"SubStateMachine-cauj9uy\"\n                },\n                {\n                    \"Expression\": \"\",\n                    \"Next\": \"ServiceTask-vdij28l\"\n                }\n            ],\n            \"Default\": \"SubStateMachin
 e-cauj9uy\",\n            \"edge\": {\n                \"SubStateMachine-cauj9uy\": {\n                    \"style\": {\n                        \"waypoints\": [\n                            {\n                                \"original\": {\n                                    \"x\": 505,\n                                    \"y\": 218\n                                },\n                                \"x\": 505,\n                                \"y\": 218\n                            },\n                            {\n                                \"x\": 530,\n                                \"y\": 218\n                            },\n                            {\n                                \"original\": {\n                                    \"x\": 550,\n                                    \"y\": 218\n                                },\n                                \"x\": 550,\n                                \"y\": 218\n                            }\n               
          ],\n                        \"source\": \"Choice-4ajl8nt\",\n                        \"target\": \"SubStateMachine-cauj9uy\"\n                    },\n                    \"Type\": \"ChoiceEntry\"\n                },\n                \"ServiceTask-vdij28l\": {\n                    \"style\": {\n                        \"waypoints\": [\n                            {\n                                \"original\": {\n                                    \"x\": 480,\n                                    \"y\": 243\n                                },\n                                \"x\": 480,\n                                \"y\": 243\n                            },\n                            {\n                                \"x\": 600,\n                                \"y\": 290\n                            },\n                            {\n                                \"original\": {\n                                    \"x\": 600,\n                                    
 \"y\": 310\n                                },\n                                \"x\": 600,\n                                \"y\": 310\n                            }\n                        ],\n                        \"source\": \"Choice-4ajl8nt\",\n                        \"target\": \"ServiceTask-vdij28l\"\n                    },\n                    \"Type\": \"ChoiceEntry\"\n                }\n            }\n        },\n        \"CompensateFirstState\": {\n            \"style\": {\n                \"bounds\": {\n                    \"x\": 300,\n                    \"y\": 310,\n                    \"width\": 100,\n                    \"height\": 80\n                }\n            },\n            \"Name\": \"CompensateFirstState\",\n            \"IsForCompensation\": true,\n            \"Input\": [\n                {}\n            ],\n            \"Output\": {},\n            \"Status\": {},\n            \"Retry\": [],\n            \"ServiceName\": \"\",\n            \"ServiceMe
 thod\": \"\",\n            \"Type\": \"ServiceTask\"\n        },\n        \"SubStateMachine-cauj9uy\": {\n            \"style\": {\n                \"bounds\": {\n                    \"x\": 550,\n                    \"y\": 178,\n                    \"width\": 100,\n                    \"height\": 80\n                }\n            },\n            \"Name\": \"SubStateMachine-cauj9uy\",\n            \"IsForCompensation\": false,\n            \"Input\": [\n                {}\n            ],\n            \"Output\": {},\n            \"Status\": {},\n            \"Retry\": [],\n            \"StateMachineName\": \"\",\n            \"Type\": \"SubStateMachine\",\n            \"Next\": \"Succeed-5x3z98u\",\n            \"edge\": {\n                \"Succeed-5x3z98u\": {\n                    \"style\": {\n                        \"waypoints\": [\n                            {\n                                \"original\": {\n                                    \"x\": 650,\n                  
                   \"y\": 218\n                                },\n                                \"x\": 650,\n                                \"y\": 218\n                            },\n                            {\n                                \"x\": 702,\n                                \"y\": 218\n                            },\n                            {\n                                \"original\": {\n                                    \"x\": 722,\n                                    \"y\": 218\n                                },\n                                \"x\": 722,\n                                \"y\": 218\n                            }\n                        ],\n                        \"source\": \"SubStateMachine-cauj9uy\",\n                        \"target\": \"Succeed-5x3z98u\"\n                    },\n                    \"Type\": \"Transition\"\n                }\n            }\n        },\n        \"ServiceTask-vdij28l\": {\n            \"style\":
  {\n                \"bounds\": {\n                    \"x\": 550,\n                    \"y\": 310,\n                    \"width\": 100,\n                    \"height\": 80\n                }\n            },\n            \"Name\": \"ServiceTask-vdij28l\",\n            \"IsForCompensation\": false,\n            \"Input\": [\n                {}\n            ],\n            \"Output\": {},\n            \"Status\": {},\n            \"Retry\": [],\n            \"ServiceName\": \"\",\n            \"ServiceMethod\": \"\",\n            \"Catch\": [\n                {\n                    \"Exceptions\": [],\n                    \"Next\": \"CompensationTrigger-uldp2ou\"\n                }\n            ],\n            \"Type\": \"ServiceTask\",\n            \"catch\": {\n                \"style\": {\n                    \"bounds\": {\n                        \"x\": 632,\n                        \"y\": 372,\n                        \"width\": 36,\n                        \"height\": 36\n      
               }\n                },\n                \"edge\": {\n                    \"CompensationTrigger-uldp2ou\": {\n                        \"style\": {\n                            \"waypoints\": [\n                                {\n                                    \"original\": {\n                                        \"x\": 668,\n                                        \"y\": 390\n                                    },\n                                    \"x\": 668,\n                                    \"y\": 390\n                                },\n                                {\n                                    \"x\": 702,\n                                    \"y\": 390\n                                },\n                                {\n                                    \"original\": {\n                                        \"x\": 722,\n                                        \"y\": 390\n                                    },\n                        
             \"x\": 722,\n                                    \"y\": 390\n                                }\n                            ],\n                            \"source\": \"ServiceTask-vdij28l\",\n                            \"target\": \"CompensationTrigger-uldp2ou\"\n                        },\n                        \"Type\": \"ExceptionMatch\"\n                    }\n                }\n            },\n            \"Next\": \"Succeed-5x3z98u\",\n            \"edge\": {\n                \"Succeed-5x3z98u\": {\n                    \"style\": {\n                        \"waypoints\": [\n                            {\n                                \"original\": {\n                                    \"x\": 600,\n                                    \"y\": 310\n                                },\n                                \"x\": 600,\n                                \"y\": 310\n                            },\n                            {\n                            
     \"x\": 740,\n                                \"y\": 256\n                            },\n                            {\n                                \"original\": {\n                                    \"x\": 740,\n                                    \"y\": 236\n                                },\n                                \"x\": 740,\n                                \"y\": 236\n                            }\n                        ],\n                        \"source\": \"ServiceTask-vdij28l\",\n                        \"target\": \"Succeed-5x3z98u\"\n                    },\n                    \"Type\": \"Transition\"\n                }\n            }\n        },\n        \"Succeed-5x3z98u\": {\n            \"style\": {\n                \"bounds\": {\n                    \"x\": 722,\n                    \"y\": 200,\n                    \"width\": 36,\n                    \"height\": 36\n                }\n            },\n            \"Name\": \"Succeed-5x3z98u\",\n  
           \"Type\": \"Succeed\"\n        },\n        \"CompensationTrigger-uldp2ou\": {\n            \"style\": {\n                \"bounds\": {\n                    \"x\": 722,\n                    \"y\": 372,\n                    \"width\": 36,\n                    \"height\": 36\n                }\n            },\n            \"Name\": \"CompensationTrigger-uldp2ou\",\n            \"Type\": \"CompensationTrigger\",\n            \"Next\": \"Fail-9roxcv5\",\n            \"edge\": {\n                \"Fail-9roxcv5\": {\n                    \"style\": {\n                        \"waypoints\": [\n                            {\n                                \"original\": {\n                                    \"x\": 758,\n                                    \"y\": 390\n                                },\n                                \"x\": 758,\n                                \"y\": 390\n                            },\n                            {\n                              
   \"x\": 792,\n                                \"y\": 390\n                            },\n                            {\n                                \"original\": {\n                                    \"x\": 812,\n                                    \"y\": 390\n                                },\n                                \"x\": 812,\n                                \"y\": 390\n                            }\n                        ],\n                        \"source\": \"CompensationTrigger-uldp2ou\",\n                        \"target\": \"Fail-9roxcv5\"\n                    },\n                    \"Type\": \"Transition\"\n                }\n            }\n        },\n        \"Fail-9roxcv5\": {\n            \"style\": {\n                \"bounds\": {\n                    \"x\": 812,\n                    \"y\": 372,\n                    \"width\": 36,\n                    \"height\": 36\n                }\n            },\n            \"Name\": \"Fail-9roxcv5\",\n     
        \"ErrorCode\": \"\",\n            \"Message\": \"\",\n            \"Type\": \"Fail\"\n        }\n    },\n    \"StartState\": \"ServiceTask-a9h2o51\",\n    \"edge\": {\n        \"style\": {\n            \"waypoints\": [\n                {\n                    \"original\": {\n                        \"x\": 236,\n                        \"y\": 218\n                    },\n                    \"x\": 236,\n                    \"y\": 218\n                },\n                {\n                    \"x\": 280,\n                    \"y\": 218\n                },\n                {\n                    \"original\": {\n                        \"x\": 300,\n                        \"y\": 218\n                    },\n                    \"x\": 300,\n                    \"y\": 218\n                }\n            ],\n            \"target\": \"ServiceTask-a9h2o51\"\n        },\n        \"Type\": \"Transition\"\n    }\n}"

Review Comment:
   I think we should add another UT, using the following file as the test source, which is better aligned with Java.
   
   https://github.com/apache/incubator-seata/blob/2.x/saga/seata-saga-statelang/src/test/resources/statelang/simple_statemachine.json



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@seata.apache.org
For additional commands, e-mail: dev-help@seata.apache.org


Re: [PR] feature: add serverice task parse in statelang [incubator-seata-go]

Posted by "wt-better (via GitHub)" <gi...@apache.org>.
wt-better commented on code in PR #650:
URL: https://github.com/apache/incubator-seata-go/pull/650#discussion_r1464359298


##########
pkg/saga/statemachine/statelang/parser/statemachine_parser.go:
##########
@@ -52,22 +41,118 @@ func (b BaseStateParser) GetString(stateName string, stateMap map[string]interfa
 	return valueAsString, nil
 }
 
-func (b BaseStateParser) GetSlice(stateName string, stateMap map[string]interface{}, key string) ([]interface{}, error) {
+func (b BaseStateParser) GetStringOrDefault(stateMap map[string]interface{}, key string, defaultValue string) string {
 	value := stateMap[key]
+	if value == nil {
+		return defaultValue
+	}
+
+	valueAsString, ok := value.(string)
+	if !ok {
+		return defaultValue
+	}
+	return valueAsString
+}
 
+func (b BaseStateParser) GetSlice(stateName string, stateMap map[string]interface{}, key string) ([]interface{}, error) {
+	value := stateMap[key]
 	if value == nil {
 		var result []interface{}
 		return result, errors.New("State [" + stateName + "] " + key + " not exist")
 	}
 
 	valueAsSlice, ok := value.([]interface{})
 	if !ok {
-		var result []interface{}
-		return result, errors.New("State [" + stateName + "] " + key + " illegal, required slice")
+		var slice []interface{}
+		return slice, errors.New("State [" + stateName + "] " + key + " illegal, required []interface{}")
 	}
 	return valueAsSlice, nil
 }
 
+func (b BaseStateParser) GetSliceOrDefault(stateMap map[string]interface{}, key string, defaultValue []interface{}) []interface{} {
+	value := stateMap[key]
+
+	if value == nil {
+		return defaultValue
+	}
+
+	valueAsSlice, ok := value.([]interface{})
+	if !ok {
+		return defaultValue
+	}
+	return valueAsSlice
+}
+
+func (b BaseStateParser) GetMapOrDefault(stateMap map[string]interface{}, key string, defaultValue map[string]interface{}) map[string]interface{} {
+	value := stateMap[key]
+
+	if value == nil {
+		return defaultValue
+	}
+
+	valueAsMap, ok := value.(map[string]interface{})
+	if !ok {
+		return defaultValue
+	}
+	return valueAsMap
+}
+
+func (b BaseStateParser) GetBool(stateName string, stateMap map[string]interface{}, key string) (bool, error) {

Review Comment:
   GetBoolOrFalse rename to GetBoolOrDefault , keep unify.
   
   GetBoolOrDefault can be reduce duplicate code, other method also.



##########
pkg/saga/statemachine/statelang/parser/statemachine_parser.go:
##########
@@ -52,22 +41,118 @@ func (b BaseStateParser) GetString(stateName string, stateMap map[string]interfa
 	return valueAsString, nil
 }
 
-func (b BaseStateParser) GetSlice(stateName string, stateMap map[string]interface{}, key string) ([]interface{}, error) {
+func (b BaseStateParser) GetStringOrDefault(stateMap map[string]interface{}, key string, defaultValue string) string {
 	value := stateMap[key]
+	if value == nil {
+		return defaultValue
+	}
+
+	valueAsString, ok := value.(string)
+	if !ok {

Review Comment:
   if value convert err, example need: int , but map , throw err or better



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@seata.apache.org
For additional commands, e-mail: dev-help@seata.apache.org


Re: [PR] feature: add serverice task parse in statelang [incubator-seata-go]

Posted by "xjlgod (via GitHub)" <gi...@apache.org>.
xjlgod commented on code in PR #650:
URL: https://github.com/apache/incubator-seata-go/pull/650#discussion_r1464992823


##########
pkg/saga/statemachine/statelang/parser/statemachine_parser.go:
##########
@@ -52,22 +41,118 @@ func (b BaseStateParser) GetString(stateName string, stateMap map[string]interfa
 	return valueAsString, nil
 }
 
-func (b BaseStateParser) GetSlice(stateName string, stateMap map[string]interface{}, key string) ([]interface{}, error) {
+func (b BaseStateParser) GetStringOrDefault(stateMap map[string]interface{}, key string, defaultValue string) string {
 	value := stateMap[key]
+	if value == nil {
+		return defaultValue
+	}
+
+	valueAsString, ok := value.(string)
+	if !ok {
+		return defaultValue
+	}
+	return valueAsString
+}
 
+func (b BaseStateParser) GetSlice(stateName string, stateMap map[string]interface{}, key string) ([]interface{}, error) {
+	value := stateMap[key]
 	if value == nil {
 		var result []interface{}
 		return result, errors.New("State [" + stateName + "] " + key + " not exist")
 	}
 
 	valueAsSlice, ok := value.([]interface{})
 	if !ok {
-		var result []interface{}
-		return result, errors.New("State [" + stateName + "] " + key + " illegal, required slice")
+		var slice []interface{}
+		return slice, errors.New("State [" + stateName + "] " + key + " illegal, required []interface{}")
 	}
 	return valueAsSlice, nil
 }
 
+func (b BaseStateParser) GetSliceOrDefault(stateMap map[string]interface{}, key string, defaultValue []interface{}) []interface{} {
+	value := stateMap[key]
+
+	if value == nil {
+		return defaultValue
+	}
+
+	valueAsSlice, ok := value.([]interface{})
+	if !ok {
+		return defaultValue
+	}
+	return valueAsSlice
+}
+
+func (b BaseStateParser) GetMapOrDefault(stateMap map[string]interface{}, key string, defaultValue map[string]interface{}) map[string]interface{} {
+	value := stateMap[key]
+
+	if value == nil {
+		return defaultValue
+	}
+
+	valueAsMap, ok := value.(map[string]interface{})
+	if !ok {
+		return defaultValue
+	}
+	return valueAsMap
+}
+
+func (b BaseStateParser) GetBool(stateName string, stateMap map[string]interface{}, key string) (bool, error) {

Review Comment:
   I modified it to keep unify now.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@seata.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@seata.apache.org
For additional commands, e-mail: dev-help@seata.apache.org