MCPcopy Create free account
hub / github.com/OpenSN-Library/OpenSN-Library / UpdateInstanceInfo

Function UpdateInstanceInfo

daemon/pkg/synchronizer/instance.go:92–111  ·  view source on GitHub ↗
(nodeIndex int, instanceID string, update func(*model.Instance) error)

Source from the content-addressed store, hash-verified

90}
91
92func 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
113func RemoveInstance(nodeIndex int, instanceID string) error {
114 instanceInfoKeyBase := fmt.Sprintf(key.NodeInstanceListKeyTemplate, nodeIndex)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected