Nat support and fix monitoring issues
This commit is contained in:
@@ -52,6 +52,7 @@ type App struct {
|
||||
Name string
|
||||
Vip *net.IPNet
|
||||
Monitors Monitors
|
||||
Nats []string
|
||||
}
|
||||
|
||||
func (a *App) Equal(other *App) bool {
|
||||
@@ -66,42 +67,37 @@ func (a *App) Equal(other *App) bool {
|
||||
return a.Name == other.Name && a.Vip.String() == other.Vip.String()
|
||||
}
|
||||
|
||||
func (a *App) needsNatRule() (bool, *Monitor) {
|
||||
for _, m := range a.Monitors {
|
||||
if m.Type == Monitor_CONSUL && m.Port != "" {
|
||||
return true, m
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func NewApp(appName, vip string, monitors []string) (*App, error) {
|
||||
func NewApp(appName, vip string, monitors []string, nats []string) (*App, error) {
|
||||
if appName == "" {
|
||||
return nil, fmt.Errorf("Invalid app name")
|
||||
}
|
||||
app := &App{Name: appName}
|
||||
app := &App{Name: appName, Nats: nats}
|
||||
_, ipnet, err := net.ParseCIDR(vip)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Invalid VIP specified, need ip/mask")
|
||||
}
|
||||
app.Vip = ipnet
|
||||
for _, m := range monitors {
|
||||
// valid monitor formats:
|
||||
// "port:tcp:123" , "exec:/local/check.sh", "consul"
|
||||
parts := strings.Split(m, ":")
|
||||
if len(parts) != 2 && len(parts) != 3 {
|
||||
glog.Errorf("Invalid monitor specified, ignoring")
|
||||
continue
|
||||
}
|
||||
mon := &Monitor{Type: MonitorMap[parts[0]]}
|
||||
switch mon.Type.String() {
|
||||
case "port":
|
||||
if len(parts) != 3 {
|
||||
return nil, fmt.Errorf("Invalid port monitor, must specify proto:port")
|
||||
}
|
||||
mon.Protocol = parts[1]
|
||||
mon.Port = parts[2]
|
||||
case "exec":
|
||||
if len(parts) != 2 {
|
||||
return nil, fmt.Errorf("Invalid exec monitor, must specify command")
|
||||
}
|
||||
mon.Cmd = parts[1]
|
||||
case "consul":
|
||||
glog.V(2).Infof("Using consul health monitor")
|
||||
glog.V(2).Infof("Will use consul healthcheck monitor")
|
||||
default:
|
||||
glog.V(2).Infof("No monitor specified")
|
||||
glog.V(2).Infof("Invalid monitor specified")
|
||||
}
|
||||
app.Monitors = append(app.Monitors, mon)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user