Skip to content

CLOUDP-57856: List all available partitions for a process, Atlas #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ gen-mocks: ## Generate mocks
mockgen -source=internal/store/global_alerts.go -destination=internal/mocks/mock_global_alerts.go -package=mocks
mockgen -source=internal/store/events.go -destination=internal/mocks/mock_events.go -package=mocks
mockgen -source=internal/store/process_measurements.go -destination=internal/mocks/mock_process_measurements.go -package=mocks
mockgen -source=internal/store/process_disks.go -destination=internal/mocks/mock_process_disks.go -package=mocks
mockgen -source=internal/store/host_measurements.go -destination=internal/mocks/mock_host_measurements.go -package=mocks
mockgen -source=internal/store/indexes.go -destination=internal/mocks/mock_indexes.go -package=mocks

.PHONY: build
Expand Down
1 change: 1 addition & 0 deletions internal/cli/atlas_measurements.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func AtlasMeasurementsBuilder() *cobra.Command {
Short: description.Measurements,
}
cmd.AddCommand(AtlasMeasurementsProcessBuilder())
cmd.AddCommand(AtlasMeasurementsDisksBuilder())

return cmd
}
32 changes: 32 additions & 0 deletions internal/cli/atlas_measurements_disks.go
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
}
82 changes: 82 additions & 0 deletions internal/cli/atlas_measurements_disks_list.go
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
}
53 changes: 53 additions & 0 deletions internal/cli/atlas_measurements_disks_list_test.go
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)
}
}
2 changes: 2 additions & 0 deletions internal/description/description.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ A user’s roles apply to all the clusters in the project.`
ListEvents = "List events for an organization or project"
UpdateDBUser = "Update a MongoDB dbuser in Atlas."
ProcessMeasurements = "Get measurements for a given host."
Disks = "List available disks or disks measurements for a given host."
ListDisks = "List available disks for a given host."
Whitelist = "Manage the IP whitelist for a project."
CreateWhitelist = "Create an IP whitelist for a project."
DeleteWhitelist = "Delete a database user for a project."
Expand Down
37 changes: 37 additions & 0 deletions internal/fixtures/measurements.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
// 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 fixtures

import atlas "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas"

func ProcessDisks() *atlas.ProcessDisksResponse {
return &atlas.ProcessDisksResponse{
Links: []*atlas.Link{
{
Rel: "self",
Href: "https://cloud.mongodb.com/api/atlas/v1.0/groups/12345678/processes/shard-00-00.mongodb.net:27017/disks",
},
},
Results: []*atlas.ProcessDisk{
{
Links: []*atlas.Link{
{
Rel: "self",
Href: "https://cloud.mongodb.com/api/atlas/v1.0/groups/12345678/processes/shard-00-00.mongodb.net:27017/disks/test",
},
},
PartitionName: "test",
},
},
TotalCount: 1,
}
}

func ProcessMeasurements() *atlas.ProcessMeasurements {
return &atlas.ProcessMeasurements{
End: "2017-08-22T20:31:14Z",
Expand Down
49 changes: 49 additions & 0 deletions internal/mocks/mock_host_measurements.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions internal/mocks/mock_process_disks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 0 additions & 38 deletions internal/mocks/mock_process_measurements.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading