mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-03 22:45:13 +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)
|
||||
}
|
||||
|
||||
var globalCfg interface{}
|
||||
publicService := map[string]interface{}{}
|
||||
nodeService := map[string]interface{}{}
|
||||
|
||||
//读取任何文件,只读符合格式的配置,目录下的文件可以自定义分文件
|
||||
for _, f := range fileInfoList {
|
||||
if f.IsDir() == false {
|
||||
filePath := strings.TrimRight(strings.TrimRight(clusterCfgPath, "/"), "\\") + "/" + f.Name()
|
||||
if f.IsDir() == true {
|
||||
continue
|
||||
}
|
||||
|
||||
filePath := strings.TrimRight(strings.TrimRight(clusterCfgPath, "/"), "\\") + "/" + f.Name()
|
||||
currGlobalCfg, serviceConfig, mapNodeService, err := cls.readServiceConfig(filePath)
|
||||
if err != nil {
|
||||
continue
|
||||
if err != nil {
|
||||
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 {
|
||||
//取公共服务配置
|
||||
pubCfg, ok := serviceConfig[s]
|
||||
if ok == true {
|
||||
cls.localServiceCfg[s] = pubCfg
|
||||
//保存公共配置
|
||||
for _, s := range cls.localNodeInfo.ServiceList {
|
||||
for {
|
||||
//取公共服务配置
|
||||
pubCfg, ok := serviceConfig[s]
|
||||
if ok == true {
|
||||
if _,publicOk := publicService[s];publicOk == true {
|
||||
return fmt.Errorf("public service [%s] does not allow repeated configuration in %s.",s,f.Name())
|
||||
}
|
||||
publicService[s] = pubCfg
|
||||
}
|
||||
|
||||
//如果结点也配置了该服务,则覆盖之
|
||||
nodeService, ok := mapNodeService[localNodeId]
|
||||
if ok == false {
|
||||
break
|
||||
}
|
||||
sCfg, ok := nodeService[s]
|
||||
if ok == false {
|
||||
break
|
||||
}
|
||||
|
||||
cls.localServiceCfg[s] = sCfg
|
||||
//取指定结点配置的服务
|
||||
nodeServiceCfg,ok := mapNodeService[localNodeId]
|
||||
if ok == false {
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user