本文整理匯總了Golang中github.com/NetSys/quilt/db.Database.InsertLabel方法的典型用法代碼示例。如果您正苦於以下問題:Golang Database.InsertLabel方法的具體用法?Golang Database.InsertLabel怎麽用?Golang Database.InsertLabel使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/NetSys/quilt/db.Database
的用法示例。
在下文中一共展示了Database.InsertLabel方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: updateDBLabels
func updateDBLabels(view db.Database, etcdData storeData, ipMap map[string]string) {
// Gather all of the label keys and IPs for single host labels, and IPs of
// the containers in a given label.
containerIPs := map[string][]string{}
labelIPs := map[string]string{}
labelKeys := map[string]struct{}{}
for _, c := range etcdData.containers {
for _, l := range c.Labels {
labelKeys[l] = struct{}{}
cIP := ipMap[strconv.Itoa(c.StitchID)]
if _, ok := etcdData.multiHost[l]; !ok {
labelIPs[l] = cIP
}
// The ordering of IPs between function calls will be consistent
// because the containers are sorted by their StitchIDs when
// inserted into etcd.
containerIPs[l] = append(containerIPs[l], cIP)
}
}
labelKeyFunc := func(val interface{}) interface{} {
return val.(db.Label).Label
}
labelKeySlice := join.StringSlice{}
for l := range labelKeys {
labelKeySlice = append(labelKeySlice, l)
}
pairs, dbls, dirKeys := join.HashJoin(db.LabelSlice(view.SelectFromLabel(nil)),
labelKeySlice, labelKeyFunc, nil)
for _, dbl := range dbls {
view.Remove(dbl.(db.Label))
}
for _, key := range dirKeys {
pairs = append(pairs, join.Pair{L: view.InsertLabel(), R: key})
}
for _, pair := range pairs {
dbl := pair.L.(db.Label)
dbl.Label = pair.R.(string)
if _, ok := etcdData.multiHost[dbl.Label]; ok {
dbl.IP = etcdData.multiHost[dbl.Label]
dbl.MultiHost = true
} else {
dbl.IP = labelIPs[dbl.Label]
dbl.MultiHost = false
}
dbl.ContainerIPs = containerIPs[dbl.Label]
view.Commit(dbl)
}
}
示例2: readLabelTransact
func readLabelTransact(view db.Database, dir directory) {
lKey := func(val interface{}) interface{} {
return val.(db.Label).Label
}
pairs, dbls, dirKeys := join.HashJoin(db.LabelSlice(view.SelectFromLabel(nil)),
join.StringSlice(dir.keys()), lKey, nil)
for _, dbl := range dbls {
view.Remove(dbl.(db.Label))
}
for _, key := range dirKeys {
pairs = append(pairs, join.Pair{L: view.InsertLabel(), R: key})
}
for _, pair := range pairs {
dbl := pair.L.(db.Label)
dbl.Label = pair.R.(string)
dbl.IP = dir[dbl.Label]["IP"]
_, dbl.MultiHost = dir[dbl.Label]["MultiHost"]
view.Commit(dbl)
}
}