| 174 | } |
| 175 | |
| 176 | func (n *ClusterNode) GetClusterInfo(ctx context.Context) (*ClusterInfo, error) { |
| 177 | infoStr, err := n.GetClient().ClusterInfo(ctx).Result() |
| 178 | if err != nil { |
| 179 | return nil, err |
| 180 | } |
| 181 | |
| 182 | clusterInfo := &ClusterInfo{CurrentEpoch: -1} |
| 183 | lines := strings.Split(infoStr, "\r\n") |
| 184 | for _, line := range lines { |
| 185 | fields := strings.Split(line, ":") |
| 186 | if len(fields) != 2 { |
| 187 | continue |
| 188 | } |
| 189 | fields[1] = strings.TrimSpace(fields[1]) |
| 190 | switch strings.ToLower(strings.TrimSpace(fields[0])) { |
| 191 | case "cluster_current_epoch": |
| 192 | clusterInfo.CurrentEpoch, err = strconv.ParseInt(fields[1], 10, 64) |
| 193 | if err != nil { |
| 194 | return nil, err |
| 195 | } |
| 196 | case "migrating_slot", "migrating_slot(s)": |
| 197 | // TODO(@git-hulk): handle multiple migrating slots |
| 198 | slotRange, err := ParseSlotRange(fields[1]) |
| 199 | if err != nil { |
| 200 | return nil, err |
| 201 | } |
| 202 | clusterInfo.MigratingSlot = FromSlotRange(*slotRange) |
| 203 | case "migrating_state": |
| 204 | clusterInfo.MigratingState = fields[1] |
| 205 | } |
| 206 | } |
| 207 | return clusterInfo, nil |
| 208 | } |
| 209 | |
| 210 | func (n *ClusterNode) GetClusterNodeInfo(ctx context.Context) (*ClusterNodeInfo, error) { |
| 211 | infoStr, err := n.GetClient().Info(ctx).Result() |