/
main.go
142 lines (120 loc) · 3.99 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package main
import (
"flag"
"net"
"os"
"strconv"
"github.com/gogo/protobuf/proto"
log "github.com/golang/glog"
mesos "github.com/mesos/mesos-go/mesosproto"
util "github.com/mesos/mesos-go/mesosutil"
sched "github.com/mesos/mesos-go/scheduler"
. "github.com/emc-cmd/test-framework/scheduler"
. "github.com/emc-cmd/test-framework/server"
"github.com/emc-cmd/test-framework/trigger"
)
const (
CPUS_PER_TASK = 1
MEM_PER_TASK = 128
defaultArtifactPort = 12345
defaultImage = "http://www.gabrielhartmann.com/Things/Plants/i-W2N2Rxp/0/O/DSCF6636.jpg"
)
var (
address = flag.String("address", "127.0.0.1", "Binding address for artifact server")
artifactPort = flag.Int("artifactPort", defaultArtifactPort, "Binding port for artifact server")
master = flag.String("master", "127.0.0.1:5050", "Master address <ip:port>")
executorPath = flag.String("executor", "./example_executor", "Path to test executor")
taskCount = flag.String("task-count", "5", "Total task count to run.")
externalServer = flag.String("externalServer", "http://192.168.0.15:3000", "IP Address of the external server for hosting container files.")
)
func init() {
flag.Parse()
}
func main() {
// Start HTTP server hosting executor binary
uri := ServeExecutorArtifact(*address, *artifactPort, *executorPath)
// Executor
exec := prepareExecutorInfo(uri, getExecutorCmd(*executorPath))
// Scheduler
numTasks, err := strconv.Atoi(*taskCount)
if err != nil {
log.Fatalf("Failed to convert '%v' to an integer with error: %v\n", taskCount, err)
os.Exit(-1)
}
scheduler := NewExampleScheduler(exec, numTasks, CPUS_PER_TASK, MEM_PER_TASK, *externalServer)
if err != nil {
log.Fatalf("Failed to create scheduler with error: %v\n", err)
os.Exit(-2)
}
//Start trigger server
go trigger.RunTriggerServer(scheduler)
// Framework
fwinfo := &mesos.FrameworkInfo{
User: proto.String(""), // Mesos-go will fill in user.
Name: proto.String("Test Framework (Go)"),
}
// Scheduler Driver
config := sched.DriverConfig{
Scheduler: scheduler,
Framework: fwinfo,
Master: *master,
Credential: (*mesos.Credential)(nil),
BindingAddress: parseIP(*address),
}
driver, err := sched.NewMesosSchedulerDriver(config)
if err != nil {
log.Fatalf("Unable to create a SchedulerDriver: %v\n", err.Error())
os.Exit(-3)
}
if stat, err := driver.Run(); err != nil {
log.Fatalf("Framework stopped with status %s and error: %s\n", stat.String(), err.Error())
os.Exit(-4)
}
}
func prepareExecutorInfo(uri string, cmd string) *mesos.ExecutorInfo {
executorUris := []*mesos.CommandInfo_URI{
{
Value: &uri,
Executable: proto.Bool(true),
},
}
return &mesos.ExecutorInfo{
ExecutorId: util.NewExecutorID("default"),
Name: proto.String("Test Executor (Go)"),
Source: proto.String("go_test"),
Command: &mesos.CommandInfo{
Value: proto.String(cmd),
Uris: executorUris,
},
}
}
func getExecutorCmd(path string) string {
return "." + GetHttpPath(path)
}
func parseIP(address string) net.IP {
addr, err := net.LookupIP(address)
if err != nil {
log.Fatal(err)
}
if len(addr) < 1 {
log.Fatalf("failed to parse IP from address '%v'", address)
}
return addr[0]
}