forked from jxwr/cc
-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.go
85 lines (75 loc) · 2.07 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"flag"
"strings"
"github.com/golang/glog"
"github.com/ksarch-saas/cc/controller"
"github.com/ksarch-saas/cc/frontend"
"github.com/ksarch-saas/cc/inspector"
"github.com/ksarch-saas/cc/log"
"github.com/ksarch-saas/cc/meta"
"github.com/ksarch-saas/cc/streams"
"github.com/ksarch-saas/cc/topo"
"github.com/ksarch-saas/cc/utils"
)
var (
appName string
localRegion string
seeds string
zkHosts string
zkService string
httpPort int
wsPort int
)
func init() {
flag.StringVar(&appName, "appname", "", "app name")
flag.StringVar(&localRegion, "local-region", "", "local region")
flag.StringVar(&seeds, "seeds", "", "redis cluster seeds, seperate by comma")
flag.StringVar(&zkHosts, "zkhosts", "", "zk hosts, seperate by comma")
flag.StringVar(&zkService, "zkservice", "", "naming service locate zookeeper")
flag.IntVar(&httpPort, "http-port", 0, "http port")
flag.IntVar(&wsPort, "ws-port", 0, "ws port")
}
func main() {
flag.Parse()
seedNodes := []*topo.Node{}
for _, addr := range strings.Split(seeds, ",") {
glog.Info(addr)
n := topo.NewNodeFromString(addr)
if n == nil {
glog.Fatal("invalid seeds %s", addr)
}
seedNodes = append(seedNodes, n)
}
if httpPort == 0 {
glog.Fatal("invalid http port")
flag.PrintDefaults()
}
if wsPort == 0 {
glog.Fatal("invalid websocket port")
flag.PrintDefaults()
}
if zkHosts == "" {
glog.Info("zkHosts not set, trying to locate by naming service")
var err error
zkHosts, err = utils.ResolvZkFromNaming(zkService)
if err != nil {
glog.Fatal("Resolve zkhosts failed")
}
glog.Infof("Resolve zkhosts from naming service, result is %s", zkHosts)
}
initCh := make(chan error)
go meta.Run(appName, localRegion, httpPort, wsPort, zkHosts, seedNodes, initCh)
err := <-initCh
if err != nil {
glog.Fatal(err)
}
streams.StartAllStreams()
streams.LogStream.Sub(log.WriteFileHandler)
streams.LogStream.Sub(log.WriteRingBufferHandler)
sp := inspector.NewInspector()
go sp.Run()
c := controller.NewController()
fe := frontend.NewFrontEnd(c, httpPort, wsPort)
fe.Run()
}