forked from coreos/fleet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
66 lines (51 loc) · 1.39 KB
/
server.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
package server
import (
"github.com/coreos/go-etcd/etcd"
"github.com/coreos/fleet/agent"
"github.com/coreos/fleet/config"
"github.com/coreos/fleet/engine"
"github.com/coreos/fleet/event"
"github.com/coreos/fleet/machine"
"github.com/coreos/fleet/registry"
)
type Server struct {
agent *agent.Agent
engine *engine.Engine
machine *machine.Machine
registry *registry.Registry
eventBus *event.EventBus
eventStream *registry.EventStream
}
func New(cfg config.Config) *Server {
m := machine.New(cfg.BootId, cfg.PublicIP, cfg.Metadata())
regClient := etcd.NewClient(cfg.EtcdServers)
regClient.SetConsistency(etcd.STRONG_CONSISTENCY)
r := registry.New(regClient)
eb := event.NewEventBus()
eb.Listen()
eventClient := etcd.NewClient(cfg.EtcdServers)
eventClient.SetConsistency(etcd.STRONG_CONSISTENCY)
es := registry.NewEventStream(eventClient)
a, err := agent.New(r, eb, m, cfg.AgentTTL, cfg.UnitPrefix)
if err != nil {
//TODO: return this as an error object rather than panicking
panic(err)
}
e := engine.New(r, eb, m)
return &Server{a, e, m, r, eb, es}
}
func (self *Server) Run() {
go self.agent.Run()
go self.engine.Run()
go self.eventBus.Listen()
go self.eventStream.Stream(self.eventBus.Channel)
}
func (self *Server) Stop() {
self.agent.Stop()
self.engine.Stop()
self.eventStream.Close()
self.eventBus.Stop()
}
func (self *Server) Purge() {
self.agent.Purge()
}