(nodeIndex int, instanceID string, update func(*model.Instance) error)
| 90 | } |
| 91 | |
| 92 | func UpdateInstanceInfo(nodeIndex int, instanceID string, update func(*model.Instance) error) error { |
| 93 | instanceInfoKeyBase := fmt.Sprintf(key.NodeInstanceListKeyTemplate, nodeIndex) |
| 94 | instanceInfoKey := fmt.Sprintf("%s/%s", instanceInfoKeyBase, instanceID) |
| 95 | _, err := concurrency.NewSTM(utils.EtcdClient, func(s concurrency.STM) error { |
| 96 | etcdOldInstance := s.Get(instanceInfoKey) |
| 97 | instance := new(model.Instance) |
| 98 | json.Unmarshal([]byte(etcdOldInstance), instance) |
| 99 | err := update(instance) |
| 100 | if err != nil { |
| 101 | return fmt.Errorf("update local new instance of %s error: %s", instanceInfoKey, err.Error()) |
| 102 | } |
| 103 | etcdNewInstance, err := json.Marshal(instance) |
| 104 | if err != nil { |
| 105 | return fmt.Errorf("format local new instance of %s error: %s", instanceInfoKey, err.Error()) |
| 106 | } |
| 107 | s.Put(instanceInfoKey, string(etcdNewInstance)) |
| 108 | return nil |
| 109 | }) |
| 110 | return err |
| 111 | } |
| 112 | |
| 113 | func RemoveInstance(nodeIndex int, instanceID string) error { |
| 114 | instanceInfoKeyBase := fmt.Sprintf(key.NodeInstanceListKeyTemplate, nodeIndex) |
nothing calls this directly
no outgoing calls
no test coverage detected