diff --git a/container.go b/container.go index 6216708..0fb98d2 100644 --- a/container.go +++ b/container.go @@ -22,7 +22,6 @@ type Container interface { Build() *aurora.Container } -// TODO(rdelvalle): Implement Mesos container builder type MesosContainer struct { container *aurora.MesosContainer } @@ -48,3 +47,29 @@ func (c DockerContainer) AddParameter(name, value string) DockerContainer { c.container.Parameters = append(c.container.Parameters, &aurora.DockerParameter{name, value}) return c } + +func NewMesosContainer() MesosContainer { + return MesosContainer{container: aurora.NewMesosContainer()} +} + +func (c MesosContainer) Build() *aurora.Container { + return &aurora.Container{Mesos: c.container} +} + +func (c MesosContainer) DockerImage(name, tag string) MesosContainer { + if c.container.Image == nil { + c.container.Image = aurora.NewImage() + } + + c.container.Image.Docker = &aurora.DockerImage{name, tag} + return c +} + +func (c MesosContainer) AppcImage(name, imageId string) MesosContainer { + if c.container.Image == nil { + c.container.Image = aurora.NewImage() + } + + c.container.Image.Appc = &aurora.AppcImage{name, imageId} + return c +} diff --git a/examples/client.go b/examples/client.go index f2ef842..434a621 100644 --- a/examples/client.go +++ b/examples/client.go @@ -156,6 +156,27 @@ func main() { } fmt.Println(resp.String()) + if resp.ResponseCode == aurora.ResponseCode_OK { + if ok, err := monitor.Instances(job.JobKey(), job.GetInstanceCount(), 10, 300); !ok || err != nil { + _, err := r.KillJob(job.JobKey()) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + } + } + break + case "createMesosContainer": + fmt.Println("Creating a docker based job") + container := realis.NewMesosContainer().DockerImage("python", "2.7") + job.Container(container) + resp, err := r.CreateJob(job) + if err != nil { + fmt.Println(err) + os.Exit(1) + } + fmt.Println(resp.String()) + if resp.ResponseCode == aurora.ResponseCode_OK { if ok, err := monitor.Instances(job.JobKey(), job.GetInstanceCount(), 10, 300); !ok || err != nil { _, err := r.KillJob(job.JobKey()) diff --git a/job.go b/job.go index 256066b..e5898c6 100644 --- a/job.go +++ b/job.go @@ -274,7 +274,6 @@ func (j AuroraJob) AddLimitConstraint(name string, limit int32) Job { } // Set a container to run for the job configuration to run. -// TODO (rdelvalle): Add no thermos mode where container is launched as a task and not an executor. func (j AuroraJob) Container(container Container) Job { j.jobConfig.TaskConfig.Container = container.Build()