blob: ab1ddd93e1c303bd28b753df53a604b29007726e [file] [log] [blame]
Illyoung Choi2e971512019-07-18 14:15:19 -07001#!/usr/bin/env python3
2
3# Copyright 2019-present Open Networking Foundation
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# 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, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17"""
18Airflow Operators
19"""
20
21from airflow.operators import PythonOperator
22from airflow.utils.decorators import apply_defaults
23
24
25class CORDModelOperator(PythonOperator):
26 """
27 Calls a python function with model accessor.
28 """
29
30 # SCARLET
31 # http://bootflat.github.io/color-picker.html
32 ui_color = '#cf3a24'
33
34 @apply_defaults
35 def __init__(
36 self,
37 python_callable,
38 cord_event_sensor_task_id=None,
39 op_args=None,
40 op_kwargs=None,
41 provide_context=True,
42 templates_dict=None,
43 templates_exts=None,
44 *args,
45 **kwargs
46 ):
47 super().__init__(
48 python_callable=python_callable,
49 op_args=op_args,
50 op_kwargs=op_kwargs,
51 provide_context=True,
52 templates_dict=templates_dict,
53 templates_exts=templates_exts,
54 *args,
55 **kwargs)
56 self.cord_event_sensor_task_id = cord_event_sensor_task_id
57
58 def execute_callable(self):
59 # TODO
60 model_accessor = None
61
62 message = None
63 if self.cord_event_sensor_task_id:
64 message = self.op_kwargs['ti'].xcom_pull(task_ids=self.cord_event_sensor_task_id)
65
66 new_op_kwargs = dict(self.op_kwargs, model_accessor=model_accessor, message=message)
67 return self.python_callable(*self.op_args, **new_op_kwargs)