(nodeIndex int)
| 43 | } |
| 44 | |
| 45 | func GetInstanceList(nodeIndex int) ([]*model.Instance, error) { |
| 46 | var instanceList []*model.Instance |
| 47 | instanceInfoKeyBase := fmt.Sprintf(key.NodeInstanceListKeyTemplate, nodeIndex) |
| 48 | nodeListEtcd, err := utils.EtcdClient.Get( |
| 49 | context.Background(), |
| 50 | instanceInfoKeyBase, |
| 51 | clientv3.WithPrefix(), |
| 52 | ) |
| 53 | if err != nil { |
| 54 | err := fmt.Errorf("get instance list from etcd error:%s", err.Error()) |
| 55 | return nil, err |
| 56 | } |
| 57 | |
| 58 | for _, v := range nodeListEtcd.Kvs { |
| 59 | instanceInfo := new(model.Instance) |
| 60 | err = json.Unmarshal(v.Value, instanceInfo) |
| 61 | if err != nil { |
| 62 | errMsg := fmt.Sprintf("Unable to parse instance info from etcd value %s, Error:%s", string(v.Value), err.Error()) |
| 63 | logrus.Error(errMsg) |
| 64 | continue |
| 65 | } |
| 66 | instanceList = append(instanceList, instanceInfo) |
| 67 | } |
| 68 | return instanceList, nil |
| 69 | } |
| 70 | |
| 71 | func AddInstanceInfo(nodeIndex int, instanceInfo *model.Instance) error { |
| 72 | instanceInfoKeyBase := fmt.Sprintf(key.NodeInstanceListKeyTemplate, nodeIndex) |
nothing calls this directly
no outgoing calls
no test coverage detected