forked from mesos/mr-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
120 lines (96 loc) · 3.74 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"github.com/mesos/mr-redis/common/types"
"github.com/mesos/mr-redis/sched/cmd"
"github.com/mesos/mr-redis/sched/httplib"
"github.com/mesos/mr-redis/sched/mesoslib"
)
//Declare all the Constants to be used in this file
const (
//HTTP_SERVER_PORT Rest server of the scheduler by default
HTTP_SERVER_PORT = "8080"
)
//MrRedisConfig struct of the json config file that is used while starting the scheduler
type MrRedisConfig struct {
Master string //MesosMaster's endpoint zk://mesos.master/2181 or 10.11.12.13:5050
ExecutorPath string //Executor's Path from where to distribute
RedisPath string //Path where redis-server executable is available
DBType string //Type of the database etcd/zk/mysql/consul etcd.,
DBEndPoint string //Endpoint of the database
LogFile string //Name of the logfile
ArtifactIP string //The IP to which we should bind to for distributing the executor among the interfaces
ArtifactPort string //The port to which we should bind to for distributing the executor
HTTPPort string //Defaults to 8080 if otherwise specify explicitly
}
//NewMrRedisDefaultConfig Default Constructor to create a config file
func NewMrRedisDefaultConfig() MrRedisConfig {
return MrRedisConfig{
Master: "127.0.0.1:5050",
ExecutorPath: "./MrRedisExecutor",
RedisPath: "./redis-server",
DBType: "etcd",
DBEndPoint: "127.0.0.1:2379",
LogFile: "stderr",
ArtifactIP: "127.0.0.1",
ArtifactPort: "5454",
HTTPPort: "5656",
}
}
func main() {
cfgFileName := flag.String("config", "./config.json", "Supply the location of MrRedis configuration file")
dumpConfig := flag.Bool("DumpEmptyConfig", false, "Dump Empty Config file")
flag.Parse()
Cfg := NewMrRedisDefaultConfig()
if *dumpConfig == true {
configBytes, err := json.MarshalIndent(Cfg, " ", " ")
if err != nil {
log.Printf("Error marshalling the dummy config file. Exiting %v", err)
return
}
fmt.Printf("%s\n", string(configBytes))
return
}
cfgFile, err := ioutil.ReadFile(*cfgFileName)
if err != nil {
log.Printf("Error Reading the configration file. Resorting to default values")
}
err = json.Unmarshal(cfgFile, &Cfg)
if err != nil {
log.Fatalf("Error parsing the config file %v", err)
}
log.Printf("Configuration file is = %v", Cfg)
log.Printf("*****************************************************************")
log.Printf("*********************Starting MrRedis-Scheduler******************")
log.Printf("*****************************************************************")
//Command line argument parsing
//Facility to overwrite the etcd endpoint for scheduler if its running in the same docker container and expose a different one for executors
dbEndpoint := os.Getenv("ETCD_LOCAL_ENDPOINT")
if dbEndpoint == "" {
dbEndpoint = Cfg.DBEndPoint
}
//Initalize the common entities like store, store configuration etc.
isInit, err := types.Initialize(Cfg.DBType, dbEndpoint)
if err != nil || isInit != true {
log.Fatalf("Failed to intialize Error:%v return %v", err, isInit)
}
//Start the Mesos library
go mesoslib.Run(Cfg.Master, Cfg.ArtifactIP, Cfg.ArtifactPort, Cfg.ExecutorPath, Cfg.RedisPath, Cfg.DBType, Cfg.DBEndPoint)
//Start the creator
go cmd.Creator()
//Start the Mainterainer
go cmd.Maintainer()
//Start the Destroyer
go cmd.Destoryer()
//Start HTTP server and related things to handle restfull calls to the scheduler
httplib.Run(Cfg.HTTPPort)
//Wait for termination signal
log.Printf("*****************************************************************")
log.Printf("*********************Finished MrRedis-Scheduler******************")
log.Printf("*****************************************************************")
}