airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject incubator-airflow git commit: [AIRFLOW-1764] The web interface should not use the experimental API
Date Wed, 01 Nov 2017 14:26:09 GMT
Repository: incubator-airflow
Updated Branches:
  refs/heads/master 6b8fe9857 -> 0bf7adb20


[AIRFLOW-1764] The web interface should not use the experimental API

The web interface should not use the experimental
api as the
authentication options differ between the two.
Additionally, rather than
having an API call to get the last run data we can
easily include it in
the generated HMTL response. One less round-trip,
less endpoints, and
less time before the page has fully rendered.

This is based original off @NielsZeilemaker's PR
for the same Jira
issue (#2734)

Closes #2738 from ashb/no-exp-api-from-web-
interface


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/0bf7adb2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/0bf7adb2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/0bf7adb2

Branch: refs/heads/master
Commit: 0bf7adb209ce969243ffaf4fc5213ff3957cbbc9
Parents: 6b8fe98
Author: Ash Berlin-Taylor <ash_github@firemirror.com>
Authored: Wed Nov 1 15:25:28 2017 +0100
Committer: Bolke de Bruin <bolke@xs4all.nl>
Committed: Wed Nov 1 15:25:28 2017 +0100

----------------------------------------------------------------------
 airflow/www/templates/airflow/dags.html | 24 +++++++++---------------
 airflow/www/views.py                    |  2 ++
 tests/core.py                           | 17 ++++++++++++++---
 3 files changed, 25 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/0bf7adb2/airflow/www/templates/airflow/dags.html
----------------------------------------------------------------------
diff --git a/airflow/www/templates/airflow/dags.html b/airflow/www/templates/airflow/dags.html
index ebf638f..eeef790 100644
--- a/airflow/www/templates/airflow/dags.html
+++ b/airflow/www/templates/airflow/dags.html
@@ -118,6 +118,15 @@
 
                 <!-- Column 7: Last Run -->
                 <td class="text-nowrap latest_dag_run {{ dag.dag_id }}">
+                  {% if dag %}
+                    {% set last_run = dag.get_last_dagrun() %}
+                    {% if last_run and last_run.execution_date %}
+                      <a href="{{ url_for('airflow.graph', dag_id=dag.dag_id, execution_date=last_run.execution_date)
}}">
+                        {{ last_run.execution_date.strftime("%Y-%m-%d %H:%M") }}
+                      </a>
+                      <span aria-hidden="true" id="statuses_info" title="Start Date: {{
last_run.start_date.strftime("%Y-%m-%d %H:%M") }}" class="glyphicon glyphicon-info-sign"></span>
+                    {% endif %}
+                  {% endif %}
                 </td>
 
                 <!-- Column 8: Dag Runs -->
@@ -296,21 +305,6 @@
           }
         });
       });
-      $.getJSON("{{ url_for('api_experimental.latest_dag_runs') }}", function(data) {
-        $.each(data["items"], function() {
-          var link = $("<a>", {
-            href: this.dag_run_url,
-            text: this.execution_date
-          });
-          var info_icon = $('<span>', {
-            "aria-hidden": "true",
-            id: "statuses_info",
-            title: "Start Date: " + this.start_date,
-            "class": "glyphicon glyphicon-info-sign"
-          });
-          $('.latest_dag_run.' + this.dag_id).append(link).append(info_icon);
-        });
-      });
       d3.json("{{ url_for('airflow.dag_stats') }}", function(error, json) {
         for(var dag_id in json) {
             states = json[dag_id];

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/0bf7adb2/airflow/www/views.py
----------------------------------------------------------------------
diff --git a/airflow/www/views.py b/airflow/www/views.py
index a4cf951..f9b1116 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -476,6 +476,7 @@ class Airflow(BaseView):
             embed=embed)
 
     @expose('/dag_stats')
+    @login_required
     def dag_stats(self):
         ds = models.DagStat
         session = Session()
@@ -510,6 +511,7 @@ class Airflow(BaseView):
         return wwwutils.json_response(payload)
 
     @expose('/task_stats')
+    @login_required
     def task_stats(self):
         TI = models.TaskInstance
         DagRun = models.DagRun

http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/0bf7adb2/tests/core.py
----------------------------------------------------------------------
diff --git a/tests/core.py b/tests/core.py
index f49dc2a..c08d63d 100644
--- a/tests/core.py
+++ b/tests/core.py
@@ -29,6 +29,7 @@ from datetime import datetime, time, timedelta
 from email.mime.multipart import MIMEMultipart
 from email.mime.application import MIMEApplication
 import signal
+from six.moves.urllib.parse import urlencode
 from time import sleep
 import warnings
 
@@ -1655,7 +1656,7 @@ class WebUiTests(unittest.TestCase):
         self.runme_0 = self.dag_bash.get_task('runme_0')
         self.example_xcom = self.dagbag.dags['example_xcom']
 
-        self.dag_bash2.create_dagrun(
+        self.dagrun_bash2 = self.dag_bash2.create_dagrun(
             run_id="test_{}".format(models.DagRun.id_for_date(datetime.utcnow())),
             execution_date=DEFAULT_DATE,
             start_date=datetime.utcnow(),
@@ -1678,8 +1679,18 @@ class WebUiTests(unittest.TestCase):
 
     def test_index(self):
         response = self.app.get('/', follow_redirects=True)
-        self.assertIn("DAGs", response.data.decode('utf-8'))
-        self.assertIn("example_bash_operator", response.data.decode('utf-8'))
+        resp_html = response.data.decode('utf-8')
+        self.assertIn("DAGs", resp_html)
+        self.assertIn("example_bash_operator", resp_html)
+
+        # The HTML should contain data for the last-run. A link to the specific run, and
the text of
+        # the date.
+        url = "/admin/airflow/graph?" + urlencode({
+            "dag_id": self.dag_bash2.dag_id,
+            "execution_date": self.dagrun_bash2.execution_date,
+            }).replace("&", "&amp;")
+        self.assertIn(url, resp_html)
+        self.assertIn(self.dagrun_bash2.execution_date.strftime("%Y-%m-%d %H:%M"), resp_html)
 
     def test_query(self):
         response = self.app.get('/admin/queryview/')


Mime
View raw message