Compare commits

...

7 Commits

Author SHA1 Message Date
orgin
ee54862be2 fixed HTTP status codes write error 2022-05-12 09:45:22 +08:00
orgin
13642d7402 新增name命令参数 2022-04-19 09:26:11 +08:00
orgin
18d620118e 在help中新增编译参数信息 2022-04-13 11:47:13 +08:00
orgin
f02592d126 在help中新增编译参数信息 2022-04-13 11:36:20 +08:00
orgin
0f890887f7 在help中新增编译时间 2022-04-13 10:24:36 +08:00
orgin
c5c05b6ae9 补充Readme:新增Global配置说明 2022-04-02 14:24:46 +08:00
orgin
68b891df51 新增全局配置 2022-04-02 14:02:33 +08:00
6 changed files with 115 additions and 77 deletions

View File

@@ -87,6 +87,9 @@ service.json如下
--------------- ---------------
``` ```
{ {
"Global": {
"AreaId": 1
},
"Service":{ "Service":{
"HttpService":{ "HttpService":{
"ListenAddr":"0.0.0.0:9402", "ListenAddr":"0.0.0.0:9402",
@@ -157,7 +160,7 @@ service.json如下
``` ```
--------------- ---------------
以上配置分为两个部分Service与NodeServiceNodeService中配置的对应结点中服务的配置如果启动程序中根据nodeid查找该域的对应的服务如果找不到时从Service公共部分查找。 以上配置分为两个部分:Global,Service与NodeService。Global是全局配置在任何服务中都可以通过cluster.GetCluster().GetGlobalCfg()获取NodeService中配置的对应结点中服务的配置如果启动程序中根据nodeid查找该域的对应的服务如果找不到时从Service公共部分查找。
**HttpService配置** **HttpService配置**
* ListenAddr:Http监听地址 * ListenAddr:Http监听地址

View File

@@ -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
}

View File

@@ -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++ {

View File

@@ -9,6 +9,7 @@ import (
"github.com/duanhf2012/origin/profiler" "github.com/duanhf2012/origin/profiler"
"github.com/duanhf2012/origin/service" "github.com/duanhf2012/origin/service"
"github.com/duanhf2012/origin/util/timer" "github.com/duanhf2012/origin/util/timer"
"github.com/duanhf2012/origin/util/buildtime"
"io/ioutil" "io/ioutil"
slog "log" slog "log"
"net/http" "net/http"
@@ -38,6 +39,7 @@ func init() {
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM,syscall.Signal(10)) signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM,syscall.Signal(10))
console.RegisterCommandBool("help",false,"<-help> This help.",usage) 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("start","","<-start nodeid=nodeid> Run originserver.",startNode)
console.RegisterCommandString("stop","","<-stop nodeid=nodeid> Stop originserver process.",stopNode) console.RegisterCommandString("stop","","<-stop nodeid=nodeid> Stop originserver process.",stopNode)
console.RegisterCommandString("config","","<-config path> Configuration file path.",setConfigPath) console.RegisterCommandString("config","","<-config path> Configuration file path.",setConfigPath)
@@ -53,13 +55,20 @@ func usage(val interface{}) error{
return nil return nil
} }
fmt.Fprintf(os.Stderr, `orgin version: orgin/2.14.20201029 if len(buildtime.GetBuildDateTime())>0 {
Usage: originserver [-help] [-start node=1] [-stop] [-config path] [-pprof 0.0.0.0:6060]... 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() console.PrintDefaults()
return nil return nil
} }
func setName(val interface{}) error {
return nil
}
func setPprof(val interface{}) error { func setPprof(val interface{}) error {
listenAddr := val.(string) listenAddr := val.(string)
if listenAddr==""{ if listenAddr==""{

View File

@@ -175,10 +175,12 @@ func (slf *HttpSession) Write(msg []byte) {
func (slf *HttpSession) WriteJsonDone(statusCode int,msgJson interface{}) error { func (slf *HttpSession) WriteJsonDone(statusCode int,msgJson interface{}) error {
msg, err := json.Marshal(msgJson) msg, err := json.Marshal(msgJson)
if err == nil { if err != nil {
slf.Write(msg) return err
} }
slf.statusCode = statusCode
slf.Write(msg)
slf.Done() slf.Done()
return err return err
} }

15
util/buildtime/build.go Normal file
View 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
}