Skip to content

Commit 537852a

Browse files
authored
Add lookout link to Airflow Operator (#207) (#3888)
1 parent 9b6f770 commit 537852a

File tree

9 files changed

+77
-13
lines changed

9 files changed

+77
-13
lines changed

docs/python_airflow_operator.md

+31
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ operator needs to be cleaned up, or it will leave ghost processes behind.
9191

9292

9393

94+
#### operator_extra_links(_: Collection[BaseOperatorLink_ _ = (LookoutLink(),_ )
95+
9496
#### _property_ pod_manager(_: KubernetesPodLogManage_ )
9597

9698
#### render_template_fields(context, jinja_env=None)
@@ -162,6 +164,35 @@ acknowledged by Armada.
162164
:type job_acknowledgement_timeout: int
163165
:param kwargs: Additional keyword arguments to pass to the BaseOperator.
164166

167+
168+
### _class_ armada.operators.armada.LookoutLink()
169+
Bases: `BaseOperatorLink`
170+
171+
172+
#### get_link(operator, \*, ti_key)
173+
Link to external system.
174+
175+
Note: The old signature of this function was `(self, operator, dttm: datetime)`. That is still
176+
supported at runtime but is deprecated.
177+
178+
179+
* **Parameters**
180+
181+
182+
* **operator** (*BaseOperator*) – The Airflow operator object this link is associated to.
183+
184+
185+
* **ti_key** (*TaskInstanceKey*) – TaskInstance ID to return link for.
186+
187+
188+
189+
* **Returns**
190+
191+
link to external system
192+
193+
194+
195+
#### name(_ = 'Lookout_ )
165196
## armada.triggers.armada module
166197

167198
## armada.auth module

third_party/airflow/armada/__init__.py

+10
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,13 @@
22

33
_extra_allowed.add("armada.model.RunningJobContext")
44
_extra_allowed.add("armada.model.GrpcChannelArgs")
5+
6+
7+
def get_provider_info():
8+
return {
9+
"package-name": "armada-airflow",
10+
"name": "Armada Airflow Operator",
11+
"description": "Armada Airflow Operator.",
12+
"extra-links": ["armada.operators.armada.LookoutLink"],
13+
"versions": ["1.0.0"],
14+
}

third_party/airflow/armada/operators/armada.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
import jinja2
2727
from airflow.configuration import conf
2828
from airflow.exceptions import AirflowException
29-
from airflow.models import BaseOperator
29+
from airflow.models import BaseOperator, BaseOperatorLink, XCom
30+
from airflow.models.taskinstancekey import TaskInstanceKey
3031
from airflow.serialization.serde import deserialize
3132
from airflow.utils.context import Context
3233
from airflow.utils.log.logging_mixin import LoggingMixin
@@ -44,6 +45,17 @@
4445
from ..utils import log_exceptions
4546

4647

48+
class LookoutLink(BaseOperatorLink):
49+
name = "Lookout"
50+
51+
def get_link(self, operator: BaseOperator, *, ti_key: TaskInstanceKey):
52+
task_state = XCom.get_value(ti_key=ti_key)
53+
if not task_state:
54+
return ""
55+
56+
return task_state.get("armada_lookout_url", "")
57+
58+
4759
class ArmadaOperator(BaseOperator, LoggingMixin):
4860
"""
4961
An Airflow operator that manages Job submission to Armada.
@@ -52,6 +64,8 @@ class ArmadaOperator(BaseOperator, LoggingMixin):
5264
and handles job cancellation if the Airflow task is killed.
5365
"""
5466

67+
operator_extra_links = (LookoutLink(),)
68+
5569
template_fields: Sequence[str] = ("job_request", "job_set_prefix")
5670
template_fields_renderers: Dict[str, str] = {"job_request": "py"}
5771

third_party/airflow/armada/plugin.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from airflow.plugins_manager import AirflowPlugin
2+
3+
from .armada.operators.armada import LookoutLink
4+
5+
6+
class AirflowExtraLinkPlugin(AirflowPlugin):
7+
name = "extra_link_plugin"
8+
operator_extra_links = [
9+
LookoutLink(),
10+
]

third_party/airflow/examples/bad_armada.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
from armada.operators.armada import ArmadaOperator
66
from armada_client.armada import submit_pb2
77
from armada_client.k8s.io.api.core.v1 import generated_pb2 as core_v1
8-
from armada_client.k8s.io.apimachinery.pkg.api.resource import (
9-
generated_pb2 as api_resource,
10-
)
8+
from armada_client.k8s.io.apimachinery.pkg.api.resource import \
9+
generated_pb2 as api_resource
1110

1211

1312
def submit_sleep_container(image: str):

third_party/airflow/examples/big_armada.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
from armada.operators.armada import ArmadaOperator
66
from armada_client.armada import submit_pb2
77
from armada_client.k8s.io.api.core.v1 import generated_pb2 as core_v1
8-
from armada_client.k8s.io.apimachinery.pkg.api.resource import (
9-
generated_pb2 as api_resource,
10-
)
8+
from armada_client.k8s.io.apimachinery.pkg.api.resource import \
9+
generated_pb2 as api_resource
1110

1211

1312
def submit_sleep_job():

third_party/airflow/examples/hello_armada.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
from armada.operators.armada import ArmadaOperator
66
from armada_client.armada import submit_pb2
77
from armada_client.k8s.io.api.core.v1 import generated_pb2 as core_v1
8-
from armada_client.k8s.io.apimachinery.pkg.api.resource import (
9-
generated_pb2 as api_resource,
10-
)
8+
from armada_client.k8s.io.apimachinery.pkg.api.resource import \
9+
generated_pb2 as api_resource
1110

1211

1312
def submit_sleep_job():

third_party/airflow/examples/hello_armada_deferrable.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
from armada.operators.armada import ArmadaOperator
66
from armada_client.armada import submit_pb2
77
from armada_client.k8s.io.api.core.v1 import generated_pb2 as core_v1
8-
from armada_client.k8s.io.apimachinery.pkg.api.resource import (
9-
generated_pb2 as api_resource,
10-
)
8+
from armada_client.k8s.io.apimachinery.pkg.api.resource import \
9+
generated_pb2 as api_resource
1110

1211

1312
def submit_sleep_job():

third_party/airflow/pyproject.toml

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ test = ["pytest==7.3.1", "coverage==7.3.2", "pytest-asyncio==0.21.1",
3131
# note(JayF): sphinx-jekyll-builder was broken by sphinx-markdown-builder 0.6 -- so pin to 0.5.5
3232
docs = ["sphinx==7.1.2", "sphinx-jekyll-builder==0.3.0", "sphinx-toolbox==3.2.0b1", "sphinx-markdown-builder==0.5.5"]
3333

34+
[project.entry-points.apache_airflow_provider]
35+
provider_info = "armada.__init__:get_provider_info"
36+
3437
[project.urls]
3538
repository='https://github.com/armadaproject/armada'
3639

0 commit comments

Comments
 (0)