D.I.Y. mesos framework part 1
Iâve covered Apache Mesos concepts in the past. Now letâs see it in action!
Setup
Iâm using a Mac so I will provide setup steps for running a local Mesos slave and master.
which mesos
# if none,
brew install mesosDocker for Mac should also be installed and running.
Get your systemâs IP: Apple -> System Preferences -> Network. The IP address will show up in the upper right. Jot it down.
Now open 4 terminal windows and letâs begin.
Launch Mesos Master and Agent
Terminal 1: Launch a Mesos Master node:
/usr/local/sbin/mesos-master --registry=in_memory ip=your_ip_addressTerminal 2: Launch a Mesos agent node:
# don't forget to put port 5050 after the ip address!
sudo /usr/local/sbin/mesos-slave --master=your_ip_address:5050 --work_dir=$(pwd)Register a custom Mesos Framework
Here is where the fun begins. We will be using the Mesos HTTP Interface to create our Framework and manage tasks.
To create the Framework, we must use curl or another tool that will keep the connection open. Why? The HTTP response to our framework-creation request is âchunkedâ from the Mesos Master, which results in a connection being left open for the remainder of the frameworkâs lifespan. Offers, task updates, and other communications with the Master node come across this connection for parsing by the framework. The effect is a âstreamingâ subscription to Mesos events.
NOTE: the âuserâ in this command must be the same as the output of a whoami command in the terminal. This becomes important later for launching tasks.
Terminal 3:
curl -v -X POST \
http://localhost:5050/api/v1/scheduler \
-H 'content-type: application/json' \
-d '{
"type" : "SUBSCRIBE",
"subscribe" : {
"framework_info" : {
"user" : "lombardo",
"name" : "HelloWorld Framework",
"roles": ["hello_world_role"],
"capabilities" : [{"type": "MULTI_ROLE"}]
}
}
}'We should see a âSubscribedâ response from Mesos. Note the following fields in the response:
Mesos-Stream-Id - in the header - mine is 274bcc35-78db-42ac-8a10-b02944c5a6eb
framework_id - 089a7212-4aba-4aac-8425-7337161ece30-0000Immediately following the âSubscribedâ event, we should see a âOfferâ. This is Mesos letting us know about resources available on the agent node which we can use to launch our tasks. Note the following fields in the offer:
agent_id mine is 089a7212-4aba-4aac-8425-7337161ece30-S0
id mine is 089a7212-4aba-4aac-8425-7337161ece30-O0NOTE - the âidâ of the offer is nested in the response at id.value
Now if we visit http://localhost:5050 and click on âFrameworksâ we will see our framework listed. Nice! We have just registered a custom framework with Mesos.
Next time we will launch some tasks.