feat: add drop-non-retryable-data to replications commands (#330)

* feat: add drop-non-retryable-data to replications commands

* refactor: use drop vs nodrop flags

* chore: use the built-in PtrBool
This commit is contained in:
William Baker 2021-11-17 14:16:58 -07:00 committed by GitHub
parent 6a7c4f6d44
commit f32a55f3bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 252 additions and 35 deletions

@ -1 +1 @@
Subproject commit 7d9edc32995f38b3474a24c36b89a8e125837f3c
Subproject commit 12c8165b70cb379486592ffbf43ac5a3dde04904

View File

@ -27,6 +27,7 @@ type Replication struct {
CurrentQueueSizeBytes int64 `json:"currentQueueSizeBytes" yaml:"currentQueueSizeBytes"`
LatestResponseCode *int32 `json:"latestResponseCode,omitempty" yaml:"latestResponseCode,omitempty"`
LatestErrorMessage *string `json:"latestErrorMessage,omitempty" yaml:"latestErrorMessage,omitempty"`
DropNonRetryableData *bool `json:"dropNonRetryableData,omitempty" yaml:"dropNonRetryableData,omitempty"`
}
// NewReplication instantiates a new Replication object
@ -342,6 +343,38 @@ func (o *Replication) SetLatestErrorMessage(v string) {
o.LatestErrorMessage = &v
}
// GetDropNonRetryableData returns the DropNonRetryableData field value if set, zero value otherwise.
func (o *Replication) GetDropNonRetryableData() bool {
if o == nil || o.DropNonRetryableData == nil {
var ret bool
return ret
}
return *o.DropNonRetryableData
}
// GetDropNonRetryableDataOk returns a tuple with the DropNonRetryableData field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *Replication) GetDropNonRetryableDataOk() (*bool, bool) {
if o == nil || o.DropNonRetryableData == nil {
return nil, false
}
return o.DropNonRetryableData, true
}
// HasDropNonRetryableData returns a boolean if a field has been set.
func (o *Replication) HasDropNonRetryableData() bool {
if o != nil && o.DropNonRetryableData != nil {
return true
}
return false
}
// SetDropNonRetryableData gets a reference to the given bool and assigns it to the DropNonRetryableData field.
func (o *Replication) SetDropNonRetryableData(v bool) {
o.DropNonRetryableData = &v
}
func (o Replication) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if true {
@ -377,6 +410,9 @@ func (o Replication) MarshalJSON() ([]byte, error) {
if o.LatestErrorMessage != nil {
toSerialize["latestErrorMessage"] = o.LatestErrorMessage
}
if o.DropNonRetryableData != nil {
toSerialize["dropNonRetryableData"] = o.DropNonRetryableData
}
return json.Marshal(toSerialize)
}

View File

@ -16,13 +16,14 @@ import (
// ReplicationCreationRequest struct for ReplicationCreationRequest
type ReplicationCreationRequest struct {
Name string `json:"name" yaml:"name"`
Description *string `json:"description,omitempty" yaml:"description,omitempty"`
OrgID string `json:"orgID" yaml:"orgID"`
RemoteID string `json:"remoteID" yaml:"remoteID"`
LocalBucketID string `json:"localBucketID" yaml:"localBucketID"`
RemoteBucketID string `json:"remoteBucketID" yaml:"remoteBucketID"`
MaxQueueSizeBytes int64 `json:"maxQueueSizeBytes" yaml:"maxQueueSizeBytes"`
Name string `json:"name" yaml:"name"`
Description *string `json:"description,omitempty" yaml:"description,omitempty"`
OrgID string `json:"orgID" yaml:"orgID"`
RemoteID string `json:"remoteID" yaml:"remoteID"`
LocalBucketID string `json:"localBucketID" yaml:"localBucketID"`
RemoteBucketID string `json:"remoteBucketID" yaml:"remoteBucketID"`
MaxQueueSizeBytes int64 `json:"maxQueueSizeBytes" yaml:"maxQueueSizeBytes"`
DropNonRetryableData *bool `json:"dropNonRetryableData,omitempty" yaml:"dropNonRetryableData,omitempty"`
}
// NewReplicationCreationRequest instantiates a new ReplicationCreationRequest object
@ -37,6 +38,8 @@ func NewReplicationCreationRequest(name string, orgID string, remoteID string, l
this.LocalBucketID = localBucketID
this.RemoteBucketID = remoteBucketID
this.MaxQueueSizeBytes = maxQueueSizeBytes
var dropNonRetryableData bool = false
this.DropNonRetryableData = &dropNonRetryableData
return &this
}
@ -47,6 +50,8 @@ func NewReplicationCreationRequestWithDefaults() *ReplicationCreationRequest {
this := ReplicationCreationRequest{}
var maxQueueSizeBytes int64 = 67108860
this.MaxQueueSizeBytes = maxQueueSizeBytes
var dropNonRetryableData bool = false
this.DropNonRetryableData = &dropNonRetryableData
return &this
}
@ -226,6 +231,38 @@ func (o *ReplicationCreationRequest) SetMaxQueueSizeBytes(v int64) {
o.MaxQueueSizeBytes = v
}
// GetDropNonRetryableData returns the DropNonRetryableData field value if set, zero value otherwise.
func (o *ReplicationCreationRequest) GetDropNonRetryableData() bool {
if o == nil || o.DropNonRetryableData == nil {
var ret bool
return ret
}
return *o.DropNonRetryableData
}
// GetDropNonRetryableDataOk returns a tuple with the DropNonRetryableData field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *ReplicationCreationRequest) GetDropNonRetryableDataOk() (*bool, bool) {
if o == nil || o.DropNonRetryableData == nil {
return nil, false
}
return o.DropNonRetryableData, true
}
// HasDropNonRetryableData returns a boolean if a field has been set.
func (o *ReplicationCreationRequest) HasDropNonRetryableData() bool {
if o != nil && o.DropNonRetryableData != nil {
return true
}
return false
}
// SetDropNonRetryableData gets a reference to the given bool and assigns it to the DropNonRetryableData field.
func (o *ReplicationCreationRequest) SetDropNonRetryableData(v bool) {
o.DropNonRetryableData = &v
}
func (o ReplicationCreationRequest) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if true {
@ -249,6 +286,9 @@ func (o ReplicationCreationRequest) MarshalJSON() ([]byte, error) {
if true {
toSerialize["maxQueueSizeBytes"] = o.MaxQueueSizeBytes
}
if o.DropNonRetryableData != nil {
toSerialize["dropNonRetryableData"] = o.DropNonRetryableData
}
return json.Marshal(toSerialize)
}

View File

@ -16,11 +16,12 @@ import (
// ReplicationUpdateRequest struct for ReplicationUpdateRequest
type ReplicationUpdateRequest struct {
Name *string `json:"name,omitempty" yaml:"name,omitempty"`
Description *string `json:"description,omitempty" yaml:"description,omitempty"`
RemoteID *string `json:"remoteID,omitempty" yaml:"remoteID,omitempty"`
RemoteBucketID *string `json:"remoteBucketID,omitempty" yaml:"remoteBucketID,omitempty"`
MaxQueueSizeBytes *int64 `json:"maxQueueSizeBytes,omitempty" yaml:"maxQueueSizeBytes,omitempty"`
Name *string `json:"name,omitempty" yaml:"name,omitempty"`
Description *string `json:"description,omitempty" yaml:"description,omitempty"`
RemoteID *string `json:"remoteID,omitempty" yaml:"remoteID,omitempty"`
RemoteBucketID *string `json:"remoteBucketID,omitempty" yaml:"remoteBucketID,omitempty"`
MaxQueueSizeBytes *int64 `json:"maxQueueSizeBytes,omitempty" yaml:"maxQueueSizeBytes,omitempty"`
DropNonRetryableData *bool `json:"dropNonRetryableData,omitempty" yaml:"dropNonRetryableData,omitempty"`
}
// NewReplicationUpdateRequest instantiates a new ReplicationUpdateRequest object
@ -200,6 +201,38 @@ func (o *ReplicationUpdateRequest) SetMaxQueueSizeBytes(v int64) {
o.MaxQueueSizeBytes = &v
}
// GetDropNonRetryableData returns the DropNonRetryableData field value if set, zero value otherwise.
func (o *ReplicationUpdateRequest) GetDropNonRetryableData() bool {
if o == nil || o.DropNonRetryableData == nil {
var ret bool
return ret
}
return *o.DropNonRetryableData
}
// GetDropNonRetryableDataOk returns a tuple with the DropNonRetryableData field value if set, nil otherwise
// and a boolean to check if the value has been set.
func (o *ReplicationUpdateRequest) GetDropNonRetryableDataOk() (*bool, bool) {
if o == nil || o.DropNonRetryableData == nil {
return nil, false
}
return o.DropNonRetryableData, true
}
// HasDropNonRetryableData returns a boolean if a field has been set.
func (o *ReplicationUpdateRequest) HasDropNonRetryableData() bool {
if o != nil && o.DropNonRetryableData != nil {
return true
}
return false
}
// SetDropNonRetryableData gets a reference to the given bool and assigns it to the DropNonRetryableData field.
func (o *ReplicationUpdateRequest) SetDropNonRetryableData(v bool) {
o.DropNonRetryableData = &v
}
func (o ReplicationUpdateRequest) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
if o.Name != nil {
@ -217,6 +250,9 @@ func (o ReplicationUpdateRequest) MarshalJSON() ([]byte, error) {
if o.MaxQueueSizeBytes != nil {
toSerialize["maxQueueSizeBytes"] = o.MaxQueueSizeBytes
}
if o.DropNonRetryableData != nil {
toSerialize["dropNonRetryableData"] = o.DropNonRetryableData
}
return json.Marshal(toSerialize)
}

View File

@ -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 {
@ -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 {
@ -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 {
@ -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 {
@ -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")
}
@ -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
@ -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
}

View File

@ -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)
})
}
}

View File

@ -76,6 +76,16 @@ func newReplicationCreateCmd() cli.Command {
Value: 67108860, // source: https://github.com/influxdata/openapi/blob/588064fe68e7dfeebd019695aa805832632cbfb6/src/oss/schemas/ReplicationCreationRequest.yml#L19
Destination: &params.MaxQueueSize,
},
&cli.BoolFlag{
Name: "drop-non-retryable-data",
Usage: "Drop data when a non-retryable error is encountered instead of retrying",
Destination: &params.DropNonRetryableData,
},
&cli.BoolFlag{
Name: "no-drop-non-retryable-data",
Usage: "Do not drop data when a non-retryable error is encountered",
Destination: &params.NoDropNonRetryableData,
},
),
Action: func(ctx *cli.Context) error {
api := getAPI(ctx)
@ -209,6 +219,16 @@ func newReplicationUpdateCmd() cli.Command {
Usage: "New max queue size in bytes",
Destination: &params.MaxQueueSize,
},
&cli.BoolFlag{
Name: "drop-non-retryable-data",
Usage: "Drop data when a non-retryable error is encountered instead of retrying",
Destination: &params.DropNonRetryableData,
},
&cli.BoolFlag{
Name: "no-drop-non-retryable-data",
Usage: "Do not drop data when a non-retryable error is encountered",
Destination: &params.NoDropNonRetryableData,
},
),
Action: func(ctx *cli.Context) error {
api := getAPI(ctx)