Exemple #1
0
    def put(self, name):
        params = request.json.get('params')
        if not isinstance(params, dict):
            abort(400, "type of 'params' must be dict")

        is_test = params.get('test', False)
        if is_test:
            del params['test']

        integration = get_integration(name)
        if integration is not None:
            abort(400, f"Integration with name '{name}' already exists")
        try:
            if 'enabled' in params:
                params['publish'] = params['enabled']
                del params['enabled']
            ca.config_obj.add_db_integration(name, params)

            mdb = ca.mindsdb_native
            cst = ca.custom_models
            model_data_arr = get_all_models_meta_data(mdb, cst)
            ca.dbw.setup_integration(name)
            if is_test is False:
                ca.dbw.register_predictors(model_data_arr)
        except Exception as e:
            print(traceback.format_exc())
            abort(500, f'Error during config update: {str(e)}')

        if is_test:
            cons = ca.dbw.check_connections()
            ca.config_obj.remove_db_integration(name)
            return {'success': cons[name]}, 200

        return '', 200
Exemple #2
0
    def put(self, name):
        params = request.json.get('params')
        if not isinstance(params, dict):
            abort(400, "type of 'params' must be dict")

        is_test = params.get('test', False)
        if is_test:
            del params['test']
            db_type = params.get('type')
            checker_class = CHECKERS.get(db_type, None)
            if checker_class is None:
                abort(400, f"Unknown integration type: {db_type}")
            checker = checker_class(**params)
            return {'success': checker.check_connection()}, 200

        integration = get_integration(name)
        if integration is not None:
            abort(400, f"Integration with name '{name}' already exists")

        try:
            if 'enabled' in params:
                params['publish'] = params['enabled']
                del params['enabled']
            ca.config_obj.add_db_integration(name, params)

            model_data_arr = get_all_models_meta_data(ca.naitve_interface,
                                                      ca.custom_models)
            ca.dbw.setup_integration(name)
            if is_test is False:
                ca.dbw.register_predictors(model_data_arr, name)
        except Exception as e:
            log.error(str(e))
            abort(500, f'Error during config update: {str(e)}')

        return '', 200
Exemple #3
0
            sys.exit(0)

    start_functions = {
        'http': start_http,
        'mysql': start_mysql,
        'mongodb': start_mongo
    }

    archive_obsolete_predictors(config, '2.11.0')

    mdb = MindsdbNative(config)
    cst = CustomModels(config)

    remove_corrupted_predictors(config, mdb)

    model_data_arr = get_all_models_meta_data(mdb, cst)

    dbw = DatabaseWrapper(config)
    dbw.register_predictors(model_data_arr)

    for broken_name in [name for name, connected in dbw.check_connections().items() if connected is False]:
        log.error(f'Error failed to integrate with database aliased: {broken_name}')

    ctx = mp.get_context('spawn')

    for api_name, api_data in apis.items():
        print(f'{api_name} API: starting...')
        try:
            p = ctx.Process(target=start_functions[api_name], args=(config_path, args.verbose))
            p.start()
            api_data['process'] = p