Skip to content
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
5 changes: 5 additions & 0 deletions docs/command/mongocli-atlas-liveMigrations-create.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ Options
- string
- false
- Organization ID to use. Overrides configuration file or environment variable settings.
* - -o, --output
- string
- false
- Output format.
Valid values: json|json-path|go-template|go-template-file
* - --sourceCACertificatePath
- string
- false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ Options
- string
- false
- Organization ID to use. Overrides configuration file or environment variable settings.
* - -o, --output
- string
- false
- Output format.
Valid values: json|json-path|go-template|go-template-file
* - --sourceCACertificatePath
- string
- false
Expand Down
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.

2 changes: 2 additions & 0 deletions docs/command/mongocli-atlas-liveMigrations-validation.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ Related Commands
----------------

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


.. toctree::
:titlesonly:

create </command/mongocli-atlas-liveMigrations-validation-create>
describe </command/mongocli-atlas-liveMigrations-validation-describe>

2 changes: 0 additions & 2 deletions internal/cli/atlas/livemigrations/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
package livemigrations

import (
"github.com/mongodb/mongocli/internal/cli"
"github.com/mongodb/mongocli/internal/cli/atlas/livemigrations/options"
"github.com/mongodb/mongocli/internal/config"
"github.com/mongodb/mongocli/internal/store"
"github.com/spf13/cobra"
)

type CreateOpts struct {
cli.OutputOpts
options.LiveMigrationsOpts
store store.LiveMigrationCreator
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
)

type LiveMigrationsOpts struct {
cli.OutputOpts
cli.GlobalOpts
DestinationClusterName string
DestinationDropEnabled bool
Expand Down Expand Up @@ -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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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)
Expand Down
2 changes: 0 additions & 2 deletions internal/cli/atlas/livemigrations/validation/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
package validation

import (
"github.com/mongodb/mongocli/internal/cli"
"github.com/mongodb/mongocli/internal/cli/atlas/livemigrations/options"
"github.com/mongodb/mongocli/internal/config"
"github.com/mongodb/mongocli/internal/store"
"github.com/spf13/cobra"
)

type CreateOpts struct {
cli.OutputOpts
options.LiveMigrationsOpts
store store.LiveMigrationValidationsCreator
}
Expand Down
78 changes: 78 additions & 0 deletions internal/cli/atlas/livemigrations/validation/describe.go
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 internal/cli/atlas/livemigrations/validation/describe_test.go
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,
},
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func Builder() *cobra.Command {

cmd.AddCommand(
CreateBuilder(),
DescribeBuilder(),
)

return cmd
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestBuilder(t *testing.T) {
test.CmdValidator(
t,
Builder(),
1,
2,
[]string{},
)
}
1 change: 1 addition & 0 deletions internal/flag/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,5 +264,6 @@ const (
OwnerID = "ownerId" // OwnerID flag
GovCloudRegionsOnly = "govCloudRegionsOnly" // GovCloudRegionsOnly flag
LiveMigrationID = "liveMigrationId" // LiveMigrationID flag
LiveMigrationValidationID = "validationId" // LiveMigrationDropCollections flag
LinkToken = "linkToken" // LinkToken flag
)
38 changes: 38 additions & 0 deletions internal/mocks/mock_live_migration.go

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

Loading