예제 #1
0
def create_app(config):
    # format logging
    logging.config.dictConfig(LOGGING_CONFIG)

    before_hook_path = os.getenv('FEDLEARNER_WEBCONSOLE_BEFORE_APP_START')
    if before_hook_path:
        module_path, func_name = before_hook_path.split(':')
        module = importlib.import_module(module_path)
        # Dynamically run the function
        getattr(module, func_name)()

    app = Flask('fedlearner_webconsole')
    app.config.from_object(config)

    db.init_app(app)
    migrate.init_app(app, db)
    jwt.init_app(app)

    # Error handlers
    app.register_error_handler(400, _handle_bad_request)
    app.register_error_handler(404, _handle_not_found)
    app.register_error_handler(WebConsoleApiException, make_response)
    app.register_error_handler(Exception, _handle_uncaught_exception)

    api = Api(prefix='/api/v2')
    initialize_auth_apis(api)
    initialize_project_apis(api)
    initialize_workflow_template_apis(api)
    initialize_workflow_apis(api)
    initialize_job_apis(api)
    initialize_dataset_apis(api)
    initialize_setting_apis(api)
    initialize_mmgr_apis(api)
    if os.environ.get('FLASK_ENV') != 'production':
        initialize_debug_apis(api)
    # A hack that use our customized error handlers
    # Ref: https://github.com/flask-restful/flask-restful/issues/280
    handle_exception = app.handle_exception
    handle_user_exception = app.handle_user_exception
    api.init_app(app)
    app.handle_exception = handle_exception
    app.handle_user_exception = handle_user_exception

    # Inits k8s related stuff first since something in composer
    # may depend on it
    if Envs.FLASK_ENV == 'production' or Envs.K8S_CONFIG_PATH is not None:
        k8s_watcher.start()

    if app.config.get('START_GRPC_SERVER', True):
        rpc_server.stop()
        rpc_server.start(app)
    if app.config.get('START_SCHEDULER', True):
        scheduler.stop()
        scheduler.start(app)
    if app.config.get('START_COMPOSER', True):
        with app.app_context():
            composer.run(db_engine=db.get_engine())

    metrics.emit_counter('create_app', 1)
    return app
예제 #2
0
파일: app.py 프로젝트: flyfoxCI/fedlearner
def create_app(config):
    app = Flask('fedlearner_webconsole')
    app.config.from_object(config)

    db.init_app(app)
    migrate.init_app(app, db)
    jwt.init_app(app)

    # Error handlers
    app.register_error_handler(400, _handle_bad_request)
    app.register_error_handler(WebConsoleApiException, make_response)
    app.register_error_handler(Exception, _handle_uncaught_exception)

    api = Api(prefix='/api/v2')
    initialize_auth_apis(api)
    initialize_project_apis(api)
    initialize_workflow_template_apis(api)
    initialize_workflow_apis(api)
    # A hack that use our customized error handlers
    # Ref: https://github.com/flask-restful/flask-restful/issues/280
    handle_exception = app.handle_exception
    handle_user_exception = app.handle_user_exception
    api.init_app(app)
    app.handle_exception = handle_exception
    app.handle_user_exception = handle_user_exception

    if app.config.get('START_GRPC_SERVER', True):
        rpc_server.stop()
        rpc_server.start(app)

    if app.config.get('START_SCHEDULER', True):
        scheduler.stop()
        scheduler.start(app)

    return app
예제 #3
0
def create_app(config):
    # format logging
    logging.config.dictConfig(LOGGING_CONFIG)

    app = Flask('fedlearner_webconsole')
    app.config.from_object(config)

    jwt.init_app(app)

    # Error handlers
    app.register_error_handler(400, _handle_bad_request)
    app.register_error_handler(404, _handle_not_found)
    app.register_error_handler(WebConsoleApiException, make_response)
    app.register_error_handler(Exception, _handle_uncaught_exception)

    # TODO(wangsen.0914): This will be removed sooner!
    db.init_app(app)

    api = Api(prefix='/api/v2')
    initialize_auth_apis(api)
    initialize_project_apis(api)
    initialize_workflow_template_apis(api)
    initialize_workflow_apis(api)
    initialize_job_apis(api)
    initialize_dataset_apis(api)
    initialize_setting_apis(api)
    initialize_mmgr_apis(api)
    initialize_sparkapps_apis(api)
    if os.environ.get('FLASK_ENV') != 'production' or Envs.DEBUG:
        initialize_debug_apis(api)
    # A hack that use our customized error handlers
    # Ref: https://github.com/flask-restful/flask-restful/issues/280
    handle_exception = app.handle_exception
    handle_user_exception = app.handle_user_exception
    api.init_app(app)
    app.handle_exception = handle_exception
    app.handle_user_exception = handle_user_exception

    # Inits k8s related stuff first since something in composer
    # may depend on it
    if Envs.FLASK_ENV == 'production' or Envs.K8S_CONFIG_PATH is not None:
        k8s_watcher.start()

    if app.config.get('START_GRPC_SERVER', True):
        rpc_server.stop()
        rpc_server.start(app)
    if app.config.get('START_SCHEDULER', True):
        scheduler.stop()
        scheduler.start(app)
    if app.config.get('START_COMPOSER', True):
        with app.app_context():
            composer.run(db_engine=db.get_engine())

    metrics.emit_counter('create_app', 1)
    return app
예제 #4
0
파일: app.py 프로젝트: piiswrong/fedlearner
def create_app(config):
    before_hook_path = os.getenv(
        'FEDLEARNER_WEBCONSOLE_BEFORE_APP_START')
    if before_hook_path:
        module_path, func_name = before_hook_path.split(':')
        module = importlib.import_module(module_path)
        # Dynamically run the function
        getattr(module, func_name)()

    app = Flask('fedlearner_webconsole')
    app.config.from_object(config)

    db.init_app(app)
    migrate.init_app(app, db)
    jwt.init_app(app)

    # Error handlers
    app.register_error_handler(400, _handle_bad_request)
    app.register_error_handler(404, _handle_not_found)
    app.register_error_handler(WebConsoleApiException, make_response)
    app.register_error_handler(Exception, _handle_uncaught_exception)

    api = Api(prefix='/api/v2')
    initialize_auth_apis(api)
    initialize_project_apis(api)
    initialize_workflow_template_apis(api)
    initialize_workflow_apis(api)
    initialize_job_apis(api)
    initialize_dataset_apis(api)
    initialize_setting_apis(api)
    # A hack that use our customized error handlers
    # Ref: https://github.com/flask-restful/flask-restful/issues/280
    handle_exception = app.handle_exception
    handle_user_exception = app.handle_user_exception
    api.init_app(app)
    app.handle_exception = handle_exception
    app.handle_user_exception = handle_user_exception

    if app.config.get('START_GRPC_SERVER', True):
        rpc_server.stop()
        rpc_server.start(app)

    if app.config.get('START_SCHEDULER', True):
        scheduler.stop()
        scheduler.start(app)

    return app