A lightweight meta-framework for assembling Apache Mesos Frameworks (schedulers). Based on:
- Akka
- Akka Streams
- Akka HTTP
- Akka Clustering
- Apache Mesos scheduler HTTP API [http://mesos.apache.org/documentation/latest/scheduler-http-api/]
See SampleFramework.scala for an example framework that:
- initiates the Apache Mesos Client subscription
- submits some tasks for execution
- kills the tasks after some time
- shuts down the Apache Mesos Client on application termination
To use in your own application:
- add dependencies to your app
Gradle:
//for mesos-actor
compile "com.adobe.api.platform.runtime:mesos-actor:0.0.1"
- implement a custom task matcher, if desired
This trait is used to match pending tasks with received offers.
Implement the com.adobe.api.platform.runtime.mesos.TaskMatcher
trait
Default is com.adobe.api.platform.runtime.mesos.DefaultTaskMatcher
- implement a custom task builder, if desired
This trait is used to build TaskInfo objects for Offers that have been matched.
Implement the com.adobe.api.platform.runtime.mesos.TaskBuilder
trait
Default is com.adobe.api.platform.runtime.mesos.DefaultTaskBuilder
- init the client:
val mesosClientActor = system.actorOf(MesosClient.props(
"sample-" + UUID.randomUUID(), //start with a new id (TODO: persist this id so restart will fail over to new instance)
"sample-framework",
"http://192.168.99.100:5050", //your mesos master ip
"sample-role", //role for this framework
30.seconds, //failover timeout
yourTaskMatcher, //optional
yourTaskBuilder //optional
))
//use ask pattern to wait for Subscribe to complete:
mesosClientActor.ask(Subscribe)(subscribeTimeout).mapTo[SubscribeComplete].onComplete(complete => {
log.info("subscribe completed successfully...")
})
You will need a mesos master and one or more mesos agents running.
- run a mesos master+agent using docker-compose (tested with docker-machine; specify the IP of your docker-machine VM):
DOCKER_IP=192.168.99.100 docker-compose up
- run your application
For a highly available framework, multiple instances of the framework must be deployed:
- Only one of those instances should be the leader
- Only the leader should subscribe to Mesos
- When the leader instance dies, another instance should take the leadership role
- The new leader should create a new subscription to Mesos master using the same framework id
- The new leader should reconcile exising tasks, and resume managing the tasks started previously
See SampleHAFramework.scala for an example.
$ make all
This command builds the sample and a docker image that can be deployed in Apache Mesos via Marathon.
$ DOCKER_IP=192.168.99.100 docker-compose up
NOTE: the command above assumes that
docker-machine
's IP is:192.168.99.100
Browse to:
$ curl http://192.168.99.100:8080/v2/apps/ --data @./marathon-config/marathon-app-local.json -H "Content-type: application/json"
After a short while the Apache Mesos UI should display a few tasks running, and a new framework should be registered.
Restart the Marathon app:
$ curl -X POST http://192.168.99.100:8080/v2/apps/akka-cluster/restart
Marathon should start new instances, wait until they become healthy, and then destroy the previous ones.
When the previous leader is destroyed, the framework should show as inactive
in Apache Mesos.
Once a new leader is selected, the framework should then show back as active
.