Skip to content

Commit 2c3d49a

Browse files
CLOUDP-59267: upgrade all agents in Org (#143)
1 parent d0a44dd commit 2c3d49a

13 files changed

+201
-7
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/mattn/go-colorable v0.1.6 // indirect
1212
github.com/mitchellh/go-homedir v1.1.0
1313
github.com/mongodb/go-client-mongodb-atlas v0.2.1-0.20200427191133-b5e334932f44
14-
github.com/mongodb/go-client-mongodb-ops-manager v0.2.2-0.20200429114541-a82d7d125cfd
14+
github.com/mongodb/go-client-mongodb-ops-manager v0.2.2
1515
github.com/pelletier/go-toml v1.6.0 // indirect
1616
github.com/spf13/afero v1.2.2
1717
github.com/spf13/cast v1.3.1 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQz
102102
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
103103
github.com/mongodb/go-client-mongodb-atlas v0.2.1-0.20200427191133-b5e334932f44 h1:PUOc5BwUVOqGVQqX5vs2MPiJJ6PEZ+jA7TYtna1gOLo=
104104
github.com/mongodb/go-client-mongodb-atlas v0.2.1-0.20200427191133-b5e334932f44/go.mod h1:LS8O0YLkA+sbtOb3fZLF10yY3tJM+1xATXMJ3oU35LU=
105-
github.com/mongodb/go-client-mongodb-ops-manager v0.2.2-0.20200429114541-a82d7d125cfd h1:vGYgslrNXKaZIkAIomQ83e6bpaByXIhwNXJgYN+yv8A=
106-
github.com/mongodb/go-client-mongodb-ops-manager v0.2.2-0.20200429114541-a82d7d125cfd/go.mod h1:RrXnfBx3CyKN64jXkXFEO07CnMBEYa5CdlHOQ/30a5A=
105+
github.com/mongodb/go-client-mongodb-ops-manager v0.2.2 h1:xQoyeLjRJmOjvCkjCwbnkzIvugpm6eNozDw4Auk84to=
106+
github.com/mongodb/go-client-mongodb-ops-manager v0.2.2/go.mod h1:RrXnfBx3CyKN64jXkXFEO07CnMBEYa5CdlHOQ/30a5A=
107107
github.com/mwielbut/pointy v1.1.0 h1:U5/YEfoIkaGCHv0St3CgjduqXID4FNRoyZgLM1kY9vg=
108108
github.com/mwielbut/pointy v1.1.0/go.mod h1:MvvO+uMFj9T5DMda33HlvogsFBX7pWWKAkFIn4teYwY=
109109
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=

internal/cli/atlas_dbusers_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (opts *atlasDBUsersListOpts) initStore() error {
3636

3737
func (opts *atlasDBUsersListOpts) Run() error {
3838
listOpts := opts.newListOptions()
39-
result, err := opts.store.DatabaseUsers(opts.projectID, listOpts)
39+
result, err := opts.store.DatabaseUsers(opts.ProjectID(), listOpts)
4040

4141
if err != nil {
4242
return err

internal/cli/ops_manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func OpsManagerBuilder() *cobra.Command {
3838
cmd.AddCommand(OpsManagerProcessesBuilder())
3939
cmd.AddCommand(OpsManagerMeasurementsBuilder())
4040
cmd.AddCommand(OpsManagerLogsBuilder())
41+
cmd.AddCommand(OpsManagerAgentsBuilder())
4142

4243
return cmd
4344
}

internal/cli/ops_manager_agents.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2020 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cli
16+
17+
import (
18+
"github.com/mongodb/mongocli/internal/description"
19+
"github.com/spf13/cobra"
20+
)
21+
22+
func OpsManagerAgentsBuilder() *cobra.Command {
23+
cmd := &cobra.Command{
24+
Use: "agents",
25+
Aliases: []string{"agent"},
26+
Short: description.Agents,
27+
}
28+
29+
cmd.AddCommand(OpsManagerAgentsUpgradeBuilder())
30+
return cmd
31+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2020 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cli
16+
17+
import (
18+
"github.com/mongodb/mongocli/internal/flags"
19+
"github.com/mongodb/mongocli/internal/json"
20+
"github.com/mongodb/mongocli/internal/store"
21+
"github.com/mongodb/mongocli/internal/usage"
22+
"github.com/spf13/cobra"
23+
)
24+
25+
type opsManagerAgentsUpgradeOpts struct {
26+
globalOpts
27+
store store.AgentUpgrader
28+
}
29+
30+
func (opts *opsManagerAgentsUpgradeOpts) initStore() error {
31+
var err error
32+
opts.store, err = store.New()
33+
return err
34+
}
35+
36+
func (opts *opsManagerAgentsUpgradeOpts) Run() error {
37+
r, err := opts.store.UpgradeAgent(opts.ProjectID())
38+
39+
if err != nil {
40+
return err
41+
}
42+
43+
return json.PrettyPrint(r)
44+
}
45+
46+
// mongocli ops-manager agents upgrade [--projectId projectId]
47+
func OpsManagerAgentsUpgradeBuilder() *cobra.Command {
48+
opts := &opsManagerAgentsUpgradeOpts{}
49+
cmd := &cobra.Command{
50+
Use: "upgrade",
51+
Args: cobra.NoArgs,
52+
PreRunE: func(cmd *cobra.Command, args []string) error {
53+
return opts.PreRunE(opts.initStore)
54+
},
55+
RunE: func(cmd *cobra.Command, args []string) error {
56+
return opts.Run()
57+
},
58+
}
59+
60+
cmd.Flags().StringVar(&opts.projectID, flags.ProjectID, "", usage.ProjectID)
61+
62+
return cmd
63+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2020 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package cli
16+
17+
import (
18+
"testing"
19+
20+
"github.com/golang/mock/gomock"
21+
om "github.com/mongodb/go-client-mongodb-ops-manager/opsmngr"
22+
"github.com/mongodb/mongocli/internal/mocks"
23+
)
24+
25+
func TestOpsManagerAgentsUpgradeOpts_Run(t *testing.T) {
26+
ctrl := gomock.NewController(t)
27+
mockStore := mocks.NewMockAgentUpgrader(ctrl)
28+
29+
defer ctrl.Finish()
30+
31+
expected := new(om.AutomationConfigAgent)
32+
33+
opts := &opsManagerAgentsUpgradeOpts{
34+
store: mockStore,
35+
}
36+
37+
mockStore.
38+
EXPECT().
39+
UpgradeAgent(opts.projectID).
40+
Return(expected, nil).
41+
Times(1)
42+
43+
err := opts.Run()
44+
if err != nil {
45+
t.Fatalf("Run() unexpected error: %v", err)
46+
}
47+
}

internal/cli/ops_manager_automation_describe.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (opts *opsManagerAutomationDescribeOpts) initStore() error {
3434
}
3535

3636
func (opts *opsManagerAutomationDescribeOpts) Run() error {
37-
r, err := opts.store.GetAutomationConfig(opts.projectID)
37+
r, err := opts.store.GetAutomationConfig(opts.ProjectID())
3838

3939
if err != nil {
4040
return err

internal/cli/ops_manager_processes_describe.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ func OpsManagerProcessDescribeBuilder() *cobra.Command {
5252
Use: "describe [processID]",
5353
Short: description.ListProcesses,
5454
Aliases: []string{"d"},
55-
Hidden: true,
5655
Args: cobra.ExactArgs(1),
5756
PreRunE: func(cmd *cobra.Command, args []string) error {
5857
return opts.PreRunE(opts.initStore)

internal/cli/ops_manager_processes_list.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ func OpsManagerProcessListBuilder() *cobra.Command {
6262
Use: "list",
6363
Short: description.ListProcesses,
6464
Aliases: []string{"ls"},
65-
Hidden: true,
6665
Args: cobra.NoArgs,
6766
PreRunE: func(cmd *cobra.Command, args []string) error {
6867
return opts.PreRunE(opts.initStore)

0 commit comments

Comments
 (0)