-
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-74585: Allow to stop monitoring a host (#483)
- Loading branch information
Showing
9 changed files
with
338 additions
and
39 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 |
---|---|---|
|
@@ -36,6 +36,7 @@ func Builder() *cobra.Command { | |
|
||
cmd.AddCommand( | ||
EnableBuilder(), | ||
StopBuilder(), | ||
) | ||
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 |
---|---|---|
|
@@ -28,7 +28,7 @@ func TestBuilder(t *testing.T) { | |
cli.CmdValidator( | ||
t, | ||
Builder(), | ||
1, | ||
2, | ||
[]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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// 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 monitoring | ||
|
||
import ( | ||
"github.com/mongodb/mongocli/internal/cli" | ||
"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" | ||
) | ||
|
||
type StopOpts struct { | ||
cli.GlobalOpts | ||
*cli.DeleteOpts | ||
store store.MonitoringStopper | ||
} | ||
|
||
func (opts *StopOpts) initStore() error { | ||
var err error | ||
opts.store, err = store.New(config.Default()) | ||
return err | ||
} | ||
|
||
func (opts *StopOpts) Run() error { | ||
return opts.Delete(opts.store.StopMonitoring, opts.ConfigProjectID()) | ||
} | ||
|
||
// mongocli ops-manager monitoring stop <ID> --force | ||
func StopBuilder() *cobra.Command { | ||
opts := &StopOpts{ | ||
DeleteOpts: cli.NewDeleteOpts("Stopped monitoring '%s'\n", "Monitoring did not stop"), | ||
} | ||
cmd := &cobra.Command{ | ||
Use: "stop <ID>", | ||
Aliases: []string{"rm"}, | ||
Short: "Stops monitoring the MongoDB process specified", | ||
Args: cobra.ExactArgs(1), | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
if err := opts.PreRunE(opts.initStore); err != nil { | ||
return err | ||
} | ||
opts.Entry = args[0] | ||
return opts.Prompt() | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return opts.Run() | ||
}, | ||
} | ||
|
||
cmd.Flags().BoolVar(&opts.Confirm, flag.Force, false, usage.Force) | ||
cmd.Flags().StringVar(&opts.ProjectID, flag.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,57 @@ | ||
// 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 monitoring | ||
|
||
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" | ||
) | ||
|
||
func TestStopBuilder(t *testing.T) { | ||
cli.CmdValidator( | ||
t, | ||
StopBuilder(), | ||
0, | ||
[]string{flag.ProjectID, flag.Force}, | ||
) | ||
} | ||
|
||
func TestStopOpts_Run(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
mockStore := mocks.NewMockMonitoringStopper(ctrl) | ||
defer ctrl.Finish() | ||
|
||
opts := &StopOpts{ | ||
store: mockStore, | ||
DeleteOpts: &cli.DeleteOpts{ | ||
Confirm: true, | ||
Entry: "test", | ||
}, | ||
} | ||
|
||
mockStore. | ||
EXPECT(). | ||
StopMonitoring(opts.ProjectID, opts.Entry). | ||
Return(nil). | ||
Times(1) | ||
|
||
if err := opts.Run(); 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
Oops, something went wrong.