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:
parent
4e8671dcc5
commit
64b1b03f8f
@ -120,9 +120,7 @@ func (c Client) List(ctx context.Context, params *ListParams) error {
|
||||
}
|
||||
|
||||
// set up query params
|
||||
req := c.GetRemoteConnections(ctx)
|
||||
|
||||
req = req.OrgID(orgID)
|
||||
req := c.GetRemoteConnections(ctx).OrgID(orgID)
|
||||
|
||||
if params.Name != "" {
|
||||
req = req.Name(params.Name)
|
||||
|
@ -2,6 +2,7 @@ package replication
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"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})
|
||||
}
|
||||
|
||||
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 {
|
||||
replication *api.Replication
|
||||
replications []api.Replication
|
||||
@ -73,8 +121,8 @@ func (c Client) printReplication(opts printReplicationOpts) error {
|
||||
return c.PrintJSON(v)
|
||||
}
|
||||
|
||||
headers := []string{"ID", "Name", "Org ID", "Remote ID", "Local Bucket ID", "Remote Bucket ID", "Max Queue Bytes",
|
||||
"Current Queue Bytes", "Latest Status Code"}
|
||||
headers := []string{"ID", "Name", "Org ID", "Remote ID", "Local Bucket ID", "Remote Bucket ID",
|
||||
"Current Queue Bytes", "Max Queue Bytes", "Latest Status Code"}
|
||||
if opts.deleted {
|
||||
headers = append(headers, "Deleted")
|
||||
}
|
||||
@ -92,8 +140,8 @@ func (c Client) printReplication(opts printReplicationOpts) error {
|
||||
"Remote ID": r.GetRemoteID(),
|
||||
"Local Bucket ID": r.GetLocalBucketID(),
|
||||
"Remote Bucket ID": r.GetRemoteBucketID(),
|
||||
"Max Queue Bytes": r.GetMaxQueueSizeBytes(),
|
||||
"Current Queue Bytes": r.GetCurrentQueueSizeBytes(),
|
||||
"Max Queue Bytes": r.GetMaxQueueSizeBytes(),
|
||||
"Latest Status Code": r.GetLatestResponseCode(),
|
||||
}
|
||||
if opts.deleted {
|
||||
|
@ -105,14 +105,52 @@ func newReplicationDeleteCmd() cli.Command {
|
||||
}
|
||||
|
||||
func newReplicationListCmd() cli.Command {
|
||||
var params replication.ListParams
|
||||
return cli.Command{
|
||||
Name: "list",
|
||||
Usage: "List all replication streams and corresponding metrics",
|
||||
Aliases: []string{"find", "ls"},
|
||||
Before: middleware.WithBeforeFns(withCli(), withApi(true), middleware.NoArgs),
|
||||
Flags: commonFlags(),
|
||||
Action: func(ctx *cli.Context) {
|
||||
fmt.Println("replication list command was called")
|
||||
Flags: append(
|
||||
commonFlags(),
|
||||
&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)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user