Loading management/data/data_dev.py +7 −4 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ from flask import Flask from flask_sqlalchemy import SQLAlchemy from management.data.shared import DataFactory from portal.database.models import Course, Review, Submission, SubmissionState from portal.database.models import Course, Review, Submission, SubmissionState, Secret from portal.tools import time Loading Loading @@ -159,9 +159,12 @@ def init_dev_data(app: Flask, db: SQLAlchemy): db.session.add_all([review]) # components factory.create_component(name='executor') factory.create_component( name='processing', component_type='processing') tomorrow = time.current_time() + timedelta(days=1) executor = factory.create_worker(name='executor', url='some-url') executor.secrets.append(Secret('executor_secret', 'executor_secret', tomorrow)) processing = factory.create_worker(name='processing', url='some-url') processing.secrets.append(Secret('processing_secret', 'processing_secret', tomorrow)) db.session.add_all([executor, processing]) # Commit to the DB db.session.commit() management/data/data_test.py +9 −6 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ from flask import Flask from flask_sqlalchemy import SQLAlchemy from management.data.shared import DataFactory from portal.database.models import Review, Submission, SubmissionState from portal.database.models import Review, Submission, SubmissionState, Secret from portal.tools import time Loading Loading @@ -157,10 +157,13 @@ def init_test_data(app: Flask, db: SQLAlchemy): db.session.add_all([review]) # components factory.create_component(name='executor') factory.create_component( name='processing', component_type='processing') # workers executor = factory.create_worker(name='executor', url="foo/url") executor.secrets.append(Secret('executor_secret', "executor_secret", time.current_time() + timedelta(hours=1))) processing = factory.create_worker(name='processing', url="bar/url") processing.secrets.append(Secret('processing_secret', "processing_secret", time.current_time() + timedelta(hours=1))) db.session.add_all([executor, processing]) # Commit to the DB db.session.commit() management/data/shared.py +3 −7 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ import random import string from flask_sqlalchemy import SQLAlchemy from portal.database.models import Component, Course, Group, Project, ReviewItem, Role, User from portal.database.models import Worker, Course, Group, Project, ReviewItem, Role, User log = logging.getLogger(__name__) Loading Loading @@ -104,12 +104,8 @@ class DataFactory(object): log.info(f"[SAMPLE] Create {entity}") return entity def create_component(self, name: str, secret: str = None, component_type: str = 'executor', ip_addr: str = '127.0.0.1', notes: str = None) -> Component: secret = secret or f"{name}_secret" notes = notes or f"Component {name} of type {type}" return self.__create_entity(Component, name=name, secret=secret, ip_address=ip_addr, notes=notes, component_type=component_type) def create_worker(self, name: str, url: str) -> Worker: return self.__create_entity(Worker, name=name, url=url) def create_course(self, codename, name=None, token=None) -> Course: name = name or codename Loading migrations/versions/e897fc93ab4e_.py→migrations/versions/38031726c9b7_.py +56 −36 Original line number Diff line number Diff line """empty message Revision ID: e897fc93ab4e Revision ID: 38031726c9b7 Revises: Create Date: 2018-08-23 17:31:11.993908 Create Date: 2018-09-02 13:40:56.387248 """ from alembic import op Loading @@ -10,7 +10,7 @@ import sqlalchemy as sa # revision identifiers, used by Alembic. revision = 'e897fc93ab4e' revision = '38031726c9b7' down_revision = None branch_labels = None depends_on = None Loading @@ -18,17 +18,10 @@ depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('component', sa.Column('created_at', sa.TIMESTAMP(), nullable=True), sa.Column('updated_at', sa.TIMESTAMP(), nullable=True), op.create_table('client', sa.Column('id', sa.String(length=36), nullable=False), sa.Column('name', sa.String(length=30), nullable=False), sa.Column('secret', sa.String(length=250), nullable=True), sa.Column('ip_address', sa.String(length=50), nullable=True), sa.Column('type', sa.String(length=25), nullable=True), sa.Column('notes', sa.Text(), nullable=True), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name') sa.Column('type', sa.Enum('USER', 'WORKER', name='ClientType'), nullable=False), sa.PrimaryKeyConstraint('id') ) op.create_table('course', sa.Column('created_at', sa.TIMESTAMP(), nullable=True), Loading @@ -41,20 +34,6 @@ def upgrade(): sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('codename', name='course_unique_codename') ) op.create_table('user', sa.Column('created_at', sa.TIMESTAMP(), nullable=True), sa.Column('updated_at', sa.TIMESTAMP(), nullable=True), sa.Column('id', sa.String(length=36), nullable=False), sa.Column('uco', sa.Integer(), nullable=True), sa.Column('email', sa.String(length=50), nullable=False), sa.Column('username', sa.String(length=30), nullable=False), sa.Column('name', sa.String(length=50), nullable=True), sa.Column('is_admin', sa.Boolean(), nullable=True), sa.Column('password_hash', sa.String(length=120), nullable=True), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('email'), sa.UniqueConstraint('username') ) op.create_table('group', sa.Column('created_at', sa.TIMESTAMP(), nullable=True), sa.Column('updated_at', sa.TIMESTAMP(), nullable=True), Loading Loading @@ -92,6 +71,49 @@ def upgrade(): sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('course_id', 'codename', name='r_course_unique_name') ) op.create_table('secret', sa.Column('id', sa.String(length=36), nullable=False), sa.Column('name', sa.String(length=40), nullable=False), sa.Column('value', sa.String(length=120), nullable=True), sa.Column('created_at', sa.TIMESTAMP(), nullable=True), sa.Column('expires_at', sa.TIMESTAMP(), nullable=False), sa.Column('client_id', sa.String(length=36), nullable=False), sa.ForeignKeyConstraint(['client_id'], ['client.id'], ondelete='cascade'), sa.PrimaryKeyConstraint('id') ) op.create_table('user', sa.Column('created_at', sa.TIMESTAMP(), nullable=True), sa.Column('updated_at', sa.TIMESTAMP(), nullable=True), sa.Column('id', sa.String(length=36), nullable=False), sa.Column('uco', sa.Integer(), nullable=True), sa.Column('email', sa.String(length=50), nullable=False), sa.Column('username', sa.String(length=30), nullable=False), sa.Column('name', sa.String(length=50), nullable=True), sa.Column('is_admin', sa.Boolean(), nullable=True), sa.Column('password_hash', sa.String(length=120), nullable=True), sa.ForeignKeyConstraint(['id'], ['client.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('email'), sa.UniqueConstraint('username') ) op.create_table('worker', sa.Column('created_at', sa.TIMESTAMP(), nullable=True), sa.Column('updated_at', sa.TIMESTAMP(), nullable=True), sa.Column('id', sa.String(length=36), nullable=False), sa.Column('name', sa.String(length=30), nullable=False), sa.Column('url', sa.String(length=250), nullable=False), sa.Column('tags', sa.Text(), nullable=True), sa.Column('state', sa.Enum('CREATED', 'READY', 'STOPPED', name='WorkerState'), nullable=False), sa.ForeignKeyConstraint(['id'], ['client.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name') ) op.create_table('clients_roles', sa.Column('client_id', sa.String(length=36), nullable=True), sa.Column('role_id', sa.String(length=36), nullable=True), sa.ForeignKeyConstraint(['client_id'], ['client.id'], ondelete='cascade'), sa.ForeignKeyConstraint(['role_id'], ['role.id'], ondelete='cascade') ) op.create_table('projectConfig', sa.Column('created_at', sa.TIMESTAMP(), nullable=True), sa.Column('updated_at', sa.TIMESTAMP(), nullable=True), Loading @@ -99,6 +121,7 @@ def upgrade(): sa.Column('project_id', sa.String(length=36), nullable=False), sa.Column('submissions_cancellation_period', sa.Integer(), nullable=True), sa.Column('test_files_source', sa.String(length=600), nullable=True), sa.Column('test_files_commit_hash', sa.String(length=64), nullable=True), sa.Column('file_whitelist', sa.Text(), nullable=True), sa.Column('pre_submit_script', sa.Text(), nullable=True), sa.Column('post_submit_script', sa.Text(), nullable=True), Loading Loading @@ -157,6 +180,7 @@ def upgrade(): sa.Column('parameters', sa.Text(), nullable=False), sa.Column('state', sa.Enum('CREATED', 'READY', 'QUEUED', 'IN_PROGRESS', 'FINISHED', 'CANCELLED', 'ABORTED', 'ARCHIVED', name='SubmissionState'), nullable=False), sa.Column('note', sa.Text(), nullable=True), sa.Column('source_hash', sa.String(length=64), nullable=True), sa.Column('user_id', sa.String(length=36), nullable=False), sa.Column('project_id', sa.String(length=36), nullable=False), sa.Column('storage_task_id', sa.String(length=36), nullable=True), Loading @@ -171,12 +195,6 @@ def upgrade(): sa.ForeignKeyConstraint(['group_id'], ['group.id'], ondelete='cascade'), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ondelete='cascade') ) op.create_table('users_roles', sa.Column('user_id', sa.String(length=36), nullable=True), sa.Column('role_id', sa.String(length=36), nullable=True), sa.ForeignKeyConstraint(['role_id'], ['role.id'], ondelete='cascade'), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ondelete='cascade') ) op.create_table('review', sa.Column('created_at', sa.TIMESTAMP(), nullable=True), sa.Column('updated_at', sa.TIMESTAMP(), nullable=True), Loading Loading @@ -205,16 +223,18 @@ def downgrade(): # ### commands auto generated by Alembic - please adjust! ### op.drop_table('reviewItem') op.drop_table('review') op.drop_table('users_roles') op.drop_table('users_groups') op.drop_table('submission') op.drop_table('rolePermissions') op.drop_table('projects_groups') op.drop_table('projectConfig') op.drop_table('clients_roles') op.drop_table('worker') op.drop_table('user') op.drop_table('secret') op.drop_table('role') op.drop_table('project') op.drop_table('group') op.drop_table('user') op.drop_table('course') op.drop_table('component') op.drop_table('client') # ### end Alembic commands ### migrations/versions/9143d16ae835_.pydeleted 100644 → 0 +0 −30 Original line number Diff line number Diff line """empty message Revision ID: 9143d16ae835 Revises: e897fc93ab4e Create Date: 2018-08-25 13:07:56.545852 """ from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision = '9143d16ae835' down_revision = 'e897fc93ab4e' branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.add_column('projectConfig', sa.Column('test_files_commit_hash', sa.String(length=64), nullable=True)) op.add_column('submission', sa.Column('source_hash', sa.String(length=64), nullable=True)) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### op.drop_column('submission', 'source_hash') op.drop_column('projectConfig', 'test_files_commit_hash') # ### end Alembic commands ### Loading
management/data/data_dev.py +7 −4 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ from flask import Flask from flask_sqlalchemy import SQLAlchemy from management.data.shared import DataFactory from portal.database.models import Course, Review, Submission, SubmissionState from portal.database.models import Course, Review, Submission, SubmissionState, Secret from portal.tools import time Loading Loading @@ -159,9 +159,12 @@ def init_dev_data(app: Flask, db: SQLAlchemy): db.session.add_all([review]) # components factory.create_component(name='executor') factory.create_component( name='processing', component_type='processing') tomorrow = time.current_time() + timedelta(days=1) executor = factory.create_worker(name='executor', url='some-url') executor.secrets.append(Secret('executor_secret', 'executor_secret', tomorrow)) processing = factory.create_worker(name='processing', url='some-url') processing.secrets.append(Secret('processing_secret', 'processing_secret', tomorrow)) db.session.add_all([executor, processing]) # Commit to the DB db.session.commit()
management/data/data_test.py +9 −6 Original line number Diff line number Diff line Loading @@ -3,7 +3,7 @@ from flask import Flask from flask_sqlalchemy import SQLAlchemy from management.data.shared import DataFactory from portal.database.models import Review, Submission, SubmissionState from portal.database.models import Review, Submission, SubmissionState, Secret from portal.tools import time Loading Loading @@ -157,10 +157,13 @@ def init_test_data(app: Flask, db: SQLAlchemy): db.session.add_all([review]) # components factory.create_component(name='executor') factory.create_component( name='processing', component_type='processing') # workers executor = factory.create_worker(name='executor', url="foo/url") executor.secrets.append(Secret('executor_secret', "executor_secret", time.current_time() + timedelta(hours=1))) processing = factory.create_worker(name='processing', url="bar/url") processing.secrets.append(Secret('processing_secret', "processing_secret", time.current_time() + timedelta(hours=1))) db.session.add_all([executor, processing]) # Commit to the DB db.session.commit()
management/data/shared.py +3 −7 Original line number Diff line number Diff line Loading @@ -7,7 +7,7 @@ import random import string from flask_sqlalchemy import SQLAlchemy from portal.database.models import Component, Course, Group, Project, ReviewItem, Role, User from portal.database.models import Worker, Course, Group, Project, ReviewItem, Role, User log = logging.getLogger(__name__) Loading Loading @@ -104,12 +104,8 @@ class DataFactory(object): log.info(f"[SAMPLE] Create {entity}") return entity def create_component(self, name: str, secret: str = None, component_type: str = 'executor', ip_addr: str = '127.0.0.1', notes: str = None) -> Component: secret = secret or f"{name}_secret" notes = notes or f"Component {name} of type {type}" return self.__create_entity(Component, name=name, secret=secret, ip_address=ip_addr, notes=notes, component_type=component_type) def create_worker(self, name: str, url: str) -> Worker: return self.__create_entity(Worker, name=name, url=url) def create_course(self, codename, name=None, token=None) -> Course: name = name or codename Loading
migrations/versions/e897fc93ab4e_.py→migrations/versions/38031726c9b7_.py +56 −36 Original line number Diff line number Diff line """empty message Revision ID: e897fc93ab4e Revision ID: 38031726c9b7 Revises: Create Date: 2018-08-23 17:31:11.993908 Create Date: 2018-09-02 13:40:56.387248 """ from alembic import op Loading @@ -10,7 +10,7 @@ import sqlalchemy as sa # revision identifiers, used by Alembic. revision = 'e897fc93ab4e' revision = '38031726c9b7' down_revision = None branch_labels = None depends_on = None Loading @@ -18,17 +18,10 @@ depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.create_table('component', sa.Column('created_at', sa.TIMESTAMP(), nullable=True), sa.Column('updated_at', sa.TIMESTAMP(), nullable=True), op.create_table('client', sa.Column('id', sa.String(length=36), nullable=False), sa.Column('name', sa.String(length=30), nullable=False), sa.Column('secret', sa.String(length=250), nullable=True), sa.Column('ip_address', sa.String(length=50), nullable=True), sa.Column('type', sa.String(length=25), nullable=True), sa.Column('notes', sa.Text(), nullable=True), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name') sa.Column('type', sa.Enum('USER', 'WORKER', name='ClientType'), nullable=False), sa.PrimaryKeyConstraint('id') ) op.create_table('course', sa.Column('created_at', sa.TIMESTAMP(), nullable=True), Loading @@ -41,20 +34,6 @@ def upgrade(): sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('codename', name='course_unique_codename') ) op.create_table('user', sa.Column('created_at', sa.TIMESTAMP(), nullable=True), sa.Column('updated_at', sa.TIMESTAMP(), nullable=True), sa.Column('id', sa.String(length=36), nullable=False), sa.Column('uco', sa.Integer(), nullable=True), sa.Column('email', sa.String(length=50), nullable=False), sa.Column('username', sa.String(length=30), nullable=False), sa.Column('name', sa.String(length=50), nullable=True), sa.Column('is_admin', sa.Boolean(), nullable=True), sa.Column('password_hash', sa.String(length=120), nullable=True), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('email'), sa.UniqueConstraint('username') ) op.create_table('group', sa.Column('created_at', sa.TIMESTAMP(), nullable=True), sa.Column('updated_at', sa.TIMESTAMP(), nullable=True), Loading Loading @@ -92,6 +71,49 @@ def upgrade(): sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('course_id', 'codename', name='r_course_unique_name') ) op.create_table('secret', sa.Column('id', sa.String(length=36), nullable=False), sa.Column('name', sa.String(length=40), nullable=False), sa.Column('value', sa.String(length=120), nullable=True), sa.Column('created_at', sa.TIMESTAMP(), nullable=True), sa.Column('expires_at', sa.TIMESTAMP(), nullable=False), sa.Column('client_id', sa.String(length=36), nullable=False), sa.ForeignKeyConstraint(['client_id'], ['client.id'], ondelete='cascade'), sa.PrimaryKeyConstraint('id') ) op.create_table('user', sa.Column('created_at', sa.TIMESTAMP(), nullable=True), sa.Column('updated_at', sa.TIMESTAMP(), nullable=True), sa.Column('id', sa.String(length=36), nullable=False), sa.Column('uco', sa.Integer(), nullable=True), sa.Column('email', sa.String(length=50), nullable=False), sa.Column('username', sa.String(length=30), nullable=False), sa.Column('name', sa.String(length=50), nullable=True), sa.Column('is_admin', sa.Boolean(), nullable=True), sa.Column('password_hash', sa.String(length=120), nullable=True), sa.ForeignKeyConstraint(['id'], ['client.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('email'), sa.UniqueConstraint('username') ) op.create_table('worker', sa.Column('created_at', sa.TIMESTAMP(), nullable=True), sa.Column('updated_at', sa.TIMESTAMP(), nullable=True), sa.Column('id', sa.String(length=36), nullable=False), sa.Column('name', sa.String(length=30), nullable=False), sa.Column('url', sa.String(length=250), nullable=False), sa.Column('tags', sa.Text(), nullable=True), sa.Column('state', sa.Enum('CREATED', 'READY', 'STOPPED', name='WorkerState'), nullable=False), sa.ForeignKeyConstraint(['id'], ['client.id'], ), sa.PrimaryKeyConstraint('id'), sa.UniqueConstraint('name') ) op.create_table('clients_roles', sa.Column('client_id', sa.String(length=36), nullable=True), sa.Column('role_id', sa.String(length=36), nullable=True), sa.ForeignKeyConstraint(['client_id'], ['client.id'], ondelete='cascade'), sa.ForeignKeyConstraint(['role_id'], ['role.id'], ondelete='cascade') ) op.create_table('projectConfig', sa.Column('created_at', sa.TIMESTAMP(), nullable=True), sa.Column('updated_at', sa.TIMESTAMP(), nullable=True), Loading @@ -99,6 +121,7 @@ def upgrade(): sa.Column('project_id', sa.String(length=36), nullable=False), sa.Column('submissions_cancellation_period', sa.Integer(), nullable=True), sa.Column('test_files_source', sa.String(length=600), nullable=True), sa.Column('test_files_commit_hash', sa.String(length=64), nullable=True), sa.Column('file_whitelist', sa.Text(), nullable=True), sa.Column('pre_submit_script', sa.Text(), nullable=True), sa.Column('post_submit_script', sa.Text(), nullable=True), Loading Loading @@ -157,6 +180,7 @@ def upgrade(): sa.Column('parameters', sa.Text(), nullable=False), sa.Column('state', sa.Enum('CREATED', 'READY', 'QUEUED', 'IN_PROGRESS', 'FINISHED', 'CANCELLED', 'ABORTED', 'ARCHIVED', name='SubmissionState'), nullable=False), sa.Column('note', sa.Text(), nullable=True), sa.Column('source_hash', sa.String(length=64), nullable=True), sa.Column('user_id', sa.String(length=36), nullable=False), sa.Column('project_id', sa.String(length=36), nullable=False), sa.Column('storage_task_id', sa.String(length=36), nullable=True), Loading @@ -171,12 +195,6 @@ def upgrade(): sa.ForeignKeyConstraint(['group_id'], ['group.id'], ondelete='cascade'), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ondelete='cascade') ) op.create_table('users_roles', sa.Column('user_id', sa.String(length=36), nullable=True), sa.Column('role_id', sa.String(length=36), nullable=True), sa.ForeignKeyConstraint(['role_id'], ['role.id'], ondelete='cascade'), sa.ForeignKeyConstraint(['user_id'], ['user.id'], ondelete='cascade') ) op.create_table('review', sa.Column('created_at', sa.TIMESTAMP(), nullable=True), sa.Column('updated_at', sa.TIMESTAMP(), nullable=True), Loading Loading @@ -205,16 +223,18 @@ def downgrade(): # ### commands auto generated by Alembic - please adjust! ### op.drop_table('reviewItem') op.drop_table('review') op.drop_table('users_roles') op.drop_table('users_groups') op.drop_table('submission') op.drop_table('rolePermissions') op.drop_table('projects_groups') op.drop_table('projectConfig') op.drop_table('clients_roles') op.drop_table('worker') op.drop_table('user') op.drop_table('secret') op.drop_table('role') op.drop_table('project') op.drop_table('group') op.drop_table('user') op.drop_table('course') op.drop_table('component') op.drop_table('client') # ### end Alembic commands ###
migrations/versions/9143d16ae835_.pydeleted 100644 → 0 +0 −30 Original line number Diff line number Diff line """empty message Revision ID: 9143d16ae835 Revises: e897fc93ab4e Create Date: 2018-08-25 13:07:56.545852 """ from alembic import op import sqlalchemy as sa # revision identifiers, used by Alembic. revision = '9143d16ae835' down_revision = 'e897fc93ab4e' branch_labels = None depends_on = None def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.add_column('projectConfig', sa.Column('test_files_commit_hash', sa.String(length=64), nullable=True)) op.add_column('submission', sa.Column('source_hash', sa.String(length=64), nullable=True)) # ### end Alembic commands ### def downgrade(): # ### commands auto generated by Alembic - please adjust! ### op.drop_column('submission', 'source_hash') op.drop_column('projectConfig', 'test_files_commit_hash') # ### end Alembic commands ###