(client *client, options *FailoverOptions, shardIndex int)
| 80 | } |
| 81 | |
| 82 | func failoverShard(client *client, options *FailoverOptions, shardIndex int) error { |
| 83 | rsp, err := client.restyCli.R(). |
| 84 | SetPathParam("namespace", options.namespace). |
| 85 | SetPathParam("cluster", options.cluster). |
| 86 | SetPathParam("shard", strconv.Itoa(shardIndex)). |
| 87 | SetBody(map[string]interface{}{ |
| 88 | "preferred_node_id": options.preferred, |
| 89 | }). |
| 90 | Post("/namespaces/{namespace}/clusters/{cluster}/shards/{shard}/failover") |
| 91 | if err != nil { |
| 92 | return err |
| 93 | } |
| 94 | if rsp.IsError() { |
| 95 | return unmarshalError(rsp.Body()) |
| 96 | } |
| 97 | var result struct { |
| 98 | NewMasterID string `json:"new_master_id"` |
| 99 | } |
| 100 | if err := unmarshalData(rsp.Body(), &result); err != nil { |
| 101 | return err |
| 102 | } |
| 103 | printLine("failover shard %d successfully, new master id: %s.", shardIndex, result.NewMasterID) |
| 104 | return nil |
| 105 | } |
| 106 | |
| 107 | func init() { |
| 108 | FailoverCommand.Flags().StringVarP(&failoverOptions.namespace, "namespace", "n", "", "The namespace of the cluster") |
no test coverage detected