def graph_display(self, session=None): conf = request.form.get("conf") active_job_id = request.form.get("active_job_id", "") try: conf = json.loads(conf) conf = dag_converter.clean_dag_dict(conf) except Exception as e: conf = self.DEFAULT_CONF return self.render("dcmp/graph_display.html", readonly=True, conf=conf, active_job_id=active_job_id, **self.CONSTANT_KWS)
def graph_display(self, session=None): conf = request.form.get("conf") active_job_id = request.form.get("active_job_id", "") dbs = session.query(Connection).order_by(Connection.conn_id).all() session.expunge_all() conn_list = [db.conn_id for db in dbs if db.get_hook()] try: conf = json.loads(conf) conf = dag_converter.clean_dag_dict(conf) except Exception as e: conf = self.DEFAULT_CONF return self.render("dcmp/graph_display.html", conn_list=conn_list, tbl_list=[], csvfile_list=get_csvfile_list(), readonly=True, conf=conf, active_job_id=active_job_id, **self.CONSTANT_KWS)
def api(self, session=None): user = get_current_user() api = request.args.get("api") if api == "delete_dag": if not can_access_approver(): return jsonify({ "code": -100, "detail": "no permission", }) dag_name = request.args.get("dag_name") if dag_name: dcmp_dag = session.query(DcmpDag).filter( DcmpDag.dag_name == dag_name, ).first() if dcmp_dag: dcmp_dag.delete_conf(user=user, session=session) session.commit() dag_converter.refresh_dags() return jsonify({ "code": 0, "detail": "succeeded", }) else: return jsonify({ "code": -1, "detail": "dag name required", }) elif api == "update_dag": dag_name = request.args.get("dag_name") data = request.get_json() try: data = dag_converter.clean_dag_dict(data, strict=True) except Exception as e: logging.exception("api.update_dag") return jsonify({ "code": -2, "detail": e.message, }) new_dag_name = data["dag_name"] if new_dag_name != dag_name: if dag_name and not can_access_approver(): return jsonify({ "code": -100, "detail": "no permission to change dag name", }) dcmp_dag = session.query(DcmpDag).filter( DcmpDag.dag_name == new_dag_name, ).first() if dcmp_dag: return jsonify({ "code": -3, "detail": "dag name duplicated", }) DcmpDag.create_or_update_conf(data, user=user, session=session) if new_dag_name != dag_name and dag_name: dcmp_dag = session.query(DcmpDag).filter( DcmpDag.dag_name == dag_name, ).first() if dcmp_dag: dcmp_dag.delete_conf(user=user, session=session) session.commit() if not need_approver(): dag_converter.refresh_dags() return jsonify({ "code": 0, "detail": "succeeded", }) elif api == "approve_dag": if not can_access_approver(): return jsonify({ "code": -100, "detail": "no permission", }) dag_name = request.args.get("dag_name") version = request.args.get("version") try: version = int(version) except Exception as e: return jsonify({ "code": -5, "detail": "version invalid", }) if version <= 0: return jsonify({ "code": -5, "detail": "version invalid", }) if dag_name: dcmp_dag = session.query(DcmpDag).filter( DcmpDag.dag_name == dag_name, ).first() if dcmp_dag: if version > dcmp_dag.version or version <= dcmp_dag.approved_version: return jsonify({ "code": -5, "detail": "version invalid", }) if not dcmp_settings.DAG_CREATION_MANAGER_CAN_APPROVE_SELF and dcmp_dag.last_editor_user_id == user.id: return jsonify({ "code": -6, "detail": "can not approve yourself", }) dcmp_dag.approve_conf(version=version, user=user, session=session) session.commit() dag_converter.refresh_dags() return jsonify({ "code": 0, "detail": "succeeded", }) else: return jsonify({ "code": -2, "detail": "dag does not exists", }) else: return jsonify({ "code": -1, "detail": "dag name required", }) elif api == "get_dag": dag_name = request.args.get("dag_name") version = request.args.get("version") if dag_name: dcmp_dag = session.query(DcmpDag).filter( DcmpDag.dag_name == dag_name, ).first() if dcmp_dag: conf = dcmp_dag.get_conf(version=version, session=session) if conf: return jsonify({ "code": 0, "detail": { "conf": conf }, }) else: return jsonify({ "code": -3, "detail": "version does not exists", }) else: return jsonify({ "code": -2, "detail": "dag does not exists", }) else: return jsonify({ "code": -1, "detail": "dag name required", }) return jsonify({ "code": 0, "detail": "succeeded", }) elif api == "render_task_conf": data = request.get_json() try: ti = dag_converter.create_task_instance_by_task_conf(data) except Exception as e: logging.exception("api.render_task_conf") return jsonify({ "code": -2, "detail": e.message, }) res = self.render_ti(ti, result_format=request.args.get( "format", None)) return jsonify({ "code": 0, "detail": res, }) elif api == "dry_run_task_conf": data = request.get_json() try: ti = dag_converter.create_task_instance_by_task_conf(data) except Exception as e: logging.exception("api.dry_run_task_conf") return jsonify({ "code": -2, "detail": e.message, }) rendered = self.render_ti(ti, result_format=request.args.get( "format", None)) with LogStreamContext() as stream: ti.dry_run() log = stream.getvalue() return jsonify({ "code": 0, "detail": { "rendered": rendered, "log": log }, }) elif api == "end_editing": dag_name = request.args.get("dag_name") if dag_name: dcmp_dag = session.query(DcmpDag).filter( DcmpDag.dag_name == dag_name, ).first() if dcmp_dag and dcmp_dag.editing and user.id == dcmp_dag.editing_user_id: dcmp_dag.end_editing() session.commit() return jsonify({ "code": 0, "detail": "succeeded", }) return jsonify({ "code": -1000, "detail": "no such api", })