2016-08-11 12:45:32 -07:00
|
|
|
# How to leverage the library (based on the [sample client](../examples/client.go))
|
2016-08-09 17:10:02 -07:00
|
|
|
|
2017-10-12 17:07:43 -07:00
|
|
|
For a more complete look at the API, please visit https://godoc.org/github.com/paypal/gorealis
|
2016-08-11 12:45:32 -07:00
|
|
|
|
|
|
|
* Create a default configuration file (alternatively, manually create your own Config):
|
2016-08-09 17:10:02 -07:00
|
|
|
```
|
|
|
|
config, err := realis.NewDefaultConfig(*url)
|
|
|
|
```
|
|
|
|
|
2016-08-11 12:45:32 -07:00
|
|
|
* Create a new Realis client by passing the configuration struct in:
|
2016-08-09 17:10:02 -07:00
|
|
|
```
|
|
|
|
r := realis.NewClient(config)
|
|
|
|
defer r.Close()
|
|
|
|
```
|
|
|
|
|
2016-08-11 12:45:32 -07:00
|
|
|
* Construct a job using a Job struct:
|
2016-08-09 17:10:02 -07:00
|
|
|
```
|
2016-08-11 12:45:32 -07:00
|
|
|
job = realis.NewJob().
|
|
|
|
Environment("prod").
|
2016-08-09 17:10:02 -07:00
|
|
|
Role("vagrant").
|
2016-08-11 12:45:32 -07:00
|
|
|
Name("docker-compose").
|
2016-08-09 17:10:02 -07:00
|
|
|
ExecutorName("docker-compose-executor").
|
|
|
|
ExecutorData("{}").
|
2016-08-11 12:45:32 -07:00
|
|
|
CPU(1).
|
|
|
|
RAM(64).
|
|
|
|
Disk(100).
|
2016-08-09 17:10:02 -07:00
|
|
|
IsService(false).
|
|
|
|
InstanceCount(1).
|
|
|
|
AddPorts(1).
|
2016-08-11 12:45:32 -07:00
|
|
|
AddLabel("fileName", "sample-app/docker-compose.yml").
|
2016-08-12 12:48:42 -07:00
|
|
|
AddURIs(true, true, "https://github.com/mesos/docker-compose-executor/releases/download/0.1.0/sample-app.tar.gz")
|
2016-08-09 17:10:02 -07:00
|
|
|
```
|
|
|
|
|
2016-08-11 12:45:32 -07:00
|
|
|
* Use client to send a job to Aurora:
|
2016-08-09 17:10:02 -07:00
|
|
|
```
|
|
|
|
r.CreateJob(job)
|
|
|
|
```
|
|
|
|
|
2016-08-11 12:45:32 -07:00
|
|
|
* Killing an Aurora Job:
|
2016-08-09 17:10:02 -07:00
|
|
|
```
|
|
|
|
r.KillJob(job.GetKey())
|
|
|
|
```
|
|
|
|
|
2016-08-11 12:45:32 -07:00
|
|
|
* Restarting all instances of an Aurora Job:
|
2016-08-09 17:10:02 -07:00
|
|
|
```
|
|
|
|
r.RestartJob(job.GetKey())
|
|
|
|
```
|
|
|
|
|
2016-08-11 12:45:32 -07:00
|
|
|
* Adding instances (based on config of instance 0) to Aurora:
|
2016-08-09 17:10:02 -07:00
|
|
|
```
|
|
|
|
r.AddInstances(&aurora.InstanceKey{job.GetKey(),0}, 5)
|
|
|
|
```
|
|
|
|
|
2016-08-11 12:45:32 -07:00
|
|
|
* Updating the job configuration of a service job:
|
2016-08-09 17:10:02 -07:00
|
|
|
```
|
|
|
|
updateJob := realis.NewUpdateJob(job)
|
|
|
|
updateJob.InstanceCount(1)
|
|
|
|
updateJob.Ram(128)
|
|
|
|
msg, err := r.UpdateJob(updateJob, "")
|
2019-05-05 11:46:22 -07:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
* Handling a timeout scenario:
|
|
|
|
|
|
|
|
When sending an API call to Aurora, the call may timeout at the client side.
|
|
|
|
This means that the time limit has been reached while waiting for the scheduler
|
|
|
|
to reply. In such a case it is recommended that the timeout is increased through
|
|
|
|
the use of the `realis.TimeoutMS()` option.
|
|
|
|
|
|
|
|
As these timeouts cannot be totally avoided, there exists a mechanism to mitigate such
|
|
|
|
scenarios. The `StartJobUpdate` and `CreateService` API will return an error that
|
|
|
|
implements the Timeout interface.
|
|
|
|
|
|
|
|
An error can be checked to see if it is a Timeout error by using the `realis.IsTimeout()`
|
|
|
|
function.
|