Merge pull request #27 from brendandburns/pod

Part one of the grand rename: Task -> Pod
pull/6/head
brendandburns 2014-06-08 21:27:00 -07:00
commit 4bd809e11e
18 changed files with 125 additions and 125 deletions

View File

@ -92,11 +92,11 @@ type TaskState struct {
type TaskList struct {
JSONBase
Items []Task `json:"items" yaml:"items,omitempty"`
Items []Pod `json:"items" yaml:"items,omitempty"`
}
// Task is a single task, used as either input (create, update) or as output (list, get)
type Task struct {
type Pod struct {
JSONBase
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
DesiredState TaskState `json:"desiredState,omitempty" yaml:"desiredState,omitempty"`

View File

@ -39,10 +39,10 @@ import (
// ClientInterface holds the methods for clients of Kubenetes, an interface to allow mock testing
type ClientInterface interface {
ListTasks(labelQuery map[string]string) (api.TaskList, error)
GetTask(name string) (api.Task, error)
GetTask(name string) (api.Pod, error)
DeleteTask(name string) error
CreateTask(api.Task) (api.Task, error)
UpdateTask(api.Task) (api.Task, error)
CreateTask(api.Pod) (api.Pod, error)
UpdateTask(api.Pod) (api.Pod, error)
GetReplicationController(name string) (api.ReplicationController, error)
CreateReplicationController(api.ReplicationController) (api.ReplicationController, error)
@ -154,8 +154,8 @@ func (client Client) ListTasks(labelQuery map[string]string) (api.TaskList, erro
}
// GetTask takes the name of the task, and returns the corresponding Task object, and an error if it occurs
func (client Client) GetTask(name string) (api.Task, error) {
var result api.Task
func (client Client) GetTask(name string) (api.Pod, error) {
var result api.Pod
_, err := client.rawRequest("GET", "tasks/"+name, nil, &result)
return result, err
}
@ -167,8 +167,8 @@ func (client Client) DeleteTask(name string) error {
}
// CreateTask takes the representation of a task. Returns the server's representation of the task, and an error, if it occurs
func (client Client) CreateTask(task api.Task) (api.Task, error) {
var result api.Task
func (client Client) CreateTask(task api.Pod) (api.Pod, error) {
var result api.Pod
body, err := json.Marshal(task)
if err == nil {
_, err = client.rawRequest("POST", "tasks", bytes.NewBuffer(body), &result)
@ -177,8 +177,8 @@ func (client Client) CreateTask(task api.Task) (api.Task, error) {
}
// UpdateTask takes the representation of a task to update. Returns the server's representation of the task, and an error, if it occurs
func (client Client) UpdateTask(task api.Task) (api.Task, error) {
var result api.Task
func (client Client) UpdateTask(task api.Pod) (api.Pod, error) {
var result api.Pod
body, err := json.Marshal(task)
if err == nil {
_, err = client.rawRequest("PUT", "tasks/"+task.ID, bytes.NewBuffer(body), &result)

View File

@ -62,8 +62,8 @@ func TestListEmptyTasks(t *testing.T) {
func TestListTasks(t *testing.T) {
expectedTaskList := api.TaskList{
Items: []api.Task{
api.Task{
Items: []api.Pod{
api.Pod{
CurrentState: api.TaskState{
Status: "Foobar",
},
@ -96,8 +96,8 @@ func TestListTasks(t *testing.T) {
func TestListTasksLabels(t *testing.T) {
expectedTaskList := api.TaskList{
Items: []api.Task{
api.Task{
Items: []api.Pod{
api.Pod{
CurrentState: api.TaskState{
Status: "Foobar",
},
@ -137,7 +137,7 @@ func TestListTasksLabels(t *testing.T) {
}
func TestGetTask(t *testing.T) {
expectedTask := api.Task{
expectedTask := api.Pod{
CurrentState: api.TaskState{
Status: "Foobar",
},
@ -184,7 +184,7 @@ func TestDeleteTask(t *testing.T) {
}
func TestCreateTask(t *testing.T) {
requestTask := api.Task{
requestTask := api.Pod{
CurrentState: api.TaskState{
Status: "Foobar",
},
@ -214,7 +214,7 @@ func TestCreateTask(t *testing.T) {
}
func TestUpdateTask(t *testing.T) {
requestTask := api.Task{
requestTask := api.Pod{
JSONBase: api.JSONBase{ID: "foo"},
CurrentState: api.TaskState{
Status: "Foobar",

View File

@ -49,9 +49,9 @@ func (client *FakeKubeClient) ListTasks(labelQuery map[string]string) (TaskList,
return client.tasks, nil
}
func (client *FakeKubeClient) GetTask(name string) (Task, error) {
func (client *FakeKubeClient) GetTask(name string) (Pod, error) {
client.actions = append(client.actions, Action{action: "get-task", value: name})
return Task{}, nil
return Pod{}, nil
}
func (client *FakeKubeClient) DeleteTask(name string) error {
@ -59,14 +59,14 @@ func (client *FakeKubeClient) DeleteTask(name string) error {
return nil
}
func (client *FakeKubeClient) CreateTask(task Task) (Task, error) {
func (client *FakeKubeClient) CreateTask(task Pod) (Pod, error) {
client.actions = append(client.actions, Action{action: "create-task"})
return Task{}, nil
return Pod{}, nil
}
func (client *FakeKubeClient) UpdateTask(task Task) (Task, error) {
func (client *FakeKubeClient) UpdateTask(task Pod) (Pod, error) {
client.actions = append(client.actions, Action{action: "update-task", value: task.ID})
return Task{}, nil
return Pod{}, nil
}
func (client *FakeKubeClient) GetReplicationController(name string) (ReplicationController, error) {
@ -118,9 +118,9 @@ func validateAction(expectedAction, actualAction Action, t *testing.T) {
func TestUpdateWithTasks(t *testing.T) {
client := FakeKubeClient{
tasks: TaskList{
Items: []Task{
Task{JSONBase: JSONBase{ID: "task-1"}},
Task{JSONBase: JSONBase{ID: "task-2"}},
Items: []Pod{
Pod{JSONBase: JSONBase{ID: "task-1"}},
Pod{JSONBase: JSONBase{ID: "task-2"}},
},
},
}
@ -272,7 +272,7 @@ func TestRequestWithBodyNoSuchFile(t *testing.T) {
func TestRequestWithBody(t *testing.T) {
file, err := ioutil.TempFile("", "foo")
expectNoError(t, err)
data, err := json.Marshal(Task{JSONBase: JSONBase{ID: "foo"}})
data, err := json.Marshal(Pod{JSONBase: JSONBase{ID: "foo"}})
expectNoError(t, err)
_, err = file.Write(data)
expectNoError(t, err)

View File

@ -57,8 +57,8 @@ func TestSyncEndpointsItems(t *testing.T) {
},
}
taskRegistry := MockTaskRegistry{
tasks: []Task{
Task{
tasks: []Pod{
Pod{
DesiredState: TaskState{
Manifest: ContainerManifest{
Containers: []Container{

View File

@ -66,8 +66,8 @@ func makeTaskKey(machine, taskID string) string {
return "/registry/hosts/" + machine + "/tasks/" + taskID
}
func (registry *EtcdRegistry) ListTasks(query *map[string]string) ([]Task, error) {
tasks := []Task{}
func (registry *EtcdRegistry) ListTasks(query *map[string]string) ([]Pod, error) {
tasks := []Pod{}
for _, machine := range registry.machines {
machineTasks, err := registry.listTasksForMachine(machine)
if err != nil {
@ -95,12 +95,12 @@ func (registry *EtcdRegistry) listEtcdNode(key string) ([]*etcd.Node, error) {
return result.Node.Nodes, nil
}
func (registry *EtcdRegistry) listTasksForMachine(machine string) ([]Task, error) {
tasks := []Task{}
func (registry *EtcdRegistry) listTasksForMachine(machine string) ([]Pod, error) {
tasks := []Pod{}
key := "/registry/hosts/" + machine + "/tasks"
nodes, err := registry.listEtcdNode(key)
for _, node := range nodes {
task := Task{}
task := Pod{}
err = json.Unmarshal([]byte(node.Value), &task)
if err != nil {
return tasks, err
@ -111,7 +111,7 @@ func (registry *EtcdRegistry) listTasksForMachine(machine string) ([]Task, error
return tasks, err
}
func (registry *EtcdRegistry) GetTask(taskID string) (*Task, error) {
func (registry *EtcdRegistry) GetTask(taskID string) (*Pod, error) {
task, _, err := registry.findTask(taskID)
return &task, err
}
@ -144,7 +144,7 @@ func (registry *EtcdRegistry) updateManifests(machine string, manifests []Contai
return err
}
func (registry *EtcdRegistry) CreateTask(machineIn string, task Task) error {
func (registry *EtcdRegistry) CreateTask(machineIn string, task Pod) error {
taskOut, machine, err := registry.findTask(task.ID)
if err == nil {
return fmt.Errorf("A task named %s already exists on %s (%#v)", task.ID, machine, taskOut)
@ -152,7 +152,7 @@ func (registry *EtcdRegistry) CreateTask(machineIn string, task Task) error {
return registry.runTask(task, machineIn)
}
func (registry *EtcdRegistry) runTask(task Task, machine string) error {
func (registry *EtcdRegistry) runTask(task Pod, machine string) error {
manifests, err := registry.loadManifests(machine)
if err != nil {
return err
@ -173,7 +173,7 @@ func (registry *EtcdRegistry) runTask(task Task, machine string) error {
return registry.updateManifests(machine, manifests)
}
func (registry *EtcdRegistry) UpdateTask(task Task) error {
func (registry *EtcdRegistry) UpdateTask(task Pod) error {
return fmt.Errorf("Unimplemented!")
}
@ -213,33 +213,33 @@ func (registry *EtcdRegistry) deleteTaskFromMachine(machine, taskID string) erro
return err
}
func (registry *EtcdRegistry) getTaskForMachine(machine, taskID string) (Task, error) {
func (registry *EtcdRegistry) getTaskForMachine(machine, taskID string) (Pod, error) {
key := makeTaskKey(machine, taskID)
result, err := registry.etcdClient.Get(key, false, false)
if err != nil {
if isEtcdNotFound(err) {
return Task{}, fmt.Errorf("Not found (%#v).", err)
return Pod{}, fmt.Errorf("Not found (%#v).", err)
} else {
return Task{}, err
return Pod{}, err
}
}
if result.Node == nil || len(result.Node.Value) == 0 {
return Task{}, fmt.Errorf("no nodes field: %#v", result)
return Pod{}, fmt.Errorf("no nodes field: %#v", result)
}
task := Task{}
task := Pod{}
err = json.Unmarshal([]byte(result.Node.Value), &task)
task.CurrentState.Host = machine
return task, err
}
func (registry *EtcdRegistry) findTask(taskID string) (Task, string, error) {
func (registry *EtcdRegistry) findTask(taskID string) (Pod, string, error) {
for _, machine := range registry.machines {
task, err := registry.getTaskForMachine(machine, taskID)
if err == nil {
return task, machine, nil
}
}
return Task{}, "", fmt.Errorf("Task not found %s", taskID)
return Pod{}, "", fmt.Errorf("Task not found %s", taskID)
}
func isEtcdNotFound(err error) bool {

View File

@ -27,7 +27,7 @@ import (
func TestEtcdGetTask(t *testing.T) {
fakeClient := MakeFakeEtcdClient(t)
fakeClient.Set("/registry/hosts/machine/tasks/foo", util.MakeJSONString(Task{JSONBase: JSONBase{ID: "foo"}}), 0)
fakeClient.Set("/registry/hosts/machine/tasks/foo", util.MakeJSONString(Pod{JSONBase: JSONBase{ID: "foo"}}), 0)
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
task, err := registry.GetTask("foo")
expectNoError(t, err)
@ -63,7 +63,7 @@ func TestEtcdCreateTask(t *testing.T) {
}
fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]ContainerManifest{}), 0)
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
err := registry.CreateTask("machine", Task{
err := registry.CreateTask("machine", Pod{
JSONBase: JSONBase{
ID: "foo",
},
@ -80,7 +80,7 @@ func TestEtcdCreateTask(t *testing.T) {
expectNoError(t, err)
resp, err := fakeClient.Get("/registry/hosts/machine/tasks/foo", false, false)
expectNoError(t, err)
var task Task
var task Pod
err = json.Unmarshal([]byte(resp.Node.Value), &task)
expectNoError(t, err)
if task.ID != "foo" {
@ -100,13 +100,13 @@ func TestEtcdCreateTaskAlreadyExisting(t *testing.T) {
fakeClient.Data["/registry/hosts/machine/tasks/foo"] = EtcdResponseWithError{
R: &etcd.Response{
Node: &etcd.Node{
Value: util.MakeJSONString(Task{JSONBase: JSONBase{ID: "foo"}}),
Value: util.MakeJSONString(Pod{JSONBase: JSONBase{ID: "foo"}}),
},
},
E: nil,
}
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
err := registry.CreateTask("machine", Task{
err := registry.CreateTask("machine", Pod{
JSONBase: JSONBase{
ID: "foo",
},
@ -131,7 +131,7 @@ func TestEtcdCreateTaskWithContainersError(t *testing.T) {
E: &etcd.EtcdError{ErrorCode: 200},
}
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
err := registry.CreateTask("machine", Task{
err := registry.CreateTask("machine", Pod{
JSONBase: JSONBase{
ID: "foo",
},
@ -163,7 +163,7 @@ func TestEtcdCreateTaskWithContainersNotFound(t *testing.T) {
E: &etcd.EtcdError{ErrorCode: 100},
}
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
err := registry.CreateTask("machine", Task{
err := registry.CreateTask("machine", Pod{
JSONBase: JSONBase{
ID: "foo",
},
@ -181,7 +181,7 @@ func TestEtcdCreateTaskWithContainersNotFound(t *testing.T) {
expectNoError(t, err)
resp, err := fakeClient.Get("/registry/hosts/machine/tasks/foo", false, false)
expectNoError(t, err)
var task Task
var task Pod
err = json.Unmarshal([]byte(resp.Node.Value), &task)
expectNoError(t, err)
if task.ID != "foo" {
@ -210,7 +210,7 @@ func TestEtcdCreateTaskWithExistingContainers(t *testing.T) {
},
}), 0)
registry := MakeTestEtcdRegistry(fakeClient, []string{"machine"})
err := registry.CreateTask("machine", Task{
err := registry.CreateTask("machine", Pod{
JSONBase: JSONBase{
ID: "foo",
},
@ -228,7 +228,7 @@ func TestEtcdCreateTaskWithExistingContainers(t *testing.T) {
expectNoError(t, err)
resp, err := fakeClient.Get("/registry/hosts/machine/tasks/foo", false, false)
expectNoError(t, err)
var task Task
var task Pod
err = json.Unmarshal([]byte(resp.Node.Value), &task)
expectNoError(t, err)
if task.ID != "foo" {
@ -246,7 +246,7 @@ func TestEtcdCreateTaskWithExistingContainers(t *testing.T) {
func TestEtcdDeleteTask(t *testing.T) {
fakeClient := MakeFakeEtcdClient(t)
key := "/registry/hosts/machine/tasks/foo"
fakeClient.Set(key, util.MakeJSONString(Task{JSONBase: JSONBase{ID: "foo"}}), 0)
fakeClient.Set(key, util.MakeJSONString(Pod{JSONBase: JSONBase{ID: "foo"}}), 0)
fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]ContainerManifest{
ContainerManifest{
Id: "foo",
@ -270,7 +270,7 @@ func TestEtcdDeleteTask(t *testing.T) {
func TestEtcdDeleteTaskMultipleContainers(t *testing.T) {
fakeClient := MakeFakeEtcdClient(t)
key := "/registry/hosts/machine/tasks/foo"
fakeClient.Set(key, util.MakeJSONString(Task{JSONBase: JSONBase{ID: "foo"}}), 0)
fakeClient.Set(key, util.MakeJSONString(Pod{JSONBase: JSONBase{ID: "foo"}}), 0)
fakeClient.Set("/registry/hosts/machine/kubelet", util.MakeJSONString([]ContainerManifest{
ContainerManifest{Id: "foo"},
ContainerManifest{Id: "bar"},
@ -337,10 +337,10 @@ func TestEtcdListTasks(t *testing.T) {
Node: &etcd.Node{
Nodes: []*etcd.Node{
&etcd.Node{
Value: util.MakeJSONString(Task{JSONBase: JSONBase{ID: "foo"}}),
Value: util.MakeJSONString(Pod{JSONBase: JSONBase{ID: "foo"}}),
},
&etcd.Node{
Value: util.MakeJSONString(Task{JSONBase: JSONBase{ID: "bar"}}),
Value: util.MakeJSONString(Pod{JSONBase: JSONBase{ID: "bar"}}),
},
},
},

View File

@ -23,13 +23,13 @@ import (
type TaskRegistry interface {
// ListTasks obtains a list of tasks that match query.
// Query may be nil in which case all tasks are returned.
ListTasks(query *map[string]string) ([]api.Task, error)
ListTasks(query *map[string]string) ([]api.Pod, error)
// Get a specific task
GetTask(taskId string) (*api.Task, error)
GetTask(taskId string) (*api.Pod, error)
// Create a task based on a specification, schedule it onto a specific machine.
CreateTask(machine string, task api.Task) error
CreateTask(machine string, task api.Pod) error
// Update an existing task
UpdateTask(task api.Task) error
UpdateTask(task api.Pod) error
// Delete an existing task
DeleteTask(taskId string) error
}

View File

@ -21,14 +21,14 @@ import (
type ManifestFactory interface {
// Make a container object for a given task, given the machine that the task is running on.
MakeManifest(machine string, task Task) (ContainerManifest, error)
MakeManifest(machine string, task Pod) (ContainerManifest, error)
}
type BasicManifestFactory struct {
serviceRegistry ServiceRegistry
}
func (b *BasicManifestFactory) MakeManifest(machine string, task Task) (ContainerManifest, error) {
func (b *BasicManifestFactory) MakeManifest(machine string, task Pod) (ContainerManifest, error) {
envVars, err := GetServiceEnvironmentVariables(b.serviceRegistry, machine)
if err != nil {
return ContainerManifest{}, err

View File

@ -27,7 +27,7 @@ func TestMakeManifestNoServices(t *testing.T) {
serviceRegistry: &registry,
}
manifest, err := factory.MakeManifest("machine", Task{
manifest, err := factory.MakeManifest("machine", Pod{
JSONBase: JSONBase{ID: "foobar"},
DesiredState: TaskState{
Manifest: ContainerManifest{
@ -66,7 +66,7 @@ func TestMakeManifestServices(t *testing.T) {
serviceRegistry: &registry,
}
manifest, err := factory.MakeManifest("machine", Task{
manifest, err := factory.MakeManifest("machine", Pod{
DesiredState: TaskState{
Manifest: ContainerManifest{
Containers: []Container{
@ -103,7 +103,7 @@ func TestMakeManifestServicesExistingEnvVar(t *testing.T) {
serviceRegistry: &registry,
}
manifest, err := factory.MakeManifest("machine", Task{
manifest, err := factory.MakeManifest("machine", Pod{
DesiredState: TaskState{
Manifest: ContainerManifest{
Containers: []Container{

View File

@ -22,21 +22,21 @@ import (
// An implementation of TaskRegistry and ControllerRegistry that is backed by memory
// Mainly used for testing.
type MemoryRegistry struct {
taskData map[string]Task
taskData map[string]Pod
controllerData map[string]ReplicationController
serviceData map[string]Service
}
func MakeMemoryRegistry() *MemoryRegistry {
return &MemoryRegistry{
taskData: map[string]Task{},
taskData: map[string]Pod{},
controllerData: map[string]ReplicationController{},
serviceData: map[string]Service{},
}
}
func (registry *MemoryRegistry) ListTasks(labelQuery *map[string]string) ([]Task, error) {
result := []Task{}
func (registry *MemoryRegistry) ListTasks(labelQuery *map[string]string) ([]Pod, error) {
result := []Pod{}
for _, value := range registry.taskData {
if LabelsMatch(value, labelQuery) {
result = append(result, value)
@ -45,7 +45,7 @@ func (registry *MemoryRegistry) ListTasks(labelQuery *map[string]string) ([]Task
return result, nil
}
func (registry *MemoryRegistry) GetTask(taskID string) (*Task, error) {
func (registry *MemoryRegistry) GetTask(taskID string) (*Pod, error) {
task, found := registry.taskData[taskID]
if found {
return &task, nil
@ -54,7 +54,7 @@ func (registry *MemoryRegistry) GetTask(taskID string) (*Task, error) {
}
}
func (registry *MemoryRegistry) CreateTask(machine string, task Task) error {
func (registry *MemoryRegistry) CreateTask(machine string, task Pod) error {
registry.taskData[task.ID] = task
return nil
}
@ -64,7 +64,7 @@ func (registry *MemoryRegistry) DeleteTask(taskID string) error {
return nil
}
func (registry *MemoryRegistry) UpdateTask(task Task) error {
func (registry *MemoryRegistry) UpdateTask(task Pod) error {
registry.taskData[task.ID] = task
return nil
}

View File

@ -32,7 +32,7 @@ func TestListTasksEmpty(t *testing.T) {
func TestMemoryListTasks(t *testing.T) {
registry := MakeMemoryRegistry()
registry.CreateTask("machine", Task{JSONBase: JSONBase{ID: "foo"}})
registry.CreateTask("machine", Pod{JSONBase: JSONBase{ID: "foo"}})
tasks, err := registry.ListTasks(nil)
expectNoError(t, err)
if len(tasks) != 1 || tasks[0].ID != "foo" {
@ -42,7 +42,7 @@ func TestMemoryListTasks(t *testing.T) {
func TestMemorySetGetTasks(t *testing.T) {
registry := MakeMemoryRegistry()
expectedTask := Task{JSONBase: JSONBase{ID: "foo"}}
expectedTask := Pod{JSONBase: JSONBase{ID: "foo"}}
registry.CreateTask("machine", expectedTask)
task, err := registry.GetTask("foo")
expectNoError(t, err)
@ -53,8 +53,8 @@ func TestMemorySetGetTasks(t *testing.T) {
func TestMemorySetUpdateGetTasks(t *testing.T) {
registry := MakeMemoryRegistry()
oldTask := Task{JSONBase: JSONBase{ID: "foo"}}
expectedTask := Task{
oldTask := Pod{JSONBase: JSONBase{ID: "foo"}}
expectedTask := Pod{
JSONBase: JSONBase{
ID: "foo",
},
@ -73,7 +73,7 @@ func TestMemorySetUpdateGetTasks(t *testing.T) {
func TestMemorySetDeleteGetTasks(t *testing.T) {
registry := MakeMemoryRegistry()
expectedTask := Task{JSONBase: JSONBase{ID: "foo"}}
expectedTask := Pod{JSONBase: JSONBase{ID: "foo"}}
registry.CreateTask("machine", expectedTask)
registry.DeleteTask("foo")
task, err := registry.GetTask("foo")

View File

@ -56,7 +56,7 @@ func (r RealTaskControl) createReplica(controllerSpec ReplicationController) {
if labels != nil {
labels["replicationController"] = controllerSpec.ID
}
task := Task{
task := Pod{
JSONBase: JSONBase{
ID: fmt.Sprintf("%x", rand.Int()),
},
@ -118,8 +118,8 @@ func (rm *ReplicationManager) handleWatchResponse(response *etcd.Response) (*Rep
return nil, nil
}
func (rm *ReplicationManager) filterActiveTasks(tasks []Task) []Task {
var result []Task
func (rm *ReplicationManager) filterActiveTasks(tasks []Pod) []Pod {
var result []Pod
for _, value := range tasks {
if strings.Index(value.CurrentState.Status, "Exit") == -1 {
result = append(result, value)

View File

@ -73,9 +73,9 @@ func makeReplicationController(replicas int) ReplicationController {
}
func makeTaskList(count int) TaskList {
tasks := []Task{}
tasks := []Pod{}
for i := 0; i < count; i++ {
tasks = append(tasks, Task{
tasks = append(tasks, Pod{
JSONBase: JSONBase{
ID: fmt.Sprintf("task%d", i),
},

View File

@ -24,7 +24,7 @@ import (
// Scheduler is an interface implemented by things that know how to schedule tasks onto machines.
type Scheduler interface {
Schedule(Task) (string, error)
Schedule(Pod) (string, error)
}
// RandomScheduler choses machines uniformly at random.
@ -40,7 +40,7 @@ func MakeRandomScheduler(machines []string, random rand.Rand) Scheduler {
}
}
func (s *RandomScheduler) Schedule(task Task) (string, error) {
func (s *RandomScheduler) Schedule(task Pod) (string, error) {
return s.machines[s.random.Int()%len(s.machines)], nil
}
@ -57,7 +57,7 @@ func MakeRoundRobinScheduler(machines []string) Scheduler {
}
}
func (s *RoundRobinScheduler) Schedule(task Task) (string, error) {
func (s *RoundRobinScheduler) Schedule(task Pod) (string, error) {
result := s.machines[s.currentIndex]
s.currentIndex = (s.currentIndex + 1) % len(s.machines)
return result, nil
@ -75,7 +75,7 @@ func MakeFirstFitScheduler(machines []string, registry TaskRegistry) Scheduler {
}
}
func (s *FirstFitScheduler) containsPort(task Task, port Port) bool {
func (s *FirstFitScheduler) containsPort(task Pod, port Port) bool {
for _, container := range task.DesiredState.Manifest.Containers {
for _, taskPort := range container.Ports {
if taskPort.HostPort == port.HostPort {
@ -86,8 +86,8 @@ func (s *FirstFitScheduler) containsPort(task Task, port Port) bool {
return false
}
func (s *FirstFitScheduler) Schedule(task Task) (string, error) {
machineToTasks := map[string][]Task{}
func (s *FirstFitScheduler) Schedule(task Pod) (string, error) {
machineToTasks := map[string][]Pod{}
tasks, err := s.registry.ListTasks(nil)
if err != nil {
return "", err

View File

@ -22,7 +22,7 @@ import (
. "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
)
func expectSchedule(scheduler Scheduler, task Task, expected string, t *testing.T) {
func expectSchedule(scheduler Scheduler, task Pod, expected string, t *testing.T) {
actual, err := scheduler.Schedule(task)
expectNoError(t, err)
if actual != expected {
@ -32,31 +32,31 @@ func expectSchedule(scheduler Scheduler, task Task, expected string, t *testing.
func TestRoundRobinScheduler(t *testing.T) {
scheduler := MakeRoundRobinScheduler([]string{"m1", "m2", "m3", "m4"})
expectSchedule(scheduler, Task{}, "m1", t)
expectSchedule(scheduler, Task{}, "m2", t)
expectSchedule(scheduler, Task{}, "m3", t)
expectSchedule(scheduler, Task{}, "m4", t)
expectSchedule(scheduler, Pod{}, "m1", t)
expectSchedule(scheduler, Pod{}, "m2", t)
expectSchedule(scheduler, Pod{}, "m3", t)
expectSchedule(scheduler, Pod{}, "m4", t)
}
func TestRandomScheduler(t *testing.T) {
random := rand.New(rand.NewSource(0))
scheduler := MakeRandomScheduler([]string{"m1", "m2", "m3", "m4"}, *random)
_, err := scheduler.Schedule(Task{})
_, err := scheduler.Schedule(Pod{})
expectNoError(t, err)
}
func TestFirstFitSchedulerNothingScheduled(t *testing.T) {
mockRegistry := MockTaskRegistry{}
scheduler := MakeFirstFitScheduler([]string{"m1", "m2", "m3"}, &mockRegistry)
expectSchedule(scheduler, Task{}, "m1", t)
expectSchedule(scheduler, Pod{}, "m1", t)
}
func makeTask(host string, hostPorts ...int) Task {
func makeTask(host string, hostPorts ...int) Pod {
networkPorts := []Port{}
for _, port := range hostPorts {
networkPorts = append(networkPorts, Port{HostPort: port})
}
return Task{
return Pod{
CurrentState: TaskState{
Host: host,
},
@ -74,7 +74,7 @@ func makeTask(host string, hostPorts ...int) Task {
func TestFirstFitSchedulerFirstScheduled(t *testing.T) {
mockRegistry := MockTaskRegistry{
tasks: []Task{
tasks: []Pod{
makeTask("m1", 8080),
},
}
@ -84,7 +84,7 @@ func TestFirstFitSchedulerFirstScheduled(t *testing.T) {
func TestFirstFitSchedulerFirstScheduledComplicated(t *testing.T) {
mockRegistry := MockTaskRegistry{
tasks: []Task{
tasks: []Pod{
makeTask("m1", 80, 8080),
makeTask("m2", 8081, 8082, 8083),
makeTask("m3", 80, 443, 8085),
@ -96,7 +96,7 @@ func TestFirstFitSchedulerFirstScheduledComplicated(t *testing.T) {
func TestFirstFitSchedulerFirstScheduledImpossible(t *testing.T) {
mockRegistry := MockTaskRegistry{
tasks: []Task{
tasks: []Pod{
makeTask("m1", 8080),
makeTask("m2", 8081),
makeTask("m3", 8080),

View File

@ -41,7 +41,7 @@ func MakeTaskRegistryStorage(registry TaskRegistry, containerInfo client.Contain
}
// LabelMatch tests to see if a Task's labels map contains 'key' mapping to 'value'
func LabelMatch(task Task, queryKey, queryValue string) bool {
func LabelMatch(task Pod, queryKey, queryValue string) bool {
for key, value := range task.Labels {
if queryKey == key && queryValue == value {
return true
@ -51,7 +51,7 @@ func LabelMatch(task Task, queryKey, queryValue string) bool {
}
// LabelMatch tests to see if a Task's labels map contains all key/value pairs in 'labelQuery'
func LabelsMatch(task Task, labelQuery *map[string]string) bool {
func LabelsMatch(task Pod, labelQuery *map[string]string) bool {
if labelQuery == nil {
return true
}
@ -99,13 +99,13 @@ func (storage *TaskRegistryStorage) Delete(id string) error {
}
func (storage *TaskRegistryStorage) Extract(body string) (interface{}, error) {
task := Task{}
task := Pod{}
err := json.Unmarshal([]byte(body), &task)
return task, err
}
func (storage *TaskRegistryStorage) Create(task interface{}) error {
taskObj := task.(Task)
taskObj := task.(Pod)
if len(taskObj.ID) == 0 {
return fmt.Errorf("ID is unspecified: %#v", task)
}
@ -117,5 +117,5 @@ func (storage *TaskRegistryStorage) Create(task interface{}) error {
}
func (storage *TaskRegistryStorage) Update(task interface{}) error {
return storage.registry.UpdateTask(task.(Task))
return storage.registry.UpdateTask(task.(Pod))
}

View File

@ -25,7 +25,7 @@ import (
type MockTaskRegistry struct {
err error
tasks []Task
tasks []Pod
}
func expectNoError(t *testing.T, err error) {
@ -34,19 +34,19 @@ func expectNoError(t *testing.T, err error) {
}
}
func (registry *MockTaskRegistry) ListTasks(*map[string]string) ([]Task, error) {
func (registry *MockTaskRegistry) ListTasks(*map[string]string) ([]Pod, error) {
return registry.tasks, registry.err
}
func (registry *MockTaskRegistry) GetTask(taskId string) (*Task, error) {
return &Task{}, registry.err
func (registry *MockTaskRegistry) GetTask(taskId string) (*Pod, error) {
return &Pod{}, registry.err
}
func (registry *MockTaskRegistry) CreateTask(machine string, task Task) error {
func (registry *MockTaskRegistry) CreateTask(machine string, task Pod) error {
return registry.err
}
func (registry *MockTaskRegistry) UpdateTask(task Task) error {
func (registry *MockTaskRegistry) UpdateTask(task Pod) error {
return registry.err
}
func (registry *MockTaskRegistry) DeleteTask(taskId string) error {
@ -83,13 +83,13 @@ func TestListEmptyTaskList(t *testing.T) {
func TestListTaskList(t *testing.T) {
mockRegistry := MockTaskRegistry{
tasks: []Task{
Task{
tasks: []Pod{
Pod{
JSONBase: JSONBase{
ID: "foo",
},
},
Task{
Pod{
JSONBase: JSONBase{
ID: "bar",
},
@ -118,7 +118,7 @@ func TestExtractJson(t *testing.T) {
storage := TaskRegistryStorage{
registry: &mockRegistry,
}
task := Task{
task := Pod{
JSONBase: JSONBase{
ID: "foo",
},
@ -134,32 +134,32 @@ func TestExtractJson(t *testing.T) {
}
}
func expectLabelMatch(t *testing.T, task Task, key, value string) {
func expectLabelMatch(t *testing.T, task Pod, key, value string) {
if !LabelMatch(task, key, value) {
t.Errorf("Unexpected match failure: %#v %s %s", task, key, value)
}
}
func expectNoLabelMatch(t *testing.T, task Task, key, value string) {
func expectNoLabelMatch(t *testing.T, task Pod, key, value string) {
if LabelMatch(task, key, value) {
t.Errorf("Unexpected match success: %#v %s %s", task, key, value)
}
}
func expectLabelsMatch(t *testing.T, task Task, query *map[string]string) {
func expectLabelsMatch(t *testing.T, task Pod, query *map[string]string) {
if !LabelsMatch(task, query) {
t.Errorf("Unexpected match failure: %#v %#v", task, *query)
}
}
func expectNoLabelsMatch(t *testing.T, task Task, query *map[string]string) {
func expectNoLabelsMatch(t *testing.T, task Pod, query *map[string]string) {
if LabelsMatch(task, query) {
t.Errorf("Unexpected match success: %#v %#v", task, *query)
}
}
func TestLabelMatch(t *testing.T) {
task := Task{
task := Pod{
Labels: map[string]string{
"foo": "bar",
"baz": "blah",
@ -172,7 +172,7 @@ func TestLabelMatch(t *testing.T) {
}
func TestLabelsMatch(t *testing.T) {
task := Task{
task := Pod{
Labels: map[string]string{
"foo": "bar",
"baz": "blah",