本文整理匯總了Golang中github.com/contiv/netplugin/netmaster/mastercfg.CfgEndpointState.ReadAll方法的典型用法代碼示例。如果您正苦於以下問題:Golang CfgEndpointState.ReadAll方法的具體用法?Golang CfgEndpointState.ReadAll怎麽用?Golang CfgEndpointState.ReadAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/contiv/netplugin/netmaster/mastercfg.CfgEndpointState
的用法示例。
在下文中一共展示了CfgEndpointState.ReadAll方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RestoreServiceProviderLBDb
//RestoreServiceProviderLBDb restores provider and servicelb db
func RestoreServiceProviderLBDb() {
log.Infof("Restoring ProviderDb and ServiceDB cache")
svcLBState := &mastercfg.CfgServiceLBState{}
stateDriver, err := utils.GetStateDriver()
if err != nil {
log.Errorf("Error Restoring Service and ProviderDb Err:%s", err)
return
}
svcLBState.StateDriver = stateDriver
svcLBCfgs, err := svcLBState.ReadAll()
if err == nil {
mastercfg.SvcMutex.Lock()
for _, svcLBCfg := range svcLBCfgs {
svcLB := svcLBCfg.(*mastercfg.CfgServiceLBState)
//mastercfg.ServiceLBDb = make(map[string]*mastercfg.ServiceLBInfo)
serviceID := GetServiceID(svcLB.ServiceName, svcLB.Tenant)
mastercfg.ServiceLBDb[serviceID] = &mastercfg.ServiceLBInfo{
IPAddress: svcLB.IPAddress,
Tenant: svcLB.Tenant,
ServiceName: svcLB.ServiceName,
Network: svcLB.Network,
}
mastercfg.ServiceLBDb[serviceID].Ports = append(mastercfg.ServiceLBDb[serviceID].Ports, svcLB.Ports...)
mastercfg.ServiceLBDb[serviceID].Selectors = make(map[string]string)
mastercfg.ServiceLBDb[serviceID].Providers = make(map[string]*mastercfg.Provider)
for k, v := range svcLB.Selectors {
mastercfg.ServiceLBDb[serviceID].Selectors[k] = v
}
for providerID, providerInfo := range svcLB.Providers {
mastercfg.ServiceLBDb[serviceID].Providers[providerID] = providerInfo
providerDBId := providerInfo.ContainerID
mastercfg.ProviderDb[providerDBId] = providerInfo
}
}
mastercfg.SvcMutex.Unlock()
}
//Recover from endpoint state as well .
epCfgState := mastercfg.CfgEndpointState{}
epCfgState.StateDriver = stateDriver
epCfgs, err := epCfgState.ReadAll()
if err == nil {
for _, epCfg := range epCfgs {
ep := epCfg.(*mastercfg.CfgEndpointState)
providerDBId := ep.ContainerID
if ep.Labels != nil && mastercfg.ProviderDb[providerDBId] == nil {
//Create provider info and store it in provider db
providerInfo := &mastercfg.Provider{}
providerInfo.ContainerID = ep.ContainerID
providerInfo.Network = strings.Split(ep.NetID, ".")[0]
providerInfo.Tenant = strings.Split(ep.NetID, ".")[1]
providerInfo.Labels = make(map[string]string)
providerInfo.IPAddress = ep.IPAddress
for k, v := range ep.Labels {
providerInfo.Labels[k] = v
}
mastercfg.SvcMutex.Lock()
mastercfg.ProviderDb[providerDBId] = providerInfo
mastercfg.SvcMutex.Unlock()
}
}
}
}