Public release of gorealis
This commit is contained in:
commit
327c6c369d
82 changed files with 45075 additions and 0 deletions
148
examples/Client.go
Normal file
148
examples/Client.go
Normal file
|
@ -0,0 +1,148 @@
|
|||
/**
|
||||
* 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 main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"gen-go/apache/aurora"
|
||||
"github.com/rdelval/gorealis"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
cmd := flag.String("cmd", "", "Action to execute on Apache Aurora Sched")
|
||||
executor := flag.String("executor", "thermos", "Executor to use, thermos by default")
|
||||
url := flag.String("url", "", "URL at which the Apache Aurora Scheduler exists [url]:[port]")
|
||||
updateId := flag.String("updateId", "", "Update ID to operate on")
|
||||
flag.Parse()
|
||||
|
||||
//Create new configuration with default transport layer
|
||||
config, err := realis.NewDefaultConfig(*url)
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Needed for authorization for Vagrant
|
||||
realis.AddBasicAuth(&config, "aurora", "secret")
|
||||
r := realis.NewClient(config)
|
||||
defer r.Close()
|
||||
|
||||
var job *realis.Job
|
||||
|
||||
switch *executor {
|
||||
case "thermos":
|
||||
payload, err := ioutil.ReadFile("thermos_payload.json")
|
||||
|
||||
if err != nil {
|
||||
fmt.Print("Error reading json config file: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
job = realis.NewJob().SetEnvironment("prod").
|
||||
SetRole("vagrant").
|
||||
SetName("hello_world_from_gorealis").
|
||||
SetExecutorName(aurora.AURORA_EXECUTOR_NAME).
|
||||
SetExecutorData(string(payload)).
|
||||
SetNumCpus(1).
|
||||
SetRam(64).
|
||||
SetDisk(100).
|
||||
SetIsService(true).
|
||||
SetInstanceCount(1).
|
||||
AddPorts(1)
|
||||
break
|
||||
case "compose":
|
||||
job = realis.NewJob().SetEnvironment("prod").
|
||||
SetRole("vagrant").
|
||||
SetName("docker-compose").
|
||||
SetExecutorName("docker-compose-executor").
|
||||
SetExecutorData("{}").
|
||||
SetNumCpus(1).
|
||||
SetRam(64).
|
||||
SetDisk(100).
|
||||
SetIsService(false).
|
||||
SetInstanceCount(1).
|
||||
AddPorts(1).
|
||||
AddLabel("fileName", "sample-app/sample-app.yml").
|
||||
AddURI("https://dl.bintray.com/rdelvalle/mesos-compose-executor/sample-app.tar.gz", true, true)
|
||||
break
|
||||
default:
|
||||
fmt.Println("Only thermos and compose are supported for now")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
switch *cmd {
|
||||
case "create":
|
||||
fmt.Println("Creating job")
|
||||
msg, err := r.CreateJob(job)
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
}
|
||||
|
||||
fmt.Print(msg)
|
||||
break
|
||||
case "kill":
|
||||
fmt.Println("Killing job")
|
||||
|
||||
msg, err := r.KillJob(job.GetJobKey())
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
}
|
||||
|
||||
fmt.Print(msg)
|
||||
break
|
||||
case "restart":
|
||||
fmt.Println("Restarting job")
|
||||
msg, err := r.RestartJob(job.GetJobKey())
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
}
|
||||
|
||||
fmt.Print(msg)
|
||||
break
|
||||
case "flexUp":
|
||||
fmt.Println("Flexing up job")
|
||||
msg, err := r.AddInstances(job.GetJobKey(), 5)
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
}
|
||||
fmt.Print(msg)
|
||||
break
|
||||
case "update":
|
||||
fmt.Println("Updating a job with a new name")
|
||||
updateJob := realis.NewUpdateJob(job)
|
||||
|
||||
updateJob.SetInstanceCount(3).SetRam(128)
|
||||
|
||||
msg, err := r.StartJobUpdate(updateJob, "")
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
}
|
||||
fmt.Print(msg)
|
||||
break
|
||||
case "abortUpdate":
|
||||
fmt.Println("Abort update")
|
||||
msg, err := r.AbortJobUpdate(job.GetJobKey(), *updateId, "")
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
}
|
||||
fmt.Print(msg)
|
||||
break
|
||||
default:
|
||||
fmt.Println("Only Create, Kill, and Restart are supported now")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
62
examples/thermos_payload.json
Normal file
62
examples/thermos_payload.json
Normal file
|
@ -0,0 +1,62 @@
|
|||
{
|
||||
"environment": "prod",
|
||||
"health_check_config": {
|
||||
"initial_interval_secs": 15.0,
|
||||
"health_checker": {
|
||||
"http": {
|
||||
"expected_response_code": 0,
|
||||
"endpoint": "/health",
|
||||
"expected_response": "ok"
|
||||
}
|
||||
},
|
||||
"interval_secs": 10.0,
|
||||
"timeout_secs": 1.0,
|
||||
"max_consecutive_failures": 0
|
||||
},
|
||||
"name": "hello_world_from_gorealis",
|
||||
"service": false,
|
||||
"max_task_failures": 1,
|
||||
"cron_collision_policy": "KILL_EXISTING",
|
||||
"enable_hooks": false,
|
||||
"cluster": "devcluster",
|
||||
"task": {
|
||||
"processes": [
|
||||
{
|
||||
"daemon": false,
|
||||
"name": "hello",
|
||||
"ephemeral": false,
|
||||
"max_failures": 1,
|
||||
"min_duration": 5,
|
||||
"cmdline": "\n while true; do\n echo hello world from GoRealis\n sleep 10\n done\n ",
|
||||
"final": false
|
||||
}
|
||||
],
|
||||
"name": "hello",
|
||||
"finalization_wait": 30,
|
||||
"max_failures": 1,
|
||||
"max_concurrency": 0,
|
||||
"resources": {
|
||||
"gpu": 0,
|
||||
"disk": 134217728,
|
||||
"ram": 134217728,
|
||||
"cpu": 1.0
|
||||
},
|
||||
"constraints": [
|
||||
{
|
||||
"order": [
|
||||
"hello"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"production": false,
|
||||
"role": "vagrant",
|
||||
"lifecycle": {
|
||||
"http": {
|
||||
"graceful_shutdown_endpoint": "/quitquitquit",
|
||||
"port": "health",
|
||||
"shutdown_endpoint": "/abortabortabort"
|
||||
}
|
||||
},
|
||||
"priority": 0
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue