Example #1
0
func get_scheduler(st settings) (scheduler.Scheduler, error) {
	var s scheduler.Scheduler

	switch st.schedulerType {
	case "DOCKER":
		log.Println("Scheduling with Docker remote API")
		s = docker.NewScheduler(st.pullImages, st.dockerHost)
	case "ECS":
		return nil, fmt.Errorf("Scheduling with ECS not yet supported. Tweet with hashtag #F12ECS if you'd like us to add this next!")
	case "KUBERNETES":
		return nil, fmt.Errorf("Scheduling with Kubernetes not yet supported. Tweet with hashtag #F12Kubernetes if you'd like us to add this next!")
	case "MESOS":
		return nil, fmt.Errorf("Scheduling with Mesos / Marathon not yet supported. Tweet with hashtag #F12Mesos if you'd like us to add this next!")
	case "NOMAD":
		return nil, fmt.Errorf("Scheduling with Nomad not yet supported. Tweet with hashtag #F12Nomad if you'd like us to add this next!")
	case "TOY":
		log.Println("Scheduling with toy scheduler")
		s = toy_scheduler.NewScheduler()
	default:
		return nil, fmt.Errorf("Bad value for F12_SCHEDULER: %s", st.schedulerType)
	}

	if s == nil {
		return nil, fmt.Errorf("No scheduler")
	}

	return s, nil
}
Example #2
0
func TestHandleDemandChange(t *testing.T) {
	tasks = make(map[string]demand.Task)
	tasks["priority1"] = demand.Task{
		FamilyName: "p1family",
		Demand:     4,
		Requested:  0,
	}

	tasks["priority2"] = demand.Task{
		FamilyName: "p2family",
		Demand:     3,
		Requested:  0,
	}

	// We might see our own task when we look at Docker, we shouldn't be scaling it!
	tasks["force12"] = demand.Task{
		FamilyName: "force12",
		Demand:     1,
		Requested:  1,
	}

	di := rng.NewDemandModel(3, 9)
	s := toy_scheduler.NewScheduler()

	ready := make(chan struct{}, 1)

	for i := 0; i < 5; i++ {
		err := handleDemandChange(di, s, ready, tasks)
		<-ready
		if err != nil {
			t.Fatalf("handleDemandChange failed")
		}
		log.Println(tasks)
	}
}
Example #3
0
func TestHandleDemandChange(t *testing.T) {
	tasks = make(map[string]demand.Task)
	tasks["priority1"] = demand.Task{
		FamilyName: "p1family",
		Demand:     4,
		Requested:  0,
	}

	tasks["priority2"] = demand.Task{
		FamilyName: "p2family",
		Demand:     3,
		Requested:  0,
	}

	s := toy_scheduler.NewScheduler()

	tests := []struct {
		td       []api.TaskDemand
		newtasks map[string]demand.Task
	}{
		{
			td: []api.TaskDemand{
				{
					App:         "priority1",
					DemandCount: 5,
				},
			},
			newtasks: map[string]demand.Task{
				"priority1": {FamilyName: "p1family", Demand: 5, Requested: 5},
				"priority2": {FamilyName: "p2family", Demand: 3, Requested: 3},
			},
		},
		{
			// We just ignore any tasks that we didn't know about
			td: []api.TaskDemand{
				{
					App:         "priority1",
					DemandCount: 5,
				}, {
					App:         "priority3",
					DemandCount: 5,
				},
			},
			newtasks: map[string]demand.Task{
				"priority1": {FamilyName: "p1family", Demand: 5, Requested: 5},
				"priority2": {FamilyName: "p2family", Demand: 3, Requested: 3},
			},
		},
	}

	for _, test := range tests {
		err := handleDemandChange(test.td, s, tasks)
		if err != nil {
			t.Fatalf("handleDemandChange failed")
		}
		log.Println(tasks)
		if !reflect.DeepEqual(tasks, test.newtasks) {
			t.Fatalf("Expected %v tasks, got %v", test.newtasks, tasks)
		}
	}
}