-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
86 lines (73 loc) · 2.55 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
86
package main
import (
"flag"
"math/rand"
"os"
"strings"
"time"
log "github.com/Sirupsen/logrus"
"github.com/codedellemc/scaleio-framework/scaleio-scheduler/config"
"github.com/codedellemc/scaleio-framework/scaleio-scheduler/scheduler"
)
// ----------------------- func init() ------------------------- //
func init() {
rand.Seed(time.Now().UnixNano())
log.SetOutput(os.Stdout)
log.Infoln("Initializing the ScaleIO Scheduler...")
}
func prerequisites(cfg *config.Config) bool {
if !cfg.Experimental && (cfg.PrimaryMdmAddress == "" &&
cfg.SecondaryMdmAddress == "" && cfg.TieBreakerMdmAddress == "") {
log.Errorln("Primary, Secondary and TieBreaker MDM nodes must be pre-configured" +
"in order for additional nodes to be added to the ScaleIO cluster.")
return false
}
if (cfg.PrimaryMdmAddress != "" && cfg.SecondaryMdmAddress != "" &&
cfg.TieBreakerMdmAddress != "") || (cfg.PrimaryMdmAddress == "" &&
cfg.SecondaryMdmAddress == "" && cfg.TieBreakerMdmAddress == "") {
return true
}
if cfg.PrimaryMdmAddress != "" {
log.Errorln("A Pre-Configured Primary MDM IP Address was provided. " +
"Using this option requires that a Pre-Configured Primary and TieBreaker MDM " +
"Nodes exist and their IP addresses be provided via command line option.")
} else if cfg.SecondaryMdmAddress != "" {
log.Errorln("A Pre-Configured Secondary MDM IP Address was provided. " +
"Using this option requires that a Pre-Configured Primary and TieBreaker MDM " +
"Nodes exist and their IP addresses be provided via command line option.")
} else if cfg.TieBreakerMdmAddress != "" {
log.Errorln("A Pre-Configured TieBreaker MDM IP Address was provided. " +
"Using this option requires that a Pre-Configured Primary and Secondary MDM " +
"Nodes exist and their IP addresses be provided via command line option.")
}
return false
}
func main() {
for _, e := range os.Environ() {
pair := strings.Split(e, "=")
log.Debugln(pair[0], "=", pair[1])
}
cfg := config.NewConfig()
fs := flag.NewFlagSet("scheduler", flag.ExitOnError)
cfg.AddFlags(fs)
fs.Parse(os.Args[1:])
level, err := log.ParseLevel(cfg.LogLevel)
if err != nil {
log.Warnln("Invalid log level. Defaulting to info.")
level = log.InfoLevel
} else {
log.Infoln("Set logging to", cfg.LogLevel)
}
log.SetLevel(level)
if !prerequisites(cfg) {
return //prerequisites not met
}
sched := scheduler.NewScaleIOScheduler(cfg)
if sched == nil {
log.Fatalln("Scheduler is nil")
return
}
log.Debugln("Starting ScaleIO Scheduler")
<-sched.Start()
log.Debugln("Scheduler terminating")
}