Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Human readable instance states #31

Merged
merged 1 commit into from

3 participants

Tomás Senart Alexander Simmerl Alexis Sellier
Tomás Senart

This change set introduces human readable state names instead of only integers.

Alexander Simmerl
Owner

:+1:

Alexis Sellier cloudhead merged commit 542eec3 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 21, 2012
  1. Human readable instance states

    Tomás Senart authored
This page is out of date. Refresh to see the latest.
7 event.go
View
@@ -9,7 +9,6 @@ import (
"fmt"
"github.com/soundcloud/doozer"
"regexp"
- "strconv"
)
// An Event represents a change to a file in the registry.
@@ -194,11 +193,7 @@ func parseEvent(src *doozer.Event) *Event {
break
}
- i, err := strconv.Atoi(string(src.Body))
- if err != nil {
- panic(err)
- }
- if State(i) != InsStateInitial {
+ if State(src.Body) != InsStateInitial {
etype = ev
}
}
4 event_test.go
View
@@ -102,7 +102,7 @@ func TestEventInstanceRegistered(t *testing.T) {
s, app, l := eventSetup("regmouse")
rev, _ := NewRevision(app, "stable", s)
pty, _ := NewProcType(rev, "web", s)
- ins, _ := NewInstance(pty, "127.0.0.1:8080", 0, s)
+ ins, _ := NewInstance(pty, "127.0.0.1:8080", InsStateInitial, s)
go WatchEvent(s, l)
@@ -117,7 +117,7 @@ func TestEventInstanceUnregistered(t *testing.T) {
s, app, l := eventSetup("unregmouse")
rev, _ := NewRevision(app, "stable", s)
pty, _ := NewProcType(rev, "web", s)
- ins, _ := NewInstance(pty, "127.0.0.1:8080", 0, s)
+ ins, _ := NewInstance(pty, "127.0.0.1:8080", InsStateInitial, s)
ins, err := ins.Register()
if err != nil {
t.Error(err)
27 instance.go
View
@@ -46,12 +46,12 @@ func (i InstanceInfo) LogString() string {
}
const (
- InsStateInitial State = 0
- InsStateStarted = 1
- InsStateReady = 2
- InsStateFailed = 3
- InsStateDead = 4
- InsStateExited = 5
+ InsStateInitial State = "initial"
+ InsStateStarted = "started"
+ InsStateReady = "ready"
+ InsStateFailed = "failed"
+ InsStateDead = "dead"
+ InsStateExited = "exited"
)
const INSTANCES_PATH = "instances"
@@ -94,7 +94,7 @@ func (i *Instance) Register() (instance *Instance, err error) {
rev, err := i.conn.SetMulti(i.Path(), map[string][]byte{
"host": []byte(i.Addr.IP.String()),
"port": []byte(strconv.Itoa(i.Addr.Port)),
- "state": []byte(strconv.Itoa(int(i.State)))}, i.Rev)
+ "state": []byte(i.State)}, i.Rev)
if err != nil {
return i, err
}
@@ -125,7 +125,7 @@ func (i *Instance) Unregister() (err error) {
// UpdateState updates the instance's state file in
// the coordinator to the given value.
func (i *Instance) UpdateState(s State) (ins *Instance, err error) {
- newrev, err := i.conn.Set(i.Path()+"/state", i.Rev, []byte(strconv.Itoa(int(s))))
+ newrev, err := i.conn.Set(i.Path()+"/state", i.Rev, []byte(s))
if err != nil {
return
}
@@ -186,14 +186,10 @@ func ProcTypeInstances(s Snapshot, ptype *ProcType) (instances []*Instance, err
return nil, e
}
- state, e := strconv.Atoi(string(vals["state"]))
- if e != nil {
- return nil, e
- }
-
addr := string(vals["host"]) + ":" + string(vals["port"])
+ state := State(vals["state"])
- instances[i], err = NewInstance(ptype, addr, State(state), s)
+ instances[i], err = NewInstance(ptype, addr, state, s)
if err != nil {
return
}
@@ -217,7 +213,6 @@ func GetInstanceInfo(s Snapshot, app string, rev string, proc string, ins string
port, _, err := s.conn.Get(path+"/port", &s.Rev)
iport, err := strconv.Atoi(string(port))
- istate, err := strconv.Atoi(string(state))
instance := &InstanceInfo{
Name: ins,
@@ -226,7 +221,7 @@ func GetInstanceInfo(s Snapshot, app string, rev string, proc string, ins string
ProcessName: ProcessName(proc),
Host: string(host),
Port: iport,
- State: State(istate),
+ State: State(state),
}
return instance, err
}
7 instance_test.go
View
@@ -39,7 +39,7 @@ func instanceSetup(addr string, pType ProcessName) (ins *Instance) {
if err != nil {
panic(err)
}
- ins, err = NewInstance(pty, addr, 0, s)
+ ins, err = NewInstance(pty, addr, InsStateInitial, s)
if err != nil {
panic(err)
}
@@ -147,8 +147,7 @@ func TestInstanceUpdateState(t *testing.T) {
t.Error(err)
}
- state, err := strconv.Atoi(string(val))
- if err != nil || state != int(InsStateStarted) {
+ if State(val) != InsStateStarted {
t.Error("Instance state wasn't persisted in the coordinator")
}
}
@@ -159,7 +158,7 @@ func TestInstances(t *testing.T) {
port := 1000
for i := 0; i < 3; i++ {
- ins, err := NewInstance(ins.ProcType, host+strconv.Itoa(port+i), 0, ins.Snapshot)
+ ins, err := NewInstance(ins.ProcType, host+strconv.Itoa(port+i), InsStateInitial, ins.Snapshot)
if err != nil {
t.Error(err)
}
20 visor.go
View
@@ -44,25 +44,7 @@ const START_PORT_PATH string = "/next-port"
type ProcessName string
type Stack string
-type State int
-
-func (s State) String() string {
- switch s {
- case InsStateInitial:
- return "initial"
- case InsStateStarted:
- return "started"
- case InsStateReady:
- return "ready"
- case InsStateFailed:
- return "failed"
- case InsStateDead:
- return "dead"
- case InsStateExited:
- return "exited"
- }
- return "?"
-}
+type State string
func Init(s Snapshot) (rev int64, err error) {
exists, _, err := s.Conn().Exists(START_PORT_PATH, &s.Rev)
Something went wrong with that request. Please try again.