Skip to content

Commit

Permalink
feat: add drop-non-retryable-data to replications commands (#330)
Browse files Browse the repository at this point in the history
* feat: add drop-non-retryable-data to replications commands

* refactor: use drop vs nodrop flags

* chore: use the built-in PtrBool
  • Loading branch information
williamhbaker committed Nov 17, 2021
1 parent 6a7c4f6 commit f32a55f
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 35 deletions.
36 changes: 36 additions & 0 deletions api/model_replication.gen.go

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

54 changes: 47 additions & 7 deletions api/model_replication_creation_request.gen.go

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

46 changes: 41 additions & 5 deletions api/model_replication_update_request.gen.go

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

80 changes: 58 additions & 22 deletions clients/replication/replication.go
Expand Up @@ -17,12 +17,14 @@ type Client struct {

type CreateParams struct {
clients.OrgParams
Name string
Description string
RemoteID string
LocalBucketID string
RemoteBucketID string
MaxQueueSize int64
Name string
Description string
RemoteID string
LocalBucketID string
RemoteBucketID string
MaxQueueSize int64
DropNonRetryableData bool
NoDropNonRetryableData bool
}

func (c Client) Create(ctx context.Context, params *CreateParams) error {
Expand All @@ -46,6 +48,12 @@ func (c Client) Create(ctx context.Context, params *CreateParams) error {
body.Description = &params.Description
}

dropNonRetryableDataBoolPtr, err := dropNonRetryableDataBoolPtrFromFlags(params.DropNonRetryableData, params.NoDropNonRetryableData)
if err != nil {
return err
}
body.DropNonRetryableData = dropNonRetryableDataBoolPtr

// send post request
res, err := c.PostReplication(ctx).ReplicationCreationRequest(body).Execute()
if err != nil {
Expand Down Expand Up @@ -102,12 +110,14 @@ func (c Client) List(ctx context.Context, params *ListParams) error {
}

type UpdateParams struct {
ReplicationID string
Name string
Description string
RemoteID string
RemoteBucketID string
MaxQueueSize int64
ReplicationID string
Name string
Description string
RemoteID string
RemoteBucketID string
MaxQueueSize int64
DropNonRetryableData bool
NoDropNonRetryableData bool
}

func (c Client) Update(ctx context.Context, params *UpdateParams) error {
Expand All @@ -134,6 +144,15 @@ func (c Client) Update(ctx context.Context, params *UpdateParams) error {
body.SetMaxQueueSizeBytes(params.MaxQueueSize)
}

dropNonRetryableDataBoolPtr, err := dropNonRetryableDataBoolPtrFromFlags(params.DropNonRetryableData, params.NoDropNonRetryableData)
if err != nil {
return err
}

if dropNonRetryableDataBoolPtr != nil {
body.SetDropNonRetryableData(*dropNonRetryableDataBoolPtr)
}

// send patch request
res, err := c.PatchReplicationByID(ctx, params.ReplicationID).ReplicationUpdateRequest(body).Execute()
if err != nil {
Expand Down Expand Up @@ -182,7 +201,7 @@ func (c Client) printReplication(opts printReplicationOpts) error {
}

headers := []string{"ID", "Name", "Org ID", "Remote ID", "Local Bucket ID", "Remote Bucket ID",
"Current Queue Bytes", "Max Queue Bytes", "Latest Status Code"}
"Current Queue Bytes", "Max Queue Bytes", "Latest Status Code", "Drop Non-Retryable Data"}
if opts.deleted {
headers = append(headers, "Deleted")
}
Expand All @@ -194,15 +213,16 @@ func (c Client) printReplication(opts printReplicationOpts) error {
var rows []map[string]interface{}
for _, r := range opts.replications {
row := map[string]interface{}{
"ID": r.GetId(),
"Name": r.GetName(),
"Org ID": r.GetOrgID(),
"Remote ID": r.GetRemoteID(),
"Local Bucket ID": r.GetLocalBucketID(),
"Remote Bucket ID": r.GetRemoteBucketID(),
"Current Queue Bytes": r.GetCurrentQueueSizeBytes(),
"Max Queue Bytes": r.GetMaxQueueSizeBytes(),
"Latest Status Code": r.GetLatestResponseCode(),
"ID": r.GetId(),
"Name": r.GetName(),
"Org ID": r.GetOrgID(),
"Remote ID": r.GetRemoteID(),
"Local Bucket ID": r.GetLocalBucketID(),
"Remote Bucket ID": r.GetRemoteBucketID(),
"Current Queue Bytes": r.GetCurrentQueueSizeBytes(),
"Max Queue Bytes": r.GetMaxQueueSizeBytes(),
"Latest Status Code": r.GetLatestResponseCode(),
"Drop Non-Retryable Data": r.GetDropNonRetryableData(),
}
if opts.deleted {
row["Deleted"] = true
Expand All @@ -212,3 +232,19 @@ func (c Client) printReplication(opts printReplicationOpts) error {

return c.PrintTable(headers, rows...)
}

func dropNonRetryableDataBoolPtrFromFlags(dropNonRetryableData, noDropNonRetryableData bool) (*bool, error) {
if dropNonRetryableData && noDropNonRetryableData {
return nil, errors.New("cannot specify both --drop-non-retryable-data and --no-drop-non-retryable-data at the same time")
}

if dropNonRetryableData {
return api.PtrBool(true), nil
}

if noDropNonRetryableData {
return api.PtrBool(false), nil
}

return nil, nil
}
49 changes: 49 additions & 0 deletions clients/replication/replication_test.go
@@ -0,0 +1,49 @@
package replication

import (
"errors"
"testing"

"github.com/influxdata/influx-cli/v2/api"
"github.com/stretchr/testify/require"
)

func TestDropNonRetryableDataBoolPtrFromFlags(t *testing.T) {
tests := []struct {
name string
dropNonRetryableData bool
noDropNonRetryableData bool
want *bool
wantErr error
}{
{
name: "both true is an error",
dropNonRetryableData: true,
noDropNonRetryableData: true,
want: nil,
wantErr: errors.New("cannot specify both --drop-non-retryable-data and --no-drop-non-retryable-data at the same time"),
},
{
name: "drop is true",
dropNonRetryableData: true,
want: api.PtrBool(true),
},
{
name: "noDrop is true",
noDropNonRetryableData: true,
want: api.PtrBool(false),
},
{
name: "both nil is nil",
want: nil,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := dropNonRetryableDataBoolPtrFromFlags(tt.dropNonRetryableData, tt.noDropNonRetryableData)
require.Equal(t, tt.want, got)
require.Equal(t, tt.wantErr, err)
})
}
}

0 comments on commit f32a55f

Please sign in to comment.