feat: added functionality for replication list command (#296)
* feat: added functionality for replication list command * chore: ran make fmt * refactor: fixed comment for clarity * refactor: chained statements together to simplify code
This commit is contained in:
@ -120,9 +120,7 @@ func (c Client) List(ctx context.Context, params *ListParams) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set up query params
|
// set up query params
|
||||||
req := c.GetRemoteConnections(ctx)
|
req := c.GetRemoteConnections(ctx).OrgID(orgID)
|
||||||
|
|
||||||
req = req.OrgID(orgID)
|
|
||||||
|
|
||||||
if params.Name != "" {
|
if params.Name != "" {
|
||||||
req = req.Name(params.Name)
|
req = req.Name(params.Name)
|
||||||
|
@ -2,6 +2,7 @@ package replication
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/influxdata/influx-cli/v2/api"
|
"github.com/influxdata/influx-cli/v2/api"
|
||||||
@ -56,6 +57,53 @@ func (c Client) Create(ctx context.Context, params *CreateParams) error {
|
|||||||
return c.printReplication(printReplicationOpts{replication: &res})
|
return c.printReplication(printReplicationOpts{replication: &res})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ListParams struct {
|
||||||
|
Name string
|
||||||
|
OrgID string
|
||||||
|
OrgName string
|
||||||
|
RemoteID string
|
||||||
|
LocalBucketID string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c Client) List(ctx context.Context, params *ListParams) error {
|
||||||
|
|
||||||
|
orgID, err := c.GetOrgId(ctx, params.OrgID, params.OrgName, c.OrganizationsApi)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// set up params
|
||||||
|
req := c.GetReplications(ctx).OrgID(orgID)
|
||||||
|
|
||||||
|
if params.Name != "" {
|
||||||
|
req = req.Name(params.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
if params.RemoteID != "" {
|
||||||
|
req = req.RemoteID(params.RemoteID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if params.LocalBucketID != "" {
|
||||||
|
req = req.LocalBucketID(params.LocalBucketID)
|
||||||
|
}
|
||||||
|
|
||||||
|
// send get request
|
||||||
|
res, err := req.Execute()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get replication streams: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// print replication stream info
|
||||||
|
printOpts := printReplicationOpts{}
|
||||||
|
if res.Replications != nil {
|
||||||
|
printOpts.replications = *res.Replications
|
||||||
|
} else {
|
||||||
|
return errors.New("no replication streams found for specified parameters")
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.printReplication(printOpts)
|
||||||
|
}
|
||||||
|
|
||||||
type printReplicationOpts struct {
|
type printReplicationOpts struct {
|
||||||
replication *api.Replication
|
replication *api.Replication
|
||||||
replications []api.Replication
|
replications []api.Replication
|
||||||
@ -73,8 +121,8 @@ func (c Client) printReplication(opts printReplicationOpts) error {
|
|||||||
return c.PrintJSON(v)
|
return c.PrintJSON(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
headers := []string{"ID", "Name", "Org ID", "Remote ID", "Local Bucket ID", "Remote Bucket ID", "Max Queue Bytes",
|
headers := []string{"ID", "Name", "Org ID", "Remote ID", "Local Bucket ID", "Remote Bucket ID",
|
||||||
"Current Queue Bytes", "Latest Status Code"}
|
"Current Queue Bytes", "Max Queue Bytes", "Latest Status Code"}
|
||||||
if opts.deleted {
|
if opts.deleted {
|
||||||
headers = append(headers, "Deleted")
|
headers = append(headers, "Deleted")
|
||||||
}
|
}
|
||||||
@ -92,8 +140,8 @@ func (c Client) printReplication(opts printReplicationOpts) error {
|
|||||||
"Remote ID": r.GetRemoteID(),
|
"Remote ID": r.GetRemoteID(),
|
||||||
"Local Bucket ID": r.GetLocalBucketID(),
|
"Local Bucket ID": r.GetLocalBucketID(),
|
||||||
"Remote Bucket ID": r.GetRemoteBucketID(),
|
"Remote Bucket ID": r.GetRemoteBucketID(),
|
||||||
"Max Queue Bytes": r.GetMaxQueueSizeBytes(),
|
|
||||||
"Current Queue Bytes": r.GetCurrentQueueSizeBytes(),
|
"Current Queue Bytes": r.GetCurrentQueueSizeBytes(),
|
||||||
|
"Max Queue Bytes": r.GetMaxQueueSizeBytes(),
|
||||||
"Latest Status Code": r.GetLatestResponseCode(),
|
"Latest Status Code": r.GetLatestResponseCode(),
|
||||||
}
|
}
|
||||||
if opts.deleted {
|
if opts.deleted {
|
||||||
|
@ -105,14 +105,52 @@ func newReplicationDeleteCmd() cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func newReplicationListCmd() cli.Command {
|
func newReplicationListCmd() cli.Command {
|
||||||
|
var params replication.ListParams
|
||||||
return cli.Command{
|
return cli.Command{
|
||||||
Name: "list",
|
Name: "list",
|
||||||
Usage: "List all replication streams and corresponding metrics",
|
Usage: "List all replication streams and corresponding metrics",
|
||||||
Aliases: []string{"find", "ls"},
|
Aliases: []string{"find", "ls"},
|
||||||
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
||||||
Flags: commonFlags(),
|
Flags: append(
|
||||||
Action: func(ctx *cli.Context) {
|
commonFlags(),
|
||||||
fmt.Println("replication list command was called")
|
&cli.StringFlag{
|
||||||
|
Name: "name, n",
|
||||||
|
Usage: "Filter results to only replication streams with a specific name",
|
||||||
|
Destination: ¶ms.Name,
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "org-id",
|
||||||
|
Usage: "Local org ID",
|
||||||
|
EnvVar: "INFLUX_ORG_ID",
|
||||||
|
Destination: ¶ms.OrgID,
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "org, o",
|
||||||
|
Usage: "Local org name",
|
||||||
|
EnvVar: "INFLUX_ORG",
|
||||||
|
Destination: ¶ms.OrgName,
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "remote-id",
|
||||||
|
Usage: "Filter results to only replication streams for a specific remote connection",
|
||||||
|
Destination: ¶ms.RemoteID,
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "local-bucket",
|
||||||
|
Usage: "Filter results to only replication streams for a specific local bucket",
|
||||||
|
Destination: ¶ms.LocalBucketID,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
Action: func(ctx *cli.Context) error {
|
||||||
|
api := getAPI(ctx)
|
||||||
|
|
||||||
|
client := replication.Client{
|
||||||
|
CLI: getCLI(ctx),
|
||||||
|
ReplicationsApi: api.ReplicationsApi,
|
||||||
|
OrganizationsApi: api.OrganizationsApi,
|
||||||
|
}
|
||||||
|
|
||||||
|
return client.List(getContext(ctx), ¶ms)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user