FinnTew commented on code in PR #805:
URL: 
https://github.com/apache/incubator-seata-go/pull/805#discussion_r2051911420


##########
pkg/saga/statemachine/engine/core/default_statemachine_config.go:
##########
@@ -191,70 +200,210 @@ func (c *DefaultStateMachineConfig) 
ScriptInvokerManager() invoker.ScriptInvoker
 }
 
 func (c *DefaultStateMachineConfig) CharSet() string {
-       return c.charset
+       return c.Charset
 }
 
 func (c *DefaultStateMachineConfig) SetCharSet(charset string) {
-       c.charset = charset
+       c.Charset = charset
 }
 
-func (c *DefaultStateMachineConfig) DefaultTenantId() string {
-       return c.defaultTenantId
+func (c *DefaultStateMachineConfig) GetDefaultTenantId() string {
+       return c.DefaultTenantId
 }
 
-func (c *DefaultStateMachineConfig) TransOperationTimeout() int {
-       return c.transOperationTimeout
+func (c *DefaultStateMachineConfig) GetTransOperationTimeout() int {
+       return c.TransOperationTimeout
 }
 
-func (c *DefaultStateMachineConfig) ServiceInvokeTimeout() int {
-       return c.serviceInvokeTimeout
+func (c *DefaultStateMachineConfig) GetServiceInvokeTimeout() int {
+       return c.ServiceInvokeTimeout
 }
 
 func (c *DefaultStateMachineConfig) IsSagaRetryPersistModeUpdate() bool {
-       return c.sagaRetryPersistModeUpdate
+       return c.SagaRetryPersistModeUpdate
 }
 
 func (c *DefaultStateMachineConfig) 
SetSagaRetryPersistModeUpdate(sagaRetryPersistModeUpdate bool) {
-       c.sagaRetryPersistModeUpdate = sagaRetryPersistModeUpdate
+       c.SagaRetryPersistModeUpdate = sagaRetryPersistModeUpdate
 }
 
 func (c *DefaultStateMachineConfig) IsSagaCompensatePersistModeUpdate() bool {
-       return c.sagaCompensatePersistModeUpdate
+       return c.SagaCompensatePersistModeUpdate
 }
 
 func (c *DefaultStateMachineConfig) 
SetSagaCompensatePersistModeUpdate(sagaCompensatePersistModeUpdate bool) {
-       c.sagaCompensatePersistModeUpdate = sagaCompensatePersistModeUpdate
+       c.SagaCompensatePersistModeUpdate = sagaCompensatePersistModeUpdate
 }
 
 func (c *DefaultStateMachineConfig) IsSagaBranchRegisterEnable() bool {
-       return c.sagaBranchRegisterEnable
+       return c.SagaBranchRegisterEnable
 }
 
 func (c *DefaultStateMachineConfig) 
SetSagaBranchRegisterEnable(sagaBranchRegisterEnable bool) {
-       c.sagaBranchRegisterEnable = sagaBranchRegisterEnable
+       c.SagaBranchRegisterEnable = sagaBranchRegisterEnable
 }
 
 func (c *DefaultStateMachineConfig) IsRmReportSuccessEnable() bool {
-       return c.rmReportSuccessEnable
+       return c.RmReportSuccessEnable
 }
 
 func (c *DefaultStateMachineConfig) 
SetRmReportSuccessEnable(rmReportSuccessEnable bool) {
-       c.rmReportSuccessEnable = rmReportSuccessEnable
+       c.RmReportSuccessEnable = rmReportSuccessEnable
+}
+
+func (c *DefaultStateMachineConfig) GetStateMachineDefinition(name string) 
*statemachine.StateMachineObject {
+       return c.stateMachineDefs[name]
+}
+
+func (c *DefaultStateMachineConfig) GetExpressionFactory(expressionType 
string) expr.ExpressionFactory {
+       return c.expressionFactoryManager.GetExpressionFactory(expressionType)
+}
+
+func (c *DefaultStateMachineConfig) GetServiceInvoker(serviceType string) 
invoker.ServiceInvoker {
+       return c.serviceInvokerManager.ServiceInvoker(serviceType)
+}
+
+func (c *DefaultStateMachineConfig) RegisterStateMachineDef(resources 
[]string) error {
+       for _, resourcePath := range resources {
+               file, err := os.Open(resourcePath)
+               if err != nil {
+                       return fmt.Errorf("open resource file failed: path=%s, 
err=%w", resourcePath, err)
+               }
+               defer file.Close()
+
+               if err := 
c.stateMachineRepository.RegistryStateMachineByReader(file); err != nil {
+                       return fmt.Errorf("register state machine from file 
failed: path=%s, err=%w", resourcePath, err)
+               }
+       }
+       return nil
+}
+
+func (c *DefaultStateMachineConfig) RegisterExpressionFactory(expressionType 
string, factory expr.ExpressionFactory) {
+       c.expressionFactoryManager.PutExpressionFactory(expressionType, factory)
+}
+
+func (c *DefaultStateMachineConfig) RegisterServiceInvoker(serviceType string, 
invoker invoker.ServiceInvoker) {
+       c.serviceInvokerManager.PutServiceInvoker(serviceType, invoker)
+}
+
+type RuntimeConfig struct {
+       TransOperationTimeout           int      
`json:"trans_operation_timeout" yaml:"trans_operation_timeout"`
+       ServiceInvokeTimeout            int      `json:"service_invoke_timeout" 
yaml:"service_invoke_timeout"`
+       Charset                         string   `json:"charset" yaml:"charset"`
+       DefaultTenantId                 string   `json:"default_tenant_id" 
yaml:"default_tenant_id"`
+       SagaRetryPersistModeUpdate      bool     
`json:"saga_retry_persist_mode_update" yaml:"saga_retry_persist_mode_update"`
+       SagaCompensatePersistModeUpdate bool     
`json:"saga_compensate_persist_mode_update" 
yaml:"saga_compensate_persist_mode_update"`
+       SagaBranchRegisterEnable        bool     
`json:"saga_branch_register_enable" yaml:"saga_branch_register_enable"`
+       RmReportSuccessEnable           bool     
`json:"rm_report_success_enable" yaml:"rm_report_success_enable"`
+       StateMachineResources           []string 
`json:"state_machine_resources" yaml:"state_machine_resources"`
+}
+
+func (c *DefaultStateMachineConfig) LoadConfig(configPath string) error {
+       content, err := os.ReadFile(configPath)
+       if err != nil {
+               return fmt.Errorf("failed to read config file: path=%s, 
error=%w", configPath, err)
+       }
+
+       var smo statemachine.StateMachineObject
+       if err := json.Unmarshal(content, &smo); err != nil {

Review Comment:
   Why do not try to reuse the logic from 
`pkg/saga/statemachine/statelang/parser/statemachine_config_parser.go`? I 
understand that what needs to be done here is to concatenate the config parser 
and the state machine, right? 



-- 
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: notifications-unsubscr...@seata.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org
For additional commands, e-mail: notifications-h...@seata.apache.org

Reply via email to