Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

import socket 

 

from flask import Flask 

from flask.ext.admin import Admin, base 

from flask.ext.cache import Cache 

 

import flask_login 

 

import airflow 

from airflow import models 

from airflow.settings import Session 

 

from airflow.www.blueprints import ck, routes 

from airflow import jobs 

from airflow import settings 

from airflow import configuration 

 

 

def create_app(config=None): 

    app = Flask(__name__) 

    app.secret_key = configuration.get('webserver', 'SECRET_KEY') 

    app.config['LOGIN_DISABLED'] = not configuration.getboolean('webserver', 'AUTHENTICATE') 

 

    #app.config = config 

    airflow.load_login() 

    airflow.login.login_manager.init_app(app) 

 

    cache = Cache( 

        app=app, config={'CACHE_TYPE': 'filesystem', 'CACHE_DIR': '/tmp'}) 

 

    app.register_blueprint(ck, url_prefix='/ck') 

    app.register_blueprint(routes) 

    app.jinja_env.add_extension("chartkick.ext.charts") 

 

    with app.app_context(): 

        from airflow.www import views 

 

        admin = Admin( 

            app, name='Airflow', 

            static_url_path='/admin', 

            index_view=views.HomeView(endpoint='', url='/admin'), 

            template_mode='bootstrap3', 

        ) 

        av = admin.add_view 

        vs = views 

        av(vs.Airflow(name='DAGs')) 

 

        av(vs.QueryView(name='Ad Hoc Query', category="Data Profiling")) 

        av(vs.ChartModelView( 

            models.Chart, Session, name="Charts", category="Data Profiling")) 

        av(vs.KnowEventView( 

            models.KnownEvent, 

            Session, name="Known Events", category="Data Profiling")) 

        av(vs.SlaMissModelView( 

            models.SlaMiss, 

            Session, name="SLA Misses", category="Browse")) 

        av(vs.TaskInstanceModelView(models.TaskInstance, 

            Session, name="Task Instances", category="Browse")) 

        av(vs.LogModelView( 

            models.Log, Session, name="Logs", category="Browse")) 

        av(vs.JobModelView( 

            jobs.BaseJob, Session, name="Jobs", category="Browse")) 

        av(vs.PoolModelView( 

            models.Pool, Session, name="Pools", category="Admin")) 

        av(vs.ConfigurationView( 

            name='Configuration', category="Admin")) 

        av(vs.UserModelView( 

            models.User, Session, name="Users", category="Admin")) 

        av(vs.ConnectionModelView( 

            models.Connection, Session, name="Connections", category="Admin")) 

        av(vs.VariableView( 

            models.Variable, Session, name="Variables", category="Admin")) 

 

        admin.add_link(base.MenuLink( 

            category='Docs', name='Documentation', 

            url='http://pythonhosted.org/airflow/')) 

        admin.add_link( 

            base.MenuLink(category='Docs', 

                name='Github',url='https://github.com/airbnb/airflow')) 

 

        av(vs.DagRunModelView( 

            models.DagRun, Session, name="DAG Runs", category="Browse")) 

        av(vs.DagModelView(models.DagModel, Session, name=None)) 

        # Hack to not add this view to the menu 

        admin._menu = admin._menu[:-1] 

 

        def integrate_plugins(): 

            """Integrate plugins to the context""" 

            from airflow.plugins_manager import ( 

                admin_views, flask_blueprints, menu_links) 

            for v in admin_views: 

                admin.add_view(v) 

            for bp in flask_blueprints: 

                app.register_blueprint(bp) 

            for ml in menu_links: 

                admin.add_link(ml) 

 

        integrate_plugins() 

 

        @app.context_processor 

        def jinja_globals(): 

            return { 

                'hostname': socket.gethostname(), 

            } 

 

        @app.teardown_appcontext 

        def shutdown_session(exception=None): 

            settings.Session.remove() 

 

        return app 

 

app = None 

def cached_app(config=None): 

    global app 

    if not app: 

        app = create_app(config) 

    return app