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

Function UpdateNode

daemon/pkg/synchronizer/node.go:107–125  ·  view source on GitHub ↗
(nodeIndex int, update func(*model.Node) error)

Source from the content-addressed store, hash-verified

105}
106
107func UpdateNode(nodeIndex int, update func(*model.Node) error) error {
108 nodeInfoKey := fmt.Sprintf("%s/%d", key.NodeIndexListKey, nodeIndex)
109 _, err := concurrency.NewSTM(utils.EtcdClient, func(s concurrency.STM) error {
110 etcdOldNode := s.Get(nodeInfoKey)
111 instance := new(model.Node)
112 json.Unmarshal([]byte(etcdOldNode), instance)
113 err := update(instance)
114 if err != nil {
115 return fmt.Errorf("update local new instance of %s error: %s", nodeInfoKey, err.Error())
116 }
117 etcdNewNode, err := json.Marshal(instance)
118 if err != nil {
119 return fmt.Errorf("format local new instance of %s error: %s", nodeInfoKey, err.Error())
120 }
121 s.Put(nodeInfoKey, string(etcdNewNode))
122 return nil
123 })
124 return err
125}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected