Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Airflow plugins, RBAC enabled Blueprint not working

Tags:

flask

airflow

We had our Airflow custom UI based on this link and it was working fine with Airflow 1.9.0. Following this we upgraded to 1.10.1 and also enabled RBAC. Our custom UI stopped coming after this.

We followed this explanation note-on-role-based-views and tried to use our old UI templates with appbuilder_views. On the using the TestAppBuilderBaseView from /tests/plugins/test_plugin.py,

class TestAppBuilderBaseView(AppBuilderBaseView):
@expose("/")
def test(self):
    return self.render("test_plugin/test.html", content="Hello galaxy!")

we get the menu and the link, but on clicking we get the error

object has no attribute 'render'

On changing this to

return self.render_template("test_plugin/test.html",content="Hello galaxy!")

we get the error

jinja2.exceptions.TemplateNotFound: test_plugin/test.html

I have tried all possible combination placing the templates folder and the html file, but still its the same error.

I do find some forums telling to enable debug on Blueprint. but I am not aware on how you can do that with Airflow

Any guidance on this please?.

Thanks in Advance
Jeenson

like image 847
Jeenson Ephraim Avatar asked Dec 10 '18 07:12

Jeenson Ephraim


1 Answers

The version 1.10.0 when released had a bug that was not installing the plugins correctly in the new UI. This was fixed in the version 1.10.1, but the code example for plugins in Airflow documentation is broken.

I wrote a sample project to make the integration work, you can check it here: https://github.com/felipegasparini/airflow_plugin_rbac_test

But in short, you need to:

  1. Import the BaseView from appbuilder correctly using:

    from flask_appbuilder import BaseView as AppBuilderBaseView

  2. Change the name of the method 'test' to 'list'

  3. Set the template_folder property to point to where your templates are.

Something like this:

from airflow.plugins_manager import AirflowPlugin
from flask_appbuilder import BaseView as AppBuilderBaseView

class TestAppBuilderBaseView(AppBuilderBaseView):

    template_folder = '/root/airflow/plugins/test_plugin/templates'

    @expose("/")
    def list(self):
        return self.render_template("test.html", content="Hello galaxy!")

v_appbuilder_view = TestAppBuilderBaseView()
v_appbuilder_package = {"name": "Test View",
                        "category": "Test Plugin",
                        "view": v_appbuilder_view}

# Defining the plugin class
class AirflowTestPlugin(AirflowPlugin):
    name = "test_plugin"
    # operators = [PluginOperator]
    # sensors = [PluginSensorOperator]
    # hooks = [PluginHook]
    # executors = [PluginExecutor]
    # macros = [plugin_macro]
    # admin_views = [v]
    # flask_blueprints = [bp]
    # menu_links = [ml]
    appbuilder_views = [v_appbuilder_package]
    # appbuilder_menu_items = [appbuilder_mitem]
like image 58
fgasparini Avatar answered Nov 09 '22 13:11

fgasparini