api: composing jobs takes region

This commit is contained in:
Ryan Uber
2015-09-16 11:42:08 -07:00
parent 39789e478d
commit 24cd105200
4 changed files with 26 additions and 34 deletions

View File

@@ -32,7 +32,7 @@ func TestCompose(t *testing.T) {
AddTask(task)
// Compose a job
job := NewServiceJob("job1", "myjob", 2).
job := NewServiceJob("job1", "myjob", "region1", 2).
SetMeta("foo", "bar").
AddDatacenter("dc1").
Constrain(HardConstraint("kernel.name", "=", "linux")).
@@ -40,6 +40,7 @@ func TestCompose(t *testing.T) {
// Check that the composed result looks correct
expect := &Job{
Region: "region1",
ID: "job1",
Name: "myjob",
Type: JobTypeService,

View File

@@ -126,23 +126,24 @@ type JobListStub struct {
// NewServiceJob creates and returns a new service-style job
// for long-lived processes using the provided name, ID, and
// relative job priority.
func NewServiceJob(id, name string, pri int) *Job {
return newJob(id, name, JobTypeService, pri)
func NewServiceJob(id, name, region string, pri int) *Job {
return newJob(id, name, region, JobTypeService, pri)
}
// NewBatchJob creates and returns a new batch-style job for
// short-lived processes using the provided name and ID along
// with the relative job priority.
func NewBatchJob(id, name string, pri int) *Job {
return newJob(id, name, JobTypeBatch, pri)
func NewBatchJob(id, name, region string, pri int) *Job {
return newJob(id, name, region, JobTypeBatch, pri)
}
// newJob is used to create a new Job struct.
func newJob(jobID, jobName, jobType string, pri int) *Job {
func newJob(id, name, region, typ string, pri int) *Job {
return &Job{
ID: jobID,
Name: jobName,
Type: jobType,
Region: region,
ID: id,
Name: name,
Type: typ,
Priority: pri,
}
}

View File

@@ -218,8 +218,9 @@ func TestJobs_ForceEvaluate(t *testing.T) {
}
func TestJobs_NewBatchJob(t *testing.T) {
job := NewBatchJob("job1", "myjob", 5)
job := NewBatchJob("job1", "myjob", "region1", 5)
expect := &Job{
Region: "region1",
ID: "job1",
Name: "myjob",
Type: JobTypeBatch,
@@ -231,8 +232,9 @@ func TestJobs_NewBatchJob(t *testing.T) {
}
func TestJobs_NewServiceJob(t *testing.T) {
job := NewServiceJob("job1", "myjob", 5)
job := NewServiceJob("job1", "myjob", "region1", 5)
expect := &Job{
Region: "region1",
ID: "job1",
Name: "myjob",
Type: JobTypeService,

View File

@@ -26,27 +26,15 @@ func assertWriteMeta(t *testing.T, wm *WriteMeta) {
}
func testJob() *Job {
return &Job{
Region: "region1",
ID: "job1",
Name: "redis",
Type: JobTypeService,
Datacenters: []string{"dc1"},
TaskGroups: []*TaskGroup{
&TaskGroup{
Name: "group1",
Count: 1,
Tasks: []*Task{
&Task{
Name: "task1",
Driver: "exec",
Resources: &Resources{
MemoryMB: 256,
},
},
},
},
},
Priority: 1,
}
task := NewTask("task1", "exec").
Require(&Resources{MemoryMB: 256})
group := NewTaskGroup("group1", 1).
AddTask(task)
job := NewBatchJob("job1", "redis", "region1", 1).
AddDatacenter("dc1").
AddTaskGroup(group)
return job
}