class Token(db.Model): __tablename__ = 'tokens' id = db.Column(db.Integer, primary_key=True) client_id = db.Column( db.String(40), db.ForeignKey('clients.client_id'), nullable=False, ) user_id = db.Column(db.Integer, db.ForeignKey('users.id')) # currently only bearer is supported token_type = db.Column(db.String(40)) access_token = db.Column(db.String(255), unique=True) refresh_token = db.Column(db.String(255), unique=True) expires = db.Column(db.DateTime) _scopes = db.Column(db.Text) def delete(self): db.session.delete(self) db.session.commit() return self @property def scopes(self): if self._scopes: return self._scopes.split() return []
class Grant(db.Model): __tablename__ = 'grants' id = db.Column(db.Integer, primary_key=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id', ondelete='CASCADE')) client_id = db.Column( db.String(40), db.ForeignKey('clients.client_id'), nullable=False, ) code = db.Column(db.String(255), index=True, nullable=False) redirect_uri = db.Column(db.String(255)) expires = db.Column(db.DateTime) _scopes = db.Column(db.Text) def delete(self): db.session.delete(self) db.session.commit() return self @property def scopes(self): if self._scopes: return self._scopes.split() return []
class PipelineCatalog(db.Model): __tablename__ = 'pipeline_catalog2' pipeline_type_id = db.Column(db.Integer, db.ForeignKey('pipeline_types.id'), primary_key=True) current_task_type_id = db.Column(db.Integer, db.ForeignKey('task_types.id'), primary_key=True) next_task_type_id = db.Column(db.Integer, db.ForeignKey('task_types.id'), primary_key=True) pipeline_type = db.relationship("PipelineType", back_populates="tasks") current_task_type = db.relationship("TaskType", foreign_keys=[current_task_type_id]) next_task_type = db.relationship("TaskType", foreign_keys=[next_task_type_id])
class Catalog(db.Model): __tablename__ = 'catalog2' container_id = db.Column(db.Integer, db.ForeignKey('containers.id'), primary_key=True) file_id = db.Column(db.Integer, db.ForeignKey('files.id'), primary_key=True) type = db.Column(db.String(50)) file = db.relationship("File", back_populates="containers") cont = db.relationship("Container", back_populates="files")
class Pipeline(PipelineJsonSerializer, db.Model): __tablename__ = 'pipelines' id = db.Column(db.Integer, primary_key=True) owner_id = db.Column(db.Integer, db.ForeignKey('users.id')) type_id = db.Column(db.Integer, db.ForeignKey('pipeline_types.id')) pipeline_type = db.relationship("PipelineType", back_populates="pipelines") tag = db.Column(db.String(256)) current_task_id = db.Column(db.Integer, db.ForeignKey('tasks.id'), default=None) status = db.Column(db.String(256)) creation_time = db.Column(db.DateTime) modification_time = db.Column(db.DateTime) def __repr__(self): return '<Pipeline id=%s name=%s>' % (self.id, self.name)
class TransferTask(db.Model): __tablename__ = 'transfertasks' id = db.Column(db.Integer, primary_key=True) replica_id = db.Column(db.Integer, db.ForeignKey('replicas.id')) se = db.Column(db.String(40)) task_id = db.Column(db.String(40)) task_status = db.Column(db.String(20))
class Task(TaskJsonSerializer, db.Model): __tablename__ = 'tasks' id = db.Column(db.Integer, primary_key=True) owner_id = db.Column(db.Integer, db.ForeignKey('users.id')) task_type_id = db.Column(db.Integer, db.ForeignKey('task_types.id')) task_type = db.relationship("TaskType", back_populates="tasks") tag = db.Column(db.String(256)) creation_time = db.Column(db.DateTime) modification_time = db.Column(db.DateTime) status = db.Column(db.String(64), default='defined') #TODO place comment - task_status= ?(defined, starting, sent,running finished, cancelled, failed). Also for pipelines -? jobs = db.relationship('Job', secondary=tasks_jobs) trf = db.Column(db.String(1024)) input = db.Column(db.Integer, db.ForeignKey('containers.id'), default=None) output = db.Column(db.Integer, db.ForeignKey('containers.id'), default=None) comment = db.Column(db.String(1024)) params = db.Column(db.Text) def __repr__(self): return '<Task id=%s tag=%s>' % (self.id, self.tag)
class Replica(db.Model): __tablename__ = 'replicas' id = db.Column(db.Integer, primary_key=True) original_id = db.Column(db.Integer, db.ForeignKey('files.id')) se = db.Column(db.String(20)) status = db.Column(db.String(20)) #ready/transfer lfn = db.Column(db.String(200)) #local file name token = db.Column(db.String(200)) #string of params to get file def __repr__(self): return '<Replica id=%s>' % self.id
class Job(JobJsonSerializer, db.Model): __tablename__ = 'jobs' id = db.Column(db.Integer, primary_key=True) pandaid = db.Column(db.Integer) status = db.Column(db.String(20)) owner_id = db.Column(db.Integer, db.ForeignKey('users.id')) distr_id = db.Column(db.Integer, db.ForeignKey('distr.id')) params = db.Column(db.String(1000)) container_id = db.Column(db.Integer, db.ForeignKey('containers.id')) creation_time = db.Column(db.DateTime) modification_time = db.Column(db.DateTime) ninputfiles = db.Column(db.Integer) noutputfiles = db.Column(db.Integer) registered = db.Column(db.Integer, default=0) registation_time = db.Column(db.DateTime) ce = db.Column(db.String(40)) corecount = db.Column(db.Integer, default=0) tags = db.Column(db.String(256), default='') attemptnr = db.Column(db.Integer, default=0) def __repr__(self): return '<Job id=%s>' % self.id
class TaskType(TaskTypeJsonSerializer, db.Model): __tablename__ = 'task_types' id = db.Column(db.Integer, primary_key=True) method = db.Column(db.String(256)) trf_template = db.Column(db.String(1024)) ifiles_template = db.Column(db.String(1024)) ofiles_template = db.Column(db.String(1024)) tasks = db.relationship("Task", back_populates="task_type") distr_id = db.Column(db.Integer, db.ForeignKey('distr.id')) distr = db.relationship("Distributive") def __repr__(self): return '<TaskType id=%s>' % self.id
class Client(db.Model): __tablename__ = 'clients' # human readable name, not required name = db.Column(db.String(40)) # human readable description, not required description = db.Column(db.String(400)) # creator of the client, not required user_id = db.Column(db.ForeignKey('users.id')) client_id = db.Column(db.String(40), primary_key=True) client_secret = db.Column(db.String(55), unique=True, index=True, nullable=False) # public or confidential is_confidential = db.Column(db.Boolean) tokens = db.relationship('Token', backref=db.backref('client', lazy='joined'), lazy='dynamic') grants = db.relationship('Grant', backref=db.backref('client', lazy='joined'), lazy='dynamic') _redirect_uris = db.Column(db.Text) _default_scopes = db.Column(db.Text) @property def client_type(self): if self.is_confidential: return 'confidential' return 'public' @property def redirect_uris(self): if self._redirect_uris: return self._redirect_uris.split() return [] @property def default_redirect_uri(self): return self.redirect_uris[0] @property def default_scopes(self): if self._default_scopes: return self._default_scopes.split() return []
class PipelineArchive(db.Model): __tablename__ = 'pipeline_archive' pipeline_id = db.Column(db.Integer, db.ForeignKey('pipelines.id'), primary_key=True) task_id = db.Column(db.Integer, db.ForeignKey('tasks.id'), primary_key=True) creation_time = db.Column(db.DateTime)
# -*- coding: utf-8 -*- """ webpanda.tasks.models ~~~~~~~~~~~~~~~~~~~~~~ Task models """ from webpanda.core import db, WebpandaError from webpanda.helpers import JsonSerializer tasks_jobs = db.Table( 'tasks_jobs', db.Column('task_id', db.Integer(), db.ForeignKey('tasks.id')), db.Column('job_id', db.Integer(), db.ForeignKey('jobs.id'))) class PipelineCatalog(db.Model): __tablename__ = 'pipeline_catalog2' pipeline_type_id = db.Column(db.Integer, db.ForeignKey('pipeline_types.id'), primary_key=True) current_task_type_id = db.Column(db.Integer, db.ForeignKey('task_types.id'), primary_key=True) next_task_type_id = db.Column(db.Integer, db.ForeignKey('task_types.id'), primary_key=True) pipeline_type = db.relationship("PipelineType", back_populates="tasks") current_task_type = db.relationship("TaskType", foreign_keys=[current_task_type_id]) next_task_type = db.relationship("TaskType", foreign_keys=[next_task_type_id]) class TaskTypeJsonSerializer(JsonSerializer): __json_public__ = ['id', 'method']