mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
新增全局配置
This commit is contained in:
@@ -43,6 +43,7 @@ var cluster Cluster
|
|||||||
type Cluster struct {
|
type Cluster struct {
|
||||||
localNodeInfo NodeInfo //本结点配置信息
|
localNodeInfo NodeInfo //本结点配置信息
|
||||||
masterDiscoveryNodeList []NodeInfo //配置发现Master结点
|
masterDiscoveryNodeList []NodeInfo //配置发现Master结点
|
||||||
|
globalCfg interface{} //全局配置
|
||||||
|
|
||||||
localServiceCfg map[string]interface{} //map[serviceName]配置数据*
|
localServiceCfg map[string]interface{} //map[serviceName]配置数据*
|
||||||
mapRpc map[int]NodeRpcInfo //nodeId
|
mapRpc map[int]NodeRpcInfo //nodeId
|
||||||
@@ -418,3 +419,7 @@ func HasService(nodeId int, serviceName string) bool {
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cls *Cluster) GetGlobalCfg() interface{} {
|
||||||
|
return cls.globalCfg
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||||
|
|
||||||
type NodeInfoList struct {
|
type NodeInfoList struct {
|
||||||
MasterDiscoveryNode []NodeInfo //用于服务发现Node
|
MasterDiscoveryNode []NodeInfo //用于服务发现Node
|
||||||
NodeList []NodeInfo
|
NodeList []NodeInfo
|
||||||
@@ -29,18 +30,19 @@ func (cls *Cluster) ReadClusterConfig(filepath string) (*NodeInfoList,error) {
|
|||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cls *Cluster) readServiceConfig(filepath string) (map[string]interface{},map[int]map[string]interface{},error) {
|
func (cls *Cluster) readServiceConfig(filepath string) (interface{}, map[string]interface{}, map[int]map[string]interface{}, error) {
|
||||||
c := map[string]interface{}{}
|
c := map[string]interface{}{}
|
||||||
//读取配置
|
//读取配置
|
||||||
d, err := ioutil.ReadFile(filepath)
|
d, err := ioutil.ReadFile(filepath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil,nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(d, &c)
|
err = json.Unmarshal(d, &c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil,nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GlobalCfg, ok := c["Global"]
|
||||||
serviceConfig := map[string]interface{}{}
|
serviceConfig := map[string]interface{}{}
|
||||||
serviceCfg, ok := c["Service"]
|
serviceCfg, ok := c["Service"]
|
||||||
if ok == true {
|
if ok == true {
|
||||||
@@ -60,7 +62,7 @@ func (cls *Cluster) readServiceConfig(filepath string) (map[string]interface{},
|
|||||||
mapNodeService[int(nodeId.(float64))] = serviceCfg
|
mapNodeService[int(nodeId.(float64))] = serviceCfg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return serviceConfig,mapNodeService,nil
|
return GlobalCfg, serviceConfig, mapNodeService, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cls *Cluster) readLocalClusterConfig(nodeId int) ([]NodeInfo, []NodeInfo, error) {
|
func (cls *Cluster) readLocalClusterConfig(nodeId int) ([]NodeInfo, []NodeInfo, error) {
|
||||||
@@ -104,7 +106,6 @@ func (cls *Cluster) readLocalClusterConfig(nodeId int) ([]NodeInfo,[]NodeInfo,er
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return masterDiscoverNodeList, nodeInfoList, nil
|
return masterDiscoverNodeList, nodeInfoList, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,11 +120,15 @@ func (cls *Cluster) readLocalService(localNodeId int) error {
|
|||||||
for _, f := range fileInfoList {
|
for _, f := range fileInfoList {
|
||||||
if f.IsDir() == false {
|
if f.IsDir() == false {
|
||||||
filePath := strings.TrimRight(strings.TrimRight(clusterCfgPath, "/"), "\\") + "/" + f.Name()
|
filePath := strings.TrimRight(strings.TrimRight(clusterCfgPath, "/"), "\\") + "/" + f.Name()
|
||||||
serviceConfig,mapNodeService,err := cls.readServiceConfig(filePath)
|
currGlobalCfg, serviceConfig, mapNodeService, err := cls.readServiceConfig(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if currGlobalCfg != nil {
|
||||||
|
cls.globalCfg = currGlobalCfg
|
||||||
|
}
|
||||||
|
|
||||||
for _, s := range cls.localNodeInfo.ServiceList {
|
for _, s := range cls.localNodeInfo.ServiceList {
|
||||||
for {
|
for {
|
||||||
//取公共服务配置
|
//取公共服务配置
|
||||||
@@ -164,7 +169,6 @@ func (cls *Cluster) parseLocalCfg(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (cls *Cluster) checkDiscoveryNodeList(discoverMasterNode []NodeInfo) bool {
|
func (cls *Cluster) checkDiscoveryNodeList(discoverMasterNode []NodeInfo) bool {
|
||||||
for i := 0; i < len(discoverMasterNode)-1; i++ {
|
for i := 0; i < len(discoverMasterNode)-1; i++ {
|
||||||
for j := i + 1; j < len(discoverMasterNode); j++ {
|
for j := i + 1; j < len(discoverMasterNode); j++ {
|
||||||
|
|||||||
Reference in New Issue
Block a user