-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CLOUDP-57856: List all available partitions for a process, Atlas (#96)
- Loading branch information
Showing
13 changed files
with
384 additions
and
54 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
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,32 @@ | ||
// 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 cli | ||
|
||
import ( | ||
"github.com/mongodb/mongocli/internal/description" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func AtlasMeasurementsDisksBuilder() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "disks", | ||
Aliases: []string{"disk"}, | ||
Short: description.Disks, | ||
} | ||
|
||
cmd.AddCommand(AtlasMeasurementsDisksListBuilder()) | ||
|
||
return cmd | ||
} |
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,82 @@ | ||
// 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 cli | ||
|
||
import ( | ||
"github.com/mongodb/mongocli/internal/description" | ||
"github.com/mongodb/mongocli/internal/flags" | ||
"github.com/mongodb/mongocli/internal/json" | ||
"github.com/mongodb/mongocli/internal/store" | ||
"github.com/mongodb/mongocli/internal/usage" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type atlasMeasurementsDisksListsOpts struct { | ||
globalOpts | ||
listOpts | ||
host string | ||
port int | ||
store store.ProcessDisksLister | ||
} | ||
|
||
func (opts *atlasMeasurementsDisksListsOpts) init() error { | ||
if opts.ProjectID() == "" { | ||
return errMissingProjectID | ||
} | ||
|
||
var err error | ||
opts.store, err = store.New() | ||
return err | ||
} | ||
|
||
func (opts *atlasMeasurementsDisksListsOpts) Run() error { | ||
listOpts := opts.newListOptions() | ||
result, err := opts.store.ProcessDisks(opts.ProjectID(), opts.host, opts.port, listOpts) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
return json.PrettyPrint(result) | ||
} | ||
|
||
// mongocli atlas measurements process(es) disks lists host:port | ||
func AtlasMeasurementsDisksListBuilder() *cobra.Command { | ||
opts := &atlasMeasurementsDisksListsOpts{} | ||
cmd := &cobra.Command{ | ||
Use: "list", | ||
Short: description.ListDisks, | ||
Aliases: []string{"ls"}, | ||
Args: cobra.ExactArgs(1), | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
return opts.init() | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
var err error | ||
opts.host, opts.port, err = GetHostNameAndPort(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return opts.Run() | ||
}, | ||
} | ||
|
||
cmd.Flags().IntVar(&opts.pageNum, flags.Page, 0, usage.Page) | ||
cmd.Flags().IntVar(&opts.itemsPerPage, flags.Limit, 0, usage.Limit) | ||
cmd.Flags().StringVar(&opts.projectID, flags.ProjectID, "", usage.ProjectID) | ||
|
||
return cmd | ||
} |
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,53 @@ | ||
// 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 cli | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/mongodb/mongocli/internal/fixtures" | ||
"github.com/mongodb/mongocli/internal/mocks" | ||
) | ||
|
||
func TestAtlasMeasurementsDisksListsOpts_Run(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
mockStore := mocks.NewMockProcessDisksLister(ctrl) | ||
|
||
defer ctrl.Finish() | ||
|
||
expected := fixtures.ProcessDisks() | ||
|
||
listOpts := &atlasMeasurementsDisksListsOpts{ | ||
host: "hard-00-00.mongodb.net", | ||
port: 27017, | ||
store: mockStore, | ||
} | ||
|
||
hostName, port, err := GetHostNameAndPort("hard-00-00.mongodb.net:27017") | ||
if err != nil { | ||
t.Fatalf("Run() unexpected error: %v", err) | ||
} | ||
|
||
opts := listOpts.newListOptions() | ||
mockStore. | ||
EXPECT().ProcessDisks(listOpts.projectID, hostName, port, opts). | ||
Return(expected, nil). | ||
Times(1) | ||
|
||
err = listOpts.Run() | ||
if err != nil { | ||
t.Fatalf("Run() unexpected error: %v", err) | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.