Skip to content

Commit 40ae0f3

Browse files
authored
fix: complete set param feature (#600)
1 parent 938eb71 commit 40ae0f3

File tree

2 files changed

+95
-21
lines changed

2 files changed

+95
-21
lines changed

internal/convert/process_config.go

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,7 @@ func newMongosProcessConfig(p *opsmngr.Process) *ProcessConfig {
241241
func newMongosProcess(p *ProcessConfig, cluster string) *opsmngr.Process {
242242
process := p.process()
243243
process.Cluster = cluster
244-
process.Args26 = opsmngr.Args26{
245-
NET: p.net(),
246-
SystemLog: p.systemLog(),
247-
}
244+
process.Args26 = p.args26()
248245
if p.Security != nil {
249246
process.Args26.Security = p.Security
250247
}
@@ -255,18 +252,27 @@ func newMongosProcess(p *ProcessConfig, cluster string) *opsmngr.Process {
255252
return process
256253
}
257254

255+
func (p *ProcessConfig) args26() opsmngr.Args26 {
256+
return opsmngr.Args26{
257+
NET: p.net(),
258+
SystemLog: p.systemLog(),
259+
SetParameter: p.SetParameter,
260+
}
261+
}
262+
263+
func (p *ProcessConfig) args26RS(rsSetName string) opsmngr.Args26 {
264+
args26 := p.args26()
265+
args26.Replication = &opsmngr.Replication{ReplSetName: rsSetName}
266+
args26.Storage = p.storage()
267+
return args26
268+
}
269+
258270
// newReplicaSetProcess generates a mongo process for a replica set mongod
259271
func newReplicaSetProcess(p *ProcessConfig, replSetName string) *opsmngr.Process {
260272
process := p.process()
261273

262-
process.Args26 = opsmngr.Args26{
263-
NET: p.net(),
264-
Replication: &opsmngr.Replication{
265-
ReplSetName: replSetName,
266-
},
267-
Storage: p.storage(),
268-
SystemLog: p.systemLog(),
269-
}
274+
process.Args26 = p.args26RS(replSetName)
275+
270276
if p.Security != nil {
271277
process.Args26.Security = p.Security
272278
}
@@ -281,15 +287,8 @@ func newReplicaSetProcess(p *ProcessConfig, replSetName string) *opsmngr.Process
281287
func newConfigRSProcess(p *ProcessConfig, rsSetName string) *opsmngr.Process {
282288
process := p.process()
283289

284-
process.Args26 = opsmngr.Args26{
285-
NET: p.net(),
286-
Replication: &opsmngr.Replication{
287-
ReplSetName: rsSetName,
288-
},
289-
Storage: p.storage(),
290-
Sharding: &opsmngr.Sharding{ClusterRole: "configsvr"},
291-
SystemLog: p.systemLog(),
292-
}
290+
process.Args26 = p.args26RS(rsSetName)
291+
process.Args26.Sharding = &opsmngr.Sharding{ClusterRole: "configsvr"}
293292
if p.Security != nil {
294293
process.Args26.Security = p.Security
295294
}

internal/convert/process_config_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ func Test_newReplicaSetProcessConfig(t *testing.T) {
5555
Destination: "file",
5656
Path: "/data/log/mongodb.log",
5757
},
58+
SetParameter: &map[string]interface{}{
59+
"param": "param",
60+
},
5861
},
5962
AuthSchemaVersion: 5,
6063
Disabled: false,
@@ -103,6 +106,9 @@ func Test_newReplicaSetProcessConfig(t *testing.T) {
103106
Disabled: false,
104107
Hidden: pointy.Bool(false),
105108
TLS: &TLS{Mode: "disabled"},
109+
SetParameter: &map[string]interface{}{
110+
"param": "param",
111+
},
106112
WiredTiger: &map[string]interface{}{
107113
"collectionConfig": map[string]interface{}{},
108114
"engineConfig": map[string]interface{}{
@@ -147,6 +153,9 @@ func Test_newConfigRSProcess(t *testing.T) {
147153
},
148154
"indexConfig": map[string]interface{}{},
149155
},
156+
SetParameter: &map[string]interface{}{
157+
"param": "param",
158+
},
150159
}
151160

152161
want := &opsmngr.Process{
@@ -180,6 +189,9 @@ func Test_newConfigRSProcess(t *testing.T) {
180189
Path: "/data/log/mongodb.log",
181190
},
182191
Sharding: &opsmngr.Sharding{ClusterRole: "configsvr"},
192+
SetParameter: &map[string]interface{}{
193+
"param": "param",
194+
},
183195
},
184196
AuthSchemaVersion: 5,
185197
Disabled: false,
@@ -229,6 +241,9 @@ func Test_newReplicaSetProcess(t *testing.T) {
229241
},
230242
"indexConfig": map[string]interface{}{},
231243
},
244+
SetParameter: &map[string]interface{}{
245+
"param": "param",
246+
},
232247
}
233248

234249
want := &opsmngr.Process{
@@ -261,6 +276,9 @@ func Test_newReplicaSetProcess(t *testing.T) {
261276
Destination: "file",
262277
Path: "/data/log/mongodb.log",
263278
},
279+
SetParameter: &map[string]interface{}{
280+
"param": "param",
281+
},
264282
},
265283
AuthSchemaVersion: 5,
266284
Disabled: false,
@@ -278,3 +296,60 @@ func Test_newReplicaSetProcess(t *testing.T) {
278296
got := newReplicaSetProcess(p, "myReplicaSet")
279297
assert.Equal(t, got, want)
280298
}
299+
300+
func Test_newMongosProcessConfig(t *testing.T) {
301+
p := &opsmngr.Process{
302+
Args26: opsmngr.Args26{
303+
NET: opsmngr.Net{
304+
Port: 27017,
305+
},
306+
SystemLog: opsmngr.SystemLog{
307+
Destination: "file",
308+
Path: "/data/mongos/mongodb.log",
309+
},
310+
SetParameter: &map[string]interface{}{
311+
"param": "param",
312+
},
313+
AuditLog: &opsmngr.AuditLog{
314+
Path: "/data/mongos/audit.log",
315+
Destination: "file",
316+
Format: "JSON",
317+
Filter: "{ atype: { $in: [ \"createCollection\", \"dropCollection\" ] } }",
318+
},
319+
},
320+
AuthSchemaVersion: 5,
321+
Cluster: "myCluster",
322+
Disabled: false,
323+
FeatureCompatibilityVersion: "3.6",
324+
Hostname: "n1.omansible.int",
325+
LogRotate: &opsmngr.LogRotate{
326+
SizeThresholdMB: 1000,
327+
TimeThresholdHrs: 24,
328+
},
329+
ManualMode: false,
330+
Name: "myCluster_mongos_4",
331+
ProcessType: "mongos",
332+
Version: "3.6.21-ent",
333+
}
334+
335+
want := &ProcessConfig{
336+
AuditLogPath: "/data/mongos/audit.log",
337+
AuditLogDestination: "file",
338+
AuditLogFormat: "JSON",
339+
AuditLogFilter: "{ atype: { $in: [ \"createCollection\", \"dropCollection\" ] } }",
340+
FCVersion: "3.6",
341+
Hostname: "n1.omansible.int",
342+
LogDestination: "file",
343+
LogPath: "/data/mongos/mongodb.log",
344+
Name: "myCluster_mongos_4",
345+
Port: 27017,
346+
ProcessType: "mongos",
347+
Version: "3.6.21-ent",
348+
Disabled: false,
349+
SetParameter: &map[string]interface{}{
350+
"param": "param",
351+
},
352+
}
353+
got := newMongosProcessConfig(p)
354+
assert.Equal(t, got, want)
355+
}

0 commit comments

Comments
 (0)