Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename OpsgenieAlertOperator to OpsgenieCreateAlertOperator #20514

Merged
merged 2 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion airflow/contrib/operators/opsgenie_alert_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,26 @@

import warnings

from airflow.providers.opsgenie.operators.opsgenie import OpsgenieAlertOperator # noqa
from airflow.providers.opsgenie.operators.opsgenie import OpsgenieCreateAlertOperator

warnings.warn(
"This module is deprecated. Please use `airflow.providers.opsgenie.operators.opsgenie`.",
DeprecationWarning,
stacklevel=2,
)


class OpsgenieAlertOperator(OpsgenieCreateAlertOperator):
"""
This class is deprecated.
Please use :class:`airflow.providers.opsgenie.operators.opsgenie.OpsgenieCreateAlertOperator`.
"""

def __init__(self, *args, **kwargs):
warnings.warn(
"This class is deprecated. "
"Please use :class:`airflow.providers.opsgenie.operators.opsgenie.OpsgenieCreateAlertOperator`.",
DeprecationWarning,
stacklevel=2,
)
super().__init__(*args, **kwargs)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
from datetime import datetime

from airflow import DAG
from airflow.providers.opsgenie.operators.opsgenie import OpsgenieAlertOperator, OpsgenieCloseAlertOperator
from airflow.providers.opsgenie.operators.opsgenie import (
OpsgenieCloseAlertOperator,
OpsgenieCreateAlertOperator,
)

with DAG(
dag_id="opsgenie_alert_operator_dag",
Expand All @@ -26,9 +29,9 @@
catchup=False,
) as dag:

# [START howto_opsgenie_alert_operator]
opsgenie_alert_operator = OpsgenieAlertOperator(task_id="opsgenie_task", message="Hello World!")
# [END howto_opsgenie_alert_operator]
# [START howto_opsgenie_create_alert_operator]
opsgenie_alert_operator = OpsgenieCreateAlertOperator(task_id="opsgenie_task", message="Hello World!")
# [END howto_opsgenie_create_alert_operator]

# [START howto_opsgenie_close_alert_operator]
opsgenie_close_alert_operator = OpsgenieCloseAlertOperator(
Expand Down
4 changes: 2 additions & 2 deletions airflow/providers/opsgenie/operators/opsgenie.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from airflow.providers.opsgenie.hooks.opsgenie import OpsgenieAlertHook


class OpsgenieAlertOperator(BaseOperator):
class OpsgenieCreateAlertOperator(BaseOperator):
"""
This operator allows you to post alerts to Opsgenie.
Accepts a connection that has an Opsgenie API key as the connection's password.
Expand All @@ -34,7 +34,7 @@ class OpsgenieAlertOperator(BaseOperator):

.. seealso::
For more information on how to use this operator, take a look at the guide:
:ref:`howto/operator:OpsgenieAlertOperator`
:ref:`howto/operator:OpsgenieCreateAlertOperator`

:param opsgenie_conn_id: The name of the Opsgenie connection to use
:type opsgenie_conn_id: str
Expand Down
18 changes: 17 additions & 1 deletion airflow/providers/opsgenie/operators/opsgenie_alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,26 @@

import warnings

from airflow.providers.opsgenie.operators.opsgenie import OpsgenieAlertOperator # noqa
from airflow.providers.opsgenie.operators.opsgenie import OpsgenieCreateAlertOperator

warnings.warn(
"This module is deprecated. Please use `airflow.providers.opsgenie.operators.opsgenie`.",
DeprecationWarning,
stacklevel=2,
)


class OpsgenieAlertOperator(OpsgenieCreateAlertOperator):
"""
This operator is deprecated.
Please use :class:`airflow.providers.opsgenie.operators.opsgenie.OpsgenieCreateAlertOperator`.
"""

def __init__(self, *args, **kwargs):
warnings.warn(
"This operator is deprecated. "
"Please use :class:`airflow.providers.opsgenie.operators.opsgenie.OpsgenieCreateAlertOperator`.",
DeprecationWarning,
stacklevel=2,
)
super().__init__(*args, **kwargs)
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
specific language governing permissions and limitations
under the License.

.. _howto/operator:OpsgenieAlertOperator:
.. _howto/operator:OpsgenieCreateAlertOperator:

OpsgenieAlertOperator
==========================
OpsgenieCreateAlertOperator
===========================

Use the :class:`~airflow.providers.opsgenie.operators.opsgenie.OpsgenieAlertOperator` to send an alert to opsgenie.
Use the :class:`~airflow.providers.opsgenie.operators.opsgenie.OpsgenieCreateAlertOperator` to send an alert to opsgenie.


Using the Operator
Expand All @@ -29,8 +29,8 @@ Send an alert to Opsgenie with a specific message.

.. exampleinclude:: /../../airflow/providers/opsgenie/example_dags/example_opsgenie_alert.py
:language: python
:start-after: [START howto_opsgenie_alert_operator]
:end-before: [END howto_opsgenie_alert_operator]
:start-after: [START howto_opsgenie_create_alert_operator]
:end-before: [END howto_opsgenie_create_alert_operator]

.. _howto/operator:OpsgenieCloseAlertOperator:

Expand Down
2 changes: 1 addition & 1 deletion tests/deprecated_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@
'airflow.contrib.operators.jenkins_job_trigger_operator.JenkinsJobTriggerOperator',
),
(
'airflow.providers.opsgenie.operators.opsgenie.OpsgenieAlertOperator',
'airflow.providers.opsgenie.operators.opsgenie.OpsgenieCreateAlertOperator',
'airflow.contrib.operators.opsgenie_alert_operator.OpsgenieAlertOperator',
),
(
Expand Down
11 changes: 7 additions & 4 deletions tests/providers/opsgenie/operators/test_opsgenie.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
import unittest

from airflow.models.dag import DAG
from airflow.providers.opsgenie.operators.opsgenie import OpsgenieAlertOperator, OpsgenieCloseAlertOperator
from airflow.providers.opsgenie.operators.opsgenie import (
OpsgenieCloseAlertOperator,
OpsgenieCreateAlertOperator,
)
from airflow.utils import timezone

DEFAULT_DATE = timezone.datetime(2017, 1, 1)


class TestOpsgenieAlertOperator(unittest.TestCase):
class TestOpsgenieCreateAlertOperator(unittest.TestCase):
_config = {
'message': 'An example alert message',
'alias': 'Life is too short for no alias',
Expand Down Expand Up @@ -79,7 +82,7 @@ def setUp(self):

def test_build_opsgenie_payload(self):
# Given / When
operator = OpsgenieAlertOperator(task_id='opsgenie_alert_job', dag=self.dag, **self._config)
operator = OpsgenieCreateAlertOperator(task_id='opsgenie_alert_job', dag=self.dag, **self._config)

payload = operator._build_opsgenie_payload()

Expand All @@ -88,7 +91,7 @@ def test_build_opsgenie_payload(self):

def test_properties(self):
# Given / When
operator = OpsgenieAlertOperator(task_id='opsgenie_alert_job', dag=self.dag, **self._config)
operator = OpsgenieCreateAlertOperator(task_id='opsgenie_alert_job', dag=self.dag, **self._config)

assert 'opsgenie_default' == operator.opsgenie_conn_id
assert self._config['message'] == operator.message
Expand Down