def build_function(): try: data = request.get_json(force=True) except ValueError: return json_error(HTTPStatus.BAD_REQUEST, reason='bad JSON body') logger.info('build_function:\n{}'.format(data)) function = data.get('function') with_mlrun = strtobool(data.get('with_mlrun', 'on')) try: fn = new_function(runtime=function) fn.set_db_connection(_db) fn.save(versioned=False) ready = build_runtime(fn, with_mlrun) fn.save(versioned=False) logger.info('Fn:\n %s', fn.to_yaml()) except Exception as err: logger.error(traceback.format_exc()) return json_error( HTTPStatus.BAD_REQUEST, reason='runtime error: {}'.format(err), ) return jsonify(ok=True, data=fn.to_dict(), ready=ready)
def _build_function( db_session, auth_info: mlrun.api.schemas.AuthInfo, function, with_mlrun, skip_deployed, mlrun_version_specifier, ): fn = None ready = None try: fn = new_function(runtime=function) run_db = get_run_db_instance(db_session, auth_info.session) fn.set_db_connection(run_db) fn.save(versioned=False) if fn.kind in RuntimeKinds.nuclio_runtimes(): mlrun.api.api.utils.ensure_function_has_auth_set(fn, auth_info) deploy_nuclio_function(fn) # deploy only start the process, the get status API is used to check readiness ready = False else: ready = build_runtime(fn, with_mlrun, mlrun_version_specifier, skip_deployed) fn.save(versioned=True) logger.info("Fn:\n %s", fn.to_yaml()) except Exception as err: logger.error(traceback.format_exc()) log_and_raise(HTTPStatus.BAD_REQUEST.value, reason=f"runtime error: {err}") return fn, ready
def _build_function(db_session, function, with_mlrun): fn = None ready = None try: fn = new_function(runtime=function) run_db = get_run_db_instance(db_session) fn.set_db_connection(run_db) fn.save(versioned=False) ready = build_runtime(fn, with_mlrun) fn.save(versioned=False) logger.info("Fn:\n %s", fn.to_yaml()) except Exception as err: logger.error(traceback.format_exc()) log_and_raise(HTTPStatus.BAD_REQUEST, reason="runtime error: {}".format(err)) return fn, ready
def _build_function(db_session, function, with_mlrun): fn = None ready = None try: fn = new_function(runtime=function) run_db = get_run_db_instance(db_session) fn.set_db_connection(run_db) fn.save(versioned=False) if fn.kind in RuntimeKinds.nuclio_runtimes(): deploy_nuclio_function(fn) # deploy only start the process, the get status API is used to check readiness ready = False else: ready = build_runtime(fn, with_mlrun) fn.save(versioned=True) logger.info("Fn:\n %s", fn.to_yaml()) except Exception as err: logger.error(traceback.format_exc()) log_and_raise(HTTPStatus.BAD_REQUEST.value, reason="runtime error: {}".format(err)) return fn, ready
def _build_function( db_session, auth_info: mlrun.api.schemas.AuthInfo, function, with_mlrun=True, skip_deployed=False, mlrun_version_specifier=None, builder_env=None, ): fn = None ready = None try: fn = new_function(runtime=function) except Exception as err: logger.error(traceback.format_exc()) log_and_raise(HTTPStatus.BAD_REQUEST.value, reason=f"runtime error: {err}") try: run_db = get_run_db_instance(db_session) fn.set_db_connection(run_db) fn.save(versioned=False) if fn.kind in RuntimeKinds.nuclio_runtimes(): mlrun.api.api.utils.ensure_function_has_auth_set(fn, auth_info) mlrun.api.api.utils.process_function_service_account(fn) if fn.kind == RuntimeKinds.serving: # Handle model monitoring try: if fn.spec.track_models: logger.info( "Tracking enabled, initializing model monitoring") _init_serving_function_stream_args(fn=fn) model_monitoring_access_key = _process_model_monitoring_secret( db_session, fn.metadata.project, "MODEL_MONITORING_ACCESS_KEY", ) _create_model_monitoring_stream( project=fn.metadata.project) mlrun.api.crud.ModelEndpoints( ).deploy_monitoring_functions( project=fn.metadata.project, model_monitoring_access_key= model_monitoring_access_key, db_session=db_session, auth_info=auth_info, ) except Exception as exc: logger.warning( "Failed deploying model monitoring infrastructure for the project", project=fn.metadata.project, exc=exc, traceback=traceback.format_exc(), ) deploy_nuclio_function(fn, auth_info=auth_info) # deploy only start the process, the get status API is used to check readiness ready = False else: ready = build_runtime( auth_info, fn, with_mlrun, mlrun_version_specifier, skip_deployed, builder_env=builder_env, ) fn.save(versioned=True) logger.info("Fn:\n %s", fn.to_yaml()) except Exception as err: logger.error(traceback.format_exc()) log_and_raise(HTTPStatus.BAD_REQUEST.value, reason=f"runtime error: {err}") return fn, ready