vandonr-amz commented on code in PR #30928:
URL: https://github.com/apache/airflow/pull/30928#discussion_r1181852279
##########
airflow/providers/amazon/aws/operators/emr.py:
##########
@@ -56,6 +57,7 @@ class EmrAddStepsOperator(BaseOperator):
:param wait_for_completion: If True, the operator will wait for all the
steps to be completed.
:param execution_role_arn: The ARN of the runtime role for a step on the
cluster.
:param do_xcom_push: if True, job_flow_id is pushed to XCom with key
job_flow_id.
+ :param deferrable: if True, the operator will run in deferrable mode.
Review Comment:
maybe add something saying that this implies waiting for completion (I know
it sets it to False, but from the user perspective, it's going to effectively
wait the the completion)
##########
airflow/providers/amazon/aws/triggers/emr.py:
##########
@@ -0,0 +1,70 @@
+# 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.
+from __future__ import annotations
+
+from typing import Any
+
+from airflow.compat.functools import cached_property
+from airflow.providers.amazon.aws.hooks.emr import EmrHook
+from airflow.triggers.base import BaseTrigger, TriggerEvent
+
+
+class EmrAddStepsTrigger(BaseTrigger):
+ """AWS Emr Add Steps Trigger"""
+
+ def __init__(
+ self,
+ job_flow_id: str,
+ step_ids: list[str],
+ aws_conn_id: str,
+ max_attempts: int | None,
+ poll_interval: int | None,
+ ):
+ self.job_flow_id = job_flow_id
+ self.step_ids = step_ids
+ self.aws_conn_id = aws_conn_id
+ self.max_attempts = max_attempts
+ self.poll_interval = poll_interval
+
+ def serialize(self) -> tuple[str, dict[str, Any]]:
+ return (
+ "airflow.providers.amazon.aws.triggers.emr.EmrAddStepsTrigger",
+ {
+ "job_flow_id": str(self.job_flow_id),
+ "step_ids": self.step_ids,
+ "poll_interval": str(self.poll_interval),
+ "max_attempts": str(self.max_attempts),
+ "aws_conn_id": str(self.aws_conn_id),
+ },
+ )
+
+ @cached_property
+ def hook(self) -> EmrHook:
+ return EmrHook(aws_conn_id=self.aws_conn_id)
Review Comment:
I was wondering if there is a point in "caching" the hook. The `run` method
where it's used is only called once, then we just await in it, so we could as
well have the hook just live in there.
##########
tests/providers/amazon/aws/triggers/test_emr_trigger.py:
##########
@@ -0,0 +1,76 @@
+# 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.
+from __future__ import annotations
+
+import sys
+
+import pytest
+
+from airflow.providers.amazon.aws.triggers.emr import EmrAddStepsTrigger
+from airflow.triggers.base import TriggerEvent
+
+if sys.version_info < (3, 8):
+ from asynctest import CoroutineMock as AsyncMock, mock as async_mock
+else:
+ from unittest import mock as async_mock
+ from unittest.mock import AsyncMock
+
+TEST_JOB_FLOW_ID = "test_job_flow_id"
+TEST_STEP_IDS = ["step1", "step2"]
+TEST_AWS_CONN_ID = "test-aws-id"
+TEST_MAX_ATTEMPT = 10
+TEST_POLL_INTERVAL = 10
+
+
+class TestEmrAddStepsTrigger:
+ def test_emr_add_steps_trigger_serialize(self):
+ emr_add_steps_trigger = EmrAddStepsTrigger(
+ job_flow_id=TEST_JOB_FLOW_ID,
+ step_ids=TEST_STEP_IDS,
+ aws_conn_id=TEST_AWS_CONN_ID,
+ max_attempts=TEST_MAX_ATTEMPT,
+ poll_interval=TEST_POLL_INTERVAL,
+ )
+ class_path, args = emr_add_steps_trigger.serialize()
+ assert class_path ==
"airflow.providers.amazon.aws.triggers.emr.EmrAddStepsTrigger"
+ assert args["job_flow_id"] == TEST_JOB_FLOW_ID
+ assert args["step_ids"] == TEST_STEP_IDS
+ assert args["poll_interval"] == str(TEST_POLL_INTERVAL)
+ assert args["max_attempts"] == str(TEST_MAX_ATTEMPT)
+ assert args["aws_conn_id"] == TEST_AWS_CONN_ID
Review Comment:
do we have a way to deserialize from the dict produced ?
Because asserting that a dict contains what we put in is kinda meaningless
to me. You're not really asserting that it works.
It'd be better to do obj1 -> serialize -> deserialize -> obj2 and assert
between obj1 and obj2 fields.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]