[GitHub] [airflow] mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] Persisting serialized DAG in DB for webserver scalability

2019-10-22 Thread GitBox
mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] 
Persisting serialized DAG in DB for webserver scalability
URL: https://github.com/apache/airflow/pull/5743#discussion_r337772203
 
 

 ##
 File path: airflow/models/serialized_dag.py
 ##
 @@ -0,0 +1,214 @@
+# -*- coding: utf-8 -*-
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Serialzed DAG table in database."""
+
+import hashlib
+from datetime import timedelta
+from typing import TYPE_CHECKING, Any, Dict, List, Optional
+
+# from sqlalchemy import Column, Index, Integer, String, Text, JSON, and_, exc
+from sqlalchemy import JSON, Column, Index, Integer, String, and_
+from sqlalchemy.sql import exists
+
+from airflow.models.base import ID_LEN, Base
+from airflow.utils import db, timezone
+from airflow.utils.log.logging_mixin import LoggingMixin
+from airflow.utils.sqlalchemy import UtcDateTime
+
+if TYPE_CHECKING:
+from airflow.models import DAG  # noqa: F401; # pylint: 
disable=cyclic-import
+from airflow.serialization import SerializedDAG  # noqa: F401
+
+
+log = LoggingMixin().log
+
+
+class SerializedDagModel(Base):
+"""A table for serialized DAGs.
+
+serialized_dag table is a snapshot of DAG files synchronized by scheduler.
+This feature is controlled by:
+
+* ``[core] store_serialized_dags = True``: enable this feature
+* ``[core] min_serialized_dag_update_interval = 30`` (s):
+  serialized DAGs are updated in DB when a file gets processed by 
scheduler,
+  to reduce DB write rate, there is a minimal interval of updating 
serialized DAGs.
+* ``[scheduler] dag_dir_list_interval = 300`` (s):
+  interval of deleting serialized DAGs in DB when the files are deleted, 
suggest
+  to use a smaller interval such as 60
+
+It is used by webserver to load dagbags when 
``store_serialized_dags=True``.
+Because reading from database is lightweight compared to importing from 
files,
+it solves the webserver scalability issue.
+"""
+__tablename__ = 'serialized_dag'
+
+dag_id = Column(String(ID_LEN), primary_key=True)
+fileloc = Column(String(2000), nullable=False)
+# The max length of fileloc exceeds the limit of indexing.
+fileloc_hash = Column(Integer, nullable=False)
+data = Column(JSON, nullable=False)
+last_updated = Column(UtcDateTime, nullable=False)
+
+__table_args__ = (
+Index('idx_fileloc_hash', fileloc_hash, unique=False),
+)
+
+def __init__(self, dag: 'DAG'):
+from airflow.serialization import SerializedDAG  # noqa # pylint: 
disable=redefined-outer-name
+
+self.dag_id = dag.dag_id
+self.fileloc = dag.full_filepath
+self.fileloc_hash = self.dag_fileloc_hash(self.fileloc)
+self.data = SerializedDAG.to_dict(dag)
+self.last_updated = timezone.utcnow()
+
+@staticmethod
+def dag_fileloc_hash(full_filepath: str) -> int:
+Hashing file location for indexing.
+
+:param full_filepath: full filepath of DAG file
+:return: hashed full_filepath
+"""
+# hashing is needed because the length of fileloc is 2000 as an 
Airflow convention,
+# which is over the limit of indexing. If we can reduce the length of 
fileloc, then
+# hashing is not needed.
+return int.from_bytes(
+hashlib.sha1(full_filepath.encode('utf-8')).digest()[-2:], 
byteorder='big', signed=False)
+
+@classmethod
+@db.provide_session
+def write_dag(cls, dag: 'DAG', min_update_interval: Optional[int] = None, 
session=None):
+"""Serializes a DAG and writes it into database.
+
+:param dag: a DAG to be written into database
+:param min_update_interval: minimal interval in seconds to update 
serialized DAG
+:param session: ORM Session
+"""
+log.debug("Writing DAG: %s to the DB", dag)
+# Checks if (Current Time - Time when the DAG was written to DB) < 
min_update_interval
+# If Yes, does nothing
+# If No or the DAG does not exists, updates / writes Serialized DAG to 
DB
+if min_update_interval is not None:
+if session.query(exists().where(
+and_(cls.dag_id == 

[GitHub] [airflow] mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] Persisting serialized DAG in DB for webserver scalability

2019-10-15 Thread GitBox
mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] 
Persisting serialized DAG in DB for webserver scalability
URL: https://github.com/apache/airflow/pull/5743#discussion_r335183403
 
 

 ##
 File path: docs/howto/enable-dag-serialization.rst
 ##
 @@ -0,0 +1,109 @@
+ .. Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+ ..   http://www.apache.org/licenses/LICENSE-2.0
+
+ .. Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+
+
+
+
+Enable DAG Serialization
+
+
+Add the following settings in ``airflow.cfg``:
+
+.. code-block:: ini
+
+[core]
+store_serialized_dags = True
+min_serialized_dag_update_interval = 30
+
+*   ``store_serialized_dags``: This flag decides whether to serialises DAGs 
and persist them in DB.
+If set to True, Webserver reads from DB instead of parsing DAG files
+*   ``min_serialized_dag_update_interval``: This flag sets the minimum 
interval (in seconds) after which
+the serialized DAG in DB should be updated. This helps in reducing 
database write rate.
+
+If you are updating Airflow from <1.10.6, please do not forget to run 
``airflow db upgrade``.
+
+
+How it works
+
+
+In order to make Airflow Webserver stateless (almost!), Airflow >=1.10.6 
supports
+DAG Serialization and DB Persistence.
+
+.. image:: ../img/dag_serialization.png
+
+As shown in the image above in Vanilla Airflow, the Webserver and the 
Scheduler both
+needs access to the DAG files. Both the scheduler and webserver parses the DAG 
files.
+
+With **DAG Serialization** we aim to decouple the webserver from DAG parsing
+which would make the Webserver very light-weight.
+
+As shown in the image above, when using the dag_serilization feature,
+the Scheduler parses the DAG files, serializes them in JSON format and saves 
them in the Metadata DB.
+
+The Webserver now instead of having to parse the DAG file again, reads the
+serialized DAGs in JSON, de-serializes them and create the DagBag and uses it
+to show in the UI.
+
+One of the key features that is implemented as the part of DAG Serialization 
is that
+instead of loading an entire DagBag when the WebServer starts we only load 
each DAG on demand from the
+Serialized Dag table. This helps reduce Webserver startup time and memory. The 
reduction is notable
+when you have large number of DAGs.
+
+Below is the screenshot of the ``serialized_dag`` table in Metadata DB:
+
+.. image:: ../img/serialized_dag_table.png
+
+Limitations
+---
+The Webserver will still need access to DAG files in the following cases,
+which is why we said "almost" stateless.
+
+*   **Rendered Template** tab will still have to parse Python file as it needs 
all the details like
+the execution date and even the data passed by the upstream task using 
Xcom.
+*   **Code View** will read the DAG File & show it using Pygments.
+However, it does not need to Parse the Python file so it is still a small 
operation.
+*   :doc:`Extra Operator Links ` would not work out of
+the box. They need to be defined in Airflow Plugin.
+
+**Existing Airflow Operators**:
+To make extra operator links work with existing operators like BigQuery, 
copy all
+the classes that are defined in ``operator_extra_links`` property.
+
+For :class:`~airflow.gcp.operators.bigquery.BigQueryOperator` you can 
create the following plugin for extra links:
+
+.. code-block:: python
+
+from airflow.plugins_manager import AirflowPlugin
+from airflow.models.baseoperator import BaseOperatorLink
+from airflow.gcp.operators.bigquery import BigQueryOperator
+
+class BigQueryConsoleLink(BaseOperatorLink):
+"""
+Helper class for constructing BigQuery link.
+"""
+name = 'BigQuery Console'
+operators = [BigQueryOperator]
+
+def get_link(self, operator, dttm):
+ti = TaskInstance(task=operator, execution_date=dttm)
+job_id = ti.xcom_pull(task_ids=operator.task_id, key='job_id')
+return BIGQUERY_JOB_DETAILS_LINK_FMT.format(job_id=job_id) if 
job_id else ''
 
 Review comment:
   This code is not 100% valid. It has been updated. 
https://github.com/apache/airflow/pull/5906/files


[GitHub] [airflow] mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] Persisting serialized DAG in DB for webserver scalability

2019-10-15 Thread GitBox
mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] 
Persisting serialized DAG in DB for webserver scalability
URL: https://github.com/apache/airflow/pull/5743#discussion_r335182483
 
 

 ##
 File path: docs/howto/enable-dag-serialization.rst
 ##
 @@ -0,0 +1,109 @@
+ .. Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+ ..   http://www.apache.org/licenses/LICENSE-2.0
+
+ .. Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+
+
+
+
+Enable DAG Serialization
+
+
+Add the following settings in ``airflow.cfg``:
+
+.. code-block:: ini
+
+[core]
+store_serialized_dags = True
+min_serialized_dag_update_interval = 30
+
+*   ``store_serialized_dags``: This flag decides whether to serialises DAGs 
and persist them in DB.
+If set to True, Webserver reads from DB instead of parsing DAG files
+*   ``min_serialized_dag_update_interval``: This flag sets the minimum 
interval (in seconds) after which
+the serialized DAG in DB should be updated. This helps in reducing 
database write rate.
+
+If you are updating Airflow from <1.10.6, please do not forget to run 
``airflow db upgrade``.
+
+
+How it works
+
+
+In order to make Airflow Webserver stateless (almost!), Airflow >=1.10.6 
supports
+DAG Serialization and DB Persistence.
+
+.. image:: ../img/dag_serialization.png
+
+As shown in the image above in Vanilla Airflow, the Webserver and the 
Scheduler both
+needs access to the DAG files. Both the scheduler and webserver parses the DAG 
files.
+
+With **DAG Serialization** we aim to decouple the webserver from DAG parsing
+which would make the Webserver very light-weight.
+
+As shown in the image above, when using the dag_serilization feature,
+the Scheduler parses the DAG files, serializes them in JSON format and saves 
them in the Metadata DB.
+
+The Webserver now instead of having to parse the DAG file again, reads the
+serialized DAGs in JSON, de-serializes them and create the DagBag and uses it
+to show in the UI.
+
+One of the key features that is implemented as the part of DAG Serialization 
is that
+instead of loading an entire DagBag when the WebServer starts we only load 
each DAG on demand from the
+Serialized Dag table. This helps reduce Webserver startup time and memory. The 
reduction is notable
+when you have large number of DAGs.
+
+Below is the screenshot of the ``serialized_dag`` table in Metadata DB:
+
+.. image:: ../img/serialized_dag_table.png
+
+Limitations
+---
+The Webserver will still need access to DAG files in the following cases,
+which is why we said "almost" stateless.
+
+*   **Rendered Template** tab will still have to parse Python file as it needs 
all the details like
+the execution date and even the data passed by the upstream task using 
Xcom.
+*   **Code View** will read the DAG File & show it using Pygments.
+However, it does not need to Parse the Python file so it is still a small 
operation.
+*   :doc:`Extra Operator Links ` would not work out of
+the box. They need to be defined in Airflow Plugin.
+
+**Existing Airflow Operators**:
+To make extra operator links work with existing operators like BigQuery, 
copy all
+the classes that are defined in ``operator_extra_links`` property.
+
+For :class:`~airflow.gcp.operators.bigquery.BigQueryOperator` you can 
create the following plugin for extra links:
+
+.. code-block:: python
+
+from airflow.plugins_manager import AirflowPlugin
 
 Review comment:
   I'm not a fan of posting python code in rst files. We use literalinclude for 
GCP guides. This allows us to automatically test code snippets from the 
documentation


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] Persisting serialized DAG in DB for webserver scalability

2019-10-15 Thread GitBox
mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] 
Persisting serialized DAG in DB for webserver scalability
URL: https://github.com/apache/airflow/pull/5743#discussion_r335181941
 
 

 ##
 File path: docs/howto/enable-dag-serialization.rst
 ##
 @@ -0,0 +1,109 @@
+ .. Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+ ..   http://www.apache.org/licenses/LICENSE-2.0
+
+ .. Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+
+
+
+
+Enable DAG Serialization
+
+
+Add the following settings in ``airflow.cfg``:
+
+.. code-block:: ini
+
+[core]
+store_serialized_dags = True
+min_serialized_dag_update_interval = 30
+
+*   ``store_serialized_dags``: This flag decides whether to serialises DAGs 
and persist them in DB.
+If set to True, Webserver reads from DB instead of parsing DAG files
+*   ``min_serialized_dag_update_interval``: This flag sets the minimum 
interval (in seconds) after which
+the serialized DAG in DB should be updated. This helps in reducing 
database write rate.
+
+If you are updating Airflow from <1.10.6, please do not forget to run 
``airflow db upgrade``.
+
+
+How it works
+
+
+In order to make Airflow Webserver stateless (almost!), Airflow >=1.10.6 
supports
+DAG Serialization and DB Persistence.
+
+.. image:: ../img/dag_serialization.png
+
+As shown in the image above in Vanilla Airflow, the Webserver and the 
Scheduler both
+needs access to the DAG files. Both the scheduler and webserver parses the DAG 
files.
+
+With **DAG Serialization** we aim to decouple the webserver from DAG parsing
+which would make the Webserver very light-weight.
+
+As shown in the image above, when using the dag_serilization feature,
+the Scheduler parses the DAG files, serializes them in JSON format and saves 
them in the Metadata DB.
+
+The Webserver now instead of having to parse the DAG file again, reads the
+serialized DAGs in JSON, de-serializes them and create the DagBag and uses it
+to show in the UI.
+
+One of the key features that is implemented as the part of DAG Serialization 
is that
+instead of loading an entire DagBag when the WebServer starts we only load 
each DAG on demand from the
+Serialized Dag table. This helps reduce Webserver startup time and memory. The 
reduction is notable
+when you have large number of DAGs.
+
+Below is the screenshot of the ``serialized_dag`` table in Metadata DB:
+
+.. image:: ../img/serialized_dag_table.png
+
+Limitations
+---
+The Webserver will still need access to DAG files in the following cases,
+which is why we said "almost" stateless.
+
+*   **Rendered Template** tab will still have to parse Python file as it needs 
all the details like
+the execution date and even the data passed by the upstream task using 
Xcom.
+*   **Code View** will read the DAG File & show it using Pygments.
+However, it does not need to Parse the Python file so it is still a small 
operation.
+*   :doc:`Extra Operator Links ` would not work out of
+the box. They need to be defined in Airflow Plugin.
+
+**Existing Airflow Operators**:
 
 Review comment:
   I don't understand the relationship of this text to DAG serialization


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] Persisting serialized DAG in DB for webserver scalability

2019-10-15 Thread GitBox
mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] 
Persisting serialized DAG in DB for webserver scalability
URL: https://github.com/apache/airflow/pull/5743#discussion_r335179483
 
 

 ##
 File path: docs/howto/enable-dag-serialization.rst
 ##
 @@ -0,0 +1,109 @@
+ .. Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+ ..   http://www.apache.org/licenses/LICENSE-2.0
+
+ .. Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+
+
+
+
+Enable DAG Serialization
+
+
+Add the following settings in ``airflow.cfg``:
+
+.. code-block:: ini
+
+[core]
+store_serialized_dags = True
+min_serialized_dag_update_interval = 30
+
+*   ``store_serialized_dags``: This flag decides whether to serialises DAGs 
and persist them in DB.
+If set to True, Webserver reads from DB instead of parsing DAG files
+*   ``min_serialized_dag_update_interval``: This flag sets the minimum 
interval (in seconds) after which
+the serialized DAG in DB should be updated. This helps in reducing 
database write rate.
+
+If you are updating Airflow from <1.10.6, please do not forget to run 
``airflow db upgrade``.
+
+
+How it works
+
+
+In order to make Airflow Webserver stateless (almost!), Airflow >=1.10.6 
supports
+DAG Serialization and DB Persistence.
+
+.. image:: ../img/dag_serialization.png
+
+As shown in the image above in Vanilla Airflow, the Webserver and the 
Scheduler both
+needs access to the DAG files. Both the scheduler and webserver parses the DAG 
files.
+
+With **DAG Serialization** we aim to decouple the webserver from DAG parsing
+which would make the Webserver very light-weight.
+
+As shown in the image above, when using the dag_serilization feature,
 
 Review comment:
   ```suggestion
   As shown in the image above, when using the this feature,
   ```


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] Persisting serialized DAG in DB for webserver scalability

2019-10-15 Thread GitBox
mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] 
Persisting serialized DAG in DB for webserver scalability
URL: https://github.com/apache/airflow/pull/5743#discussion_r335179058
 
 

 ##
 File path: docs/howto/enable-dag-serialization.rst
 ##
 @@ -0,0 +1,109 @@
+ .. Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+ ..   http://www.apache.org/licenses/LICENSE-2.0
+
+ .. Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+
+
+
+
+Enable DAG Serialization
+
+
+Add the following settings in ``airflow.cfg``:
+
+.. code-block:: ini
+
+[core]
+store_serialized_dags = True
+min_serialized_dag_update_interval = 30
+
+*   ``store_serialized_dags``: This flag decides whether to serialises DAGs 
and persist them in DB.
+If set to True, Webserver reads from DB instead of parsing DAG files
+*   ``min_serialized_dag_update_interval``: This flag sets the minimum 
interval (in seconds) after which
+the serialized DAG in DB should be updated. This helps in reducing 
database write rate.
+
+If you are updating Airflow from <1.10.6, please do not forget to run 
``airflow db upgrade``.
+
+
+How it works
+
+
+In order to make Airflow Webserver stateless (almost!), Airflow >=1.10.6 
supports
+DAG Serialization and DB Persistence.
+
+.. image:: ../img/dag_serialization.png
+
+As shown in the image above in Vanilla Airflow, the Webserver and the 
Scheduler both
 
 Review comment:
   ```suggestion
   In Vanilla Airflow, the Webserver and the Scheduler both
   ```
   
   The term "Vanilia Airflow" seems strange to me. Are you sure you need to 
enter this terms in the documentation? I would prefer "Airflow with DAG 
persistence in DB" and "Airflow without DAG persistence in DB".


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] Persisting serialized DAG in DB for webserver scalability

2019-10-15 Thread GitBox
mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] 
Persisting serialized DAG in DB for webserver scalability
URL: https://github.com/apache/airflow/pull/5743#discussion_r335177865
 
 

 ##
 File path: docs/howto/enable-dag-serialization.rst
 ##
 @@ -0,0 +1,109 @@
+ .. Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+ ..   http://www.apache.org/licenses/LICENSE-2.0
+
+ .. Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+
+
+
+
+Enable DAG Serialization
 
 Review comment:
   I think that you should first describe the feature and then describe how to 
enable it.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] Persisting serialized DAG in DB for webserver scalability

2019-10-15 Thread GitBox
mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] 
Persisting serialized DAG in DB for webserver scalability
URL: https://github.com/apache/airflow/pull/5743#discussion_r334886490
 
 

 ##
 File path: airflow/models/baseoperator.py
 ##
 @@ -1021,8 +1039,8 @@ def xcom_pull(
 @cached_property
 def extra_links(self) -> Iterable[str]:
 """@property: extra links for the task. """
-return list(set(self.operator_extra_link_dict.keys())
-.union(self.global_operator_extra_link_dict.keys()))
+return sorted(list(set(self.operator_extra_link_dict.keys())
 
 Review comment:
   ```suggestion
   return sorted(set(self.operator_extra_link_dict.keys())
   ```


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] Persisting serialized DAG in DB for webserver scalability

2019-10-14 Thread GitBox
mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] 
Persisting serialized DAG in DB for webserver scalability
URL: https://github.com/apache/airflow/pull/5743#discussion_r334419161
 
 

 ##
 File path: airflow/dag/serialization/schema.json
 ##
 @@ -0,0 +1,196 @@
+{
+  "$schema": "http://json-schema.org/draft-07/schema#;,
+  "$id": "https://airflow.apache.com/schemas/serialized-dags.json;,
+  "definitions": {
+"datetime": {
+  "description": "A date time, stored as fractional seconds since the 
epoch",
+  "type": "number"
+},
+"typed_datetime": {
+  "type": "object",
+  "properties": {
+"__type": {
+  "type": "string",
+  "const": "datetime"
+},
+"__var": { "$ref": "#/definitions/datetime" }
+  },
+  "required": [
+"__type",
+"__var"
+  ],
+  "additionalProperties": false
+},
+"timedelta": {
+  "type": "number",
+  "minimum": 0
+},
+"typed_timedelta": {
+  "type": "object",
+  "properties": {
+"__type": {
+  "type": "string",
+  "const": "timedelta"
+},
+"__var": { "$ref": "#/definitions/timedelta" }
+  },
+  "required": [
+"__type",
+"__var"
+  ],
+  "additionalProperties": false
+},
+"typed_relativedelta": {
+  "type": "object",
+  "description": "A dateutil.relativedelta.relativedelta object",
+  "properties": {
+"__type": {
+  "type": "string",
+  "const": "relativedelta"
+},
+"__var": {
+  "type": "object",
+  "properties": {
+"weekday": {
+  "type": "array",
+  "items": { "type": "integer" },
+  "minItems": 1,
+  "maxItems": 2
+}
+  },
+  "additionalProperties": { "type": "integer" }
+}
+  }
+},
+"timezone": {
+  "type": "string"
+},
+"dict": {
+  "description": "A python dictionary containing values of any type",
+  "type": "object"
+},
+"color": {
+  "type": "string",
+  "pattern": "^#[a-fA-F0-9]{3,6}$"
+},
+"stringset": {
+  "description": "A set of strings",
+  "type": "object",
+  "properties": {
+"__type": {
+  "type": "string",
+  "const": "set"
+},
+"__var": {
+  "type": "array",
+  "items": { "type": "string" }
+}
+  },
+  "required": [
+"__type",
+"__var"
+  ]
+},
+"dag": {
+  "type": "object",
+  "properties": {
+"params": { "$ref": "#/definitions/dict" },
+"_dag_id": { "type": "string" },
+"task_dict": {  "$ref": "#/definitions/task_dict" },
+"timezone": { "$ref": "#/definitions/timezone" },
+"schedule_interval": {
+  "anyOf": [
+{ "type": "null" },
+{ "type": "string" },
+{ "$ref": "#/definitions/typed_timedelta" },
+{ "$ref": "#/definitions/typed_relativedelta" }
+  ]
+},
+"catchup": { "type": "boolean" },
+"is_subdag": { "type": "boolean" },
+"fileloc": { "type" : "string"},
+"orientation": { "type" : "string"},
+"_description": { "type" : "string"},
+"_concurrency": { "type" : "number"},
+"max_active_runs": { "type" : "number"},
+"default_args": { "$ref": "#/definitions/dict" },
+"start_date": { "$ref": "#/definitions/datetime" },
+"dagrun_timeout": { "$ref": "#/definitions/timedelta" },
+"doc_md": { "type" : "string"}
+  },
+  "required": [
+"params",
+"_dag_id",
+"fileloc",
+"task_dict"
+  ],
+  "additionalProperties": false
+},
+"task_dict": {
+  "type": "object",
+  "additionalProperties": { "$ref": "#/definitions/operator" }
+},
+"operator": {
+  "$comment": "A task/operator in a DAG",
+  "type": "object",
+  "required": [
+"_task_type",
+"_task_module",
+"task_id",
+"ui_color",
+"ui_fgcolor",
+"template_fields"
+  ],
+  "properties": {
+"_task_type": { "type": "string" },
+"_task_module": { "type": "string" },
+"task_id": { "type": "string" },
+"owner": { "type": "string" },
+"start_date": { "$ref": "#/definitions/datetime" },
+"end_date": { "$ref": "#/definitions/datetime" },
+"trigger_rule": { "type": "string" },
+"depends_on_past": { "type": "boolean" },
+"wait_for_downstream": { "type": "boolean" },
+"retries": { "type": "number" },
+"queue": { "type": "string" },
+"pool": { "type": "string" },
+"execution_timeout": { "$ref": "#/definitions/timedelta" },
+"retry_delay": { "$ref": "#/definitions/timedelta" },
+"retry_exponential_backoff": { 

[GitHub] [airflow] mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] Persisting serialized DAG in DB for webserver scalability

2019-10-14 Thread GitBox
mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] 
Persisting serialized DAG in DB for webserver scalability
URL: https://github.com/apache/airflow/pull/5743#discussion_r334419161
 
 

 ##
 File path: airflow/dag/serialization/schema.json
 ##
 @@ -0,0 +1,196 @@
+{
+  "$schema": "http://json-schema.org/draft-07/schema#;,
+  "$id": "https://airflow.apache.com/schemas/serialized-dags.json;,
+  "definitions": {
+"datetime": {
+  "description": "A date time, stored as fractional seconds since the 
epoch",
+  "type": "number"
+},
+"typed_datetime": {
+  "type": "object",
+  "properties": {
+"__type": {
+  "type": "string",
+  "const": "datetime"
+},
+"__var": { "$ref": "#/definitions/datetime" }
+  },
+  "required": [
+"__type",
+"__var"
+  ],
+  "additionalProperties": false
+},
+"timedelta": {
+  "type": "number",
+  "minimum": 0
+},
+"typed_timedelta": {
+  "type": "object",
+  "properties": {
+"__type": {
+  "type": "string",
+  "const": "timedelta"
+},
+"__var": { "$ref": "#/definitions/timedelta" }
+  },
+  "required": [
+"__type",
+"__var"
+  ],
+  "additionalProperties": false
+},
+"typed_relativedelta": {
+  "type": "object",
+  "description": "A dateutil.relativedelta.relativedelta object",
+  "properties": {
+"__type": {
+  "type": "string",
+  "const": "relativedelta"
+},
+"__var": {
+  "type": "object",
+  "properties": {
+"weekday": {
+  "type": "array",
+  "items": { "type": "integer" },
+  "minItems": 1,
+  "maxItems": 2
+}
+  },
+  "additionalProperties": { "type": "integer" }
+}
+  }
+},
+"timezone": {
+  "type": "string"
+},
+"dict": {
+  "description": "A python dictionary containing values of any type",
+  "type": "object"
+},
+"color": {
+  "type": "string",
+  "pattern": "^#[a-fA-F0-9]{3,6}$"
+},
+"stringset": {
+  "description": "A set of strings",
+  "type": "object",
+  "properties": {
+"__type": {
+  "type": "string",
+  "const": "set"
+},
+"__var": {
+  "type": "array",
+  "items": { "type": "string" }
+}
+  },
+  "required": [
+"__type",
+"__var"
+  ]
+},
+"dag": {
+  "type": "object",
+  "properties": {
+"params": { "$ref": "#/definitions/dict" },
+"_dag_id": { "type": "string" },
+"task_dict": {  "$ref": "#/definitions/task_dict" },
+"timezone": { "$ref": "#/definitions/timezone" },
+"schedule_interval": {
+  "anyOf": [
+{ "type": "null" },
+{ "type": "string" },
+{ "$ref": "#/definitions/typed_timedelta" },
+{ "$ref": "#/definitions/typed_relativedelta" }
+  ]
+},
+"catchup": { "type": "boolean" },
+"is_subdag": { "type": "boolean" },
+"fileloc": { "type" : "string"},
+"orientation": { "type" : "string"},
+"_description": { "type" : "string"},
+"_concurrency": { "type" : "number"},
+"max_active_runs": { "type" : "number"},
+"default_args": { "$ref": "#/definitions/dict" },
+"start_date": { "$ref": "#/definitions/datetime" },
+"dagrun_timeout": { "$ref": "#/definitions/timedelta" },
+"doc_md": { "type" : "string"}
+  },
+  "required": [
+"params",
+"_dag_id",
+"fileloc",
+"task_dict"
+  ],
+  "additionalProperties": false
+},
+"task_dict": {
+  "type": "object",
+  "additionalProperties": { "$ref": "#/definitions/operator" }
+},
+"operator": {
+  "$comment": "A task/operator in a DAG",
+  "type": "object",
+  "required": [
+"_task_type",
+"_task_module",
+"task_id",
+"ui_color",
+"ui_fgcolor",
+"template_fields"
+  ],
+  "properties": {
+"_task_type": { "type": "string" },
+"_task_module": { "type": "string" },
+"task_id": { "type": "string" },
+"owner": { "type": "string" },
+"start_date": { "$ref": "#/definitions/datetime" },
+"end_date": { "$ref": "#/definitions/datetime" },
+"trigger_rule": { "type": "string" },
+"depends_on_past": { "type": "boolean" },
+"wait_for_downstream": { "type": "boolean" },
+"retries": { "type": "number" },
+"queue": { "type": "string" },
+"pool": { "type": "string" },
+"execution_timeout": { "$ref": "#/definitions/timedelta" },
+"retry_delay": { "$ref": "#/definitions/timedelta" },
+"retry_exponential_backoff": { 

[GitHub] [airflow] mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] Persisting serialized DAG in DB for webserver scalability

2019-10-14 Thread GitBox
mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] 
Persisting serialized DAG in DB for webserver scalability
URL: https://github.com/apache/airflow/pull/5743#discussion_r334341545
 
 

 ##
 File path: airflow/dag/serialization/serialization.py
 ##
 @@ -53,81 +50,81 @@ class Serialization:
 _primitive_types = (int, bool, float, str)
 
 # Time types.
-_datetime_types = (datetime.datetime, datetime.date, datetime.time)
+# datetime.date and datetime.time are converted to strings.
+_datetime_types = (datetime.datetime,)
 
 # Object types that are always excluded in serialization.
 # FIXME: not needed if _included_fields of DAG and operator are customized.
 _excluded_types = (logging.Logger, Connection, type)
 
-_json_schema = None # type: Optional[Dict]
+_json_schema = None  # type: Optional[Validator]
+
+_CONSTRUCTOR_PARAMS = {}  # type: Dict[str, Parameter]
+
+SERIALIZER_VERSION = 1
 
 @classmethod
 def to_json(cls, var: Union[DAG, BaseOperator, dict, list, set, tuple]) -> 
str:
 """Stringifies DAGs and operators contained by var and returns a JSON 
string of var.
 """
-return json.dumps(cls._serialize(var, {}), ensure_ascii=True)
+return json.dumps(cls.to_dict(var), ensure_ascii=True)
 
 @classmethod
-def from_json(cls, json_str: str) -> Union[
+def to_dict(cls, var: Union[DAG, BaseOperator, dict, list, set, tuple]) -> 
dict:
+"""Stringifies DAGs and operators contained by var and returns a dict 
of var.
+"""
+# Don't call on this class directly - only SerializedDAG or
+# SerializedBaseOperator should be used as the "entrypoint"
+raise NotImplementedError()
+
+@classmethod
+def from_json(cls, serialized_obj: str) -> Union[
 'SerializedDAG', 'SerializedBaseOperator', dict, list, set, tuple]:
 """Deserializes json_str and reconstructs all DAGs and operators it 
contains."""
-return cls._deserialize(json.loads(json_str), {})
+return cls.from_dict(json.loads(serialized_obj))
 
 @classmethod
-def validate_json(cls, json_str: str):
-"""Validate json_str satisfies JSON schema."""
+def from_dict(cls, serialized_obj: dict) -> Union[
+'SerializedDAG', 'SerializedBaseOperator', dict, list, set, tuple]:
+"""Deserializes a python dict stored with type decorators and
+reconstructs all DAGs and operators it contains."""
+return cls._deserialize(serialized_obj)
+
+@classmethod
+def validate_schema(cls, serialized_obj: Union[str, dict]):
+"""Validate serialized_obj satisfies JSON schema."""
 if cls._json_schema is None:
 raise AirflowException('JSON schema of {:s} is not 
set.'.format(cls.__name__))
-jsonschema.validate(json.loads(json_str), cls._json_schema)
+
+if isinstance(serialized_obj, dict):
+cls._json_schema.validate(serialized_obj)
+elif isinstance(serialized_obj, str):
+cls._json_schema.validate(json.loads(serialized_obj))
 
 Review comment:
   ```suggestion
   cls._json_schema.validate(json.loads(serialized_obj))
  else:
  raise TypeError("Invalid type: Only dict and str are supported.")
   ```
   It is better not to return None in an undefined state.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] Persisting serialized DAG in DB for webserver scalability

2019-10-14 Thread GitBox
mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] 
Persisting serialized DAG in DB for webserver scalability
URL: https://github.com/apache/airflow/pull/5743#discussion_r334341545
 
 

 ##
 File path: airflow/dag/serialization/serialization.py
 ##
 @@ -53,81 +50,81 @@ class Serialization:
 _primitive_types = (int, bool, float, str)
 
 # Time types.
-_datetime_types = (datetime.datetime, datetime.date, datetime.time)
+# datetime.date and datetime.time are converted to strings.
+_datetime_types = (datetime.datetime,)
 
 # Object types that are always excluded in serialization.
 # FIXME: not needed if _included_fields of DAG and operator are customized.
 _excluded_types = (logging.Logger, Connection, type)
 
-_json_schema = None # type: Optional[Dict]
+_json_schema = None  # type: Optional[Validator]
+
+_CONSTRUCTOR_PARAMS = {}  # type: Dict[str, Parameter]
+
+SERIALIZER_VERSION = 1
 
 @classmethod
 def to_json(cls, var: Union[DAG, BaseOperator, dict, list, set, tuple]) -> 
str:
 """Stringifies DAGs and operators contained by var and returns a JSON 
string of var.
 """
-return json.dumps(cls._serialize(var, {}), ensure_ascii=True)
+return json.dumps(cls.to_dict(var), ensure_ascii=True)
 
 @classmethod
-def from_json(cls, json_str: str) -> Union[
+def to_dict(cls, var: Union[DAG, BaseOperator, dict, list, set, tuple]) -> 
dict:
+"""Stringifies DAGs and operators contained by var and returns a dict 
of var.
+"""
+# Don't call on this class directly - only SerializedDAG or
+# SerializedBaseOperator should be used as the "entrypoint"
+raise NotImplementedError()
+
+@classmethod
+def from_json(cls, serialized_obj: str) -> Union[
 'SerializedDAG', 'SerializedBaseOperator', dict, list, set, tuple]:
 """Deserializes json_str and reconstructs all DAGs and operators it 
contains."""
-return cls._deserialize(json.loads(json_str), {})
+return cls.from_dict(json.loads(serialized_obj))
 
 @classmethod
-def validate_json(cls, json_str: str):
-"""Validate json_str satisfies JSON schema."""
+def from_dict(cls, serialized_obj: dict) -> Union[
+'SerializedDAG', 'SerializedBaseOperator', dict, list, set, tuple]:
+"""Deserializes a python dict stored with type decorators and
+reconstructs all DAGs and operators it contains."""
+return cls._deserialize(serialized_obj)
+
+@classmethod
+def validate_schema(cls, serialized_obj: Union[str, dict]):
+"""Validate serialized_obj satisfies JSON schema."""
 if cls._json_schema is None:
 raise AirflowException('JSON schema of {:s} is not 
set.'.format(cls.__name__))
-jsonschema.validate(json.loads(json_str), cls._json_schema)
+
+if isinstance(serialized_obj, dict):
+cls._json_schema.validate(serialized_obj)
+elif isinstance(serialized_obj, str):
+cls._json_schema.validate(json.loads(serialized_obj))
 
 Review comment:
   ```suggestion
   cls._json_schema.validate(json.loads(serialized_obj))
  else:
  raise ValueError("Invalid type: Only dict and str are supported.")
   ```
   It is better not to return None in an undefined state.


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] Persisting serialized DAG in DB for webserver scalability

2019-10-14 Thread GitBox
mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] 
Persisting serialized DAG in DB for webserver scalability
URL: https://github.com/apache/airflow/pull/5743#discussion_r334341545
 
 

 ##
 File path: airflow/dag/serialization/serialization.py
 ##
 @@ -53,81 +50,81 @@ class Serialization:
 _primitive_types = (int, bool, float, str)
 
 # Time types.
-_datetime_types = (datetime.datetime, datetime.date, datetime.time)
+# datetime.date and datetime.time are converted to strings.
+_datetime_types = (datetime.datetime,)
 
 # Object types that are always excluded in serialization.
 # FIXME: not needed if _included_fields of DAG and operator are customized.
 _excluded_types = (logging.Logger, Connection, type)
 
-_json_schema = None # type: Optional[Dict]
+_json_schema = None  # type: Optional[Validator]
+
+_CONSTRUCTOR_PARAMS = {}  # type: Dict[str, Parameter]
+
+SERIALIZER_VERSION = 1
 
 @classmethod
 def to_json(cls, var: Union[DAG, BaseOperator, dict, list, set, tuple]) -> 
str:
 """Stringifies DAGs and operators contained by var and returns a JSON 
string of var.
 """
-return json.dumps(cls._serialize(var, {}), ensure_ascii=True)
+return json.dumps(cls.to_dict(var), ensure_ascii=True)
 
 @classmethod
-def from_json(cls, json_str: str) -> Union[
+def to_dict(cls, var: Union[DAG, BaseOperator, dict, list, set, tuple]) -> 
dict:
+"""Stringifies DAGs and operators contained by var and returns a dict 
of var.
+"""
+# Don't call on this class directly - only SerializedDAG or
+# SerializedBaseOperator should be used as the "entrypoint"
+raise NotImplementedError()
+
+@classmethod
+def from_json(cls, serialized_obj: str) -> Union[
 'SerializedDAG', 'SerializedBaseOperator', dict, list, set, tuple]:
 """Deserializes json_str and reconstructs all DAGs and operators it 
contains."""
-return cls._deserialize(json.loads(json_str), {})
+return cls.from_dict(json.loads(serialized_obj))
 
 @classmethod
-def validate_json(cls, json_str: str):
-"""Validate json_str satisfies JSON schema."""
+def from_dict(cls, serialized_obj: dict) -> Union[
+'SerializedDAG', 'SerializedBaseOperator', dict, list, set, tuple]:
+"""Deserializes a python dict stored with type decorators and
+reconstructs all DAGs and operators it contains."""
+return cls._deserialize(serialized_obj)
+
+@classmethod
+def validate_schema(cls, serialized_obj: Union[str, dict]):
+"""Validate serialized_obj satisfies JSON schema."""
 if cls._json_schema is None:
 raise AirflowException('JSON schema of {:s} is not 
set.'.format(cls.__name__))
-jsonschema.validate(json.loads(json_str), cls._json_schema)
+
+if isinstance(serialized_obj, dict):
+cls._json_schema.validate(serialized_obj)
+elif isinstance(serialized_obj, str):
+cls._json_schema.validate(json.loads(serialized_obj))
 
 Review comment:
   ```suggestion
   cls._json_schema.validate(json.loads(serialized_obj))
  else:
  raise ValueError("Invalid type: Only dict and str are supported.")
   ```


This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [airflow] mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] Persisting serialized DAG in DB for webserver scalability

2019-10-14 Thread GitBox
mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] 
Persisting serialized DAG in DB for webserver scalability
URL: https://github.com/apache/airflow/pull/5743#discussion_r334340613
 
 

 ##
 File path: airflow/dag/serialization/schema.json
 ##
 @@ -0,0 +1,196 @@
+{
+  "$schema": "http://json-schema.org/draft-07/schema#;,
+  "$id": "https://airflow.apache.com/schemas/serialized-dags.json;,
+  "definitions": {
+"datetime": {
+  "description": "A date time, stored as fractional seconds since the 
epoch",
+  "type": "number"
+},
+"typed_datetime": {
+  "type": "object",
+  "properties": {
+"__type": {
+  "type": "string",
+  "const": "datetime"
+},
+"__var": { "$ref": "#/definitions/datetime" }
+  },
+  "required": [
+"__type",
+"__var"
+  ],
+  "additionalProperties": false
+},
+"timedelta": {
+  "type": "number",
+  "minimum": 0
+},
+"typed_timedelta": {
+  "type": "object",
+  "properties": {
+"__type": {
+  "type": "string",
+  "const": "timedelta"
+},
+"__var": { "$ref": "#/definitions/timedelta" }
+  },
+  "required": [
+"__type",
+"__var"
+  ],
+  "additionalProperties": false
+},
+"typed_relativedelta": {
+  "type": "object",
+  "description": "A dateutil.relativedelta.relativedelta object",
+  "properties": {
+"__type": {
+  "type": "string",
+  "const": "relativedelta"
+},
+"__var": {
+  "type": "object",
+  "properties": {
+"weekday": {
+  "type": "array",
+  "items": { "type": "integer" },
+  "minItems": 1,
+  "maxItems": 2
+}
+  },
+  "additionalProperties": { "type": "integer" }
+}
+  }
+},
+"timezone": {
+  "type": "string"
+},
+"dict": {
+  "description": "A python dictionary containing values of any type",
+  "type": "object"
+},
+"color": {
+  "type": "string",
+  "pattern": "^#[a-fA-F0-9]{3,6}$"
+},
+"stringset": {
+  "description": "A set of strings",
+  "type": "object",
+  "properties": {
+"__type": {
+  "type": "string",
+  "const": "set"
+},
+"__var": {
+  "type": "array",
+  "items": { "type": "string" }
+}
+  },
+  "required": [
+"__type",
+"__var"
+  ]
+},
+"dag": {
+  "type": "object",
+  "properties": {
+"params": { "$ref": "#/definitions/dict" },
+"_dag_id": { "type": "string" },
+"task_dict": {  "$ref": "#/definitions/task_dict" },
+"timezone": { "$ref": "#/definitions/timezone" },
+"schedule_interval": {
+  "anyOf": [
+{ "type": "null" },
+{ "type": "string" },
+{ "$ref": "#/definitions/typed_timedelta" },
+{ "$ref": "#/definitions/typed_relativedelta" }
+  ]
+},
+"catchup": { "type": "boolean" },
+"is_subdag": { "type": "boolean" },
+"fileloc": { "type" : "string"},
+"orientation": { "type" : "string"},
+"_description": { "type" : "string"},
+"_concurrency": { "type" : "number"},
+"max_active_runs": { "type" : "number"},
+"default_args": { "$ref": "#/definitions/dict" },
+"start_date": { "$ref": "#/definitions/datetime" },
+"dagrun_timeout": { "$ref": "#/definitions/timedelta" },
+"doc_md": { "type" : "string"}
+  },
+  "required": [
+"params",
+"_dag_id",
+"fileloc",
+"task_dict"
+  ],
+  "additionalProperties": false
+},
+"task_dict": {
+  "type": "object",
+  "additionalProperties": { "$ref": "#/definitions/operator" }
+},
+"operator": {
+  "$comment": "A task/operator in a DAG",
+  "type": "object",
+  "required": [
+"_task_type",
+"_task_module",
+"task_id",
+"ui_color",
+"ui_fgcolor",
+"template_fields"
+  ],
+  "properties": {
+"_task_type": { "type": "string" },
+"_task_module": { "type": "string" },
+"task_id": { "type": "string" },
+"owner": { "type": "string" },
+"start_date": { "$ref": "#/definitions/datetime" },
+"end_date": { "$ref": "#/definitions/datetime" },
+"trigger_rule": { "type": "string" },
+"depends_on_past": { "type": "boolean" },
+"wait_for_downstream": { "type": "boolean" },
+"retries": { "type": "number" },
+"queue": { "type": "string" },
+"pool": { "type": "string" },
+"execution_timeout": { "$ref": "#/definitions/timedelta" },
+"retry_delay": { "$ref": "#/definitions/timedelta" },
+"retry_exponential_backoff": { 

[GitHub] [airflow] mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] Persisting serialized DAG in DB for webserver scalability

2019-10-14 Thread GitBox
mik-laj commented on a change in pull request #5743: [AIRFLOW-5088][AIP-24] 
Persisting serialized DAG in DB for webserver scalability
URL: https://github.com/apache/airflow/pull/5743#discussion_r334340394
 
 

 ##
 File path: airflow/dag/serialization/schema.json
 ##
 @@ -0,0 +1,196 @@
+{
+  "$schema": "http://json-schema.org/draft-07/schema#;,
+  "$id": "https://airflow.apache.com/schemas/serialized-dags.json;,
+  "definitions": {
+"datetime": {
+  "description": "A date time, stored as fractional seconds since the 
epoch",
+  "type": "number"
+},
+"typed_datetime": {
+  "type": "object",
+  "properties": {
+"__type": {
+  "type": "string",
+  "const": "datetime"
+},
+"__var": { "$ref": "#/definitions/datetime" }
+  },
+  "required": [
+"__type",
+"__var"
+  ],
+  "additionalProperties": false
+},
+"timedelta": {
+  "type": "number",
+  "minimum": 0
+},
+"typed_timedelta": {
+  "type": "object",
+  "properties": {
+"__type": {
+  "type": "string",
+  "const": "timedelta"
+},
+"__var": { "$ref": "#/definitions/timedelta" }
+  },
+  "required": [
+"__type",
+"__var"
+  ],
+  "additionalProperties": false
+},
+"typed_relativedelta": {
+  "type": "object",
+  "description": "A dateutil.relativedelta.relativedelta object",
+  "properties": {
+"__type": {
+  "type": "string",
+  "const": "relativedelta"
+},
+"__var": {
+  "type": "object",
+  "properties": {
+"weekday": {
+  "type": "array",
+  "items": { "type": "integer" },
+  "minItems": 1,
+  "maxItems": 2
+}
+  },
+  "additionalProperties": { "type": "integer" }
+}
+  }
+},
+"timezone": {
+  "type": "string"
+},
+"dict": {
+  "description": "A python dictionary containing values of any type",
+  "type": "object"
+},
+"color": {
+  "type": "string",
+  "pattern": "^#[a-fA-F0-9]{3,6}$"
+},
+"stringset": {
+  "description": "A set of strings",
+  "type": "object",
+  "properties": {
+"__type": {
+  "type": "string",
+  "const": "set"
+},
+"__var": {
+  "type": "array",
+  "items": { "type": "string" }
+}
+  },
+  "required": [
+"__type",
+"__var"
+  ]
+},
+"dag": {
+  "type": "object",
+  "properties": {
+"params": { "$ref": "#/definitions/dict" },
+"_dag_id": { "type": "string" },
+"task_dict": {  "$ref": "#/definitions/task_dict" },
+"timezone": { "$ref": "#/definitions/timezone" },
+"schedule_interval": {
+  "anyOf": [
+{ "type": "null" },
+{ "type": "string" },
+{ "$ref": "#/definitions/typed_timedelta" },
+{ "$ref": "#/definitions/typed_relativedelta" }
+  ]
+},
+"catchup": { "type": "boolean" },
+"is_subdag": { "type": "boolean" },
+"fileloc": { "type" : "string"},
+"orientation": { "type" : "string"},
+"_description": { "type" : "string"},
+"_concurrency": { "type" : "number"},
+"max_active_runs": { "type" : "number"},
+"default_args": { "$ref": "#/definitions/dict" },
+"start_date": { "$ref": "#/definitions/datetime" },
+"dagrun_timeout": { "$ref": "#/definitions/timedelta" },
+"doc_md": { "type" : "string"}
+  },
+  "required": [
+"params",
+"_dag_id",
+"fileloc",
+"task_dict"
+  ],
+  "additionalProperties": false
+},
+"task_dict": {
+  "type": "object",
+  "additionalProperties": { "$ref": "#/definitions/operator" }
+},
+"operator": {
+  "$comment": "A task/operator in a DAG",
+  "type": "object",
+  "required": [
+"_task_type",
+"_task_module",
+"task_id",
+"ui_color",
+"ui_fgcolor",
+"template_fields"
+  ],
+  "properties": {
+"_task_type": { "type": "string" },
+"_task_module": { "type": "string" },
+"task_id": { "type": "string" },
+"owner": { "type": "string" },
+"start_date": { "$ref": "#/definitions/datetime" },
+"end_date": { "$ref": "#/definitions/datetime" },
+"trigger_rule": { "type": "string" },
+"depends_on_past": { "type": "boolean" },
+"wait_for_downstream": { "type": "boolean" },
+"retries": { "type": "number" },
+"queue": { "type": "string" },
+"pool": { "type": "string" },
+"execution_timeout": { "$ref": "#/definitions/timedelta" },
+"retry_delay": { "$ref": "#/definitions/timedelta" },
+"retry_exponential_backoff": {