@@ -12,7 +12,6 @@ import (
12
12
"gopkg.in/mgo.v2/bson"
13
13
14
14
"github.com/moiot/gravity/pkg/logutil"
15
- "github.com/moiot/gravity/pkg/utils"
16
15
)
17
16
18
17
var DefaultBinlogSyncerTimeout = "10s"
@@ -69,7 +68,7 @@ type PipelineConfig struct {
69
68
70
69
TableConfig []* TableConfig `toml:"table-config" json:"table-config"`
71
70
72
- TargetMySQL * utils. DBConfig `toml:"target-mysql" json:"target-mysql"`
71
+ TargetMySQL * DBConfig `toml:"target-mysql" json:"target-mysql"`
73
72
74
73
TargetMySQLWorkerCfg * TargetMySQLWorkerConfig `toml:"target-mysql-worker" json:"target-mysql-worker"`
75
74
@@ -93,8 +92,8 @@ type SourceKafkaConfig struct {
93
92
}
94
93
95
94
type SourceProbeCfg struct {
96
- SourceMySQL * utils. DBConfig `mapstructure:"mysql" toml:"mysql" json:"mysql"`
97
- Annotation string `mapstructure:"annotation" toml:"annotation" json:"annotation"`
95
+ SourceMySQL * DBConfig `mapstructure:"mysql" toml:"mysql" json:"mysql"`
96
+ Annotation string `mapstructure:"annotation" toml:"annotation" json:"annotation"`
98
97
}
99
98
100
99
type MongoPosition bson.MongoTimestamp
@@ -110,14 +109,14 @@ type MongoConfigs struct {
110
109
}
111
110
112
111
type MySQLConfig struct {
113
- IgnoreBiDirectionalData bool `mapstructure:"ignore-bidirectional-data" toml:"ignore-bidirectional-data" json:"ignore-bidirectional-data"`
114
- Source * utils. DBConfig `mapstructure:"source" toml:"source" json:"source"`
115
- SourceSlave * utils. DBConfig `mapstructure:"source-slave" toml:"source-slave" json:"source-slave"`
116
- StartPosition * utils. MySQLBinlogPosition `mapstructure:"start-position" toml:"start-position" json:"start-position"`
112
+ IgnoreBiDirectionalData bool `mapstructure:"ignore-bidirectional-data" toml:"ignore-bidirectional-data" json:"ignore-bidirectional-data"`
113
+ Source * DBConfig `mapstructure:"source" toml:"source" json:"source"`
114
+ SourceSlave * DBConfig `mapstructure:"source-slave" toml:"source-slave" json:"source-slave"`
115
+ StartPosition * MySQLBinlogPosition `mapstructure:"start-position" toml:"start-position" json:"start-position"`
117
116
}
118
117
119
118
type SourceTiDBConfig struct {
120
- SourceDB * utils. DBConfig `mapstructure:"source-db" toml:"source-db" json:"source-db"`
119
+ SourceDB * DBConfig `mapstructure:"source-db" toml:"source-db" json:"source-db"`
121
120
SourceKafka * SourceKafkaConfig `mapstructure:"source-kafka" toml:"source-kafka" json:"source-kafka"`
122
121
// OffsetStoreConfig *SourceProbeCfg `mapstructure:"offset-store" toml:"offset-store" json:"offset-store"`
123
122
PositionRepo * GenericPluginConfig `mapstructure:"position-repo" toml:"position-repo" json:"position-repo"`
@@ -140,6 +139,44 @@ type MongoConnConfig struct {
140
139
Direct bool `mapstructure:"direct" toml:"direct" json:"direct"`
141
140
}
142
141
142
+ func (cfg MongoConnConfig ) URI () string {
143
+ username := ""
144
+ if cfg .Username != "" {
145
+ username = cfg .Username
146
+ }
147
+
148
+ password := ""
149
+ if cfg .Password != "" {
150
+ password = cfg .Password
151
+ }
152
+
153
+ host := "localhost"
154
+ if cfg .Host != "" {
155
+ host = cfg .Host
156
+ }
157
+
158
+ port := 27017
159
+ if cfg .Port != 0 {
160
+ port = cfg .Port
161
+ }
162
+
163
+ db := cfg .Database
164
+
165
+ var url string
166
+ if username == "" || password == "" {
167
+ url = fmt .Sprintf ("mongodb://%s:%d/%s" , host , port , db )
168
+ } else {
169
+ url = fmt .Sprintf ("mongodb://%s:%s@%s:%d/%s" , username , password , host , port , db )
170
+ }
171
+
172
+ //If not specified, the connection will timeout, probably because the replica set has not been initialized yet.
173
+ if cfg .Direct {
174
+ url += "?connect=direct"
175
+ }
176
+
177
+ return url
178
+ }
179
+
143
180
type TargetMySQLWorkerConfig struct {
144
181
EnableDDL bool `toml:"enable-ddl" json:"enable-ddl"`
145
182
UseBidirection bool `toml:"use-bidirection" json:"use-bidirection"`
0 commit comments