| 100 | } |
| 101 | |
| 102 | func (e *Etcd) Add(k *protocol.Kite, v *kontrolprotocol.RegisterValue) error { |
| 103 | etcdKey := KitesPrefix + k.String() |
| 104 | etcdIDKey := KitesPrefix + "/" + k.ID |
| 105 | |
| 106 | p, err := json.Marshal(v) |
| 107 | if err != nil { |
| 108 | return err |
| 109 | } |
| 110 | |
| 111 | value := string(p) |
| 112 | |
| 113 | // Set the kite key. |
| 114 | // Example "/koding/production/os/0.0.1/sj/kontainer1.sj.koding.com/1234asdf..." |
| 115 | _, err = e.client.Set(context.TODO(), |
| 116 | etcdKey, |
| 117 | value, |
| 118 | &etcd.SetOptions{ |
| 119 | TTL: KeyTTL, |
| 120 | PrevExist: etcd.PrevIgnore, |
| 121 | }, |
| 122 | ) |
| 123 | if err != nil { |
| 124 | return err |
| 125 | } |
| 126 | |
| 127 | // Also store the the kite.Key Id for easy lookup |
| 128 | _, err = e.client.Set(context.TODO(), |
| 129 | etcdIDKey, |
| 130 | value, |
| 131 | &etcd.SetOptions{ |
| 132 | TTL: KeyTTL, |
| 133 | PrevExist: etcd.PrevIgnore, |
| 134 | }, |
| 135 | ) |
| 136 | |
| 137 | return err |
| 138 | } |
| 139 | |
| 140 | func (e *Etcd) Update(k *protocol.Kite, v *kontrolprotocol.RegisterValue) error { |
| 141 | etcdKey := KitesPrefix + k.String() |