-
Notifications
You must be signed in to change notification settings - Fork 88
CLOUDP-97432: live migration validation job status command #859
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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
70 changes: 70 additions & 0 deletions
70
docs/command/mongocli-atlas-liveMigrations-validation-describe.txt
This file contains hidden or 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,70 @@ | ||
| .. _mongocli-atlas-liveMigrations-validation-describe: | ||
|
|
||
| ================================================= | ||
| mongocli atlas liveMigrations validation describe | ||
| ================================================= | ||
|
|
||
| .. default-domain:: mongodb | ||
|
|
||
| .. contents:: On this page | ||
| :local: | ||
| :backlinks: none | ||
| :depth: 1 | ||
| :class: singlecol | ||
|
|
||
| Return one validation job. | ||
|
|
||
| Your API Key must have the Organization Owner role to successfully run this command. | ||
|
|
||
| Syntax | ||
| ------ | ||
|
|
||
| .. code-block:: | ||
|
|
||
| mongocli atlas liveMigrations validation describe [options] | ||
|
|
||
| Options | ||
| ------- | ||
|
|
||
| .. list-table:: | ||
| :header-rows: 1 | ||
| :widths: 20 10 10 60 | ||
|
|
||
| * - Name | ||
| - Type | ||
| - Required | ||
| - Description | ||
| * - -h, --help | ||
| - | ||
| - false | ||
| - help for describe | ||
| * - -o, --output | ||
| - string | ||
| - false | ||
| - Output format. | ||
| Valid values: json|json-path|go-template|go-template-file | ||
| * - --projectId | ||
| - string | ||
| - false | ||
| - Project ID to use. Overrides configuration file or environment variable settings. | ||
| * - --validationId | ||
| - string | ||
| - false | ||
| - Unique 24-hexadecimal digit string that identifies the validation job. | ||
|
|
||
| Inherited Options | ||
| ----------------- | ||
|
|
||
| .. list-table:: | ||
| :header-rows: 1 | ||
| :widths: 20 10 10 60 | ||
|
|
||
| * - Name | ||
| - Type | ||
| - Required | ||
| - Description | ||
| * - -P, --profile | ||
| - string | ||
| - false | ||
| - Profile to use from your configuration file. | ||
|
|
This file contains hidden or 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 hidden or 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 hidden or 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,6 +28,7 @@ import ( | |
| ) | ||
|
|
||
| type LiveMigrationsOpts struct { | ||
| cli.OutputOpts | ||
| cli.GlobalOpts | ||
| DestinationClusterName string | ||
| DestinationDropEnabled bool | ||
|
|
@@ -138,6 +139,7 @@ func (opts *LiveMigrationsOpts) GenerateFlags(cmd *cobra.Command) { | |
| cmd.Flags().StringVar(&opts.DestinationClusterName, flag.ClusterName, "", usage.LiveMigrationDestinationClusterName) | ||
| cmd.Flags().StringSliceVar(&opts.MigrationHosts, flag.LiveMigrationHost, []string{}, usage.LiveMigrationHostEntries) | ||
| cmd.Flags().BoolVar(&opts.DestinationDropEnabled, flag.LiveMigrationDropCollections, false, usage.LiveMigrationDropCollections) | ||
| cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut) | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [flyby] Allowing json output for the live migration commands |
||
|
|
||
| _ = cmd.MarkFlagRequired(flag.LiveMigrationSourceClusterName) | ||
| _ = cmd.MarkFlagRequired(flag.LiveMigrationSourceProjectID) | ||
|
|
||
This file contains hidden or 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 hidden or 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,78 @@ | ||
| // Copyright 2021 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 validation | ||
|
|
||
| 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 DescribeOpts struct { | ||
| cli.GlobalOpts | ||
| cli.OutputOpts | ||
| validationID string | ||
| store store.LiveMigrationValidationsDescriber | ||
| } | ||
|
|
||
| func (opts *DescribeOpts) initStore() error { | ||
| var err error | ||
| opts.store, err = store.New(store.AuthenticatedPreset(config.Default())) | ||
| return err | ||
| } | ||
|
|
||
| var describeTemplate = `ID PROJECT ID SOURCE PROJECT ID STATUS | ||
| {{.ID}} {{.GroupID}} {{.SourceGroupID}} {{.Status}}` | ||
|
|
||
| func (opts *DescribeOpts) Run() error { | ||
| r, err := opts.store.GetValidationStatus(opts.ConfigProjectID(), opts.validationID) | ||
|
|
||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return opts.Print(r) | ||
| } | ||
|
|
||
| // mongocli atlas liveMigrations|lm validation(s) describe|get <validationId> [--projectId projectId]. | ||
|
|
||
| func DescribeBuilder() *cobra.Command { | ||
| opts := new(DescribeOpts) | ||
| cmd := &cobra.Command{ | ||
| Use: "describe", | ||
| Aliases: []string{"get"}, | ||
| Short: "Return one validation job.", | ||
| Long: "Your API Key must have the Organization Owner role to successfully run this command.", | ||
| PreRunE: func(cmd *cobra.Command, args []string) error { | ||
| return opts.PreRunE( | ||
| opts.ValidateProjectID, | ||
| opts.initStore, | ||
| opts.InitOutput(cmd.OutOrStdout(), describeTemplate), | ||
| ) | ||
| }, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return opts.Run() | ||
| }, | ||
| } | ||
|
|
||
| cmd.Flags().StringVar(&opts.ProjectID, flag.ProjectID, "", usage.ProjectID) | ||
| cmd.Flags().StringVar(&opts.validationID, flag.LiveMigrationValidationID, "", usage.LiveMigrationValidationID) | ||
| cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut) | ||
|
|
||
| return cmd | ||
| } |
62 changes: 62 additions & 0 deletions
62
internal/cli/atlas/livemigrations/validation/describe_test.go
This file contains hidden or 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 2021 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. | ||
|
|
||
| //go:build unit | ||
|
|
||
| package validation | ||
|
|
||
| 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" | ||
| "github.com/mongodb/mongocli/internal/test" | ||
| "go.mongodb.org/atlas/mongodbatlas" | ||
| ) | ||
|
|
||
| func TestValidationDescribeOpts_Run(t *testing.T) { | ||
| ctrl := gomock.NewController(t) | ||
| mockStore := mocks.NewMockLiveMigrationValidationsDescriber(ctrl) | ||
| defer ctrl.Finish() | ||
|
|
||
| expected := mongodbatlas.Validation{} | ||
|
|
||
| describeOpts := &DescribeOpts{ | ||
| GlobalOpts: cli.GlobalOpts{ProjectID: "2"}, | ||
| validationID: "3", | ||
| store: mockStore, | ||
| } | ||
|
|
||
| mockStore. | ||
| EXPECT().GetValidationStatus(describeOpts.ProjectID, describeOpts.validationID).Return(&expected, nil). | ||
| Times(1) | ||
|
|
||
| if err := describeOpts.Run(); err != nil { | ||
| t.Fatalf("Run() unexpected error: %v", err) | ||
| } | ||
| } | ||
|
|
||
| func TestDescribeBuilder(t *testing.T) { | ||
| test.CmdValidator( | ||
| t, | ||
| DescribeBuilder(), | ||
| 0, | ||
| []string{ | ||
| flag.ProjectID, | ||
| flag.LiveMigrationValidationID, | ||
| }, | ||
| ) | ||
| } |
This file contains hidden or 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,6 +26,7 @@ func Builder() *cobra.Command { | |
|
|
||
| cmd.AddCommand( | ||
| CreateBuilder(), | ||
| DescribeBuilder(), | ||
| ) | ||
|
|
||
| return cmd | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ func TestBuilder(t *testing.T) { | |
| test.CmdValidator( | ||
| t, | ||
| Builder(), | ||
| 1, | ||
| 2, | ||
| []string{}, | ||
| ) | ||
| } | ||
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.