Skip to content

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 13 commits into from
May 5, 2020
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ gen-mocks: ## Generate mocks
mockgen -source=internal/store/host_databases.go -destination=internal/mocks/mock_host_databases.go -package=mocks
mockgen -source=internal/store/host_disks.go -destination=internal/mocks/mock_host_disks.go -package=mocks
mockgen -source=internal/store/host_disk_measurements.go -destination=internal/mocks/mock_host_disk_measurements.go -package=mocks
mockgen -source=internal/store/diagnose_archive.go -destination=internal/mocks/mock_diagnose_archive.go -package=mocks

.PHONY: build
build: ## Generate a binary in ./bin
Expand Down
1 change: 1 addition & 0 deletions internal/cli/ops_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func OpsManagerBuilder() *cobra.Command {
cmd.AddCommand(OpsManagerMeasurementsBuilder())
cmd.AddCommand(OpsManagerLogsBuilder())
cmd.AddCommand(OpsManagerAgentsBuilder())
cmd.AddCommand(OpsManagerDiagnoseArchive())

return cmd
}
31 changes: 31 additions & 0 deletions internal/cli/ops_manager_diagnose_archive.go
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
}
97 changes: 97 additions & 0 deletions internal/cli/ops_manager_diagnose_archive_download.go
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()

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 internal/cli/ops_manager_diagnose_archive_download_test.go
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)
}
}
1 change: 1 addition & 0 deletions internal/cli/ops_manager_logs_jobs_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (opts *opsManagerLogsJobsDownloadOpts) Run() error {
if err != nil {
return err
}
defer out.Close()

if err := opts.store.DownloadLogJob(opts.ProjectID(), opts.id, out); err != nil {
return err
Expand Down
182 changes: 92 additions & 90 deletions internal/description/description.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,96 +14,98 @@
package description

const (
Atlas = "Atlas operations."
Alerts = "Manage alerts for your project."
AcknowledgeAlerts = "Acknowledge an alert."
Config = "Manage alerts configuration for your project."
ConfigLong = "The configs command provides access to your alerts configurations. You can create, edit, and delete alert configurations."
CreateAlertsConfig = "Create an alert configuration for a project."
DeleteAlertsConfig = "Delete an alert config."
AlertsConfigFields = "Manage alert configuration fields for your project."
AlertsConfigFieldsType = "List alert configurations available field types."
ListAlertsConfigs = "List alert configurations for a project."
UpdateAlertsConfig = "Update an alert configuration for a project."
DescribeAlert = "Describe an alert for a project."
ListAlerts = "List alerts for a project."
Backup = "Manage continuous backups for your project."
Checkpoints = "Manage backup checkpoints for your project."
ListCheckpoints = "List continuous backup checkpoints."
Restores = "Manage restore jobs."
ListRestores = "Lists restore jobs for a project and cluster."
StartRestore = "Start a restore job."
Snapshots = "Manage continuous snapshots for your project."
ListSnapshots = "List continuous snapshots for a project."
Logs = "Download host logs."
Clusters = "Manage clusters for your project."
ClustersIndexes = "Manage cluster rolling indexes for your project."
ClustersLong = "The clusters command provides access to your cluster configurations. You can create, edit, and delete clusters."
CreateCluster = "Create a MongoDB cluster."
CreateIndex = "Create a rolling index for your MongoDB cluster."
ApplyCluster = "Apply a new cluster configuration."
DeleteCluster = "Delete a cluster."
DescribeCluster = "Describe a cluster."
ListClusters = "List clusters for a project."
UpdateCluster = "Update a MongoDB cluster."
PauseCluster = "Pause a running MongoDB cluster in Atlas."
StartCluster = "Start a paused MongoDB cluster in Atlas."
WatchCluster = "Watch for a cluster to be available."
Processes = "Manage MongoDB processes for your project."
ListProcesses = "List MongoDB processes for a project."
DBUsers = "Manage database users for your project."
CreateDBUser = "Create a database user for a project."
DeleteDBUser = "Delete a database user for a project."
ListDBUsers = "List Atlas database users for a project."
ListEvents = "List events for an organization or project"
UpdateDBUser = "Update a MongoDB dbuser in Atlas."
ProcessMeasurements = "Get measurements for a given host."
Disks = "List available disks or disks measurements for a given host."
ListDisks = "List available disks for a given host."
DescribeDisks = "Describe disks measurements for a given host partition."
Databases = "List available databases or databases measurements for a given host."
ListDatabases = "List available databases for a given host."
Whitelist = "Manage the IP whitelist for a project."
CreateWhitelist = "Create an IP whitelist for a project."
DeleteWhitelist = "Delete a database user for a project."
DescribeWhitelist = "Describe an Atlas whitelist."
ListWhitelist = "List Atlas whitelist for a project."
CloudManager = "Cloud Manager operations."
ShutdownCluster = "Shutdown a cluster."
StartUpCluster = "Start up a cluster."
ConfigDescription = "Configure a profile. This let you store access settings to your cloud."
ConfigSetDescription = "Configure specific properties of the profile."
IAM = "Authentication operations."
Organization = "Organization operations."
OrganizationLong = "Create, list and manage your MongoDB organizations."
CreateOrganization = "Create an organization."
DeleteOrganization = "Delete an organization."
ListOrganizations = "List organizations."
Projects = "Project operations."
ProjectsLong = "Create, list and manage your MongoDB projects."
CreateProject = "Create a project."
DeleteProject = "Delete a project."
ListProjects = "List projects."
DownloadLogs = "Download logs from a log collection job."
OpsManager = "Ops Manager operations."
Agents = "Manage Ops Manager agents."
ListGlobalAlerts = "List global alerts."
Automation = "Manage Ops Manager automation config."
ShowAutomationStatus = "Show the current status of the automation config."
Global = "Manage Ops Manager global properties."
Owner = "Manage Ops Manager owners."
CreateOwner = "Create the first user for Ops Manager."
Servers = "Manage Ops Manager servers."
ListServer = "List all available servers running an automation agent for the given project."
Security = "Manage clusters security configuration."
EnableSecurity = "Enable authentication mechanisms for the project."
Events = "Manage events for your project."
Measurements = "Get measurements on the state of the MongoDB process."
LogCollection = "Manage log collection jobs."
StartLogCollectionJob = "Start a job to collect logs."
ListLogCollectionJobs = "List log collection jobs."
DeleteLogCollectionJob = "Delete a log collection job."
DBUsersLong = `The dbusers command retrieves, creates and modifies the MongoDB database users in your cluster.
Atlas = "Atlas operations."
Alerts = "Manage alerts for your project."
AcknowledgeAlerts = "Acknowledge an alert."
Config = "Manage alerts configuration for your project."
ConfigLong = "The configs command provides access to your alerts configurations. You can create, edit, and delete alert configurations."
CreateAlertsConfig = "Create an alert configuration for a project."
DeleteAlertsConfig = "Delete an alert config."
AlertsConfigFields = "Manage alert configuration fields for your project."
AlertsConfigFieldsType = "List alert configurations available field types."
ListAlertsConfigs = "List alert configurations for a project."
UpdateAlertsConfig = "Update an alert configuration for a project."
DescribeAlert = "Describe an alert for a project."
ListAlerts = "List alerts for a project."
Backup = "Manage continuous backups for your project."
Checkpoints = "Manage backup checkpoints for your project."
ListCheckpoints = "List continuous backup checkpoints."
Restores = "Manage restore jobs."
ListRestores = "Lists restore jobs for a project and cluster."
StartRestore = "Start a restore job."
Snapshots = "Manage continuous snapshots for your project."
ListSnapshots = "List continuous snapshots for a project."
Logs = "Download host logs."
Clusters = "Manage clusters for your project."
ClustersIndexes = "Manage cluster rolling indexes for your project."
ClustersLong = "The clusters command provides access to your cluster configurations. You can create, edit, and delete clusters."
CreateCluster = "Create a MongoDB cluster."
CreateIndex = "Create a rolling index for your MongoDB cluster."
ApplyCluster = "Apply a new cluster configuration."
DeleteCluster = "Delete a cluster."
DescribeCluster = "Describe a cluster."
ListClusters = "List clusters for a project."
UpdateCluster = "Update a MongoDB cluster."
PauseCluster = "Pause a running MongoDB cluster in Atlas."
StartCluster = "Start a paused MongoDB cluster in Atlas."
WatchCluster = "Watch for a cluster to be available."
Processes = "Manage MongoDB processes for your project."
ListProcesses = "List MongoDB processes for a project."
DBUsers = "Manage database users for your project."
DiagnoseArchive = "Manage diagnose archives."
DownloadDiagnoseArchive = "Download diagnose archives."
CreateDBUser = "Create a database user for a project."
DeleteDBUser = "Delete a database user for a project."
ListDBUsers = "List Atlas database users for a project."
ListEvents = "List events for an organization or project"
UpdateDBUser = "Update a MongoDB dbuser in Atlas."
ProcessMeasurements = "Get measurements for a given host."
Disks = "List available disks or disks measurements for a given host."
ListDisks = "List available disks for a given host."
DescribeDisks = "Describe disks measurements for a given host partition."
Databases = "List available databases or databases measurements for a given host."
ListDatabases = "List available databases for a given host."
Whitelist = "Manage the IP whitelist for a project."
CreateWhitelist = "Create an IP whitelist for a project."
DeleteWhitelist = "Delete a database user for a project."
DescribeWhitelist = "Describe an Atlas whitelist."
ListWhitelist = "List Atlas whitelist for a project."
CloudManager = "Cloud Manager operations."
ShutdownCluster = "Shutdown a cluster."
StartUpCluster = "Start up a cluster."
ConfigDescription = "Configure a profile. This let you store access settings to your cloud."
ConfigSetDescription = "Configure specific properties of the profile."
IAM = "Authentication operations."
Organization = "Organization operations."
OrganizationLong = "Create, list and manage your MongoDB organizations."
CreateOrganization = "Create an organization."
DeleteOrganization = "Delete an organization."
ListOrganizations = "List organizations."
Projects = "Project operations."
ProjectsLong = "Create, list and manage your MongoDB projects."
CreateProject = "Create a project."
DeleteProject = "Delete a project."
ListProjects = "List projects."
DownloadLogs = "Download logs from a log collection job."
OpsManager = "Ops Manager operations."
Agents = "Manage Ops Manager agents."
ListGlobalAlerts = "List global alerts."
Automation = "Manage Ops Manager automation config."
ShowAutomationStatus = "Show the current status of the automation config."
Global = "Manage Ops Manager global properties."
Owner = "Manage Ops Manager owners."
CreateOwner = "Create the first user for Ops Manager."
Servers = "Manage Ops Manager servers."
ListServer = "List all available servers running an automation agent for the given project."
Security = "Manage clusters security configuration."
EnableSecurity = "Enable authentication mechanisms for the project."
Events = "Manage events for your project."
Measurements = "Get measurements on the state of the MongoDB process."
LogCollection = "Manage log collection jobs."
StartLogCollectionJob = "Start a job to collect logs."
ListLogCollectionJobs = "List log collection jobs."
DeleteLogCollectionJob = "Delete a log collection job."
DBUsersLong = `The dbusers command retrieves, creates and modifies the MongoDB database users in your cluster.
Each user has a set of roles that provide access to the project’s databases.
A user’s roles apply to all the clusters in the project.`
ConfigLongDescription = `Setting API keys is optional and env variables can be used instead.
Expand Down
Loading