Skip to content

Commit dde89d6

Browse files
authored
CLOUDP-97432: live migration validation job status command (#859)
1 parent 896ea51 commit dde89d6

15 files changed

+280
-8
lines changed

docs/command/mongocli-atlas-liveMigrations-create.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ Options
5454
- string
5555
- false
5656
- Organization ID to use. Overrides configuration file or environment variable settings.
57+
* - -o, --output
58+
- string
59+
- false
60+
- Output format.
61+
Valid values: json|json-path|go-template|go-template-file
5762
* - --sourceCACertificatePath
5863
- string
5964
- false

docs/command/mongocli-atlas-liveMigrations-validation-create.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ Options
5454
- string
5555
- false
5656
- Organization ID to use. Overrides configuration file or environment variable settings.
57+
* - -o, --output
58+
- string
59+
- false
60+
- Output format.
61+
Valid values: json|json-path|go-template|go-template-file
5762
* - --sourceCACertificatePath
5863
- string
5964
- false
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
.. _mongocli-atlas-liveMigrations-validation-describe:
2+
3+
=================================================
4+
mongocli atlas liveMigrations validation describe
5+
=================================================
6+
7+
.. default-domain:: mongodb
8+
9+
.. contents:: On this page
10+
:local:
11+
:backlinks: none
12+
:depth: 1
13+
:class: singlecol
14+
15+
Return one validation job.
16+
17+
Your API Key must have the Organization Owner role to successfully run this command.
18+
19+
Syntax
20+
------
21+
22+
.. code-block::
23+
24+
mongocli atlas liveMigrations validation describe [options]
25+
26+
Options
27+
-------
28+
29+
.. list-table::
30+
:header-rows: 1
31+
:widths: 20 10 10 60
32+
33+
* - Name
34+
- Type
35+
- Required
36+
- Description
37+
* - -h, --help
38+
-
39+
- false
40+
- help for describe
41+
* - -o, --output
42+
- string
43+
- false
44+
- Output format.
45+
Valid values: json|json-path|go-template|go-template-file
46+
* - --projectId
47+
- string
48+
- false
49+
- Project ID to use. Overrides configuration file or environment variable settings.
50+
* - --validationId
51+
- string
52+
- false
53+
- Unique 24-hexadecimal digit string that identifies the validation job.
54+
55+
Inherited Options
56+
-----------------
57+
58+
.. list-table::
59+
:header-rows: 1
60+
:widths: 20 10 10 60
61+
62+
* - Name
63+
- Type
64+
- Required
65+
- Description
66+
* - -P, --profile
67+
- string
68+
- false
69+
- Profile to use from your configuration file.
70+

docs/command/mongocli-atlas-liveMigrations-validation.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,12 @@ Related Commands
5050
----------------
5151

5252
* :ref:`mongocli-atlas-liveMigrations-validation-create` - Create one new validation request.
53+
* :ref:`mongocli-atlas-liveMigrations-validation-describe` - Return one validation job.
5354

5455

5556
.. toctree::
5657
:titlesonly:
5758

5859
create </command/mongocli-atlas-liveMigrations-validation-create>
60+
describe </command/mongocli-atlas-liveMigrations-validation-describe>
5961

internal/cli/atlas/livemigrations/create.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
package livemigrations
1616

1717
import (
18-
"github.com/mongodb/mongocli/internal/cli"
1918
"github.com/mongodb/mongocli/internal/cli/atlas/livemigrations/options"
2019
"github.com/mongodb/mongocli/internal/config"
2120
"github.com/mongodb/mongocli/internal/store"
2221
"github.com/spf13/cobra"
2322
)
2423

2524
type CreateOpts struct {
26-
cli.OutputOpts
2725
options.LiveMigrationsOpts
2826
store store.LiveMigrationCreator
2927
}

internal/cli/atlas/livemigrations/options/live_migrations_opts.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
)
2929

3030
type LiveMigrationsOpts struct {
31+
cli.OutputOpts
3132
cli.GlobalOpts
3233
DestinationClusterName string
3334
DestinationDropEnabled bool
@@ -138,6 +139,7 @@ func (opts *LiveMigrationsOpts) GenerateFlags(cmd *cobra.Command) {
138139
cmd.Flags().StringVar(&opts.DestinationClusterName, flag.ClusterName, "", usage.LiveMigrationDestinationClusterName)
139140
cmd.Flags().StringSliceVar(&opts.MigrationHosts, flag.LiveMigrationHost, []string{}, usage.LiveMigrationHostEntries)
140141
cmd.Flags().BoolVar(&opts.DestinationDropEnabled, flag.LiveMigrationDropCollections, false, usage.LiveMigrationDropCollections)
142+
cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut)
141143

142144
_ = cmd.MarkFlagRequired(flag.LiveMigrationSourceClusterName)
143145
_ = cmd.MarkFlagRequired(flag.LiveMigrationSourceProjectID)

internal/cli/atlas/livemigrations/validation/create.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
package validation
1616

1717
import (
18-
"github.com/mongodb/mongocli/internal/cli"
1918
"github.com/mongodb/mongocli/internal/cli/atlas/livemigrations/options"
2019
"github.com/mongodb/mongocli/internal/config"
2120
"github.com/mongodb/mongocli/internal/store"
2221
"github.com/spf13/cobra"
2322
)
2423

2524
type CreateOpts struct {
26-
cli.OutputOpts
2725
options.LiveMigrationsOpts
2826
store store.LiveMigrationValidationsCreator
2927
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright 2021 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package validation
16+
17+
import (
18+
"github.com/mongodb/mongocli/internal/cli"
19+
"github.com/mongodb/mongocli/internal/config"
20+
"github.com/mongodb/mongocli/internal/flag"
21+
"github.com/mongodb/mongocli/internal/store"
22+
"github.com/mongodb/mongocli/internal/usage"
23+
"github.com/spf13/cobra"
24+
)
25+
26+
type DescribeOpts struct {
27+
cli.GlobalOpts
28+
cli.OutputOpts
29+
validationID string
30+
store store.LiveMigrationValidationsDescriber
31+
}
32+
33+
func (opts *DescribeOpts) initStore() error {
34+
var err error
35+
opts.store, err = store.New(store.AuthenticatedPreset(config.Default()))
36+
return err
37+
}
38+
39+
var describeTemplate = `ID PROJECT ID SOURCE PROJECT ID STATUS
40+
{{.ID}} {{.GroupID}} {{.SourceGroupID}} {{.Status}}`
41+
42+
func (opts *DescribeOpts) Run() error {
43+
r, err := opts.store.GetValidationStatus(opts.ConfigProjectID(), opts.validationID)
44+
45+
if err != nil {
46+
return err
47+
}
48+
49+
return opts.Print(r)
50+
}
51+
52+
// mongocli atlas liveMigrations|lm validation(s) describe|get <validationId> [--projectId projectId].
53+
54+
func DescribeBuilder() *cobra.Command {
55+
opts := new(DescribeOpts)
56+
cmd := &cobra.Command{
57+
Use: "describe",
58+
Aliases: []string{"get"},
59+
Short: "Return one validation job.",
60+
Long: "Your API Key must have the Organization Owner role to successfully run this command.",
61+
PreRunE: func(cmd *cobra.Command, args []string) error {
62+
return opts.PreRunE(
63+
opts.ValidateProjectID,
64+
opts.initStore,
65+
opts.InitOutput(cmd.OutOrStdout(), describeTemplate),
66+
)
67+
},
68+
RunE: func(cmd *cobra.Command, args []string) error {
69+
return opts.Run()
70+
},
71+
}
72+
73+
cmd.Flags().StringVar(&opts.ProjectID, flag.ProjectID, "", usage.ProjectID)
74+
cmd.Flags().StringVar(&opts.validationID, flag.LiveMigrationValidationID, "", usage.LiveMigrationValidationID)
75+
cmd.Flags().StringVarP(&opts.Output, flag.Output, flag.OutputShort, "", usage.FormatOut)
76+
77+
return cmd
78+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright 2021 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:build unit
16+
17+
package validation
18+
19+
import (
20+
"testing"
21+
22+
"github.com/golang/mock/gomock"
23+
"github.com/mongodb/mongocli/internal/cli"
24+
"github.com/mongodb/mongocli/internal/flag"
25+
"github.com/mongodb/mongocli/internal/mocks"
26+
"github.com/mongodb/mongocli/internal/test"
27+
"go.mongodb.org/atlas/mongodbatlas"
28+
)
29+
30+
func TestValidationDescribeOpts_Run(t *testing.T) {
31+
ctrl := gomock.NewController(t)
32+
mockStore := mocks.NewMockLiveMigrationValidationsDescriber(ctrl)
33+
defer ctrl.Finish()
34+
35+
expected := mongodbatlas.Validation{}
36+
37+
describeOpts := &DescribeOpts{
38+
GlobalOpts: cli.GlobalOpts{ProjectID: "2"},
39+
validationID: "3",
40+
store: mockStore,
41+
}
42+
43+
mockStore.
44+
EXPECT().GetValidationStatus(describeOpts.ProjectID, describeOpts.validationID).Return(&expected, nil).
45+
Times(1)
46+
47+
if err := describeOpts.Run(); err != nil {
48+
t.Fatalf("Run() unexpected error: %v", err)
49+
}
50+
}
51+
52+
func TestDescribeBuilder(t *testing.T) {
53+
test.CmdValidator(
54+
t,
55+
DescribeBuilder(),
56+
0,
57+
[]string{
58+
flag.ProjectID,
59+
flag.LiveMigrationValidationID,
60+
},
61+
)
62+
}

internal/cli/atlas/livemigrations/validation/validation.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func Builder() *cobra.Command {
2626

2727
cmd.AddCommand(
2828
CreateBuilder(),
29+
DescribeBuilder(),
2930
)
3031

3132
return cmd

0 commit comments

Comments
 (0)