airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maximebeauche...@apache.org
Subject [30/34] incubator-airflow-site git commit: Initial commit
Date Sun, 05 Jun 2016 05:24:20 GMT
http://git-wip-us.apache.org/repos/asf/incubator-airflow-site/blob/9e19165c/_modules/airflow/operators/docker_operator.html
----------------------------------------------------------------------
diff --git a/_modules/airflow/operators/docker_operator.html b/_modules/airflow/operators/docker_operator.html
new file mode 100644
index 0000000..a1d8fca
--- /dev/null
+++ b/_modules/airflow/operators/docker_operator.html
@@ -0,0 +1,383 @@
+
+
+<!DOCTYPE html>
+<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
+<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
+<head>
+  <meta charset="utf-8">
+  
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  
+  <title>airflow.operators.docker_operator &mdash; Airflow Documentation</title>
+  
+
+  
+  
+
+  
+
+  
+  
+    
+
+  
+
+  
+  
+    <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
+  
+
+  
+
+  
+    <link rel="top" title="Airflow Documentation" href="../../../index.html"/>
+        <link rel="up" title="Module code" href="../../index.html"/> 
+
+  
+  <script src="../../../_static/js/modernizr.min.js"></script>
+
+</head>
+
+<body class="wy-body-for-nav" role="document">
+
+  <div class="wy-grid-for-nav">
+
+    
+    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
+      <div class="wy-side-scroll">
+        <div class="wy-side-nav-search">
+          
+
+          
+            <a href="../../../index.html" class="icon icon-home"> Airflow
+          
+
+          
+          </a>
+
+          
+            
+            
+          
+
+          
+<div role="search">
+  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
+    <input type="text" name="q" placeholder="Search docs" />
+    <input type="hidden" name="check_keywords" value="yes" />
+    <input type="hidden" name="area" value="default" />
+  </form>
+</div>
+
+          
+        </div>
+
+        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main
navigation">
+          
+            
+            
+                <ul>
+<li class="toctree-l1"><a class="reference internal" href="../../../project.html">Project</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../license.html">License</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../start.html">Quick
Start</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../installation.html">Installation</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../tutorial.html">Tutorial</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../configuration.html">Configuration</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../ui.html">UI
/ Screenshots</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../concepts.html">Concepts</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../profiling.html">Data
Profiling</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../cli.html">Command
Line Interface</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../scheduler.html">Scheduling
&amp; Triggers</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../plugins.html">Plugins</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../security.html">Security</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../faq.html">FAQ</a></li>
+<li class="toctree-l1"><a class="reference internal" href="../../../code.html">API
Reference</a></li>
+</ul>
+
+            
+          
+        </div>
+      </div>
+    </nav>
+
+    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
+
+      
+      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
+        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
+        <a href="../../../index.html">Airflow</a>
+      </nav>
+
+
+      
+      <div class="wy-nav-content">
+        <div class="rst-content">
+          
+
+
+
+
+
+<div role="navigation" aria-label="breadcrumbs navigation">
+  <ul class="wy-breadcrumbs">
+    <li><a href="../../../index.html">Docs</a> &raquo;</li>
+      
+          <li><a href="../../index.html">Module code</a> &raquo;</li>
+      
+    <li>airflow.operators.docker_operator</li>
+      <li class="wy-breadcrumbs-aside">
+        
+          
+        
+      </li>
+  </ul>
+  <hr/>
+</div>
+          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
+           <div itemprop="articleBody">
+            
+  <h1>Source code for airflow.operators.docker_operator</h1><div class="highlight"><pre>
+<span></span><span class="kn">import</span> <span class="nn">json</span>
+<span class="kn">import</span> <span class="nn">logging</span>
+<span class="kn">from</span> <span class="nn">airflow.exceptions</span>
<span class="kn">import</span> <span class="n">AirflowException</span>
+<span class="kn">from</span> <span class="nn">airflow.models</span>
<span class="kn">import</span> <span class="n">BaseOperator</span>
+<span class="kn">from</span> <span class="nn">airflow.utils.decorators</span>
<span class="kn">import</span> <span class="n">apply_defaults</span>
+<span class="kn">from</span> <span class="nn">airflow.utils.file</span>
<span class="kn">import</span> <span class="n">TemporaryDirectory</span>
+<span class="kn">from</span> <span class="nn">docker</span> <span
class="kn">import</span> <span class="n">Client</span><span class="p">,</span>
<span class="n">tls</span>
+<span class="kn">import</span> <span class="nn">ast</span>
+
+
+<div class="viewcode-block" id="DockerOperator"><a class="viewcode-back" href="../../../code.html#airflow.operators.docker_operator.DockerOperator">[docs]</a><span
class="k">class</span> <span class="nc">DockerOperator</span><span
class="p">(</span><span class="n">BaseOperator</span><span class="p">):</span>
+    <span class="sd">&quot;&quot;&quot;</span>
+<span class="sd">    Execute a command inside a docker container.</span>
+
+<span class="sd">    A temporary directory is created on the host and mounted into
a container to allow storing files</span>
+<span class="sd">    that together exceed the default disk size of 10GB in a container.
The path to the mounted</span>
+<span class="sd">    directory can be accessed via the environment variable ``AIRFLOW_TMP_DIR``.</span>
+
+<span class="sd">    :param image: Docker image from which to create the container.</span>
+<span class="sd">    :type image: str</span>
+<span class="sd">    :param api_version: Remote API version.</span>
+<span class="sd">    :type api_version: str</span>
+<span class="sd">    :param command: Command to be run in the container.</span>
+<span class="sd">    :type command: str or list</span>
+<span class="sd">    :param cpus: Number of CPUs to assign to the container.</span>
+<span class="sd">        This value gets multiplied with 1024. See</span>
+<span class="sd">        https://docs.docker.com/engine/reference/run/#cpu-share-constraint</span>
+<span class="sd">    :type cpus: float</span>
+<span class="sd">    :param docker_url: URL of the host running the docker daemon.</span>
+<span class="sd">    :type docker_url: str</span>
+<span class="sd">    :param environment: Environment variables to set in the container.</span>
+<span class="sd">    :type environment: dict</span>
+<span class="sd">    :param force_pull: Pull the docker image on every run.</span>
+<span class="sd">    :type force_pull: bool</span>
+<span class="sd">    :param mem_limit: Maximum amount of memory the container can use.
Either a float value, which</span>
+<span class="sd">        represents the limit in bytes, or a string like ``128m`` or
``1g``.</span>
+<span class="sd">    :type mem_limit: float or str</span>
+<span class="sd">    :param network_mode: Network mode for the container.</span>
+<span class="sd">    :type network_mode: str</span>
+<span class="sd">    :param tls_ca_cert: Path to a PEM-encoded certificate authority
to secure the docker connection.</span>
+<span class="sd">    :type tls_ca_cert: str</span>
+<span class="sd">    :param tls_client_cert: Path to the PEM-encoded certificate used
to authenticate docker client.</span>
+<span class="sd">    :type tls_client_cert: str</span>
+<span class="sd">    :param tls_client_key: Path to the PEM-encoded key used to authenticate
docker client.</span>
+<span class="sd">    :type tls_client_key: str</span>
+<span class="sd">    :param tls_hostname: Hostname to match against the docker server
certificate or False to</span>
+<span class="sd">        disable the check.</span>
+<span class="sd">    :type tls_hostname: str or bool</span>
+<span class="sd">    :param tls_ssl_version: Version of SSL to use when communicating
with docker daemon.</span>
+<span class="sd">    :type tls_ssl_version: str</span>
+<span class="sd">    :param tmp_dir: Mount point inside the container to a temporary
directory created on the host by</span>
+<span class="sd">        the operator. The path is also made available via the environment
variable</span>
+<span class="sd">        ``AIRFLOW_TMP_DIR`` inside the container.</span>
+<span class="sd">    :type tmp_dir: str</span>
+<span class="sd">    :param user: Default user inside the docker container.</span>
+<span class="sd">    :type user: int or str</span>
+<span class="sd">    :param volumes: List of volumes to mount into the container, e.g.</span>
+<span class="sd">        ``[&#39;/host/path:/container/path&#39;, &#39;/host/path2:/container/path2:ro&#39;]``.</span>
+<span class="sd">    :param xcom_push: Does the stdout will be pushed to the next step
using XCom.</span>
+<span class="sd">           The default is False.</span>
+<span class="sd">    :type xcom_push: bool</span>
+<span class="sd">    :param xcom_all: Push all the stdout or just the last line. The
default is False (last line).</span>
+<span class="sd">    :type xcom_all: bool</span>
+<span class="sd">    &quot;&quot;&quot;</span>
+    <span class="n">template_fields</span> <span class="o">=</span>
<span class="p">(</span><span class="s1">&#39;command&#39;</span><span
class="p">,)</span>
+    <span class="n">template_ext</span> <span class="o">=</span>
<span class="p">(</span><span class="s1">&#39;.sh&#39;</span><span
class="p">,</span> <span class="s1">&#39;.bash&#39;</span><span
class="p">,)</span>
+
+    <span class="nd">@apply_defaults</span>
+    <span class="k">def</span> <span class="nf">__init__</span><span
class="p">(</span>
+            <span class="bp">self</span><span class="p">,</span>
+            <span class="n">image</span><span class="p">,</span>
+            <span class="n">api_version</span><span class="o">=</span><span
class="bp">None</span><span class="p">,</span>
+            <span class="n">command</span><span class="o">=</span><span
class="bp">None</span><span class="p">,</span>
+            <span class="n">cpus</span><span class="o">=</span><span
class="mf">1.0</span><span class="p">,</span>
+            <span class="n">docker_url</span><span class="o">=</span><span
class="s1">&#39;unix://var/run/docker.sock&#39;</span><span class="p">,</span>
+            <span class="n">environment</span><span class="o">=</span><span
class="bp">None</span><span class="p">,</span>
+            <span class="n">force_pull</span><span class="o">=</span><span
class="bp">False</span><span class="p">,</span>
+            <span class="n">mem_limit</span><span class="o">=</span><span
class="bp">None</span><span class="p">,</span>
+            <span class="n">network_mode</span><span class="o">=</span><span
class="bp">None</span><span class="p">,</span>
+            <span class="n">tls_ca_cert</span><span class="o">=</span><span
class="bp">None</span><span class="p">,</span>
+            <span class="n">tls_client_cert</span><span class="o">=</span><span
class="bp">None</span><span class="p">,</span>
+            <span class="n">tls_client_key</span><span class="o">=</span><span
class="bp">None</span><span class="p">,</span>
+            <span class="n">tls_hostname</span><span class="o">=</span><span
class="bp">None</span><span class="p">,</span>
+            <span class="n">tls_ssl_version</span><span class="o">=</span><span
class="bp">None</span><span class="p">,</span>
+            <span class="n">tmp_dir</span><span class="o">=</span><span
class="s1">&#39;/tmp/airflow&#39;</span><span class="p">,</span>
+            <span class="n">user</span><span class="o">=</span><span
class="bp">None</span><span class="p">,</span>
+            <span class="n">volumes</span><span class="o">=</span><span
class="bp">None</span><span class="p">,</span>
+            <span class="n">xcom_push</span><span class="o">=</span><span
class="bp">False</span><span class="p">,</span>
+            <span class="n">xcom_all</span><span class="o">=</span><span
class="bp">False</span><span class="p">,</span>
+            <span class="o">*</span><span class="n">args</span><span
class="p">,</span>
+            <span class="o">**</span><span class="n">kwargs</span><span
class="p">):</span>
+
+        <span class="nb">super</span><span class="p">(</span><span
class="n">DockerOperator</span><span class="p">,</span> <span class="bp">self</span><span
class="p">)</span><span class="o">.</span><span class="n">__init__</span><span
class="p">(</span><span class="o">*</span><span class="n">args</span><span
class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span
class="p">)</span>
+        <span class="bp">self</span><span class="o">.</span><span
class="n">api_version</span> <span class="o">=</span> <span class="n">api_version</span>
+        <span class="bp">self</span><span class="o">.</span><span
class="n">command</span> <span class="o">=</span> <span class="n">command</span>
+        <span class="bp">self</span><span class="o">.</span><span
class="n">cpus</span> <span class="o">=</span> <span class="n">cpus</span>
+        <span class="bp">self</span><span class="o">.</span><span
class="n">docker_url</span> <span class="o">=</span> <span class="n">docker_url</span>
+        <span class="bp">self</span><span class="o">.</span><span
class="n">environment</span> <span class="o">=</span> <span class="n">environment</span>
<span class="ow">or</span> <span class="p">{}</span>
+        <span class="bp">self</span><span class="o">.</span><span
class="n">force_pull</span> <span class="o">=</span> <span class="n">force_pull</span>
+        <span class="bp">self</span><span class="o">.</span><span
class="n">image</span> <span class="o">=</span> <span class="n">image</span>
+        <span class="bp">self</span><span class="o">.</span><span
class="n">mem_limit</span> <span class="o">=</span> <span class="n">mem_limit</span>
+        <span class="bp">self</span><span class="o">.</span><span
class="n">network_mode</span> <span class="o">=</span> <span class="n">network_mode</span>
+        <span class="bp">self</span><span class="o">.</span><span
class="n">tls_ca_cert</span> <span class="o">=</span> <span class="n">tls_ca_cert</span>
+        <span class="bp">self</span><span class="o">.</span><span
class="n">tls_client_cert</span> <span class="o">=</span> <span class="n">tls_client_cert</span>
+        <span class="bp">self</span><span class="o">.</span><span
class="n">tls_client_key</span> <span class="o">=</span> <span class="n">tls_client_key</span>
+        <span class="bp">self</span><span class="o">.</span><span
class="n">tls_hostname</span> <span class="o">=</span> <span class="n">tls_hostname</span>
+        <span class="bp">self</span><span class="o">.</span><span
class="n">tls_ssl_version</span> <span class="o">=</span> <span class="n">tls_ssl_version</span>
+        <span class="bp">self</span><span class="o">.</span><span
class="n">tmp_dir</span> <span class="o">=</span> <span class="n">tmp_dir</span>
+        <span class="bp">self</span><span class="o">.</span><span
class="n">user</span> <span class="o">=</span> <span class="n">user</span>
+        <span class="bp">self</span><span class="o">.</span><span
class="n">volumes</span> <span class="o">=</span> <span class="n">volumes</span>
<span class="ow">or</span> <span class="p">[]</span>
+        <span class="bp">self</span><span class="o">.</span><span
class="n">xcom_push</span> <span class="o">=</span> <span class="n">xcom_push</span>
+        <span class="bp">self</span><span class="o">.</span><span
class="n">xcom_all</span> <span class="o">=</span> <span class="n">xcom_all</span>
+
+        <span class="bp">self</span><span class="o">.</span><span
class="n">cli</span> <span class="o">=</span> <span class="bp">None</span>
+        <span class="bp">self</span><span class="o">.</span><span
class="n">container</span> <span class="o">=</span> <span class="bp">None</span>
+
+    <span class="k">def</span> <span class="nf">execute</span><span
class="p">(</span><span class="bp">self</span><span class="p">,</span>
<span class="n">context</span><span class="p">):</span>
+        <span class="n">logging</span><span class="o">.</span><span
class="n">info</span><span class="p">(</span><span class="s1">&#39;Starting
docker container from image &#39;</span> <span class="o">+</span> <span
class="bp">self</span><span class="o">.</span><span class="n">image</span><span
class="p">)</span>
+
+        <span class="n">tls_config</span> <span class="o">=</span>
<span class="bp">None</span>
+        <span class="k">if</span> <span class="bp">self</span><span
class="o">.</span><span class="n">tls_ca_cert</span> <span class="ow">and</span>
<span class="bp">self</span><span class="o">.</span><span class="n">tls_client_cert</span>
<span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span
class="n">tls_client_key</span><span class="p">:</span>
+            <span class="n">tls_config</span> <span class="o">=</span>
<span class="n">tls</span><span class="o">.</span><span class="n">TLSConfig</span><span
class="p">(</span>
+                    <span class="n">ca_cert</span><span class="o">=</span><span
class="bp">self</span><span class="o">.</span><span class="n">tls_ca_cert</span><span
class="p">,</span>
+                    <span class="n">client_cert</span><span class="o">=</span><span
class="p">(</span><span class="bp">self</span><span class="o">.</span><span
class="n">tls_client_cert</span><span class="p">,</span> <span class="bp">self</span><span
class="o">.</span><span class="n">tls_client_key</span><span class="p">),</span>
+                    <span class="n">verify</span><span class="o">=</span><span
class="bp">True</span><span class="p">,</span>
+                    <span class="n">ssl_version</span><span class="o">=</span><span
class="bp">self</span><span class="o">.</span><span class="n">tls_ssl_version</span><span
class="p">,</span>
+                    <span class="n">assert_hostname</span><span class="o">=</span><span
class="bp">self</span><span class="o">.</span><span class="n">tls_hostname</span>
+            <span class="p">)</span>
+            <span class="bp">self</span><span class="o">.</span><span
class="n">docker_url</span> <span class="o">=</span> <span class="bp">self</span><span
class="o">.</span><span class="n">docker_url</span><span class="o">.</span><span
class="n">replace</span><span class="p">(</span><span class="s1">&#39;tcp://&#39;</span><span
class="p">,</span> <span class="s1">&#39;https://&#39;</span><span
class="p">)</span>
+
+        <span class="bp">self</span><span class="o">.</span><span
class="n">cli</span> <span class="o">=</span> <span class="n">Client</span><span
class="p">(</span><span class="n">base_url</span><span class="o">=</span><span
class="bp">self</span><span class="o">.</span><span class="n">docker_url</span><span
class="p">,</span> <span class="n">version</span><span class="o">=</span><span
class="bp">self</span><span class="o">.</span><span class="n">api_version</span><span
class="p">,</span> <span class="n">tls</span><span class="o">=</span><span
class="n">tls_config</span><span class="p">)</span>
+
+        <span class="k">if</span> <span class="s1">&#39;:&#39;</span>
<span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span
class="o">.</span><span class="n">image</span><span class="p">:</span>
+            <span class="n">image</span> <span class="o">=</span>
<span class="bp">self</span><span class="o">.</span><span class="n">image</span>
<span class="o">+</span> <span class="s1">&#39;:latest&#39;</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">image</span> <span class="o">=</span>
<span class="bp">self</span><span class="o">.</span><span class="n">image</span>
+
+        <span class="k">if</span> <span class="bp">self</span><span
class="o">.</span><span class="n">force_pull</span> <span class="ow">or</span>
<span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span
class="o">.</span><span class="n">cli</span><span class="o">.</span><span
class="n">images</span><span class="p">(</span><span class="n">name</span><span
class="o">=</span><span class="n">image</span><span class="p">))</span>
<span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
+            <span class="n">logging</span><span class="o">.</span><span
class="n">info</span><span class="p">(</span><span class="s1">&#39;Pulling
docker image &#39;</span> <span class="o">+</span> <span class="n">image</span><span
class="p">)</span>
+            <span class="k">for</span> <span class="n">l</span> <span
class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span
class="n">cli</span><span class="o">.</span><span class="n">pull</span><span
class="p">(</span><span class="n">image</span><span class="p">,</span>
<span class="n">stream</span><span class="o">=</span><span class="bp">True</span><span
class="p">):</span>
+                <span class="n">output</span> <span class="o">=</span>
<span class="n">json</span><span class="o">.</span><span class="n">loads</span><span
class="p">(</span><span class="n">l</span><span class="p">)</span>
+                <span class="n">logging</span><span class="o">.</span><span
class="n">info</span><span class="p">(</span><span class="s2">&quot;{}&quot;</span><span
class="o">.</span><span class="n">format</span><span class="p">(</span><span
class="n">output</span><span class="p">[</span><span class="s1">&#39;status&#39;</span><span
class="p">]))</span>
+
+        <span class="n">cpu_shares</span> <span class="o">=</span>
<span class="nb">int</span><span class="p">(</span><span class="nb">round</span><span
class="p">(</span><span class="bp">self</span><span class="o">.</span><span
class="n">cpus</span> <span class="o">*</span> <span class="mi">1024</span><span
class="p">))</span>
+
+        <span class="k">with</span> <span class="n">TemporaryDirectory</span><span
class="p">(</span><span class="n">prefix</span><span class="o">=</span><span
class="s1">&#39;airflowtmp&#39;</span><span class="p">)</span>
<span class="k">as</span> <span class="n">host_tmp_dir</span><span
class="p">:</span>
+            <span class="bp">self</span><span class="o">.</span><span
class="n">environment</span><span class="p">[</span><span class="s1">&#39;AIRFLOW_TMP_DIR&#39;</span><span
class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span
class="o">.</span><span class="n">tmp_dir</span>
+            <span class="bp">self</span><span class="o">.</span><span
class="n">volumes</span><span class="o">.</span><span class="n">append</span><span
class="p">(</span><span class="s1">&#39;{0}:{1}&#39;</span><span
class="o">.</span><span class="n">format</span><span class="p">(</span><span
class="n">host_tmp_dir</span><span class="p">,</span> <span class="bp">self</span><span
class="o">.</span><span class="n">tmp_dir</span><span class="p">))</span>
+
+            <span class="bp">self</span><span class="o">.</span><span
class="n">container</span> <span class="o">=</span> <span class="bp">self</span><span
class="o">.</span><span class="n">cli</span><span class="o">.</span><span
class="n">create_container</span><span class="p">(</span>
+                    <span class="n">command</span><span class="o">=</span><span
class="bp">self</span><span class="o">.</span><span class="n">get_command</span><span
class="p">(),</span>
+                    <span class="n">cpu_shares</span><span class="o">=</span><span
class="n">cpu_shares</span><span class="p">,</span>
+                    <span class="n">environment</span><span class="o">=</span><span
class="bp">self</span><span class="o">.</span><span class="n">environment</span><span
class="p">,</span>
+                    <span class="n">host_config</span><span class="o">=</span><span
class="bp">self</span><span class="o">.</span><span class="n">cli</span><span
class="o">.</span><span class="n">create_host_config</span><span class="p">(</span><span
class="n">binds</span><span class="o">=</span><span class="bp">self</span><span
class="o">.</span><span class="n">volumes</span><span class="p">,</span>
+                                                            <span class="n">network_mode</span><span
class="o">=</span><span class="bp">self</span><span class="o">.</span><span
class="n">network_mode</span><span class="p">),</span>
+                    <span class="n">image</span><span class="o">=</span><span
class="n">image</span><span class="p">,</span>
+                    <span class="n">mem_limit</span><span class="o">=</span><span
class="bp">self</span><span class="o">.</span><span class="n">mem_limit</span><span
class="p">,</span>
+                    <span class="n">user</span><span class="o">=</span><span
class="bp">self</span><span class="o">.</span><span class="n">user</span>
+            <span class="p">)</span>
+            <span class="bp">self</span><span class="o">.</span><span
class="n">cli</span><span class="o">.</span><span class="n">start</span><span
class="p">(</span><span class="bp">self</span><span class="o">.</span><span
class="n">container</span><span class="p">[</span><span class="s1">&#39;Id&#39;</span><span
class="p">])</span>
+
+            <span class="n">line</span> <span class="o">=</span>
<span class="s1">&#39;&#39;</span>
+            <span class="k">for</span> <span class="n">line</span>
<span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span
class="n">cli</span><span class="o">.</span><span class="n">logs</span><span
class="p">(</span><span class="n">container</span><span class="o">=</span><span
class="bp">self</span><span class="o">.</span><span class="n">container</span><span
class="p">[</span><span class="s1">&#39;Id&#39;</span><span
class="p">],</span> <span class="n">stream</span><span class="o">=</span><span
class="bp">True</span><span class="p">):</span>
+                <span class="n">logging</span><span class="o">.</span><span
class="n">info</span><span class="p">(</span><span class="s2">&quot;{}&quot;</span><span
class="o">.</span><span class="n">format</span><span class="p">(</span><span
class="n">line</span><span class="o">.</span><span class="n">strip</span><span
class="p">()))</span>
+
+            <span class="n">exit_code</span> <span class="o">=</span>
<span class="bp">self</span><span class="o">.</span><span class="n">cli</span><span
class="o">.</span><span class="n">wait</span><span class="p">(</span><span
class="bp">self</span><span class="o">.</span><span class="n">container</span><span
class="p">[</span><span class="s1">&#39;Id&#39;</span><span
class="p">])</span>
+            <span class="k">if</span> <span class="n">exit_code</span>
<span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
+                <span class="k">raise</span> <span class="n">AirflowException</span><span
class="p">(</span><span class="s1">&#39;docker container failed&#39;</span><span
class="p">)</span>
+
+            <span class="k">if</span> <span class="bp">self</span><span
class="o">.</span><span class="n">xcom_push</span><span class="p">:</span>
+                <span class="k">return</span> <span class="bp">self</span><span
class="o">.</span><span class="n">cli</span><span class="o">.</span><span
class="n">logs</span><span class="p">(</span><span class="n">container</span><span
class="o">=</span><span class="bp">self</span><span class="o">.</span><span
class="n">container</span><span class="p">[</span><span class="s1">&#39;Id&#39;</span><span
class="p">])</span> <span class="k">if</span> <span class="bp">self</span><span
class="o">.</span><span class="n">xcom_all</span> <span class="k">else</span>
<span class="nb">str</span><span class="p">(</span><span class="n">line</span><span
class="o">.</span><span class="n">strip</span><span class="p">())</span>
+
+    <span class="k">def</span> <span class="nf">get_command</span><span
class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">if</span> <span class="bp">self</span><span
class="o">.</span><span class="n">command</span> <span class="ow">is</span>
<span class="ow">not</span> <span class="bp">None</span> <span
class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span
class="n">command</span><span class="o">.</span><span class="n">strip</span><span
class="p">()</span><span class="o">.</span><span class="n">find</span><span
class="p">(</span><span class="s1">&#39;[&#39;</span><span
class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span
class="p">:</span>
+            <span class="n">commands</span> <span class="o">=</span>
<span class="n">ast</span><span class="o">.</span><span class="n">literal_eval</span><span
class="p">(</span><span class="bp">self</span><span class="o">.</span><span
class="n">command</span><span class="p">)</span>
+        <span class="k">else</span><span class="p">:</span>
+            <span class="n">commands</span> <span class="o">=</span>
<span class="bp">self</span><span class="o">.</span><span class="n">command</span>
+        <span class="k">return</span> <span class="n">commands</span>
+
+    <span class="k">def</span> <span class="nf">on_kill</span><span
class="p">(</span><span class="bp">self</span><span class="p">):</span>
+        <span class="k">if</span> <span class="bp">self</span><span
class="o">.</span><span class="n">cli</span> <span class="ow">is</span>
<span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
+            <span class="n">logging</span><span class="o">.</span><span
class="n">info</span><span class="p">(</span><span class="s1">&#39;Stopping
docker container&#39;</span><span class="p">)</span>
+            <span class="bp">self</span><span class="o">.</span><span
class="n">cli</span><span class="o">.</span><span class="n">stop</span><span
class="p">(</span><span class="bp">self</span><span class="o">.</span><span
class="n">container</span><span class="p">[</span><span class="s1">&#39;Id&#39;</span><span
class="p">])</span></div>
+</pre></div>
+
+           </div>
+          </div>
+          <footer>
+  
+
+  <hr/>
+
+  <div role="contentinfo">
+    <p>
+        &copy; Copyright 2014, Maxime Beauchemin, Airbnb.
+
+    </p>
+  </div>
+  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>. 
+
+</footer>
+
+        </div>
+      </div>
+
+    </section>
+
+  </div>
+  
+
+
+  
+
+    <script type="text/javascript">
+        var DOCUMENTATION_OPTIONS = {
+            URL_ROOT:'../../../',
+            VERSION:'',
+            COLLAPSE_INDEX:false,
+            FILE_SUFFIX:'.html',
+            HAS_SOURCE:  true
+        };
+    </script>
+      <script type="text/javascript" src="../../../_static/jquery.js"></script>
+      <script type="text/javascript" src="../../../_static/underscore.js"></script>
+      <script type="text/javascript" src="../../../_static/doctools.js"></script>
+
+  
+
+  
+  
+    <script type="text/javascript" src="../../../_static/js/theme.js"></script>
+  
+
+  
+  
+  <script type="text/javascript">
+      jQuery(function () {
+          SphinxRtdTheme.StickyNav.enable();
+      });
+  </script>
+   
+
+</body>
+</html>
\ No newline at end of file


Mime
View raw message