2016-08-09 16:29:37 -07:00
# Running custom executors on Aurora
2016-08-10 11:45:54 -07:00
In this document, we will be using the docker-compose executor to demonstrate
how Aurora can use multiple executors on a single Scheduler. For this guide,
we will be using a vagrant instance to demonstrate the setup process. Many of the same
steps also apply to an Aurora installation made via a package manager. Differences in how to configure
the cluster between the vagrant image and the package manager will be clarified when necessary.
2016-08-15 12:29:38 -07:00
## Pre-configured Aurora Vagrant box
2016-08-11 11:39:10 -07:00
Alternatively, if Vagrant and VirtualBox are already configured your machine,
you may use a pre-configured vagrant image and skip to the [Creating Aurora Jobs ](#creating-aurora-jobs ).
2016-08-11 21:21:47 -07:00
To take this path, start by cloning the following repository and checking out the DockerComposeExecutor branch:
2016-08-11 11:39:10 -07:00
```
2016-08-11 21:21:47 -07:00
$ git clone -b DockerComposeExecutor git@github .com:rdelval/aurora.git
2016-08-11 11:39:10 -07:00
```
And bringing the vagrant box
```
$ cd aurora
$ vagrant up
```
**The pre-configured Vagrant box will most likely run on a stale version of Aurora (compared to the master)**
2016-08-15 12:29:38 -07:00
## Configuring Aurora manually
### Spinning up an Aurora instance with Vagrant
Follow the guide at http://aurora.apache.org/documentation/latest/getting-started/vagrant/
until the end of step 4 (Start the local cluster) and skip to configuring Docker-Compose executor.
### Installing Aurora through a package manager
Follow the guide at http://aurora.apache.org/documentation/latest/operations/installation/
### Configuring Scheduler to use Docker-Compose executor
2016-08-09 16:29:37 -07:00
In order use the docker compose executor with Aurora, we must first give the scheduler
a configuration file that contains information on how to run the executor.
2016-08-15 12:29:38 -07:00
#### Configuration file
2016-08-09 16:29:37 -07:00
The configuration is a JSON file that contains where to find the executor and how to run it.
2016-08-10 15:25:02 -07:00
More information about how an executor may be configured for consumption by Aurora can be found [here ](https://github.com/apache/aurora/blob/master/docs/operations/configuration.md#custom-executors )
2016-08-10 11:45:54 -07:00
under the custom executors section.
2016-08-09 16:29:37 -07:00
A sample config file for the docker-compose executor looks like this:
```
[
{
"executor":{
"command":{
2016-08-10 11:45:54 -07:00
"value":"java -jar docker-compose-executor_0.1.0.jar",
2016-08-09 16:29:37 -07:00
"shell":"true",
"uris":[
{
"cache":false,
"executable":true,
"extract":false,
2016-08-10 11:45:54 -07:00
"value":"https://github.com/mesos/docker-compose-executor/releases/download/0.1.0/docker-compose-executor_0.1.0.jar"
2016-08-09 16:29:37 -07:00
}
]
},
"name":"docker-compose-executor",
"resources":[]
},
"task_prefix":"compose-"
}
]
```
2016-08-15 12:29:38 -07:00
#### Configuring the Scheduler to run a custom executor
##### Setting the proper flags
2016-08-10 11:45:54 -07:00
Some flags need to be set on the Aurora scheduler in order for custom executors to work properly.
2016-08-09 16:29:37 -07:00
2016-08-10 16:07:19 -07:00
The `-custom_executor_config` flag must point to the location of the JSON blob.
2016-08-09 16:29:37 -07:00
2016-08-10 16:07:19 -07:00
The `-enable_mesos_fetcher` flag must be set to true in order to allow jobs to fetch resources.
2016-08-09 16:29:37 -07:00
2016-08-15 12:29:38 -07:00
##### On vagrant
2016-08-10 11:45:54 -07:00
* Log into the vagrant image by going to the folder at which the Aurora repository
was cloned and running:
```
$ vagrant ssh
```
* Write the sample JSON blob provided above to a file inside the vagrant image.
* Inside the vagrant image, modify the file `/etc/init/aurora-scheduler.conf` to include:
2016-08-09 16:29:37 -07:00
```
2016-08-10 16:07:19 -07:00
-custom_executor_config=< Location of JSON blob > \
-enable_mesos_fetcher=true
2016-08-09 16:29:37 -07:00
```
2016-08-15 12:29:38 -07:00
##### On a scheduler installed via package manager
2016-08-10 11:45:54 -07:00
* Write the sample JSON blob provided above to a file on the same machine where the scheduler is running.
2016-08-10 16:07:19 -07:00
* Modify `EXTRA_SCHEDULER_ARGS` in the file file `/etc/default/aurora-scheduler` to be:
2016-08-09 16:29:37 -07:00
```
2016-08-10 16:07:19 -07:00
EXTRA_SCHEDULER_ARGS="-custom_executor_config=< Location of JSON blob > -enable_mesos_fetcher=true"
2016-08-09 16:29:37 -07:00
```
2016-08-15 12:29:38 -07:00
For these configurations to kick in, the aurora-scheduler must be restarted.
Depending on the distribution of choice being used this command may look a bit different.
On Ubuntu, restarting the aurora-scheduler can be achieved by running the following command:
```
$ sudo service aurora-scheduler restart
```
### Using a custom client
Pystachio does yet support launching tasks using custom executors. Therefore, a custom
2016-08-09 16:29:37 -07:00
client must be used in order to launch tasks using a custom executor. In this case,
we will be using [gorealis ](https://github.com/rdelval/gorealis ) to launch a task with
the compose executor on Aurora.
2016-08-15 12:29:38 -07:00
## Configuring the system to run a custom client and docker-compose executor
2016-08-09 16:29:37 -07:00
2016-08-15 12:29:38 -07:00
### Installing Go
2016-08-09 16:29:37 -07:00
2016-08-15 12:29:38 -07:00
#### Linux
2016-08-09 16:29:37 -07:00
2016-08-15 12:29:38 -07:00
##### Ubuntu
2016-08-09 16:29:37 -07:00
2016-08-15 12:29:38 -07:00
###### Adding a PPA and install via apt-get
2016-08-09 16:29:37 -07:00
```
$ sudo add-apt-repository ppa:ubuntu-lxc/lxd-stable
$ sudo apt-get update
$ sudo apt-get install golang
```
2016-08-15 12:29:38 -07:00
###### Configuring the GOPATH
2016-08-09 16:29:37 -07:00
Configure the environment to be able to compile and run Go code.
```
$ mkdir $HOME/go
2016-08-10 11:45:54 -07:00
$ echo export GOPATH=$HOME/go >> $HOME/.bashrc
2016-08-15 12:29:38 -07:00
$ echo export GOROOT=/usr/lib/go >> $HOME/.bashrc
2016-08-10 11:45:54 -07:00
$ echo export PATH=$PATH:$GOPATH/bin >> $HOME/.bashrc
$ echo export PATH=$PATH:$GOROOT/bin >> $HOME/.bashrc
```
Finally we must reload the .bashrc configuration:
```
$ source $HOME/.bashrc
2016-08-09 16:29:37 -07:00
```
2016-08-15 12:29:38 -07:00
#### OS X
2016-08-09 16:29:37 -07:00
One way to install go on OS X is by using [Homebrew ](http://brew.sh/ )
2016-08-15 12:29:38 -07:00
##### Installing Homebrew
2016-08-09 16:29:37 -07:00
Run the following command from the terminal to install Hombrew:
```
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
```
2016-08-15 12:29:38 -07:00
##### Installing Go using Hombrew
2016-08-09 16:29:37 -07:00
Run the following command from the terminal to install Go:
```
$ brew install go
```
2016-08-15 12:29:38 -07:00
##### Configuring the GOPATH
2016-08-09 16:29:37 -07:00
Configure the environment to be able to compile and run Go code.
```
$ mkdir $HOME/go
$ echo export GOPATH=$HOME/go >> $HOME/.profile
$ echo export GOROOT=/usr/local/opt/go/libexec >> $HOME/.profile
$ echo export PATH=$PATH:$GOPATH/bin >> $HOME/.profile
$ echo export PATH=$PATH:$GOROOT/bin >> $HOME/.profile
```
2016-08-10 15:25:02 -07:00
Finally we must reload the .profile configuration:
```
$ source $HOME/.profile
```
2016-08-10 16:07:19 -07:00
2016-08-15 12:29:38 -07:00
#### Windows
2016-08-09 16:29:37 -07:00
Download and run the msi installer from https://golang.org/dl/
## Installing Docker Compose
2016-08-10 11:45:54 -07:00
To show Aurora's new multi executor feature, we need to use at least one custom executor.
In this case we will be using the [docker-compose-executor ](https://github.com/mesos/docker-compose-executor ).
2016-08-09 16:29:37 -07:00
2016-08-10 11:45:54 -07:00
In order to run the docker-compose executor, each agent must have docker-compose installed on it.
2016-08-09 16:29:37 -07:00
This can be done using pip:
```
$ sudo pip install docker-compose
```
## Downloading gorealis
Finally, we must get `gorealis` using the `go get` command:
```
go get github.com/rdelval/gorealis
```
# Creating Aurora Jobs
2016-08-15 12:29:38 -07:00
## Creating a thermos job
2016-08-09 16:29:37 -07:00
To demonstrate that we are able to run jobs using different executors on the
same scheduler, we'll first launch a thermos job using the default Aurora Client.
We can use a sample job for this:
hello_world.aurora
```
hello = Process(
name = 'hello',
cmdline = """
while true; do
echo hello world
sleep 10
done
""")
task = SequentialTask(
processes = [hello],
resources = Resources(cpu = 1.0, ram = 128*MB, disk = 128*MB))
jobs = [Service(
task = task, cluster = 'devcluster', role = 'www-data', environment = 'prod', name = 'hello')]
```
Now we create the job:
```
aurora job create devcluster/www-data/prod/hello hello_world.aurora
```
2016-08-15 12:29:38 -07:00
## Creating a docker-compose-executor job
2016-08-09 16:29:37 -07:00
Now that we have a thermos job running, it's time to launch a docker-compose job.
We'll be using the gorealis library sample client to send a create job request
2016-08-10 11:45:54 -07:00
to the scheduler, specifying that we would like to use the docker-compose executor.
2016-08-09 16:29:37 -07:00
Furthermore, we will be specifying what resources we need to download in order to
successfully run a docker compose job.
2016-08-10 15:25:02 -07:00
For example, the job configuration in the sample client looks like this:
2016-08-09 16:29:37 -07:00
```
job = realis.NewJob().
2016-08-10 11:45:54 -07:00
Environment("prod").
Role("vagrant").
Name("docker-compose").
ExecutorName("docker-compose-executor").
ExecutorData("{}").
CPU(1).
RAM(64).
Disk(100).
IsService(false).
InstanceCount(1).
AddPorts(1).
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 16:29:37 -07:00
```
2016-08-10 15:25:02 -07:00
Using a vagrant setup as an example, we can run the following command to create a compose job:
2016-08-09 16:29:37 -07:00
```
2016-08-10 15:25:02 -07:00
go run $GOPATH/src/github.com/rdelval/gorealis/examples/client.go -executor=compose -url=http://192.168.33.7:8081 -cmd=create
2016-08-09 16:29:37 -07:00
```
If everything went according to plan, a new job will be shown in the Aurora UI.
2016-08-11 11:39:10 -07:00
We can further investigate inside the Mesos task sandbox. Inside the sandbox, under
the sample-app folder, we can find a docker-compose.yml-generated.yml. If we inspect this file,
we can find the port at which we can find the web server we launched.
2016-08-09 16:29:37 -07:00
Under Web->Ports, we find the port Mesos allocated. We can then navigate to:
2016-08-10 15:25:02 -07:00
`<agent address>:<assigned port>` . (In vagrant's case the agent address is `192.68.33.7` )
2016-08-09 16:29:37 -07:00
2016-08-10 15:25:02 -07:00
A message from the executor should greet us.
2016-08-09 16:29:37 -07:00
2016-08-15 12:29:38 -07:00
## Creating a Thermos job using gorealis
2016-08-11 11:39:10 -07:00
It is also possible to create a thermos job using gorealis. To do this, however,
a thermos payload is required. A thermos payload consists of a JSON blob that details
the entire task as it exists inside the Aurora Scheduler. *Creating the blob is unfortunately
out of the scope of was gorealis does*, so a thermos payload must be generated beforehand or
retrieved from the structdump of an existing task for testing purposes.
A sample thermos JSON payload may be found [here ](../examples/thermos_payload.json ) in the examples folder.
The job struct configuration for a Thermos job looks something like this:
```
payload, err := ioutil.ReadFile("examples/thermos_payload.json")
job = realis.NewJob().
Environment("prod").
Role("vagrant").
Name("hello_world_from_gorealis").
ExecutorName(aurora.AURORA_EXECUTOR_NAME).
ExecutorData(string(payload)).
CPU(1).
RAM(64).
Disk(100).
IsService(true).
InstanceCount(1).
AddPorts(1)
```
Using a vagrant setup as an example, we can run the following command to create a Thermos job:
```
$ cd $GOPATH/src/github.com/rdelval/gorealis
$ go run examples/client.go -executor=thermos -url=http://192.168.33.7:8081 -cmd=create -executor=thermos
```
# Cleaning up
2016-08-09 16:29:37 -07:00
2016-08-10 15:25:02 -07:00
To stop the jobs we've launched, we can need to send a job kill request to Aurora.
It should be noted that although we can't create jobs using a custom executor using the default Aurora client,
we can use the default Aurora client to kill them. In addition, we can use gorealis perform the clean up as well.
2016-08-11 11:39:10 -07:00
## Using the Default Client
2016-08-09 16:29:37 -07:00
```
$ aurora job killall devcluster/www-data/prod/hello
$ aurora job killall devcluster/vagrant/prod/docker-compose
```
2016-08-11 11:39:10 -07:00
## Using gorealis
2016-08-09 16:29:37 -07:00
```
2016-08-10 15:25:02 -07:00
$ go run $GOPATH/src/github.com/rdelval/gorealis/examples/client.go -executor=compose -url=http://192.168.33.7:8081 -cmd=kill
$ go run $GOPATH/src/github.com/rdelval/gorealis/examples/client.go -executor=thermos -url=http://192.168.33.7:8081 -cmd=kill
2016-08-09 16:29:37 -07:00
```