mirror of
https://github.com/duanhf2012/origin.git
synced 2026-06-12 08:53:13 +08:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13642d7402 | ||
|
|
18d620118e | ||
|
|
f02592d126 | ||
|
|
0f890887f7 | ||
|
|
c5c05b6ae9 | ||
|
|
68b891df51 |
@@ -87,6 +87,9 @@ service.json如下:
|
||||
---------------
|
||||
```
|
||||
{
|
||||
"Global": {
|
||||
"AreaId": 1
|
||||
},
|
||||
"Service":{
|
||||
"HttpService":{
|
||||
"ListenAddr":"0.0.0.0:9402",
|
||||
@@ -157,7 +160,7 @@ service.json如下:
|
||||
```
|
||||
|
||||
---------------
|
||||
以上配置分为两个部分:Service与NodeService,NodeService中配置的对应结点中服务的配置,如果启动程序中根据nodeid查找该域的对应的服务,如果找不到时,从Service公共部分查找。
|
||||
以上配置分为两个部分:Global,Service与NodeService。Global是全局配置,在任何服务中都可以通过cluster.GetCluster().GetGlobalCfg()获取,NodeService中配置的对应结点中服务的配置,如果启动程序中根据nodeid查找该域的对应的服务,如果找不到时,从Service公共部分查找。
|
||||
|
||||
**HttpService配置**
|
||||
* ListenAddr:Http监听地址
|
||||
|
||||
@@ -43,6 +43,7 @@ var cluster Cluster
|
||||
type Cluster struct {
|
||||
localNodeInfo NodeInfo //本结点配置信息
|
||||
masterDiscoveryNodeList []NodeInfo //配置发现Master结点
|
||||
globalCfg interface{} //全局配置
|
||||
|
||||
localServiceCfg map[string]interface{} //map[serviceName]配置数据*
|
||||
mapRpc map[int]NodeRpcInfo //nodeId
|
||||
@@ -418,3 +419,7 @@ func HasService(nodeId int, serviceName string) bool {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (cls *Cluster) GetGlobalCfg() interface{} {
|
||||
return cls.globalCfg
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
)
|
||||
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
|
||||
type NodeInfoList struct {
|
||||
MasterDiscoveryNode []NodeInfo //用于服务发现Node
|
||||
NodeList []NodeInfo
|
||||
@@ -29,18 +30,19 @@ func (cls *Cluster) ReadClusterConfig(filepath string) (*NodeInfoList,error) {
|
||||
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{}{}
|
||||
//读取配置
|
||||
d, err := ioutil.ReadFile(filepath)
|
||||
if err != nil {
|
||||
return nil,nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
err = json.Unmarshal(d, &c)
|
||||
if err != nil {
|
||||
return nil,nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
GlobalCfg, ok := c["Global"]
|
||||
serviceConfig := map[string]interface{}{}
|
||||
serviceCfg, ok := c["Service"]
|
||||
if ok == true {
|
||||
@@ -60,7 +62,7 @@ func (cls *Cluster) readServiceConfig(filepath string) (map[string]interface{},
|
||||
mapNodeService[int(nodeId.(float64))] = serviceCfg
|
||||
}
|
||||
}
|
||||
return serviceConfig,mapNodeService,nil
|
||||
return GlobalCfg, serviceConfig, mapNodeService, nil
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -119,11 +120,15 @@ func (cls *Cluster) readLocalService(localNodeId int) error {
|
||||
for _, f := range fileInfoList {
|
||||
if f.IsDir() == false {
|
||||
filePath := strings.TrimRight(strings.TrimRight(clusterCfgPath, "/"), "\\") + "/" + f.Name()
|
||||
serviceConfig,mapNodeService,err := cls.readServiceConfig(filePath)
|
||||
currGlobalCfg, serviceConfig, mapNodeService, err := cls.readServiceConfig(filePath)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if currGlobalCfg != nil {
|
||||
cls.globalCfg = currGlobalCfg
|
||||
}
|
||||
|
||||
for _, s := range cls.localNodeInfo.ServiceList {
|
||||
for {
|
||||
//取公共服务配置
|
||||
@@ -164,7 +169,6 @@ func (cls *Cluster) parseLocalCfg(){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func (cls *Cluster) checkDiscoveryNodeList(discoverMasterNode []NodeInfo) bool {
|
||||
for i := 0; i < len(discoverMasterNode)-1; i++ {
|
||||
for j := i + 1; j < len(discoverMasterNode); j++ {
|
||||
|
||||
15
node/node.go
15
node/node.go
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/duanhf2012/origin/profiler"
|
||||
"github.com/duanhf2012/origin/service"
|
||||
"github.com/duanhf2012/origin/util/timer"
|
||||
"github.com/duanhf2012/origin/util/buildtime"
|
||||
"io/ioutil"
|
||||
slog "log"
|
||||
"net/http"
|
||||
@@ -38,6 +39,7 @@ func init() {
|
||||
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM,syscall.Signal(10))
|
||||
|
||||
console.RegisterCommandBool("help",false,"<-help> This help.",usage)
|
||||
console.RegisterCommandString("name","","<-name nodeName> Node's name.",setName)
|
||||
console.RegisterCommandString("start","","<-start nodeid=nodeid> Run originserver.",startNode)
|
||||
console.RegisterCommandString("stop","","<-stop nodeid=nodeid> Stop originserver process.",stopNode)
|
||||
console.RegisterCommandString("config","","<-config path> Configuration file path.",setConfigPath)
|
||||
@@ -53,13 +55,20 @@ func usage(val interface{}) error{
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Fprintf(os.Stderr, `orgin version: orgin/2.14.20201029
|
||||
Usage: originserver [-help] [-start node=1] [-stop] [-config path] [-pprof 0.0.0.0:6060]...
|
||||
`)
|
||||
if len(buildtime.GetBuildDateTime())>0 {
|
||||
fmt.Fprintf(os.Stderr, "Welcome to Origin(build info: %s)\nUsage: originserver [-help] [-start node=1] [-stop] [-config path] [-pprof 0.0.0.0:6060]...\n",buildtime.GetBuildDateTime())
|
||||
}else{
|
||||
fmt.Fprintf(os.Stderr, "Welcome to Origin\nUsage: originserver [-help] [-start node=1] [-stop] [-config path] [-pprof 0.0.0.0:6060]...\n")
|
||||
}
|
||||
|
||||
console.PrintDefaults()
|
||||
return nil
|
||||
}
|
||||
|
||||
func setName(val interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func setPprof(val interface{}) error {
|
||||
listenAddr := val.(string)
|
||||
if listenAddr==""{
|
||||
|
||||
15
util/buildtime/build.go
Normal file
15
util/buildtime/build.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package buildtime
|
||||
|
||||
/*
|
||||
//查询buildtime包中的位置,在github.com/duanhf2012/origin/util/buildtime.BuildTime中
|
||||
go tool nm ./originserver.exe |grep buildtime
|
||||
|
||||
//编译传入编译时间信息
|
||||
go build -ldflags "-X 'github.com/duanhf2012/origin/util/buildtime.BuildTime=20200101'"
|
||||
*/
|
||||
var BuildTime string
|
||||
|
||||
|
||||
func GetBuildDateTime() string {
|
||||
return BuildTime
|
||||
}
|
||||
Reference in New Issue
Block a user