forked from kubeedge/kubeedge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudhub.go
90 lines (73 loc) · 2.29 KB
/
cloudhub.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
86
87
88
89
90
package cloudhub
import (
"github.com/kubeedge/beehive/pkg/common/log"
"github.com/kubeedge/kubeedge/cloud/pkg/cloudhub/servers"
"io/ioutil"
"os"
"github.com/kubeedge/beehive/pkg/common/config"
"github.com/kubeedge/beehive/pkg/core"
"github.com/kubeedge/beehive/pkg/core/context"
"github.com/kubeedge/kubeedge/cloud/pkg/cloudhub/channelq"
"github.com/kubeedge/kubeedge/cloud/pkg/cloudhub/common/util"
chconfig "github.com/kubeedge/kubeedge/cloud/pkg/cloudhub/config"
)
type cloudHub struct {
context *context.Context
}
func init() {
core.Register(&cloudHub{})
}
func (a *cloudHub) Name() string {
return "cloudhub"
}
func (a *cloudHub) Group() string {
return "cloudhub"
}
func (a *cloudHub) Start(c *context.Context) {
a.context = c
cafile, err := config.CONFIG.GetValue("cloudhub.ca").ToString()
if err != nil {
log.LOGGER.Info("missing cloudhub.ca configuration key, loading default path and filename ./" + chconfig.DefaultCAFile)
cafile = chconfig.DefaultCAFile
}
certfile, err := config.CONFIG.GetValue("cloudhub.cert").ToString()
if err != nil {
log.LOGGER.Info("missing cloudhub.cert configuration key, loading default path and filename ./" + chconfig.DefaultCertFile)
certfile = chconfig.DefaultCertFile
}
keyfile, err := config.CONFIG.GetValue("cloudhub.key").ToString()
if err != nil {
log.LOGGER.Info("missing cloudhub.key configuration key, loading default path and filename ./" + chconfig.DefaultKeyFile)
keyfile = chconfig.DefaultKeyFile
}
errs := make([]string, 0)
util.HubConfig.Ca, err = ioutil.ReadFile(cafile)
if err != nil {
errs = append(errs, err.Error())
}
util.HubConfig.Cert, err = ioutil.ReadFile(certfile)
if err != nil {
errs = append(errs, err.Error())
}
util.HubConfig.Key, err = ioutil.ReadFile(keyfile)
if err != nil {
errs = append(errs, err.Error())
}
if len(errs) > 0 {
log.LOGGER.Errorf("cloudhub failed with errors : %v", errs)
os.Exit(1)
}
eventq, err := channelq.NewChannelEventQueue(c)
// start the cloudhub server
if util.HubConfig.ProtocolWebsocket {
go servers.StartCloudHub(servers.ProtocolWebsocket, eventq, c)
}
if util.HubConfig.ProtocolQuic {
go servers.StartCloudHub(servers.ProtocolQuic, eventq, c)
}
stopchan := make(chan bool)
<-stopchan
}
func (a *cloudHub) Cleanup() {
a.context.Cleanup(a.Name())
}