Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Added logic to read NetworkInfo from /state.json. #266

Merged
merged 6 commits into from
Sep 17, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
re-add timestamp checking for task statuses
James DeFelice committed Sep 17, 2015
commit 4622dac6db63912074f47fc6eafb30153111ea57
16 changes: 11 additions & 5 deletions records/state/state.go
Original file line number Diff line number Diff line change
@@ -155,13 +155,19 @@ func mesosIPs(t *Task) []string {
}

// statusIPs returns the latest running status IPs extracted with the given src
func statusIPs(st []Status, src func(*Status) []string) []string {
for i := len(st) - 1; i >= 0; i-- {
if st[i].State == "TASK_RUNNING" {
return src(&st[i])
func statusIPs(st []Status, src func(*Status) []string) (ips []string) {
// the state.json we extract from mesos makes no guarantees re: the order
// of the task statuses so we should check the timestamps to avoid problems
// down the line. we can't rely on seeing the same sequence. (@joris)
// https://github.com/apache/mesos/blob/0.24.0/src/slave/slave.cpp#L5226-L5238
lastTimestamp := float64(-1.0)
for i := range st {
if st[i].State == "TASK_RUNNING" && st[i].Timestamp > lastTimestamp {
lastTimestamp = st[i].Timestamp
ips = src(&st[i])
}
}
return nil
return
}

// labels returns all given Status.[]Labels' values whose keys are equal
13 changes: 10 additions & 3 deletions records/state/state_test.go
Original file line number Diff line number Diff line change
@@ -81,12 +81,15 @@ func TestTask_IPs(t *testing.T) {
{ // statuses ordering
Task: task(
statuses(
status(state("TASK_RUNNING"), netinfo("1.2.3.4")),
status(state("TASK_RUNNING"), labels(DockerIPLabel, "2.3.4.5")),
status(state("TASK_RUNNING"), netinfo("1.2.3.4"), timestamp(1)),
status(state("TASK_RUNNING"), netinfo("1.3.5.7"), timestamp(4)),
status(state("TASK_RUNNING"), labels(DockerIPLabel, "2.3.4.5"), timestamp(3)),
status(state("TASK_RUNNING"), labels(DockerIPLabel, "2.4.6.8"), timestamp(5)),
status(state("TASK_RUNNING"), labels(DockerIPLabel, "2.5.8.1"), timestamp(2)),
),
),
srcs: []string{"docker", "netinfo"},
want: ips("2.3.4.5"),
want: ips("2.4.6.8"),
},
{ // label ordering
Task: task(
@@ -172,3 +175,7 @@ func netinfo(ips ...string) statusOpt {
}
}
}

func timestamp(t float64) statusOpt {
return func(s *Status) { s.Timestamp = t }
}