当前位置: 首页>>代码示例>>Golang>>正文


Golang CfgEndpointState.ReadAll方法代码示例

本文整理汇总了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()
			}
		}
	}
}
开发者ID:jojimt,项目名称:netplugin,代码行数:71,代码来源:servicelb.go


注:本文中的github.com/contiv/netplugin/netmaster/mastercfg.CfgEndpointState.ReadAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。