baseoperatorlink.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. from __future__ import annotations
  18. from abc import ABCMeta, abstractmethod
  19. from typing import TYPE_CHECKING, ClassVar
  20. import attr
  21. if TYPE_CHECKING:
  22. from airflow.models.baseoperator import BaseOperator
  23. from airflow.models.taskinstancekey import TaskInstanceKey
  24. @attr.s(auto_attribs=True)
  25. class BaseOperatorLink(metaclass=ABCMeta):
  26. """Abstract base class that defines how we get an operator link."""
  27. operators: ClassVar[list[type[BaseOperator]]] = []
  28. """
  29. This property will be used by Airflow Plugins to find the Operators to which you want
  30. to assign this Operator Link
  31. :return: List of Operator classes used by task for which you want to create extra link
  32. """
  33. @property
  34. @abstractmethod
  35. def name(self) -> str:
  36. """Name of the link. This will be the button name on the task UI."""
  37. @abstractmethod
  38. def get_link(self, operator: BaseOperator, *, ti_key: TaskInstanceKey) -> str:
  39. """
  40. Link to external system.
  41. Note: The old signature of this function was ``(self, operator, dttm: datetime)``. That is still
  42. supported at runtime but is deprecated.
  43. :param operator: The Airflow operator object this link is associated to.
  44. :param ti_key: TaskInstance ID to return link for.
  45. :return: link to external system
  46. """