You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/05/28 07:37:54 UTC

[GitHub] [airflow] mik-laj opened a new pull request #9045: [WIP] Add basic read-only DAG Model endpoints

mik-laj opened a new pull request #9045:
URL: https://github.com/apache/airflow/pull/9045


   ---
   Make sure to mark the boxes below before creating PR: [x]
   
   - [X] Description above provides context of the change
   - [X] Unit tests coverage for changes (not needed for documentation changes)
   - [X] Target Github ISSUE in description if exists
   - [X] Commits follow "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)"
   - [X] Relevant documentation is updated including usage instructions.
   - [X] I will engage committers as explained in [Contribution Workflow Example](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#contribution-workflow-example).
   
   ---
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
   Read the [Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines) for more information.
   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] mik-laj merged pull request #9045: Add read-only endpoints for DAG Model

Posted by GitBox <gi...@apache.org>.
mik-laj merged pull request #9045:
URL: https://github.com/apache/airflow/pull/9045


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] mik-laj commented on a change in pull request #9045: Add read-only endpoints for DAG Model

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #9045:
URL: https://github.com/apache/airflow/pull/9045#discussion_r451470554



##########
File path: tests/api_connexion/endpoints/test_dag_endpoint.py
##########
@@ -133,11 +163,101 @@ def test_should_response_200_serialized(self):
 
 
 class TestGetDags(TestDagEndpoint):
-    @pytest.mark.skip(reason="Not implemented yet")
+
     def test_should_response_200(self):
-        response = self.client.get("/api/v1/dags/1")
+        self._create_dag_models(2)
+
+        response = self.client.get("api/v1/dags")
+
+        assert response.status_code == 200
+
+        self.assertEqual(
+            {
+                "dags": [
+                    {
+                        "dag_id": "TEST_DAG_1",
+                        "description": None,
+                        "fileloc": "/tmp/dag_1.py",
+                        "is_paused": False,
+                        "is_subdag": False,
+                        "owners": [],
+                        "root_dag_id": None,
+                        "schedule_interval": {"__type": "CronExpression", "value": "2 2 * * *"},
+                        "tags": [],
+                    },
+                    {
+                        "dag_id": "TEST_DAG_2",
+                        "description": None,
+                        "fileloc": "/tmp/dag_2.py",
+                        "is_paused": False,
+                        "is_subdag": False,
+                        "owners": [],
+                        "root_dag_id": None,
+                        "schedule_interval": {"__type": "CronExpression", "value": "2 2 * * *"},
+                        "tags": [],
+                    },
+                ],
+                "total_entries": 2,
+            },
+            response.json,
+        )
+
+    @parameterized.expand(
+        [
+            ("api/v1/dags?limit=1", ["TEST_DAG_1"]),
+            ("api/v1/dags?limit=2", ["TEST_DAG_1", "TEST_DAG_10"]),
+            (
+                "api/v1/dags?offset=5",
+                [
+                    "TEST_DAG_5",
+                    "TEST_DAG_6",
+                    "TEST_DAG_7",
+                    "TEST_DAG_8",
+                    "TEST_DAG_9",
+                ],
+            ),
+            (
+                "api/v1/dags?offset=0",
+                [
+                    "TEST_DAG_1",
+                    "TEST_DAG_10",
+                    "TEST_DAG_2",
+                    "TEST_DAG_3",

Review comment:
       Sorting numbers in strings is always tricky. ;-) 




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] turbaszek commented on a change in pull request #9045: Add read-only endpoints for DAG Model

Posted by GitBox <gi...@apache.org>.
turbaszek commented on a change in pull request #9045:
URL: https://github.com/apache/airflow/pull/9045#discussion_r451461848



##########
File path: tests/api_connexion/endpoints/test_dag_endpoint.py
##########
@@ -133,11 +163,101 @@ def test_should_response_200_serialized(self):
 
 
 class TestGetDags(TestDagEndpoint):
-    @pytest.mark.skip(reason="Not implemented yet")
+
     def test_should_response_200(self):
-        response = self.client.get("/api/v1/dags/1")
+        self._create_dag_models(2)
+
+        response = self.client.get("api/v1/dags")
+
+        assert response.status_code == 200
+
+        self.assertEqual(
+            {
+                "dags": [
+                    {
+                        "dag_id": "TEST_DAG_1",
+                        "description": None,
+                        "fileloc": "/tmp/dag_1.py",
+                        "is_paused": False,
+                        "is_subdag": False,
+                        "owners": [],
+                        "root_dag_id": None,
+                        "schedule_interval": {"__type": "CronExpression", "value": "2 2 * * *"},
+                        "tags": [],
+                    },
+                    {
+                        "dag_id": "TEST_DAG_2",
+                        "description": None,
+                        "fileloc": "/tmp/dag_2.py",
+                        "is_paused": False,
+                        "is_subdag": False,
+                        "owners": [],
+                        "root_dag_id": None,
+                        "schedule_interval": {"__type": "CronExpression", "value": "2 2 * * *"},
+                        "tags": [],
+                    },
+                ],
+                "total_entries": 2,
+            },
+            response.json,
+        )
+
+    @parameterized.expand(
+        [
+            ("api/v1/dags?limit=1", ["TEST_DAG_1"]),
+            ("api/v1/dags?limit=2", ["TEST_DAG_1", "TEST_DAG_10"]),
+            (
+                "api/v1/dags?offset=5",
+                [
+                    "TEST_DAG_5",
+                    "TEST_DAG_6",
+                    "TEST_DAG_7",
+                    "TEST_DAG_8",
+                    "TEST_DAG_9",
+                ],
+            ),
+            (
+                "api/v1/dags?offset=0",
+                [
+                    "TEST_DAG_1",
+                    "TEST_DAG_10",
+                    "TEST_DAG_2",
+                    "TEST_DAG_3",

Review comment:
       Do you think it would make sense to sort the response data from API?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] mik-laj commented on a change in pull request #9045: Add read-only endpoints for DAG Model

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #9045:
URL: https://github.com/apache/airflow/pull/9045#discussion_r451462807



##########
File path: tests/api_connexion/endpoints/test_dag_endpoint.py
##########
@@ -133,11 +163,101 @@ def test_should_response_200_serialized(self):
 
 
 class TestGetDags(TestDagEndpoint):
-    @pytest.mark.skip(reason="Not implemented yet")
+
     def test_should_response_200(self):
-        response = self.client.get("/api/v1/dags/1")
+        self._create_dag_models(2)
+
+        response = self.client.get("api/v1/dags")
+
+        assert response.status_code == 200
+
+        self.assertEqual(
+            {
+                "dags": [
+                    {
+                        "dag_id": "TEST_DAG_1",
+                        "description": None,
+                        "fileloc": "/tmp/dag_1.py",
+                        "is_paused": False,
+                        "is_subdag": False,
+                        "owners": [],
+                        "root_dag_id": None,
+                        "schedule_interval": {"__type": "CronExpression", "value": "2 2 * * *"},
+                        "tags": [],
+                    },
+                    {
+                        "dag_id": "TEST_DAG_2",
+                        "description": None,
+                        "fileloc": "/tmp/dag_2.py",
+                        "is_paused": False,
+                        "is_subdag": False,
+                        "owners": [],
+                        "root_dag_id": None,
+                        "schedule_interval": {"__type": "CronExpression", "value": "2 2 * * *"},
+                        "tags": [],
+                    },
+                ],
+                "total_entries": 2,
+            },
+            response.json,
+        )
+
+    @parameterized.expand(
+        [
+            ("api/v1/dags?limit=1", ["TEST_DAG_1"]),
+            ("api/v1/dags?limit=2", ["TEST_DAG_1", "TEST_DAG_10"]),
+            (
+                "api/v1/dags?offset=5",
+                [
+                    "TEST_DAG_5",
+                    "TEST_DAG_6",
+                    "TEST_DAG_7",
+                    "TEST_DAG_8",
+                    "TEST_DAG_9",
+                ],
+            ),
+            (
+                "api/v1/dags?offset=0",
+                [
+                    "TEST_DAG_1",
+                    "TEST_DAG_10",
+                    "TEST_DAG_2",
+                    "TEST_DAG_3",

Review comment:
       The data is sorted.
   ```
   .order_by(DagModel.dag_id)
   ```




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] turbaszek commented on a change in pull request #9045: Add read-only endpoints for DAG Model

Posted by GitBox <gi...@apache.org>.
turbaszek commented on a change in pull request #9045:
URL: https://github.com/apache/airflow/pull/9045#discussion_r451460913



##########
File path: tests/api_connexion/endpoints/test_dag_endpoint.py
##########
@@ -58,13 +60,41 @@ def setUp(self) -> None:
     def tearDown(self) -> None:
         self.clean_db()
 
+    @provide_session
+    def _create_dag_models(self, count, session=None):
+        for num in range(1, count + 1):
+            dag_model = DagModel(
+                dag_id=f"TEST_DAG_{num}",
+                fileloc=f"/tmp/dag_{num}.py",
+                schedule_interval="2 2 * * *"
+            )
+            session.add(dag_model)
+
 
 class TestGetDag(TestDagEndpoint):
-    @pytest.mark.skip(reason="Not implemented yet")
     def test_should_response_200(self):
-        response = self.client.get("/api/v1/dags/1/")
+        self._create_dag_models(1)
+        response = self.client.get("/api/v1/dags/TEST_DAG_1")
         assert response.status_code == 200
 
+        current_response = response.json
+        current_response["fileloc"] = "/tmp/test-dag.py"
+        self.assertEqual({
+            'dag_id': 'TEST_DAG_1',
+            'description': None,
+            'fileloc': '/tmp/test-dag.py',
+            'is_paused': False,
+            'is_subdag': False,
+            'owners': [],
+            'root_dag_id': None,
+            'schedule_interval': {'__type': 'CronExpression', 'value': '2 2 * * *'},
+            'tags': []
+        }, current_response)
+
+    def test_should_response_404(self):
+        response = self.client.get("/api/v1/dags/INVALID_DAG/")

Review comment:
       ```suggestion
           response = self.client.get("/api/v1/dags/INVALID_DAG")
   ```




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [airflow] turbaszek commented on a change in pull request #9045: Add read-only endpoints for DAG Model

Posted by GitBox <gi...@apache.org>.
turbaszek commented on a change in pull request #9045:
URL: https://github.com/apache/airflow/pull/9045#discussion_r451466234



##########
File path: tests/api_connexion/endpoints/test_dag_endpoint.py
##########
@@ -133,11 +163,101 @@ def test_should_response_200_serialized(self):
 
 
 class TestGetDags(TestDagEndpoint):
-    @pytest.mark.skip(reason="Not implemented yet")
+
     def test_should_response_200(self):
-        response = self.client.get("/api/v1/dags/1")
+        self._create_dag_models(2)
+
+        response = self.client.get("api/v1/dags")
+
+        assert response.status_code == 200
+
+        self.assertEqual(
+            {
+                "dags": [
+                    {
+                        "dag_id": "TEST_DAG_1",
+                        "description": None,
+                        "fileloc": "/tmp/dag_1.py",
+                        "is_paused": False,
+                        "is_subdag": False,
+                        "owners": [],
+                        "root_dag_id": None,
+                        "schedule_interval": {"__type": "CronExpression", "value": "2 2 * * *"},
+                        "tags": [],
+                    },
+                    {
+                        "dag_id": "TEST_DAG_2",
+                        "description": None,
+                        "fileloc": "/tmp/dag_2.py",
+                        "is_paused": False,
+                        "is_subdag": False,
+                        "owners": [],
+                        "root_dag_id": None,
+                        "schedule_interval": {"__type": "CronExpression", "value": "2 2 * * *"},
+                        "tags": [],
+                    },
+                ],
+                "total_entries": 2,
+            },
+            response.json,
+        )
+
+    @parameterized.expand(
+        [
+            ("api/v1/dags?limit=1", ["TEST_DAG_1"]),
+            ("api/v1/dags?limit=2", ["TEST_DAG_1", "TEST_DAG_10"]),
+            (
+                "api/v1/dags?offset=5",
+                [
+                    "TEST_DAG_5",
+                    "TEST_DAG_6",
+                    "TEST_DAG_7",
+                    "TEST_DAG_8",
+                    "TEST_DAG_9",
+                ],
+            ),
+            (
+                "api/v1/dags?offset=0",
+                [
+                    "TEST_DAG_1",
+                    "TEST_DAG_10",
+                    "TEST_DAG_2",
+                    "TEST_DAG_3",

Review comment:
       Hm, it's interesting that `TEST_DAG_10` is before `TEST_DAG_2` as it's a longer name 🤔 




----------------------------------------------------------------
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:
users@infra.apache.org