mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
优化service配置读取规则
This commit is contained in:
@@ -116,44 +116,80 @@ func (cls *Cluster) readLocalService(localNodeId int) error {
|
|||||||
return fmt.Errorf("Read dir %s is fail :%+v", clusterCfgPath, err)
|
return fmt.Errorf("Read dir %s is fail :%+v", clusterCfgPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var globalCfg interface{}
|
||||||
|
publicService := map[string]interface{}{}
|
||||||
|
nodeService := map[string]interface{}{}
|
||||||
|
|
||||||
//读取任何文件,只读符合格式的配置,目录下的文件可以自定义分文件
|
//读取任何文件,只读符合格式的配置,目录下的文件可以自定义分文件
|
||||||
for _, f := range fileInfoList {
|
for _, f := range fileInfoList {
|
||||||
if f.IsDir() == false {
|
if f.IsDir() == true {
|
||||||
filePath := strings.TrimRight(strings.TrimRight(clusterCfgPath, "/"), "\\") + "/" + f.Name()
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
filePath := strings.TrimRight(strings.TrimRight(clusterCfgPath, "/"), "\\") + "/" + f.Name()
|
||||||
currGlobalCfg, serviceConfig, mapNodeService, err := cls.readServiceConfig(filePath)
|
currGlobalCfg, serviceConfig, mapNodeService, err := cls.readServiceConfig(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if currGlobalCfg != nil {
|
||||||
|
//不允许重复的配置global配置
|
||||||
|
if globalCfg != nil {
|
||||||
|
return fmt.Errorf("[Global] does not allow repeated configuration in %s.",f.Name())
|
||||||
}
|
}
|
||||||
|
globalCfg = currGlobalCfg
|
||||||
|
}
|
||||||
|
|
||||||
if currGlobalCfg != nil {
|
//保存公共配置
|
||||||
cls.globalCfg = currGlobalCfg
|
for _, s := range cls.localNodeInfo.ServiceList {
|
||||||
}
|
for {
|
||||||
|
//取公共服务配置
|
||||||
for _, s := range cls.localNodeInfo.ServiceList {
|
pubCfg, ok := serviceConfig[s]
|
||||||
for {
|
if ok == true {
|
||||||
//取公共服务配置
|
if _,publicOk := publicService[s];publicOk == true {
|
||||||
pubCfg, ok := serviceConfig[s]
|
return fmt.Errorf("public service [%s] does not allow repeated configuration in %s.",s,f.Name())
|
||||||
if ok == true {
|
|
||||||
cls.localServiceCfg[s] = pubCfg
|
|
||||||
}
|
}
|
||||||
|
publicService[s] = pubCfg
|
||||||
|
}
|
||||||
|
|
||||||
//如果结点也配置了该服务,则覆盖之
|
//取指定结点配置的服务
|
||||||
nodeService, ok := mapNodeService[localNodeId]
|
nodeServiceCfg,ok := mapNodeService[localNodeId]
|
||||||
if ok == false {
|
if ok == false {
|
||||||
break
|
|
||||||
}
|
|
||||||
sCfg, ok := nodeService[s]
|
|
||||||
if ok == false {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
cls.localServiceCfg[s] = sCfg
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
nodeCfg, ok := nodeServiceCfg[s]
|
||||||
|
if ok == false {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
if _,nodeOK := nodeService[s];nodeOK == true {
|
||||||
|
return fmt.Errorf("NodeService NodeId[%d] Service[%s] does not allow repeated configuration in %s.",cls.localNodeInfo.NodeId,s,f.Name())
|
||||||
|
}
|
||||||
|
nodeService[s] = nodeCfg
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//组合所有的配置
|
||||||
|
for _, s := range cls.localNodeInfo.ServiceList {
|
||||||
|
//先从NodeService中找
|
||||||
|
var serviceCfg interface{}
|
||||||
|
var ok bool
|
||||||
|
serviceCfg,ok = nodeService[s]
|
||||||
|
if ok == true {
|
||||||
|
cls.localServiceCfg[s] =serviceCfg
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
//如果找不到从PublicService中找
|
||||||
|
serviceCfg,ok = publicService[s]
|
||||||
|
if ok == true {
|
||||||
|
cls.localServiceCfg[s] =serviceCfg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cls.globalCfg = globalCfg
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user