提交 b7357569 编写于 作者: T tssujt

Proofread plugin section

上级 f08787e3
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
| [21 数据分析](zh/21.md) | [@ImPerat0R\_](https://github.com/tssujt) | | [21 数据分析](zh/21.md) | [@ImPerat0R\_](https://github.com/tssujt) |
| [22 命令行接口](zh/22.md) | [@ImPerat0R\_](https://github.com/tssujt) | | [22 命令行接口](zh/22.md) | [@ImPerat0R\_](https://github.com/tssujt) |
| [23 调度和触发器](zh/23.md) | [@Ray](https://github.com/echo-ray) | | [23 调度和触发器](zh/23.md) | [@Ray](https://github.com/echo-ray) |
| [24 插件](zh/24.md) | | | [24 插件](zh/24.md) | [@ImPerat0R\_](https://github.com/tssujt) |
| [25 安全](zh/25.md) | | | [25 安全](zh/25.md) | |
| [26 时区](zh/26.md) | | | [26 时区](zh/26.md) | |
| [27 实验性 Rest API](zh/27.md) | [@ImPerat0R\_](https://github.com/tssujt) | | [27 实验性 Rest API](zh/27.md) | [@ImPerat0R\_](https://github.com/tssujt) |
......
...@@ -2,41 +2,41 @@ ...@@ -2,41 +2,41 @@
Airflow内置了一个简单的插件管理器,可以通过简单地删除`$AIRFLOW_HOME/plugins`文件夹中的文件,将外部功能集成到其核心。 Airflow内置了一个简单的插件管理器,可以通过简单地删除`$AIRFLOW_HOME/plugins`文件夹中的文件,将外部功能集成到其核心。
`plugins`文件夹中的python模块将被导入, **钩子****操作符****传感器****宏****执行器**和Web **视图**将集成到Airflow的主要集合中,并可供使用。 `plugins`文件夹中的python模块将被导入,**钩子****操作符****传感器****宏****执行器**和Web**视图**将集成到Airflow的主要集合中,并可供使用。
## 做什么的? ## 做什么的?
Airflow提供了一个用于处理数据的通用工具箱。 不同的组织有不同的堆栈和不同的需求。 使用Airflow插件可以让公司定制他们的Airflow安装以反映他们的生态系统。 Airflow提供了一个用于处理数据的通用工具箱。不同的组织有不同的堆栈和不同的需求。 使用Airflow插件可以让公司定制他们的Airflow安装以反映他们的生态系统。
插件可以用作编写,共享和激活新功能集的简便方法 插件可以简便地用作编写,共享和激活新功能集
还需要一组更复杂的应用程序来与不同风格的数据和元数据进行交互。 当然还需要一组更复杂的应用程序来与不同风格的数据和元数据进行交互。
例子: 例子:
* 一组用于解析Hive日志和公开Hive元数据(CPU / IO /阶段/倾斜/ ...)的工具 * 一组用于解析Hive日志和公开Hive元数据(CPU/IO/阶段/倾斜/...)的工具
* 异常检测框架,允许人们收集指标,设置阈值和警报 * 异常检测框架,允许人们收集指标,设置阈值和警报
* 审计工具,帮助了解谁访问了什么 * 审计工具,帮助了解谁访问了什么
* 配置驱动的SLA监控工具,允许您设置受监控的表以及应该在何时着陆,提醒人员并公开停机的可视化 * 配置驱动的SLA监控工具,允许您设置受监控的表以及应该在何时着陆,提醒人员并公开停机的可视化
* ... * ...
## 为什么要建立在Airflow之上? ## 为什么要建立在Airflow之上?
Airflow有许多组件可以在构建应用程序时重用: Airflow有许多组件可以在构建应用程序时重用:
* 可用于呈现视图的Web服务器 * 可用于呈现视图的Web服务器
* 用于存储模型的元数据数据库 * 用于存储模型的元数据数据库
* 访问您的数据库,以及如何连接到它们的知识 * 访问您的数据库,以及如何连接到它们
* 应用程序可以将工作负载推送到的一组工作者 * 应用程序可以将工作负载推送到的一组Workers
* 部署了Airflow,您可以专注于部署物流 * 部署了Airflow,您可以专注于后面的工作
* 基本的图表功能,底层库和抽象 * 基本的图表功能,底层库和抽象
## 接口 ## 接口
要创建插件,您需要派生`airflow.plugins_manager.AirflowPlugin`类并引用要插入Airflow的对象。 以下是您需要派生的类看起来像 要创建插件,您需要派生`airflow.plugins_manager.AirflowPlugin`类并引用要插入Airflow的对象。以下是类似您需要派生的类
``` ```
class AirflowPlugin ( object ): class AirflowPlugin(object):
# The name of your plugin (str) # The name of your plugin (str)
name = None name = None
# A list of class(es) derived from BaseOperator # A list of class(es) derived from BaseOperator
...@@ -52,37 +52,26 @@ Airflow有许多组件可以在构建应用程序时重用: ...@@ -52,37 +52,26 @@ Airflow有许多组件可以在构建应用程序时重用:
# A list of objects created from a class derived # A list of objects created from a class derived
# from flask_admin.BaseView # from flask_admin.BaseView
admin_views = [] admin_views = []
# A list of Blueprint object created from flask.Blueprint # A list of Blueprint object created from flask.Blueprint. For use with the flask_admin based GUI
flask_blueprints = [] flask_blueprints = []
# A list of menu links (flask_admin.base.MenuLink) # A list of menu links (flask_admin.base.MenuLink). For use with the flask_admin based GUI
menu_links = [] menu_links = []
# A list of dictionaries containing FlaskAppBuilder BaseView object and some metadata. See example below
``` appbuilder_views = []
# A list of dictionaries containing FlaskAppBuilder BaseView object and some metadata. See example below
您可以通过继承派生它(请参阅下面的示例)。 请注意,必须指定此类中的`name` appbuilder_menu_items = []
将插件导入Airflow后,您可以使用类似语句调用它
```
from airflow. { type , like "operators" , "sensors" } . { name specificed inside the plugin class } import *
``` ```
当您编写自己的插件时,请确保您理解它们。 每种类型的插件都有一些基本属性。 例如, ## 示例
* 对于`Operator`插件,必须使用`execute`方法。
* 对于`Sensor`插件,必须使用返回布尔值的`poke`方法。
## 例
下面的代码定义了一个插件,它在Airflow中注入一组虚拟对象定义。 下面的代码定义了一个插件,它在Airflow中注入一组虚拟对象定义。
``` ```
# This is the class you derive to create a plugin # This is the class you derive to create a plugin
from airflow.plugins_manager import AirflowPlugin from airflow.plugins_manager import AirflowPlugin
from flask import Blueprint from flask import Blueprint
from flask_admin import BaseView , expose from flask_admin import BaseView, expose
from flask_admin.base import MenuLink from flask_admin.base import MenuLink
# Importing base classes that we need to derive # Importing base classes that we need to derive
...@@ -92,55 +81,76 @@ from airflow.sensors.base_sensor_operator import BaseSensorOperator ...@@ -92,55 +81,76 @@ from airflow.sensors.base_sensor_operator import BaseSensorOperator
from airflow.executors.base_executor import BaseExecutor from airflow.executors.base_executor import BaseExecutor
# Will show up under airflow.hooks.test_plugin.PluginHook # Will show up under airflow.hooks.test_plugin.PluginHook
class PluginHook ( BaseHook ): class PluginHook(BaseHook):
pass pass
# Will show up under airflow.operators.test_plugin.PluginOperator # Will show up under airflow.operators.test_plugin.PluginOperator
class PluginOperator ( BaseOperator ): class PluginOperator(BaseOperator):
pass pass
# Will show up under airflow.sensors.test_plugin.PluginSensorOperator # Will show up under airflow.sensors.test_plugin.PluginSensorOperator
class PluginSensorOperator ( BaseSensorOperator ): class PluginSensorOperator(BaseSensorOperator):
pass pass
# Will show up under airflow.executors.test_plugin.PluginExecutor # Will show up under airflow.executors.test_plugin.PluginExecutor
class PluginExecutor ( BaseExecutor ): class PluginExecutor(BaseExecutor):
pass pass
# Will show up under airflow.macros.test_plugin.plugin_macro # Will show up under airflow.macros.test_plugin.plugin_macro
def plugin_macro (): def plugin_macro():
pass pass
# Creating a flask admin BaseView # Creating a flask admin BaseView
class TestView ( BaseView ): class TestView(BaseView):
@expose ( '/' ) @expose('/')
def test ( self ): def test(self):
# in this example, put your test_plugin/test.html template at airflow/plugins/templates/test_plugin/test.html # in this example, put your test_plugin/test.html template at airflow/plugins/templates/test_plugin/test.html
return self . render ( "test_plugin/test.html" , content = "Hello galaxy!" ) return self.render("test_plugin/test.html", content="Hello galaxy!")
v = TestView ( category = "Test Plugin" , name = "Test View" ) v = TestView(category="Test Plugin", name="Test View")
# Creating a flask blueprint to integrate the templates and static folder # Creating a flask blueprint to integrate the templates and static folder
bp = Blueprint ( bp = Blueprint(
"test_plugin" , __name__ , "test_plugin", __name__,
template_folder = 'templates' , # registers airflow/plugins/templates as a Jinja template folder template_folder='templates', # registers airflow/plugins/templates as a Jinja template folder
static_folder = 'static' , static_folder='static',
static_url_path = '/static/test_plugin' ) static_url_path='/static/test_plugin')
ml = MenuLink ( ml = MenuLink(
category = 'Test Plugin' , category='Test Plugin',
name = 'Test Menu Link' , name='Test Menu Link',
url = 'https://airflow.incubator.apache.org/' ) url='https://airflow.incubator.apache.org/')
# Creating a flask appbuilder BaseView
class TestAppBuilderBaseView(AppBuilderBaseView):
@expose("/")
def test(self):
return self.render("test_plugin/test.html", content="Hello galaxy!")
v_appbuilder_view = TestAppBuilderBaseView()
v_appbuilder_package = {"name": "Test View",
"category": "Test Plugin",
"view": v_appbuilder_view}
# Creating a flask appbuilder Menu Item
appbuilder_mitem = {"name": "Google",
"category": "Search",
"category_icon": "fa-th",
"href": "https://www.google.com"}
# Defining the plugin class # Defining the plugin class
class AirflowTestPlugin ( AirflowPlugin ): class AirflowTestPlugin(AirflowPlugin):
name = "test_plugin" name = "test_plugin"
operators = [ PluginOperator ] operators = [PluginOperator]
sensors = [ PluginSensorOperator ] sensors = [PluginSensorOperator]
hooks = [ PluginHook ] hooks = [PluginHook]
executors = [ PluginExecutor ] executors = [PluginExecutor]
macros = [ plugin_macro ] macros = [plugin_macro]
admin_views = [ v ] admin_views = [v]
flask_blueprints = [ bp ] flask_blueprints = [bp]
menu_links = [ ml ] menu_links = [ml]
appbuilder_views = [v_appbuilder_package]
``` appbuilder_menu_items = [appbuilder_mitem]
\ No newline at end of file ```
## 注意基于角色的视图
Airflow 1.10使用FlaskAppBuilder引入了基于角色的视图。您可以通过设置rbac = True来配置使用的UI。为了支持两个版本的UI的插件视图和链接并保持向后兼容性,请将字段appbuilder_views和appbuilder_menu_items添加到AirflowTestPlugin类中。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册