Skip to content

Commit

Permalink
CLOUDP-188144: remove by cluster name - support multiple replica sets…
Browse files Browse the repository at this point in the history
… and mongos (#204)
  • Loading branch information
tibulca committed Jul 5, 2023
1 parent 1b240c2 commit ba0918b
Show file tree
Hide file tree
Showing 3 changed files with 281 additions and 7 deletions.
270 changes: 270 additions & 0 deletions atmcfg/fixtures.go
Expand Up @@ -221,6 +221,276 @@ func automationConfigWithOneShardedCluster(name string, disabled bool) *opsmngr.
}
}

func automationConfigWithThreeShardsCluster(name string, disabled bool) *opsmngr.AutomationConfig {
configRSPort := defaultMongoPort + 1
mongosPort := configRSPort + 1
slaveDelay := float64(0)
return &opsmngr.AutomationConfig{
Processes: []*opsmngr.Process{
// mongod processes
{
Args26: opsmngr.Args26{
NET: opsmngr.Net{
Port: defaultMongoPort,
},
Replication: &opsmngr.Replication{
ReplSetName: name,
},
Sharding: nil,
Storage: &opsmngr.Storage{
DBPath: "/data/db/",
},
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/db/mongodb.log",
},
},
AuthSchemaVersion: authSchemaVersion,
Name: name + "_shard_0_0",
Disabled: disabled,
ManualMode: disabled,
FeatureCompatibilityVersion: "4.2",
Hostname: "host0",
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: defaultSizeThresholdMB,
TimeThresholdHrs: defaultTimeThresholdHrs,
},
ProcessType: "mongod",
Version: "4.2.2",
},
{
Args26: opsmngr.Args26{
NET: opsmngr.Net{
Port: defaultMongoPort,
},
Replication: &opsmngr.Replication{
ReplSetName: name,
},
Sharding: nil,
Storage: &opsmngr.Storage{
DBPath: "/data/db/",
},
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/db/mongodb.log",
},
},
AuthSchemaVersion: authSchemaVersion,
Name: name + "_shard_1_0",
Disabled: disabled,
ManualMode: disabled,
FeatureCompatibilityVersion: "4.2",
Hostname: "host4",
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: defaultSizeThresholdMB,
TimeThresholdHrs: defaultTimeThresholdHrs,
},
ProcessType: "mongod",
Version: "4.2.2",
},
{
Args26: opsmngr.Args26{
NET: opsmngr.Net{
Port: defaultMongoPort,
},
Replication: &opsmngr.Replication{
ReplSetName: name,
},
Sharding: nil,
Storage: &opsmngr.Storage{
DBPath: "/data/db/",
},
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/db/mongodb.log",
},
},
AuthSchemaVersion: authSchemaVersion,
Name: name + "_shard_2_0",
Disabled: disabled,
ManualMode: disabled,
FeatureCompatibilityVersion: "4.2",
Hostname: "host5",
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: defaultSizeThresholdMB,
TimeThresholdHrs: defaultTimeThresholdHrs,
},
ProcessType: "mongod",
Version: "4.2.2",
},
// configRS processes
{
Args26: opsmngr.Args26{
NET: opsmngr.Net{
Port: configRSPort,
},
Replication: &opsmngr.Replication{
ReplSetName: name + "_configRS",
},
Sharding: &opsmngr.Sharding{
ClusterRole: "configsvr",
},
Storage: &opsmngr.Storage{
DBPath: "/data/db/",
},
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/db/mongodb.log",
},
},
AuthSchemaVersion: authSchemaVersion,
Name: name + "_configRS_0",
Disabled: disabled,
ManualMode: disabled,
FeatureCompatibilityVersion: "4.2",
Hostname: "host2",
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: defaultSizeThresholdMB,
TimeThresholdHrs: defaultTimeThresholdHrs,
},
ProcessType: "mongod",
Version: "4.2.2",
},
// mongos processes
{
Args26: opsmngr.Args26{
NET: opsmngr.Net{
Port: mongosPort,
},
Replication: nil,
Sharding: nil,
Storage: nil,
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/db/mongos.log",
},
},
AuthSchemaVersion: authSchemaVersion,
Cluster: name,
Name: name + "_mongos_0",
Disabled: disabled,
ManualMode: disabled,
FeatureCompatibilityVersion: "4.2",
Hostname: "host1",
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: defaultSizeThresholdMB,
TimeThresholdHrs: defaultTimeThresholdHrs,
},
ProcessType: "mongos",
Version: "4.2.2",
},
{
Args26: opsmngr.Args26{
NET: opsmngr.Net{
Port: mongosPort,
},
Replication: nil,
Sharding: nil,
Storage: nil,
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/db/mongos.log",
},
},
AuthSchemaVersion: authSchemaVersion,
Cluster: name,
Name: name + "_mongos_1",
Disabled: disabled,
ManualMode: disabled,
FeatureCompatibilityVersion: "4.2",
Hostname: "host3",
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: defaultSizeThresholdMB,
TimeThresholdHrs: defaultTimeThresholdHrs,
},
ProcessType: "mongos",
Version: "4.2.2",
},
},
ReplicaSets: []*opsmngr.ReplicaSet{
{
ID: name + "_shard_0",
ProtocolVersion: "1",
Members: []opsmngr.Member{
{
ArbiterOnly: false,
BuildIndexes: true,
Hidden: false,
Host: name + "_shard_0_0",
Priority: 1,
SlaveDelay: &slaveDelay,
Votes: 1,
},
},
},
{
ID: name + "_shard_1",
ProtocolVersion: "1",
Members: []opsmngr.Member{
{
ArbiterOnly: false,
BuildIndexes: true,
Hidden: false,
Host: name + "_shard_1_0",
Priority: 1,
SlaveDelay: &slaveDelay,
Votes: 1,
},
},
},
{
ID: name + "_shard_2",
ProtocolVersion: "1",
Members: []opsmngr.Member{
{
ArbiterOnly: false,
BuildIndexes: true,
Hidden: false,
Host: name + "_shard_2_0",
Priority: 1,
SlaveDelay: &slaveDelay,
Votes: 1,
},
},
},
{
ID: name + "_configRS",
ProtocolVersion: "1",
Members: []opsmngr.Member{
{
ArbiterOnly: false,
BuildIndexes: true,
Hidden: false,
Host: name + "_configRS_0",
Priority: 1,
SlaveDelay: &slaveDelay,
Votes: 1,
},
},
},
},
Sharding: []*opsmngr.ShardingConfig{
{
Name: name,
ConfigServerReplica: name + "_configRS",
Shards: []*opsmngr.Shard{
{
ID: name + "_shard_0",
RS: name + "_shard_0",
},
{
ID: name + "_shard_1",
RS: name + "_shard_1",
}, {
ID: name + "_shard_2",
RS: name + "_shard_2",
},
},
},
},
}
}

func automationConfigWithoutMongoDBUsers() *opsmngr.AutomationConfig {
return &opsmngr.AutomationConfig{
Auth: opsmngr.Auth{
Expand Down
16 changes: 10 additions & 6 deletions atmcfg/remove.go
Expand Up @@ -38,11 +38,13 @@ func removeByReplicaSetName(out *opsmngr.AutomationConfig, name string) {
rs := out.ReplicaSets[i]
out.ReplicaSets = append(out.ReplicaSets[:i], out.ReplicaSets[i+1:]...)
for _, m := range rs.Members {
for k, p := range out.Processes {
if p.Name == m.Host {
out.Processes = append(out.Processes[:k], out.Processes[k+1:]...)
processes := []*opsmngr.Process{}
for _, p := range out.Processes {
if p.Name != m.Host {
processes = append(processes, p)
}
}
out.Processes = processes
}
}
}
Expand All @@ -61,10 +63,12 @@ func removeByShardName(out *opsmngr.AutomationConfig, name string) {
// remove config rs
removeByReplicaSetName(out, s.ConfigServerReplica)
// remove mongos
for j := range out.Processes {
if out.Processes[j].Cluster == name {
out.Processes = append(out.Processes[:j], out.Processes[j+1:]...)
processes := []*opsmngr.Process{}
for _, p := range out.Processes {
if p.Cluster != name {
processes = append(processes, p)
}
}
out.Processes = processes
}
}
2 changes: 1 addition & 1 deletion atmcfg/remove_test.go
Expand Up @@ -26,7 +26,7 @@ func TestRemoveByClusterName(t *testing.T) {
}
})
t.Run("sharded cluster", func(t *testing.T) {
config := automationConfigWithOneShardedCluster(clusterName, false)
config := automationConfigWithThreeShardsCluster(clusterName, false)

RemoveByClusterName(config, clusterName)
if len(config.Processes) != 0 {
Expand Down

0 comments on commit ba0918b

Please sign in to comment.