<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ Mesos - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ Mesos - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Mon, 25 May 2026 15:49:22 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/mesos/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ Experimenting with the Apache Mesos HTTP API for Fun and Profit ]]>
                </title>
                <description>
                    <![CDATA[ By Marco Massenzio Apache Mesos is a tool used in production at large-scale services like Twitter and Airbnb. Here’s its textbook description: The Mesos kernel runs on every machine and provides applications (e.g., Hadoop, Spark, Kafka, Elasticsearc... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/experimenting-with-the-apache-mesos-http-api-for-fun-and-profit-part-1-of-3-cf5736e84f85/</link>
                <guid isPermaLink="false">66c34a084f7405e6476b01a9</guid>
                
                    <category>
                        <![CDATA[ Mesos ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Devops ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Docker ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Python ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sat, 27 Aug 2016 21:59:44 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*YWIt5Ajh2lAk4e2yj4jO8Q.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Marco Massenzio</p>
<p>Apache Mesos is a tool used in production at large-scale services like Twitter and Airbnb. Here’s its textbook description:</p>
<blockquote>
<p>The Mesos kernel runs on every machine and provides applications (e.g., Hadoop, Spark, Kafka, Elasticsearch) with API’s for resource management and scheduling across entire datacenter and cloud environments. — from the <a target="_blank" href="https://mesos.apache.org">Apache Mesos</a> project site.</p>
</blockquote>
<p>This is the first of a series of three articles that show how to setup a Vagrant-based Apache Mesos test/development environment on your laptop, how to run a Python notebook against the HTTP API, and how to launch Docker containers on the running Agent VM.</p>
<p>This series is an extended (and updated) version of the <a target="_blank" href="https://youtu.be/G7xfEs0lX5U">talk</a> I gave at <strong>MesosCon Europe 2015</strong> updated for Apache Mesos 1.0.0, which has just been released (August 2016) — you can also find the <a target="_blank" href="http://events.linuxfoundation.org/sites/events/files/slides/MesosCon%20EU%20-%20HTTP%20API%20Framework.pdf">slides</a> there.</p>
<p>This post is pretty jam-packed, and will require you to be familiarity with some concepts around containers, VMs, and Mesos. But I’ll take the time to show all the intermediate steps (hence, the 3-parts). It should be easy to follow, even if you’ve never used Vagrant, Mesos, or even Jupyter notebooks before.</p>
<p>I recommend you first have a basic familiarity with Python and handling HTTP requests and responses, as we will not be going those details there.</p>
<p>All the code is available <a target="_blank" href="https://github.com/massenz/zk-mesos">on the zk-mesos git repository</a>:</p>
<pre><code>git clone git@github.com:massenz/zk-mesos.git
</code></pre><p>And you can also view the <a target="_blank" href="https://github.com/massenz/zk-mesos">README</a>.</p>
<h3 id="heading-getting-started">Getting Started</h3>
<p>In order to follow along, you will need to clone the repository (as shown above) and install <a target="_blank" href="http://virtualbox.org">Virtualbox</a> and <a target="_blank" href="https://www.vagrantup.com/docs">Vagrant</a>. Follow the instructions on their respective sites and you’ll be up and running in no time.</p>
<p>I also recommend quickly scanning the Vagrant documentation. A knowledge of Vagrant beyond <code>_vagrant up</code>_ is not really required to get the most out of this series, but it may help if you get stuck (or would like to experiment and improve on our <em>Vagrantfile</em>).</p>
<p>If you’re not familiar with <a target="_blank" href="https://mesos.apache.org">Apache Mesos</a> I recommend taking a look at the project’s site. I recommend reading <a target="_blank" href="http://amzn.to/2citsRx">Mesos in Action</a> (note that I was one of the manuscript’s reviewers).</p>
<p>We will <strong>not</strong> be building Mesos from source here, but will instead use <a target="_blank" href="http://open.mesosphere.com/downloads/mesos/">Mesosphere packages</a>. You don’t need to download them. The <em>Vagrantfile</em> will automatically download and install on the VMs.</p>
<p>To run the Python notebook, we’ll take advantage of the <a target="_blank" href="http://jupyter.org">Jupyter</a> packages, and use a <em>virtualenv</em> to run all of our code. Virtualenv isn’t strictly necessary, but will prevent you messing up your system Python.</p>
<p>If you‘ve never used <a target="_blank" href="https://virtualenv.pypa.io/en/stable/installation/">virtualenv</a> before:</p>
<pre><code>$ sudo pip install virtualenv
</code></pre><p>And then create and run a <em>virtualenv</em>:</p>
<pre><code>$ cd zk-mesos $ virtualenv mesos-demo$ source mesos-demo/bin/activate $ pip install -r requirements.txt
</code></pre><p>Finally, verify that you can run and load the Jupyter notebook:</p>
<pre><code>$ jupyter notebook
</code></pre><p>This should automatically open your browser and point it to <a target="_blank" href="http://localhost:8888">http://localhost:8888</a>. From here you can select the <em>notebooks/Demo-API.ipynb</em> file. Don’t run it just yet, but if it shows up, it will confirm that your Python setup is just fine.</p>
<h3 id="heading-building-and-installing-apache-mesos">Building and installing Apache Mesos</h3>
<p>This is where the beauty of Vagrant shines in all its glory. Installing Apache Mesos Master and Agent are not trivial tasks, but in our case, it’s just a matter of:</p>
<pre><code>$ cd vagrant $ vagrant up
</code></pre><p>Make sure that you’re in the same directory as the <em>Vagrantfile</em> when issuing any of the Vagrant commands, or it will complain about it.</p>
<p>It is worth noting that we are building <strong>two</strong> Vagrant boxes, so any command will operate on <strong>both</strong> unless specified. To avoid this, you can specify the name of the VM after the command. For example, to SSH onto the Agent:</p>
<pre><code>$ vagrant ssh agent
</code></pre><p>This should log you in on that box. From there, you can explore, experiment, and diagnose any issues.</p>
<p>The <em>vagrant up</em> command will take some time to execute, but it should eventually lead your Virtualbox to have two VMs, named respectively <em>mesos-master</em> and <em>mesos-agent</em>. Incidentally, you should never need to use VirtualBox to manage them. All the tasks can be undertaken via Vagrant commands. But you can manage them manually if necessary or desired.</p>
<p>Once your VMs are built, ensure you can access Mesos HTTP UI at:</p>
<pre><code>http:<span class="hljs-comment">//192.168.33.10:5050</span>
</code></pre><p><img src="https://cdn-media-1.freecodecamp.org/images/uzGS7oJkLwPeUpQvw8H3eoHEVZeq3Nurmg0O" alt="Image" width="800" height="631" loading="lazy">
<em>Mesos Master web UI — reachable at http://192.168.33.10:5050</em></p>
<p>You should also see one agent running, accessible either via the Master UI.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/crYwNv0fIdcZmmrQiHPotFET2aviNHr3etEO" alt="Image" width="800" height="271" loading="lazy">
<em>Agents view on the Mesos Master web UI</em></p>
<p>Or directly at:</p>
<pre><code>http:<span class="hljs-comment">//192.168.33.11:5051/state</span>
</code></pre><p><img src="https://cdn-media-1.freecodecamp.org/images/TjtQITaW3MEkyObTyLMGbQSDnqqpsOP4tVnd" alt="Image" width="800" height="724" loading="lazy">
<em>JSON response from the Agent, when hitting the /state endpoint</em></p>
<p>Note that the Agent runs not only on a different IP address than the Master, but also on a different port (5051 instead of 5050).</p>
<p>Look into vagrant/run-agent.sh to see a few of the command line flags that we use to run the Agent (and in run-master.sh for the Master).</p>
<h3 id="heading-zookeeper">Zookeeper</h3>
<p>It’s worth noting that we are also running an instance of Zookeeper (for Leader election and Master/Agent coordination) on the <em>mesos-master</em> VM, inside a Docker container: partly because we can, but also to show how easy it is to do so using containers.</p>
<p>This one line (in <em>run-master.sh</em>), will give you a perfectly good ZK instance (albeit, a catastrophically unreliable one in a production environment, where you’d want to run at least 3–5 nodes, at least, on physically separate machines/racks):</p>
<pre><code>docker run -d --name zookeeper -p <span class="hljs-number">2181</span>:<span class="hljs-number">2181</span> -p <span class="hljs-number">2888</span>:<span class="hljs-number">2888</span> \    -p <span class="hljs-number">3888</span>:<span class="hljs-number">3888</span> jplock/zookeeper:<span class="hljs-number">3.4</span><span class="hljs-number">.8</span>
</code></pre><p>And because we expose the ports (in particular, 2181) to the host VM, we can connect to it via the Zookeeper CLI utility (<em>zkCli.sh</em>) and explore it. From your development machine (you will need to first download Zookeeper) you can use:</p>
<pre><code>$ zkCli.sh -server <span class="hljs-number">192.168</span><span class="hljs-number">.33</span><span class="hljs-number">.10</span>:<span class="hljs-number">2181.</span>..[zk: <span class="hljs-number">192.168</span><span class="hljs-number">.33</span><span class="hljs-number">.10</span>:<span class="hljs-number">2181</span>(CONNECTED) <span class="hljs-number">4</span>] get /mesos/vagrant/json.info_0000000000
</code></pre><pre><code># Formatted <span class="hljs-keyword">for</span> better readability:{<span class="hljs-string">"address"</span>:  { <span class="hljs-string">"hostname"</span>: <span class="hljs-string">"mesos-master"</span>,    <span class="hljs-string">"ip"</span>:<span class="hljs-string">"192.168.33.10"</span>,    <span class="hljs-string">"port"</span>:<span class="hljs-number">5050</span>  },  <span class="hljs-string">"hostname"</span>:<span class="hljs-string">"mesos-master"</span>,  <span class="hljs-string">"id"</span>:<span class="hljs-string">"7eb34f10-b07c-4921-aece-bbaece09dfd1"</span>,  <span class="hljs-string">"ip"</span>:<span class="hljs-number">169978048</span>,  <span class="hljs-string">"pid"</span>:<span class="hljs-string">"master@192.168.33.10:5050"</span>,  <span class="hljs-string">"port"</span>:<span class="hljs-number">5050</span>,  <span class="hljs-string">"version"</span>:<span class="hljs-string">"1.0.0"</span>}
</code></pre><pre><code>cZxid = <span class="hljs-number">0xbc</span>time = Sat Aug <span class="hljs-number">27</span> <span class="hljs-number">14</span>:<span class="hljs-number">00</span>:<span class="hljs-number">44</span> PDT <span class="hljs-number">2016.</span>..
</code></pre><p>This is how Agents get information about how to connect to the Master node.</p>
<p>The <strong>000000_ suffix gets incremented every time a new Leader gets elected, so depending on how long the ZK instance has been running and whether the Master was restarted, it may become something like </strong>0000005._ That is an “<em>ephemeral node”</em> in Zookeeper’s parlance.</p>
<p>In that record above, it is worth noting that “pid” is <em>libprocess</em> unique identifier and “ip” as a compressed 4-byte representation of an IPv4 octect quadruple. These legacy fields and may eventually be removed.</p>
<h4 id="heading-wrap-up">Wrap Up</h4>
<p>You are now the proud owner of a Master/Agent 2-node Apache Mesos deployment. Welcome in the same league as Twitter and Airbnb production wizards.</p>
<p>In Part 2, we’ll run our Python notebook against the Master API and will accept the Agent’s offers to launch a Docker container.</p>
<p>If you’ve got time, let’s jump on in and learn <a target="_blank" href="https://medium.com/@massenz/a-python-notebook-to-experiment-with-the-apache-mesos-http-api-part-2-of-3-7f97fbe32e80#.yhx3zxpws">how to connect to Mesos Master and accept Resource Offers</a>.</p>
<p><em>Originally published at <a target="_blank" href="https://codetrips.com/2016/08/27/a-python-notebook-to-experiment-with-the-apache-mesos-http-api-part-1-of-3/">codetrips.com</a> on August 27, 2016.</em></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
