class StructuredDataSchema(ApiStrictSchema): type = fields.String(allow_none=True) columns_names = fields.List(fields.String(), load_from="columns", dump_to="columns", allow_none=True) columns_types = fields.Dict(load_from="dtypes", dump_to="dtypes", allow_none=True) # Shape: Tuple of ints-> (records, columns) -> fields.Tuple() added in marshmallow 3.0.0. shape = fields.List(fields.Integer(allow_none=True), allow_none=True) byte_size = fields.Integer(load_from="size.bytes", dump_to="size.bytes", allow_none=True) @pre_load def pre_load(self, data: dict) -> dict: # Support Snowflake & PostgreSQL data_schemas before dbnd-sdk-0.61.0 columns_types = data.get("column_types") if columns_types: data["columns_types"] = columns_types return data @post_load def make_object(self, data) -> DataSchemaArgs: return DataSchemaArgs(**data)
class TaskSchema(ApiStrictSchema): upstream_task_ids = fields.List(fields.String()) downstream_task_ids = fields.List(fields.String()) task_type = fields.String() task_source_code = fields.String(allow_none=True) task_source_hash = fields.String(allow_none=True) task_module_code = fields.String(allow_none=True) module_source_hash = fields.String(allow_none=True) dag_id = fields.String() task_id = fields.String() retries = fields.Integer() command = fields.String(allow_none=True) task_args = fields.Dict()
class ScheduledJobSchemaV2(Schema): class Meta: strict = True uid = fields.Str(attribute="DbndScheduledJob.uid", allow_none=True) name = fields.Str(attribute="DbndScheduledJob.name", required=True) cmd = fields.Str(attribute="DbndScheduledJob.cmd", required=True) schedule_interval = fields.Str( attribute="DbndScheduledJob.schedule_interval", required=True) start_date = fields.DateTime(allow_none=True, attribute="DbndScheduledJob.start_date", format="iso") end_date = fields.DateTime(allow_none=True, attribute="DbndScheduledJob.end_date", format="iso") readable_schedule_interval = fields.Str( attribute="DbndScheduledJob.readable_schedule_interval", allow_none=True) scheduled_interval_in_seconds = fields.Integer( attribute="DbndScheduledJob.scheduled_interval_in_seconds", allow_none=True) catchup = fields.Boolean(allow_none=True, attribute="DbndScheduledJob.catchup") depends_on_past = fields.Boolean( allow_none=True, attribute="DbndScheduledJob.depends_on_past") retries = fields.Int(allow_none=True, attribute="DbndScheduledJob.retries") active = fields.Boolean(allow_none=True, attribute="DbndScheduledJob.active") create_user = fields.Str(allow_none=True, attribute="DbndScheduledJob.create_user") create_time = fields.DateTime(allow_none=True, attribute="DbndScheduledJob.create_time") update_user = fields.Str(allow_none=True, attribute="DbndScheduledJob.update_user") update_time = fields.DateTime(allow_none=True, attribute="DbndScheduledJob.update_time") from_file = fields.Boolean(allow_none=True, attribute="DbndScheduledJob.from_file") deleted_from_file = fields.Boolean( allow_none=True, attribute="DbndScheduledJob.deleted_from_file") next_job_date = fields.DateTime(attribute="DbndScheduledJob.next_job_date", allow_none=True) alerts = fields.List( fields.Nested(AlertEventSchema), attribute="DbndScheduledJob.alerts", allow_none=True, ) job_name = fields.Str(dump_only=True, attribute="DbndScheduledJob.job_name") last_run_uid = fields.UUID(dump_only=True) last_run_job = fields.Str(dump_only=True) last_job_date = fields.DateTime(dump_only=True) last_run_state = fields.Str(dump_only=True) is_airflow_synced = fields.Bool(dump_only=True) list_order = fields.Integer(attribute="DbndScheduledJob.list_order", allow_none=True) validation_errors = fields.Str( allow_none=True, attribute="DbndScheduledJob.validation_errors")
class LogTargetMetricsSchema(_ApiCallSchema): task_run_uid = fields.UUID(required=True) task_run_attempt_uid = fields.UUID(required=True) target_path = fields.String() value_preview = fields.String(allow_none=True) data_dimensions = fields.List(fields.Integer(), allow_none=True) data_schema = fields.String(allow_none=True)
class TaskRunsInfoSchema(ApiObjectSchema): run_uid = fields.UUID() root_run_uid = fields.UUID() task_run_env_uid = fields.UUID() parent_child_map = fields.List(fields.List(fields.UUID())) task_runs = fields.Nested(TaskRunInfoSchema, many=True, exclude=("task_signature_source", )) upstreams_map = fields.List(fields.List(fields.UUID())) dynamic_task_run_update = fields.Boolean() targets = fields.Nested(TargetInfoSchema, many=True) task_definitions = fields.Nested(TaskDefinitionInfoSchema, many=True) af_context = fields.Nested(AirflowTaskContextSchema, allow_none=True) @post_load def make_run_info(self, data, **kwargs): return _as_dotted_dict(**data)
class DagSchema(ApiStrictSchema): description = fields.String() root_task_ids = fields.List(fields.String()) tasks = fields.Nested(TaskSchema, many=True) owner = fields.String() dag_id = fields.String() schedule_interval = fields.String() catchup = fields.Boolean(allow_none=True) start_date = fields.DateTime(allow_none=True) end_date = fields.DateTime(allow_none=True) is_committed = fields.Boolean() git_commit = fields.String() dag_folder = fields.String() hostname = fields.String() source_code = fields.String(allow_none=True) module_source_hash = fields.String(allow_none=True) is_subdag = fields.Boolean() tags = fields.List(fields.String(), allow_none=True) task_type = fields.String() task_args = fields.Dict() is_active = fields.Boolean(allow_none=True) is_paused = fields.Boolean(allow_none=True)
class LogTargetSchema(_ApiCallSchema): run_uid = fields.UUID(required=True) task_run_uid = fields.UUID(required=True) task_run_name = fields.String() task_run_attempt_uid = fields.UUID(required=True) target_path = fields.String() param_name = fields.String(allow_none=True) task_def_uid = fields.UUID(allow_none=True) operation_type = EnumField(DbndTargetOperationType) operation_status = EnumField(DbndTargetOperationStatus) value_preview = fields.String(allow_none=True) data_dimensions = fields.List(fields.Integer(), allow_none=True) data_schema = fields.String(allow_none=True) data_hash = fields.String(allow_none=True)
class JobsSetArchiveSchema(ApiStrictSchema): ids = fields.List(fields.Integer(), required=True, validate=validate.Length(min=1)) is_archived = fields.Boolean(required=True)
class GetRunningDagRunsResponseSchema(ApiStrictSchema): dag_run_ids = fields.List(fields.Integer()) last_seen_dag_run_id = fields.Integer(allow_none=True) last_seen_log_id = fields.Integer(allow_none=True)
class AlertDefsSchema(ApiStrictSchema): severity = fields.Str(required=True) type = fields.Str(required=True) user_metric = fields.Str() operator = fields.Str() is_str_value = fields.Bool() created_at = fields.DateTime() scheduled_job_name = fields.Str(attribute="scheduled_job.name") source_instance_name = fields.Method("get_tracking_source_name") env = fields.Method("get_tracking_source_env") # TODO_CORE: API: Deprecate airflow_server_info airflow_instance_name = fields.Method("get_tracking_source_name") project_id = fields.Int(attribute="job.project_id") project_name = fields.Str(attribute="job.project.name") alert_on_historical_runs = fields.Bool() group_uid = fields.Str(allow_none=True, load_from="alert_group_uid") root_group_uid = fields.Str(allow_none=True, load_from="alert_root_group_uid") uid = fields.Str(allow_none=True) value = fields.Str(allow_none=True) job_id = fields.Int(allow_none=True) summary = fields.Str(allow_none=True) job_name = fields.Str(attribute="job.name", allow_none=True) task_repr = fields.Str(allow_none=True) task_name = fields.Str(allow_none=True) custom_name = fields.Str(allow_none=True) original_uid = fields.Str(allow_none=True) advanced_json = fields.Str(allow_none=True) scheduled_job_uid = fields.Str(allow_none=True) custom_description = fields.Str(allow_none=True) ml_alert = fields.Nested(MLAlert, allow_none=True) # Fields for DatasetSlaAlert/DatasetSlaAdvancedAlert alert # -------------------------------------- seconds_delta = fields.Int( allow_none=True) # Converts to datetime.timedelta dataset_partial_name = fields.Str(allow_none=True) datasets_uids = fields.List(fields.Str(), allow_none=True) # Fields for OperationColumnStatAdvancedAlert alert # -------------------------------------- dataset_uid = fields.Str(allow_none=True) # Operation type (e.g. "read", "write", None=any) to filter stats by operation_type = fields.Str(allow_none=True) # Type of MetricRule, found in dbnd_web. Used to build advanced_json metrics_rules = fields.List(fields.Dict(), allow_none=True) # Used only used by the UI affected_datasets = fields.List(fields.Dict(), allow_none=True, dump_only=True) assigned_jobs = fields.Method(serialize="get_assigned_jobs", dump_only=True) is_system = fields.Function(lambda alert_def: alert_def.owner == "system", dump_only=True) def get_tracking_source_name(self, obj): return self._get_tracking_source_instance(obj).name def get_tracking_source_env(self, obj): return self._get_tracking_source_instance(obj).env def _get_tracking_source_instance(self, obj): if obj.job: return obj.job.tracking_source return obj.tracking_source @pre_load def prepere(self, data: dict, **kwargs): value = data.get("value", None) if value is not None: data["value"] = str(data["value"]) return data def get_assigned_jobs(self, alert_def): self_job = (alert_def.job_id, alert_def.job_name) sub_alerts_jobs = ((sub_alert.job_id, sub_alert.job_name) for sub_alert in alert_def.sub_alert_definitions) alert_jobs = chain(sub_alerts_jobs, [self_job]) alert_jobs = set(filter(lambda l: l != (None, None), alert_jobs)) serialized_assigned_jobs = [{ "job_id": job_id, "job_name": job_name } for job_id, job_name in alert_jobs] return serialized_assigned_jobs