Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
Add command cluster get-failure-domain (#22)
Browse files Browse the repository at this point in the history
Master issue: #2 

output example:

```
➜  pulsarctl git:(clusters_get_failure_domain) ./pulsarctl cluster get-failure-domain -h
USED FOR:
    This command is used for getting the specified failure domain on the specified cluster.

REQUIRED PERMISSION:
    This command requires super-user permissions.

EXAMPLES:
    #getting the broker list in the <cluster-name> cluster failure domain <domain-name>
    pulsarctl clusters get-failure-domain -n <domain-name> <cluster-name>

OUTPUT:
    #output example
    {
      "brokers" : [
        "failure-broker-A",
        "failure-broker-B",
      ]
    }

    #the cluster name is not specified or the cluster name is specified more than one
    [✖]  only one argument is allowed to be used as a name

    #the specified cluster does not exist in the broker
    [✖]  code: 404 reason: Cluster does not exist

Usage: pulsarctl clusters get-failure-domain [flags]

Aliases: get-failure-domain, gfd

FailureDomain flags:
  -n, --domain-name string   The failure domain name

Common flags:
  -s, --admin-service-url string   The admin web service url that pulsarctl connects to. (default "http://localhost:8080")
  -C, --color string               toggle colorized logs (true,false,fabulous) (default "true")
  -h, --help                       help for this command
  -v, --verbose int                set log level, use 0 to silence, 4 for debugging (default 3)

Use 'pulsarctl clusters get-failure-domain [command] --help' for more information about a command.
```
  • Loading branch information
zymap authored and maxsxu committed Mar 14, 2023
1 parent 6832850 commit ffcacd5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions pkg/pulsar/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Clusters interface {
UpdatePeerClusters(string, []string) error
GetPeerClusters(string) ([]string, error)
CreateFailureDomain(FailureDomainData) error
GetFailureDomain(clusterName, domainName string) (FailureDomainData, error)
}

type clusters struct {
Expand Down Expand Up @@ -52,6 +53,7 @@ func (c *clusters) Update(cdata ClusterData) error {
endpoint := c.client.endpoint(c.basePath, cdata.Name)
return c.client.post(endpoint, &cdata, nil)
}

func (c *clusters) GetPeerClusters(name string) ([]string, error) {
var peerClusters []string
endpoint := c.client.endpoint(c.basePath, name, "peers")
Expand All @@ -68,3 +70,10 @@ func (c *clusters) CreateFailureDomain(data FailureDomainData) error {
endpoint := c.client.endpoint(c.basePath, data.ClusterName, "failureDomains", data.DomainName)
return c.client.post(endpoint, &data, nil)
}

func (c *clusters) GetFailureDomain(clusterName string, domainName string) (FailureDomainData, error) {
var res FailureDomainData
endpoint := c.client.endpoint(c.basePath, clusterName, "failureDomains", domainName)
err := c.client.get(endpoint, &res)
return res, err
}
2 changes: 1 addition & 1 deletion pkg/pulsar/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ type FunctionData struct {
type FailureDomainData struct {
ClusterName string `json:"-"`
DomainName string `json:"-"`
BrokerList []string `json:"brokerList"`
BrokerList []string `json:"brokers"`
}

0 comments on commit ffcacd5

Please sign in to comment.