Adding support for configuring tasks with Docker Containers
This commit is contained in:
parent
c83e5d268a
commit
66a2868aab
3 changed files with 85 additions and 4 deletions
51
container.go
Normal file
51
container.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package realis
|
||||
|
||||
import (
|
||||
"github.com/rdelval/gorealis/gen-go/apache/aurora"
|
||||
)
|
||||
|
||||
type Container interface {
|
||||
Build() *aurora.Container
|
||||
}
|
||||
|
||||
// TODO(rdelvalle): Implement Mesos container builder
|
||||
type MesosContainer struct {
|
||||
container *aurora.MesosContainer
|
||||
}
|
||||
|
||||
type DockerContainer struct {
|
||||
container *aurora.DockerContainer
|
||||
}
|
||||
|
||||
func NewDockerContainer() DockerContainer {
|
||||
return DockerContainer{container: aurora.NewDockerContainer()}
|
||||
}
|
||||
|
||||
func (c DockerContainer) Build() *aurora.Container {
|
||||
return &aurora.Container{Docker: c.container}
|
||||
}
|
||||
|
||||
func (c DockerContainer) Image(image string) DockerContainer {
|
||||
c.container.Image = image
|
||||
return c
|
||||
}
|
||||
|
||||
func (c DockerContainer) AddParameter(name, value string) DockerContainer {
|
||||
c.container.Parameters = append(c.container.Parameters, &aurora.DockerParameter{name, value})
|
||||
return c
|
||||
}
|
||||
|
|
@ -29,7 +29,7 @@ func main() {
|
|||
executor := flag.String("executor", "thermos", "Executor to use")
|
||||
url := flag.String("url", "", "URL at which the Aurora Scheduler exists as [url]:[port]")
|
||||
clustersConfig := flag.String("clusters", "", "Location of the clusters.json file used by aurora.")
|
||||
clusterName := flag.String("cluster", "devcluster", "Name of cluster to run job on")
|
||||
clusterName := flag.String("cluster", "devcluster", "Name of cluster to run job on (only necessary if clusters is set)")
|
||||
updateId := flag.String("updateId", "", "Update ID to operate on")
|
||||
username := flag.String("username", "aurora", "Username to use for authorization")
|
||||
password := flag.String("password", "secret", "Password to use for authorization")
|
||||
|
@ -82,7 +82,7 @@ func main() {
|
|||
job = realis.NewJob().
|
||||
Environment("prod").
|
||||
Role("vagrant").
|
||||
Name("hello_world_from_gorealis").
|
||||
Name("hello_world_from_gorealis_docker").
|
||||
ExecutorName(aurora.AURORA_EXECUTOR_NAME).
|
||||
ExecutorData(string(payload)).
|
||||
CPU(1).
|
||||
|
@ -133,6 +133,27 @@ func main() {
|
|||
}
|
||||
}
|
||||
break
|
||||
case "createDocker":
|
||||
fmt.Println("Creating a docker based job")
|
||||
container := realis.NewDockerContainer().Image("python:2.7").AddParameter("network", "host")
|
||||
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())
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
case "scheduleCron":
|
||||
fmt.Println("Scheduling a Cron job")
|
||||
// Cron config
|
||||
|
|
13
job.go
13
job.go
|
@ -25,8 +25,8 @@ type Job interface {
|
|||
Role(role string) Job
|
||||
Name(name string) Job
|
||||
CPU(cpus float64) Job
|
||||
CronSchedule(cron string) Job
|
||||
CronCollisionPolicy(policy aurora.CronCollisionPolicy) Job
|
||||
CronSchedule(cron string) Job
|
||||
CronCollisionPolicy(policy aurora.CronCollisionPolicy) Job
|
||||
Disk(disk int64) Job
|
||||
RAM(ram int64) Job
|
||||
ExecutorName(name string) Job
|
||||
|
@ -44,6 +44,7 @@ type Job interface {
|
|||
InstanceCount(instCount int32) Job
|
||||
GetInstanceCount() int32
|
||||
MaxFailure(maxFail int32) Job
|
||||
Container(container Container) Job
|
||||
}
|
||||
|
||||
// Structure to collect all information pertaining to an Aurora job.
|
||||
|
@ -262,3 +263,11 @@ func (j AuroraJob) AddLimitConstraint(name string, limit int32) Job {
|
|||
|
||||
return j
|
||||
}
|
||||
|
||||
// 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()
|
||||
|
||||
return j
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue