赞
踩
(接上篇)
1)EdgehubConfig初始化具体如下所示。
config.InitEdgehubConfig() |
config.InitEdgehubConfig()函数定义具体如下所示。
KubeEdge/edge/pkg/edgehub/config/config.go |
// InitEdgehubConfig init edgehub config func InitEdgehubConfig() { err := getControllerConfig() ... if edgeHubConfig.CtrConfig.Protocol == protocolWebsocket { err = getWebSocketConfig() ... } else if edgeHubConfig.CtrConfig.Protocol == protocolQuic { err = getQuicConfig() ... } else { ... } } |
InitEdgehubConfig()函数首先通过err := getControllerConfig()获得EdgeHub Controller的配置信息,然后通过获得的配置信息中的Protocol字段来判断是哪个协议,最后根据判断结果获取相应的协议绑定的配置信息或报错。针对以上获取配置的操作,重点分析获得EdgeHub Controller的配置信息。
getControllerConfig()函数定义具体下所示。
KubeEdge/edge/pkg/edgehub/config/config.go |
var edgeHubConfig EdgeHubConfig ... func getControllerConfig() error { protocol, err := config.CONFIG.GetValue("edgehub.controller.protocol").ToString() ... edgeHubConfig.CtrConfig.Protocol = protocol heartbeat, err := config.CONFIG.GetValue("edgehub.controller.heartbeat").ToInt() ... edgeHubConfig.CtrConfig.HeartbeatPeriod = time.Duration(heartbeat) * time.Second projectID, err := config.CONFIG.GetValue("edgehub.controller.project-id").ToString() ... edgeHubConfig.CtrConfig.ProjectID = projectID nodeID, err := config.CONFIG.GetValue("edgehub.controller.node-id").ToString() ... edgeHubConfig.CtrConfig.NodeID = nodeID return nil } |
getControllerConfig()获取edgehub.controller.*相关的配置信息并赋值给变量edgeHubConfig。
到此,前面提到的EdgeHubConfig赋值也得到了解答。
2)EdgeHub Controller初始化具体如下所示。
err := ehc.initial(ctx) |
ehc.initial()函数定义具体如下所示。
KubeEdge/edge/pkg/edgehub/controller.go |
func (ehc *Controller) initial(ctx *context.Context) (err error) { config.GetConfig().WSConfig.URL, err = bhconfig.CONFIG.GetValue("edgehub.websocket.url").ToString() ... cloudHubClient, err := clients.GetClient(ehc.config.Protocol, config.GetConfig()) ... ehc.context = ctx ehc.chClient = cloudHubClient return nil } |
其中,第一行单独获取edgehub.websocket.url,这里感觉与“初始化EdgehubConfig”中的websocket配置信息初始化重复,在此留个疑问——
获取websocket配置信息重复。
「未完待续……」
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。