diff --git a/server/internal/service/delivery.go b/server/internal/service/delivery.go index 8bbe8dd..b93e206 100644 --- a/server/internal/service/delivery.go +++ b/server/internal/service/delivery.go @@ -2385,18 +2385,20 @@ type cloudDMRegisterRequest struct { } type cloudDMDataSource struct { - InstanceName string `json:"instanceName"` - InstanceDesc string `json:"instanceDesc"` - DSType string `json:"dsType"` - Host string `json:"host"` - SecurityType string `json:"securityType"` - UserName string `json:"userName"` - Password string `json:"password"` - DefaultSchema any `json:"defaultSchema"` - ClientTimeZone string `json:"clientTimeZone"` - ConnectTimeoutMs int `json:"connectTimeoutMs"` - SocketTimeoutSecs int `json:"socketTimeoutSeconds"` - ConnectionCharset string `json:"connectionCharset"` + InstanceName string `json:"instanceName"` + InstanceDesc string `json:"instanceDesc"` + DSType string `json:"dsType"` + Host string `json:"host"` + ClusterID *uint64 `json:"cluster_id"` + MySQLVersion string `json:"mysql_version"` + SecurityType string `json:"securityType"` + UserName string `json:"userName"` + Password string `json:"password"` + DefaultSchema any `json:"defaultSchema"` + ClientTimeZone string `json:"clientTimeZone"` + ConnectTimeoutMs int `json:"connectTimeoutMs"` + SocketTimeoutSecs int `json:"socketTimeoutSeconds"` + ConnectionCharset string `json:"connectionCharset"` } func cloudDMExternalResourceID(instanceID uint64) string { @@ -2466,6 +2468,13 @@ func buildCloudDMRegisterRequest(instance model.DeploymentResult, payload delive if description == "" { description = instance.InstanceName } + mysqlVersion := strings.TrimSpace(instance.Version) + if mysqlVersion == "" { + mysqlVersion = strings.TrimSpace(payload.MySQLVersion) + } + if mysqlVersion == "" { + mysqlVersion = "8.0" + } return cloudDMRegisterRequest{ SourceSystem: "xinfra", ResourceType: "MYSQL_INSTANCE", @@ -2475,6 +2484,8 @@ func buildCloudDMRegisterRequest(instance model.DeploymentResult, payload delive InstanceDesc: description, DSType: "MySQL", Host: net.JoinHostPort(instance.Host, strconv.Itoa(instance.Port)), + ClusterID: nil, + MySQLVersion: mysqlVersion, SecurityType: "USER_PASSWD", UserName: "root", Password: password, diff --git a/server/internal/service/delivery_test.go b/server/internal/service/delivery_test.go index ccb01ee..7eea0e8 100644 --- a/server/internal/service/delivery_test.go +++ b/server/internal/service/delivery_test.go @@ -147,7 +147,7 @@ func TestAllocatePort(t *testing.T) { func TestBuildCloudDMRegisterRequest(t *testing.T) { req := buildCloudDMRegisterRequest( - model.DeploymentResult{ID: 42, InstanceName: "mysql-payment-prod", Host: "10.0.0.10", Port: 3306}, + model.DeploymentResult{ID: 42, InstanceName: "mysql-payment-prod", Host: "10.0.0.10", Port: 3306, Version: "8.4"}, deliveryPayload{MySQLDeliveryInput: MySQLDeliveryInput{InstanceDesc: "支付生产 MySQL", Timezone: "Asia/Shanghai"}}, "secret", ) @@ -160,6 +160,12 @@ func TestBuildCloudDMRegisterRequest(t *testing.T) { if req.DataSource.Host != "10.0.0.10:3306" || req.DataSource.Password != "secret" { t.Fatalf("unexpected data source fields: %#v", req.DataSource) } + if req.DataSource.ClusterID != nil { + t.Fatalf("cluster_id must be nullable when xinfra cannot resolve it, got %#v", req.DataSource.ClusterID) + } + if req.DataSource.MySQLVersion != "8.4" { + t.Fatalf("unexpected mysql version: %#v", req.DataSource.MySQLVersion) + } if req.DataSource.ClientTimeZone != "Asia/Shanghai" || req.DataSource.ConnectionCharset != "utf8" { t.Fatalf("unexpected time zone or charset: %#v", req.DataSource) } @@ -175,6 +181,12 @@ func TestBuildCloudDMRegisterRequest(t *testing.T) { if value, ok := dataSource["defaultSchema"]; !ok || value != nil { t.Fatalf("defaultSchema must be present as null, got %#v", dataSource["defaultSchema"]) } + if value, ok := dataSource["cluster_id"]; !ok || value != nil { + t.Fatalf("cluster_id must be present as null, got %#v", dataSource["cluster_id"]) + } + if value, ok := dataSource["mysql_version"]; !ok || value != "8.4" { + t.Fatalf("mysql_version must be propagated from deployed instance, got %#v", value) + } } func TestCloudDMDataSourceIDFromResponse(t *testing.T) {