Skip to content

Commit

Permalink
Merge pull request #37 from keis/immutable-task-info
Browse files Browse the repository at this point in the history
Don't modify the input when creating mesos task
  • Loading branch information
keis committed Dec 9, 2015
2 parents 206253b + f927a67 commit 48edf50
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type eremeticScheduler struct {
done chan struct{}
}

func (s *eremeticScheduler) newTask(offer *mesos.Offer, spec *types.EremeticTask) *mesos.TaskInfo {
func (s *eremeticScheduler) newTask(spec types.EremeticTask, offer *mesos.Offer) (types.EremeticTask, *mesos.TaskInfo) {
return createTaskInfo(spec, offer)
}

Expand Down Expand Up @@ -75,7 +75,7 @@ loop:
}

log.Debugf("Preparing to launch task %s with offer %s", tid, offer.Id.GetValue())
task := s.newTask(offer, &t)
t, task := s.newTask(t, offer)
database.PutTask(&t)
driver.LaunchTasks([]*mesos.OfferID{offer.Id}, []*mesos.TaskInfo{task}, defaultFilter)

Expand Down
5 changes: 3 additions & 2 deletions scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ func TestScheduler(t *testing.T) {
},
Hostname: proto.String("hostname"),
}
newTask := s.newTask(&offer, &task)
taskData, mesosTask := s.newTask(task, &offer)

So(newTask.GetTaskId().GetValue(), ShouldEqual, task.ID)
So(mesosTask.GetTaskId().GetValue(), ShouldEqual, task.ID)
So(taskData.SlaveId, ShouldEqual, "slave-id")
})

Convey("createEremeticScheduler", func() {
Expand Down
4 changes: 2 additions & 2 deletions scheduler/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ func createEremeticTask(request types.Request) (types.EremeticTask, error) {
return task, nil
}

func createTaskInfo(task *types.EremeticTask, offer *mesos.Offer) *mesos.TaskInfo {
func createTaskInfo(task types.EremeticTask, offer *mesos.Offer) (types.EremeticTask, *mesos.TaskInfo) {
task.FrameworkId = *offer.FrameworkId.Value
task.SlaveId = *offer.SlaveId.Value
task.Hostname = *offer.Hostname

return &mesos.TaskInfo{
return task, &mesos.TaskInfo{
TaskId: &mesos.TaskID{
Value: proto.String(task.ID),
},
Expand Down
3 changes: 2 additions & 1 deletion scheduler/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ func TestTask(t *testing.T) {
Hostname: proto.String("hostname"),
}

taskInfo := createTaskInfo(&eremeticTask, &offer)
net, taskInfo := createTaskInfo(eremeticTask, &offer)
So(taskInfo.TaskId.GetValue(), ShouldEqual, eremeticTask.ID)
So(taskInfo.GetName(), ShouldEqual, eremeticTask.Name)
So(taskInfo.GetResources()[0].GetScalar().GetValue(), ShouldEqual, eremeticTask.TaskCPUs)
So(taskInfo.GetResources()[1].GetScalar().GetValue(), ShouldEqual, eremeticTask.TaskMem)
So(net.SlaveId, ShouldEqual, "slave-id")
})
}

0 comments on commit 48edf50

Please sign in to comment.