...
1
18
19
20 package db
21
22 import (
23 "discovery/config"
24 "discovery/log"
25 "discovery/types"
26 "net"
27 "time"
28 )
29
30 const DatabasePath = "db"
31 const DatabaseName = "p2pfaas-discovery.db"
32
33 func init() {
34 log.Log.Debugf("Starting DB module")
35
36 initBackend()
37
38 AddInitServers(config.GetInitServers())
39 log.Log.Debugf("Added init servers %v", config.GetInitServers())
40
41 log.Log.Debugf("Init successfully")
42 }
43
44 func Start() {
45
46 }
47
48 func AddInitServers(initServersArr []string) {
49 initServersValid := 0
50
51 for _, s := range initServersArr {
52
53 ip := net.ParseIP(s)
54 if ip == nil {
55 continue
56 }
57
58 err := MachineAdd(&types.Machine{
59 IP: s,
60 Alive: true,
61 DeadPolls: 0,
62 LastUpdate: time.Now().Unix(),
63 }, true)
64
65 if err != nil {
66 log.Log.Errorf("Could not add %s as init server: %s", s, err.Error())
67 } else {
68 initServersValid++
69 log.Log.Debugf("Added " + s + " as init server")
70 }
71 }
72 log.Log.Infof("Init DB with %d init servers", initServersValid)
73 }
74
View as plain text