Skip to content

Commit

Permalink
Add command cluster update (streamnative/pulsar-admin-go#17)
Browse files Browse the repository at this point in the history
Master issue: streamnative/pulsar-admin-go#2 

```
➜  pulsarctl git:(cluster_update) ✗ ./pulsarctl clusters update -h
USED FOR:
    This command is used for updating the cluster data of the specified cluster.

REQUIRED PERMISSION:
    This command requires super-user permissions.

EXAMPLES:
    #updating the web service url of the <cluster-name>
    pulsarctl clusters update --url http://example:8080 <cluster-name>

    #updating the tls secured web service url of the <cluster-name>
    pulsarctl clusters update --url-tls https://example:8080 <cluster-name>

    #updating the broker service url of the <cluster-name>
    pulsarctl clusters update --broker-url pulsar://example:6650 <cluster-name>

    #updating the tls secured web service url of the <cluster-name>
    pulsarctl clusters update --broker-url-tls pulsar+ssl://example:6650 <cluster-name>

    #registered as a peer-cluster of the <cluster-name> clusters
    pulsarctl clusters update -p <cluster-a>,<cluster-b> <cluster>

OUTPUT:
    #normal output
    Cluster <cluster-name> updated

    #output of doesn't specified  a cluster name
    [✖]  only one argument is allowed to be used as a name

    #Output of cluster doesn't exist
    [✖]  code: 404 reason: Cluster does not exist

Usage: pulsarctl clusters update [flags]

Aliases: update, update

ClusterData flags:
      --url string                 Pulsar cluster web service url, e.g. http://example.pulsar.io:8080
      --url-tls string             Pulsar cluster tls secured web service url, e.g. https://example.pulsar.io:8443
      --broker-url string          Pulsar cluster broker service url, e.g. pulsar://example.pulsar.io:6650
      --broker-url-tls string      Pulsar cluster tls secured broker service url, e.g. pulsar+ssl://example.pulsar.io:6651
  -p, --peer-cluster stringArray   Cluster to be registered as a peer-cluster of this cluster.

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 update [command] --help' for more information about a command.
```
  • Loading branch information
zymap authored and tisonkun committed Aug 15, 2023
1 parent 7d88118 commit 5fce4b5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
14 changes: 9 additions & 5 deletions pulsaradmin/pkg/pulsar/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ type Clusters interface {
Get(string) (ClusterData, error)
Create(ClusterData) error
Delete(string) error
Update(ClusterData) error
}

type clusters struct {
client *client
basePath string
client *client
basePath string
}

func (c *client) Clusters() Clusters {
return &clusters{
client: c,
basePath:"/clusters",
client: c,
basePath: "/clusters",
}
}

Expand Down Expand Up @@ -45,4 +46,7 @@ func (c *clusters) Delete(name string) error {
return c.client.delete(endpoint, nil)
}


func (c *clusters) Update(cdata ClusterData) error {
endpoint := c.client.endpoint(c.basePath, cdata.Name)
return c.client.post(endpoint, &cdata, nil)
}
4 changes: 2 additions & 2 deletions pulsaradmin/pkg/pulsar/descriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ func (desc *LongDescription) ToString() string {
PERMISSION + "\n" +
SPACES + desc.CommandPermission + "\n\n" +
EXAMPLES + "\n" +
desc.exampleToString() + "\n" +
desc.exampleToString() +
OUTPUT + "\n" +
desc.outputToString()
}

func (desc *LongDescription) exampleToString() string {
var result string
for _, v := range desc.CommandExamples {
result += SPACES + "#" + v.Desc + "\n" + SPACES + v.Command + "\n"
result += SPACES + "#" + v.Desc + "\n" + SPACES + v.Command + "\n\n"
}
return result
}
Expand Down
2 changes: 1 addition & 1 deletion pulsaradmin/pkg/pulsar/descriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestLongDescription_exampleToString(t *testing.T) {
res := desc.exampleToString()

expect := " #command description\n" +
" command\n"
" command\n\n"

assert.Equal(t, expect, res)
}
Expand Down

0 comments on commit 5fce4b5

Please sign in to comment.