-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmain.go
129 lines (109 loc) · 3.5 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
/**
* 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"
"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/mesosphere/mesos-framework-tutorial/scheduler"
. "github.com/mesosphere/mesos-framework-tutorial/server"
)
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")
)
func init() {
flag.Parse()
}
func main() {
// Start HTTP server hosting executor binary
uri := ServeExecutorArtifact(*address, *artifactPort, *executorPath)
// Executor
exec := prepareExecutorInfo(uri, getExecutorCmd(*executorPath))
// Scheduler
scheduler, err := NewExampleScheduler(exec, CPUS_PER_TASK, MEM_PER_TASK)
if err != nil {
log.Fatalf("Failed to create scheduler with error: %v\n", err)
os.Exit(-2)
}
// 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]
}