-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLOUDP-73721: mongocli ops-manager admin backup blockstore(s) update (#…
…475)
- Loading branch information
1 parent
f377aa9
commit feff114
Showing
10 changed files
with
275 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ func TestBuilder(t *testing.T) { | |
cli.CmdValidator( | ||
t, | ||
Builder(), | ||
3, | ||
4, | ||
[]string{}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2020 MongoDB Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package blockstore | ||
|
||
import ( | ||
"github.com/mongodb/mongocli/internal/cli" | ||
"github.com/mongodb/mongocli/internal/cli/opsmanager/admin/backupstore" | ||
"github.com/mongodb/mongocli/internal/config" | ||
"github.com/mongodb/mongocli/internal/flag" | ||
"github.com/mongodb/mongocli/internal/store" | ||
"github.com/mongodb/mongocli/internal/usage" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var updateTemplate = "Blockstore configuration '{{.ID}}' updated.\n" | ||
|
||
type UpdateOpts struct { | ||
cli.OutputOpts | ||
backupstore.AdminOpts | ||
store store.BlockstoresUpdater | ||
} | ||
|
||
func (opts *UpdateOpts) init() error { | ||
var err error | ||
opts.store, err = store.New(config.Default()) | ||
return err | ||
} | ||
|
||
func (opts *UpdateOpts) Run() error { | ||
r, err := opts.store.UpdateBlockstore(opts.NewBackupStore()) | ||
if err != nil { | ||
return err | ||
} | ||
return opts.Print(r) | ||
} | ||
|
||
// mongocli ops-manager admin backup blockstore(s) update <ID> [--assignment][--encryptedCredentials] | ||
// [--label label][--loadFactor loadFactor][--maxCapacityGB maxCapacityGB][--uri uri][--ssl][--writeConcern writeConcern] | ||
func UpdateBuilder() *cobra.Command { | ||
opts := &UpdateOpts{} | ||
opts.Template = updateTemplate | ||
cmd := &cobra.Command{ | ||
Use: "update <ID>", | ||
Short: update, | ||
Args: cobra.ExactArgs(1), | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
opts.OutWriter = cmd.OutOrStdout() | ||
return opts.init() | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
opts.ID = args[0] | ||
return opts.Run() | ||
}, | ||
} | ||
|
||
cmd.Flags().BoolVar(&opts.Assignment, flag.Assignment, false, usage.Assignment) | ||
cmd.Flags().BoolVar(&opts.EncryptedCredentials, flag.EncryptedCredentials, false, usage.EncryptedCredentials) | ||
cmd.Flags().StringSliceVar(&opts.Label, flag.Label, []string{}, usage.Label) | ||
cmd.Flags().Int64Var(&opts.LoadFactor, flag.LoadFactor, 0, usage.LoadFactor) | ||
cmd.Flags().Int64Var(&opts.MaxCapacityGB, flag.MaxCapacityGB, 0, usage.MaxCapacityGB) | ||
cmd.Flags().StringVar(&opts.URI, flag.URI, "", usage.BlockstoreURI) | ||
cmd.Flags().BoolVar(&opts.SSL, flag.SSL, false, usage.BlockstoreSSL) | ||
cmd.Flags().StringVar(&opts.WriteConcern, flag.WriteConcern, "", usage.WriteConcern) | ||
|
||
cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut) | ||
|
||
return cmd | ||
} |
58 changes: 58 additions & 0 deletions
58
internal/cli/opsmanager/admin/backup/blockstore/update_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2020 MongoDB Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// +build unit | ||
|
||
package blockstore | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/mongodb/mongocli/internal/cli" | ||
"github.com/mongodb/mongocli/internal/flag" | ||
"github.com/mongodb/mongocli/internal/mocks" | ||
"go.mongodb.org/ops-manager/opsmngr" | ||
) | ||
|
||
func TestUpdate_Run(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
mockStore := mocks.NewMockBlockstoresUpdater(ctrl) | ||
defer ctrl.Finish() | ||
|
||
expected := &opsmngr.BackupStore{} | ||
|
||
opts := &UpdateOpts{ | ||
store: mockStore, | ||
} | ||
|
||
mockStore. | ||
EXPECT().UpdateBlockstore(opts.NewBackupStore()). | ||
Return(expected, nil). | ||
Times(1) | ||
|
||
err := opts.Run() | ||
if err != nil { | ||
t.Fatalf("Run() unexpected error: %v", err) | ||
} | ||
} | ||
|
||
func TestUpdateBuilder(t *testing.T) { | ||
cli.CmdValidator( | ||
t, | ||
UpdateBuilder(), | ||
0, | ||
[]string{flag.Output, flag.SSL, flag.EncryptedCredentials, flag.LoadFactor, | ||
flag.MaxCapacityGB, flag.Assignment, flag.Label, flag.URI, flag.WriteConcern}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright 2020 MongoDB Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package backupstore | ||
|
||
import "go.mongodb.org/ops-manager/opsmngr" | ||
|
||
type AdminOpts struct { | ||
Assignment bool | ||
EncryptedCredentials bool | ||
SSL bool | ||
ID string | ||
Label []string | ||
WriteConcern string | ||
URI string | ||
LoadFactor int64 | ||
MaxCapacityGB int64 | ||
} | ||
|
||
func (opts *AdminOpts) NewBackupStore() *opsmngr.BackupStore { | ||
backupStore := &opsmngr.BackupStore{ | ||
AdminBackupConfig: opsmngr.AdminBackupConfig{ | ||
ID: opts.ID, | ||
URI: opts.URI, | ||
WriteConcern: opts.WriteConcern, | ||
Labels: opts.Label, | ||
}, | ||
} | ||
|
||
if opts.SSL { | ||
backupStore.SSL = &opts.SSL | ||
} | ||
|
||
if opts.EncryptedCredentials { | ||
backupStore.EncryptedCredentials = &opts.EncryptedCredentials | ||
} | ||
|
||
if opts.Assignment { | ||
backupStore.AssignmentEnabled = &opts.Assignment | ||
} | ||
|
||
if opts.MaxCapacityGB != 0 { | ||
backupStore.MaxCapacityGB = &opts.MaxCapacityGB | ||
} | ||
|
||
if opts.LoadFactor != 0 { | ||
backupStore.LoadFactor = &opts.LoadFactor | ||
} | ||
|
||
return backupStore | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.