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: 1 addition & 4 deletions internal/cli/ops_manager_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ func OpsManagerLogsBuilder() *cobra.Command {
Short: description.LogCollection,
}

cmd.AddCommand(OpsManagerLogsCollectOptsBuilder())
cmd.AddCommand(OpsManagerLogsListOptsBuilder())
cmd.AddCommand(OpsManagerLogsDownloadOptsBuilder())
cmd.AddCommand(OpsManagerLogsDeleteOptsBuilder())
cmd.AddCommand(OpsManagerLogsJobsBuilder())

return cmd
}
35 changes: 35 additions & 0 deletions internal/cli/ops_manager_logs_jobs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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 OpsManagerLogsJobsBuilder() *cobra.Command {
cmd := &cobra.Command{
Use: "jobs",
Aliases: []string{"job"},
Short: description.LogCollection,
}

cmd.AddCommand(OpsManagerLogsJobsCollectOptsBuilder())
cmd.AddCommand(OpsManagerLogsJobsListOptsBuilder())
cmd.AddCommand(OpsManagerLogsJobsDownloadOptsBuilder())
cmd.AddCommand(OpsManagerLogsJobsDeleteOptsBuilder())

return cmd
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/spf13/cobra"
)

type opsManagerLogsCollectOpts struct {
type opsManagerLogsJobsCollectOpts struct {
globalOpts
resourceType string
resourceName string
Expand All @@ -38,21 +38,21 @@ type opsManagerLogsCollectOpts struct {
store store.LogCollector
}

func (opts *opsManagerLogsCollectOpts) initStore() error {
func (opts *opsManagerLogsJobsCollectOpts) initStore() error {
var err error
opts.store, err = store.New()
return err
}

func (opts *opsManagerLogsCollectOpts) Run() error {
func (opts *opsManagerLogsJobsCollectOpts) Run() error {
result, err := opts.store.Collect(opts.ProjectID(), opts.newLog())
if err != nil {
return err
}
return json.PrettyPrint(result)
}

func (opts *opsManagerLogsCollectOpts) newLog() *om.LogCollectionJob {
func (opts *opsManagerLogsJobsCollectOpts) newLog() *om.LogCollectionJob {
return &om.LogCollectionJob{
ResourceType: opts.resourceType,
ResourceName: opts.resourceName,
Expand All @@ -62,9 +62,9 @@ func (opts *opsManagerLogsCollectOpts) newLog() *om.LogCollectionJob {
}
}

// mongocli om logs collect resourceType resourceName --sizeRequestedPerFileBytes size --type type --redacted redacted [--projectId projectId]
func OpsManagerLogsCollectOptsBuilder() *cobra.Command {
opts := &opsManagerLogsCollectOpts{}
// mongocli om logs jobs collect resourceType resourceName --sizeRequestedPerFileBytes size --type type --redacted redacted [--projectId projectId]
func OpsManagerLogsJobsCollectOptsBuilder() *cobra.Command {
opts := &opsManagerLogsJobsCollectOpts{}
cmd := &cobra.Command{
Use: "collect [resourceType] [resourceName]",
Short: description.StartLogCollectionJob,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestOpsManagerLogsCollectOpts_Run(t *testing.T) {

expected := &om.LogCollectionJob{ID: "1"}

listOpts := &opsManagerLogsCollectOpts{
listOpts := &opsManagerLogsJobsCollectOpts{
redacted: false,
sizeRequestedPerFileBytes: 64,
resourceType: "CLUSTER",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@ import (
"github.com/spf13/cobra"
)

type opsManagerLogsDeleteOpts struct {
type opsManagerLogsJobsDeleteOpts struct {
globalOpts
deleteOpts
store store.LogJobDeleter
}

func (opts *opsManagerLogsDeleteOpts) initStore() error {
func (opts *opsManagerLogsJobsDeleteOpts) initStore() error {
var err error
opts.store, err = store.New()
return err
}

func (opts *opsManagerLogsDeleteOpts) Run() error {
func (opts *opsManagerLogsJobsDeleteOpts) Run() error {
return opts.store.DeleteCollectionJob(opts.ProjectID(), opts.entry)
}

// mongocli om logs delete id [--projectId projectId] [--force]
func OpsManagerLogsDeleteOptsBuilder() *cobra.Command {
opts := &opsManagerLogsDeleteOpts{
// mongocli om logs jobs delete id [--projectId projectId] [--force]
func OpsManagerLogsJobsDeleteOptsBuilder() *cobra.Command {
opts := &opsManagerLogsJobsDeleteOpts{
deleteOpts: deleteOpts{
successMessage: "Log collection entry '%s' deleted\n",
failMessage: "Log collection entry not deleted",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestOpsManagerWhitelistDelete_Run(t *testing.T) {

defer ctrl.Finish()

deleteOpts := &opsManagerLogsDeleteOpts{
deleteOpts := &opsManagerLogsJobsDeleteOpts{
deleteOpts: deleteOpts{
confirm: true,
entry: "test",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@ import (
"github.com/spf13/cobra"
)

type opsManagerLogsDownloadOpts struct {
type opsManagerLogsJobsDownloadOpts struct {
globalOpts
id string
out string
fs afero.Fs
store store.LogJobsDownloader
}

func (opts *opsManagerLogsDownloadOpts) initStore() error {
func (opts *opsManagerLogsJobsDownloadOpts) initStore() error {
var err error
opts.store, err = store.New()
return err
}

func (opts *opsManagerLogsDownloadOpts) Run() error {
func (opts *opsManagerLogsJobsDownloadOpts) Run() error {
out, err := opts.newWriteCloser()
if err != nil {
return err
Expand All @@ -53,16 +53,16 @@ func (opts *opsManagerLogsDownloadOpts) Run() error {
return nil
}

func (opts *opsManagerLogsDownloadOpts) newWriteCloser() (io.WriteCloser, error) {
func (opts *opsManagerLogsJobsDownloadOpts) 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
}

// mongocli om logs download id [--out out] [--projectId projectId]
func OpsManagerLogsDownloadOptsBuilder() *cobra.Command {
opts := &opsManagerLogsDownloadOpts{
// mongocli om logs jobs download id [--out out] [--projectId projectId]
func OpsManagerLogsJobsDownloadOptsBuilder() *cobra.Command {
opts := &opsManagerLogsJobsDownloadOpts{
fs: afero.NewOsFs(),
}
cmd := &cobra.Command{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestOpsManagerLogsDownloadOpts_Run(t *testing.T) {

appFS := afero.NewMemMapFs()

opts := &opsManagerLogsDownloadOpts{
opts := &opsManagerLogsJobsDownloadOpts{
id: "1",
fs: appFS,
store: mockStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,33 +24,33 @@ import (
"github.com/spf13/cobra"
)

type opsManagerLogsListOpts struct {
type opsManagerLogsJobsListOpts struct {
globalOpts
verbose bool
store store.LogJobLister
}

func (opts *opsManagerLogsListOpts) initStore() error {
func (opts *opsManagerLogsJobsListOpts) initStore() error {
var err error
opts.store, err = store.New()
return err
}

func (opts *opsManagerLogsListOpts) Run() error {
func (opts *opsManagerLogsJobsListOpts) Run() error {
result, err := opts.store.LogCollectionJobs(opts.ProjectID(), opts.newLogListOptions())
if err != nil {
return err
}
return json.PrettyPrint(result)
}

func (opts *opsManagerLogsListOpts) newLogListOptions() *om.LogListOptions {
func (opts *opsManagerLogsJobsListOpts) newLogListOptions() *om.LogListOptions {
return &om.LogListOptions{Verbose: opts.verbose}
}

// mongocli om logs list --verbose verbose [--projectId projectId]
func OpsManagerLogsListOptsBuilder() *cobra.Command {
opts := &opsManagerLogsListOpts{}
// mongocli om logs jobs list --verbose verbose [--projectId projectId]
func OpsManagerLogsJobsListOptsBuilder() *cobra.Command {
opts := &opsManagerLogsJobsListOpts{}
cmd := &cobra.Command{
Use: "list",
Aliases: []string{"ls"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestOpsManagerLogsListOpts_Run(t *testing.T) {

expected := &om.LogCollectionJobs{}

listOpts := &opsManagerLogsListOpts{
listOpts := &opsManagerLogsJobsListOpts{
store: mockStore,
verbose: true,
}
Expand Down