Skip to content

Commit

Permalink
Merge pull request #41 from Aratz/refactor_rebased
Browse files Browse the repository at this point in the history
Remove support for mover
  • Loading branch information
Aratz authored Oct 13, 2022
2 parents 8f346fc + 728cfbc commit 2ebef93
Show file tree
Hide file tree
Showing 27 changed files with 1,001 additions and 1,278 deletions.
33 changes: 33 additions & 0 deletions alembic/versions/74b309c44134_drop_ddsproject_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Drop DDSProject table
Revision ID: 74b309c44134
Revises: 8a4cc1553379
Create Date: 2022-06-16 15:37:24.124003
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '74b309c44134'
down_revision = '8a4cc1553379'
branch_labels = None
depends_on = None


def upgrade():
op.drop_table('dds_projects')
op.add_column(
'delivery_orders',
sa.Column('ngi_project_name', sa.String(), nullable=True))


def downgrade():
op.drop_column('delivery_orders', 'ngi_project_name')
op.create_table(
'dds_projects',
sa.Column('dds_project_id', sa.String(), nullable=False),
sa.Column('project_name', sa.String(), nullable=True),
sa.PrimaryKeyConstraint('dds_project_id')
)
7 changes: 5 additions & 2 deletions alembic/versions/85082f64ccd0_add_dds_project_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
branch_labels = None
depends_on = None


def upgrade():
op.create_table('dds_projects',
sa.Column('dds_project_id', sa.String, nullable=False, primary_key=True),
op.create_table(
'dds_projects',
sa.Column(
'dds_project_id', sa.String, nullable=False, primary_key=True),
sa.Column('project_name', sa.String),
)

Expand Down
30 changes: 30 additions & 0 deletions alembic/versions/8a4cc1553379_decommission_mover.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""decommission mover
Revision ID: 8a4cc1553379
Revises: 85082f64ccd0
Create Date: 2022-06-02 10:35:30.789457
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '8a4cc1553379'
down_revision = '85082f64ccd0'
branch_labels = None
depends_on = None


def upgrade():
with op.batch_alter_table('delivery_orders') as batch_op:
batch_op.drop_column('mover_delivery_id')
batch_op.drop_column('md5sum_file')
batch_op.alter_column('mover_pid', new_column_name='dds_pid')


def downgrade():
with op.batch_alter_table('delivery_orders') as batch_op:
batch_op.alter_column('dds_pid', new_column_name='mover_pid')
op.add_column('delivery_orders', sa.Column('md5sum_file', sa.String(), nullable=True))
op.add_column('delivery_orders', sa.Column('mover_delivery_id', sa.String(), nullable=True))
1 change: 0 additions & 1 deletion config/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ runfolder_directory: tests/resources/runfolders
general_project_directory: tests/resources/projects
staging_directory: /tmp/
project_links_directory: /tmp/
path_to_mover: '/usr/local/mover/1.0.0/'
dds_conf:
log_path: dds.log
port: 9999
81 changes: 40 additions & 41 deletions delivery/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@
FileSystemBasedUnorganisedRunfolderRepository
from delivery.repositories.staging_repository import DatabaseBasedStagingRepository
from delivery.repositories.deliveries_repository import DatabaseBasedDeliveriesRepository
from delivery.repositories.project_repository import GeneralProjectRepository, UnorganisedRunfolderProjectRepository, DDSProjectRepository
from delivery.repositories.project_repository import GeneralProjectRepository, UnorganisedRunfolderProjectRepository
from delivery.repositories.delivery_sources_repository import DatabaseBasedDeliverySourcesRepository
from delivery.repositories.sample_repository import RunfolderProjectBasedSampleRepository


from delivery.services.mover_service import MoverDeliveryService
from delivery.services.dds_service import DDSService
from delivery.services.external_program_service import ExternalProgramService
from delivery.services.staging_service import StagingService
Expand Down Expand Up @@ -100,16 +99,17 @@ def create_and_migrate_db(db_engine, alembic_path, db_connection_string):

def compose_application(config):
"""
Instantiates all service, repos, etc which are then used by the application.
The resulting dictionary can then be passed on to routes which instantiates the
http handlers.
Instantiates all service, repos, etc which are then used by the
application. The resulting dictionary can then be passed on to routes
which instantiates the http handlers.
:param config: a configuration instance
:return: a dictionary with references to any relevant resources
"""

def _assert_is_dir(directory):
if not FileSystemService.isdir(directory):
raise AssertionError("{} is not a directory".format(os.path.abspath(directory)))
raise AssertionError(
"{} is not a directory".format(os.path.abspath(directory)))

staging_dir = config['staging_directory']
_assert_is_dir(staging_dir)
Expand All @@ -132,7 +132,8 @@ def _assert_is_dir(directory):
general_project_dir = config['general_project_directory']
_assert_is_dir(general_project_dir)

general_project_repo = GeneralProjectRepository(root_directory=general_project_dir)
general_project_repo = GeneralProjectRepository(
root_directory=general_project_dir)
external_program_service = ExternalProgramService()

db_connection_string = config["db_connection_string"]
Expand All @@ -144,46 +145,45 @@ def _assert_is_dir(directory):
session_factory = scoped_session(sessionmaker())
session_factory.configure(bind=engine)

staging_repo = DatabaseBasedStagingRepository(session_factory=session_factory)
staging_repo = DatabaseBasedStagingRepository(
session_factory=session_factory)

staging_service = StagingService(external_program_service=external_program_service,
runfolder_repo=runfolder_repo,
project_dir_repo=general_project_repo,
staging_repo=staging_repo,
staging_dir=staging_dir,
project_links_directory=project_links_directory,
session_factory=session_factory)
staging_service = StagingService(
external_program_service=external_program_service,
runfolder_repo=runfolder_repo,
project_dir_repo=general_project_repo,
staging_repo=staging_repo,
staging_dir=staging_dir,
project_links_directory=project_links_directory,
session_factory=session_factory)

delivery_repo = DatabaseBasedDeliveriesRepository(session_factory=session_factory)

path_to_mover = config['path_to_mover']
mover_delivery_service = MoverDeliveryService(external_program_service=external_program_service,
staging_service=staging_service,
delivery_repo=delivery_repo,
session_factory=session_factory,
path_to_mover=path_to_mover)
delivery_repo = DatabaseBasedDeliveriesRepository(
session_factory=session_factory)

dds_conf = config['dds_conf']
dds_project_repo = DDSProjectRepository(session_factory=session_factory)
dds_service = DDSService(external_program_service=external_program_service,
staging_service=staging_service,
staging_dir=staging_dir,
delivery_repo=delivery_repo,
dds_project_repo=dds_project_repo,
session_factory=session_factory,
dds_conf=dds_conf)

delivery_sources_repo = DatabaseBasedDeliverySourcesRepository(session_factory=session_factory)
dds_service = DDSService(
external_program_service=external_program_service,
staging_service=staging_service,
staging_dir=staging_dir,
delivery_repo=delivery_repo,
session_factory=session_factory,
dds_conf=dds_conf)

delivery_sources_repo = DatabaseBasedDeliverySourcesRepository(
session_factory=session_factory)

runfolder_service = RunfolderService(runfolder_repo)

delivery_service = DeliveryService(mover_service=mover_delivery_service,
staging_service=staging_service,
delivery_sources_repo=delivery_sources_repo,
general_project_repo=general_project_repo,
runfolder_service=runfolder_service,
project_links_directory=project_links_directory)
delivery_service = DeliveryService(
dds_service=dds_service,
staging_service=staging_service,
delivery_sources_repo=delivery_sources_repo,
general_project_repo=general_project_repo,
runfolder_service=runfolder_service,
project_links_directory=project_links_directory)

best_practice_analysis_service = BestPracticeAnalysisService(general_project_repo)
best_practice_analysis_service = BestPracticeAnalysisService(
general_project_repo)

organise_service = OrganiseService(
runfolder_service=RunfolderService(unorganised_runfolder_repo))
Expand All @@ -192,7 +192,6 @@ def _assert_is_dir(directory):
runfolder_repo=runfolder_repo,
external_program_service=external_program_service,
staging_service=staging_service,
mover_delivery_service=mover_delivery_service,
dds_service=dds_service,
delivery_service=delivery_service,
general_project_repo=general_project_repo,
Expand Down
27 changes: 12 additions & 15 deletions delivery/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@

class RunfolderNotFoundException(Exception):
"""
Should be raised when a runfolder is not found
Should be raised when a runfolder is not found.
"""
pass


class ChecksumNotFoundException(Exception):
"""
Should be raised when a file checksum could not be found in the list of checksums
Should be raised when a file checksum could not be found in the list of
checksums.
"""
pass


class ChecksumFileNotFoundException(Exception):
"""
Should be raised when an expected checksum file could not be found
Should be raised when an expected checksum file could not be found.
"""
pass

Expand All @@ -37,22 +38,16 @@ class ProjectReportNotFoundException(Exception):

class TooManyProjectsFound(Exception):
"""
Should be raise when to many projects match some specific criteria
Should be raise when to many projects match some specific criteria.
"""
pass


class InvalidStatusException(Exception):
"""
Should be raised when an object is found to be in a invalid state, e.g. if the program tries to start staging
on a StagingOrder which is already `in_progress`
"""
pass


class CannotParseMoverOutputException(Exception):
"""
Should be raised when movers output cannot be parsed for e.g. a mover delivery id.
Should be raised when an object is found to be in a invalid state, e.g. if
the program tries to start staging on a StagingOrder which is already
`in_progress`.
"""
pass

Expand Down Expand Up @@ -81,12 +76,14 @@ class SamplesheetNotFoundException(Exception):

class ProjectsDirNotfoundException(Exception):
"""
Should be raised when a directory containing projects could not be found
Should be raised when a directory containing projects could not be found.
"""
pass


class CannotParseDDSOutputException(Exception):
"""
Should be raised when DDS's output cannot be parsed for e.g. creating a project.
Should be raised when DDS's output cannot be parsed for e.g. creating a
project.
"""
pass
22 changes: 7 additions & 15 deletions delivery/handlers/dds_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from delivery.handlers import *
from delivery.handlers.utility_handlers import ArteriaDeliveryBaseHandler
from delivery.models.project import DDSProject

import os
import tempfile
Expand Down Expand Up @@ -50,20 +51,11 @@ async def post(self, project_name):
project_metadata = self.body_as_object(
required_members=required_members)

with tempfile.NamedTemporaryFile(mode='w', delete=True) as token_file:
if os.path.exists(project_metadata["auth_token"]):
token_path = project_metadata["auth_token"]
else:
token_file.write(project_metadata["auth_token"])
token_file.flush()

token_path = token_file.name

dds_project_id = await self.dds_service.create_dds_project(
project_name,
project_metadata,
token_path,
)
dds_project = await DDSProject.new(
project_name,
project_metadata,
project_metadata["auth_token"],
self.dds_service)

self.set_status(ACCEPTED)
self.write_json({'dds_project_id': dds_project_id})
self.write_json({'dds_project_id': dds_project.project_id})
Loading

0 comments on commit 2ebef93

Please sign in to comment.