-
Notifications
You must be signed in to change notification settings - Fork 88
CLOUDP-57865: Download tar.gz / .zip diagnose archive #152
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
13 commits
Select commit
Hold shift + click to select a range
7c198bc
Refactoring
andreaangiolillo 1dacaa0
Merge remote-tracking branch 'origin/master'
andreaangiolillo 39b30ca
Merge remote-tracking branch 'origin/master'
andreaangiolillo 861d88e
Merge remote-tracking branch 'origin/master'
andreaangiolillo a1ba80a
Merge remote-tracking branch 'origin/master'
andreaangiolillo bb665d9
Download tar.gz / .zip diagnose archive
andreaangiolillo 1052ff1
Refactoring
andreaangiolillo 43111e2
Merge remote-tracking branch 'origin/master' into CLOUDP-57865
andreaangiolillo a9eba19
Updated description
andreaangiolillo 17ca034
Addressed PR Comments
andreaangiolillo 678a02d
Addressed PR comment - 2
andreaangiolillo 8515a6c
Refactoring
andreaangiolillo f24b848
Addressed PR Comments
andreaangiolillo 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
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,31 @@ | ||
// 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 OpsManagerDiagnoseArchive() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "diagnose-archive", | ||
Short: description.DiagnoseArchive, | ||
} | ||
|
||
cmd.AddCommand(OpsManagerDiagnoseArchiveDownloadBuilder()) | ||
|
||
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 |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// 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 ( | ||
"io" | ||
"os" | ||
|
||
"github.com/mongodb/mongocli/internal/description" | ||
"github.com/mongodb/mongocli/internal/flags" | ||
"github.com/mongodb/mongocli/internal/store" | ||
"github.com/mongodb/mongocli/internal/usage" | ||
"github.com/spf13/afero" | ||
"github.com/spf13/cobra" | ||
"go.mongodb.org/ops-manager/opsmngr" | ||
) | ||
|
||
type opsManagerDiagnoseArchiveDownloadOpts struct { | ||
globalOpts | ||
out string | ||
limit int64 | ||
minutes int64 | ||
fs afero.Fs | ||
store store.ArchivesDownloader | ||
} | ||
|
||
func (opts *opsManagerDiagnoseArchiveDownloadOpts) initStore() error { | ||
var err error | ||
opts.store, err = store.New() | ||
return err | ||
} | ||
|
||
func (opts *opsManagerDiagnoseArchiveDownloadOpts) Run() error { | ||
out, err := opts.newWriteCloser() | ||
if err != nil { | ||
return err | ||
} | ||
defer out.Close() | ||
|
||
andreaangiolillo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err := opts.store.DownloadArchive(opts.ProjectID(), opts.newDiagnosticsListOpts(), out); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (opts *opsManagerDiagnoseArchiveDownloadOpts) newWriteCloser() (io.WriteCloser, error) { | ||
// Create file only if is not there already (don't overwrite) | ||
ff := os.O_CREATE | os.O_TRUNC | os.O_WRONLY | os.O_EXCL | ||
f, err := opts.fs.OpenFile(opts.out, ff, 0777) | ||
return f, err | ||
} | ||
|
||
func (opts *opsManagerDiagnoseArchiveDownloadOpts) newDiagnosticsListOpts() *opsmngr.DiagnosticsListOpts { | ||
return &opsmngr.DiagnosticsListOpts{ | ||
Limit: opts.limit, | ||
Minutes: opts.minutes, | ||
} | ||
} | ||
|
||
// mongocli om diagnose-archive download [--out out] [--projectId projectId] | ||
func OpsManagerDiagnoseArchiveDownloadBuilder() *cobra.Command { | ||
opts := &opsManagerDiagnoseArchiveDownloadOpts{ | ||
fs: afero.NewOsFs(), | ||
} | ||
cmd := &cobra.Command{ | ||
Use: "download", | ||
Aliases: []string{"get"}, | ||
Short: description.DownloadDiagnoseArchive, | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
return opts.PreRunE(opts.initStore) | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
return opts.Run() | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVarP(&opts.out, flags.Out, flags.OutShort, "diagnose-archive.tar.gz", usage.DiagnoseOut) | ||
cmd.Flags().Int64Var(&opts.limit, flags.Limit, 0, usage.ArchiveLimit) | ||
cmd.Flags().Int64Var(&opts.minutes, flags.Minutes, 0, usage.ArchiveMinutes) | ||
|
||
cmd.Flags().StringVar(&opts.projectID, flags.ProjectID, "", usage.ProjectID) | ||
|
||
return cmd | ||
} |
50 changes: 50 additions & 0 deletions
50
internal/cli/ops_manager_diagnose_archive_download_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,50 @@ | ||
// 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/mocks" | ||
"github.com/spf13/afero" | ||
) | ||
|
||
func TestOpsManagerDiagnoseArchiveDownloadOpts_Run(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
mockStore := mocks.NewMockArchivesDownloader(ctrl) | ||
|
||
appFS := afero.NewMemMapFs() | ||
|
||
opts := &opsManagerDiagnoseArchiveDownloadOpts{ | ||
fs: appFS, | ||
store: mockStore, | ||
} | ||
|
||
f, err := opts.newWriteCloser() | ||
if err != nil { | ||
t.Fatalf("newWriteCloser() unexpected error: %v", err) | ||
} | ||
|
||
mockStore. | ||
EXPECT(). | ||
DownloadArchive(opts.projectID, opts.newDiagnosticsListOpts(), f). | ||
Return(nil). | ||
Times(1) | ||
|
||
if err := opts.Run(); err != nil { | ||
t.Fatalf("Run() unexpected error: %v", err) | ||
} | ||
} |
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
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.