Skip to content

Commit

Permalink
Omics - re-do frontend, added to environment, clean-up code, naming c…
Browse files Browse the repository at this point in the history
…onventions, json prettify
  • Loading branch information
dlpzx committed Feb 2, 2024
1 parent 0007751 commit 0f92390
Show file tree
Hide file tree
Showing 30 changed files with 433 additions and 584 deletions.
2 changes: 0 additions & 2 deletions backend/dataall/modules/omics/api/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,3 @@
# ],
# resolver=delete_omics_run,
# )


2 changes: 1 addition & 1 deletion backend/dataall/modules/omics/api/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

getOmicsWorkflow = gql.QueryField(
name="getOmicsWorkflow",
args=[gql.Argument(name="workflowId", type=gql.NonNullableType(gql.String))],
args=[gql.Argument(name="workflowUri", type=gql.NonNullableType(gql.String))],
type=gql.Ref("OmicsWorkflow"),
resolver=get_omics_workflow,
)
Expand Down
18 changes: 8 additions & 10 deletions backend/dataall/modules/omics/api/resolvers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import logging
from dataall.base.api.context import Context
from dataall.core.stacks.api import stack_helper
from dataall.base.db import exceptions
from dataall.modules.omics.services.omics_service import OmicsService
from dataall.modules.omics.services.omics_enums import OmicsWorkflowType
from dataall.modules.omics.db.models import OmicsRun, OmicsWorkflow

log = logging.getLogger(__name__)


class RequestValidator:
"""Aggregates all validation logic for operating with omics"""
@staticmethod
Expand All @@ -30,6 +31,7 @@ def _required(data: dict, name: str):
if not data.get(name):
raise exceptions.RequiredParameter(name)


def create_omics_run(context: Context, source, input=None):
RequestValidator.validate_creation_request(input)
# request = OmicsRunCreationRequest.from_dict(input)
Expand All @@ -52,13 +54,10 @@ def list_omics_workflows(context: Context, source, filter: dict = None):
return OmicsService.list_omics_workflows(filter)


def get_omics_workflow(context: Context, source, workflowId: str = None):
RequestValidator.required_uri(workflowId)
return OmicsService.get_omics_workflow(workflowId)
def get_omics_workflow(context: Context, source, workflowUri: str = None):
RequestValidator.required_uri(workflowUri)
return OmicsService.get_omics_workflow(workflowUri)

def run_omics_workflow(context: Context, source, workflowId: str = None, workflowType: str = 'READY2RUN', roleArn: str = None, parameters: str = None):
RequestValidator.required_uri(workflowId)
return OmicsService.run_omics_workflow(workflowId,workflowType,roleArn,parameters)

def delete_omics_run(context: Context, source, runUri: str = None, deleteFromAWS: bool = None):
RequestValidator.required_uri(runUri)
Expand All @@ -67,11 +66,10 @@ def delete_omics_run(context: Context, source, runUri: str = None, deleteFromAWS
delete_from_aws=deleteFromAWS
)


def resolve_omics_workflow(context, source: OmicsRun, **kwargs):
return OmicsService.get_omics_workflow(source.workflowId)
return OmicsService.get_omics_workflow(source.workflowUri)


def resolve_omics_run_details(context, source: OmicsRun, **kwargs):
return OmicsService.get_omics_run_from_aws(source.runUri)


37 changes: 13 additions & 24 deletions backend/dataall/modules/omics/api/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
OmicsWorkflow = gql.ObjectType(
name="OmicsWorkflow",
fields=[
gql.Field(name="arn", type=gql.String),
gql.Field(name="workflowUri", type=gql.String),
gql.Field(name="id", type=gql.String),
gql.Field(name="arn", type=gql.String),
gql.Field(name="name", type=gql.String),
gql.Field(name="status", type=gql.String),
gql.Field(name="label", type=gql.String),
gql.Field(name="type", type=gql.String),
gql.Field(name="description", type=gql.String),
gql.Field(name="parameterTemplate", type=gql.String), # from the omics client
gql.Field(name="parameterTemplate", type=gql.String),
gql.Field(name="environmentUri", type=gql.String),
],
)
Expand All @@ -29,21 +30,13 @@
],
)

# TODO: not used at the moment
# OmicsRunStatus = gql.ObjectType(
# name="OmicsRunStatus",
# fields=[
# gql.Field(name="arn", type=gql.String),
# gql.Field(name="id", type=gql.String),
# gql.Field(name="status", type=gql.String),
# gql.Field(name="runId", type=gql.String),
# gql.Field(name="roleArn", type=gql.String),
# gql.Field(name="statusMessage", type=gql.String),
# gql.Field(name="creationTime", type=gql.String),
# gql.Field(name="startTime", type=gql.String),
# gql.Field(name="stopTime", type=gql.String),
# ],
# )
OmicsRunStatus = gql.ObjectType(
name="OmicsRunStatus",
fields=[
gql.Field(name="status", type=gql.String),
gql.Field(name="statusMessage", type=gql.String)
],
)


OmicsRun = gql.ObjectType(
Expand All @@ -54,17 +47,15 @@
gql.Field("organizationUri", type=gql.String),
gql.Field("name", type=gql.String),
gql.Field("label", type=gql.String),
gql.Field("description", type=gql.String),
gql.Field("tags", type=gql.ArrayType(gql.String)),
gql.Field("created", type=gql.String),
gql.Field("updated", type=gql.String),
gql.Field("owner", type=gql.String),
gql.Field("AwsAccountId", type=gql.String),
gql.Field("region", type=gql.String),
gql.Field("workflowId", type=gql.String),
gql.Field("workflowUri", type=gql.String),
gql.Field("SamlAdminGroupName", type=gql.String),
gql.Field("parameterTemplate", type=gql.String),
gql.Field("outputUri", type=gql.String),
gql.Field("outputDatasetUri", type=gql.String),
gql.Field(
name='environment',
type=gql.Ref('Environment'),
Expand Down Expand Up @@ -100,5 +91,3 @@
gql.Field(name="nodes", type=gql.ArrayType(OmicsRun)),
],
)


29 changes: 14 additions & 15 deletions backend/dataall/modules/omics/aws/omics_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,64 +21,63 @@ class OmicsClient:
def client(awsAccountId: str, region: str):
session = SessionHelper.remote_session(awsAccountId)
return session.client('omics', region_name=region)

@staticmethod
def get_omics_workflow(id: str, session):
workflow = OmicsRepository(session).get_workflow(id=id)
def get_omics_workflow(workflowUri: str, session):
workflow = OmicsRepository(session).get_workflow(workflowUri=workflowUri)
environment = EnvironmentRepository.get_environment_by_uri(session=session, uri=workflow.environmentUri)
client = OmicsClient.client(awsAccountId=environment.AwsAccountId, region=environment.region)
try:
response = client.get_workflow(
id=id,
id=workflow.id,
type='READY2RUN'
)
return response
except ClientError as e:
logger.error(
f'Could not retrieve Ready2Run Omics Workflows status due to: {e} '
)
return 'ERROR LISTING WORKFLOWS'
raise e

@staticmethod
def get_omics_run(session, runUri: str):
omics_db = OmicsRepository(session)
omics_run = omics_db.get_omics_run(runUri=runUri)
workflow = omics_db.get_workflow(id=omics_run.workflowId)
workflow = omics_db.get_workflow(workflowUri=omics_run.workflowUri)
environment = EnvironmentRepository.get_environment_by_uri(session=session, uri=workflow.environmentUri)
client = OmicsClient.client(awsAccountId=environment.AwsAccountId, region=environment.region)
try:
response = client.get_run(id=omics_run.runUri
)
response = client.get_run(id=omics_run.runUri)
# TODO: remove prints
print(response)
return response
except ClientError as e:
logger.error(
f'Could not retrieve workflow run status due to: {e} '
)
return 'ERROR GETTING WORKFLOW RUN'

return 'ERROR GETTING WORKFLOW RUN'

@staticmethod
def run_omics_workflow(omics_run: OmicsRun, session):
group = EnvironmentService.get_environment_group(session, omics_run.SamlAdminGroupName, omics_run.environmentUri)
workflow = OmicsRepository(session=session).get_workflow(workflowUri=omics_run.workflowUri)
client = OmicsClient.client(awsAccountId=omics_run.AwsAccountId, region=omics_run.region)
try:
response = client.start_run(
workflowId=omics_run.workflowId,
workflowType='READY2RUN',
workflowId=workflow.id,
workflowType=workflow.type,
roleArn=group.environmentIAMRoleArn,
parameters=json.loads(omics_run.parameterTemplate),
outputUri=omics_run.outputUri
)
return response
except ClientError as e:
# TODO: Check if we need to raise an error!
logger.error(
f'Could not retrieve workflow run status due to: {e} '
)
return 'ERROR RUNNING OMICS WORKFLOW'

return 'ERROR RUNNING OMICS WORKFLOW'


@staticmethod
def list_workflows(awsAccountId, region, type) -> list:
try:
Expand Down
12 changes: 6 additions & 6 deletions backend/dataall/modules/omics/cdk/omics_policy.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from aws_cdk import aws_iam as iam

from dataall.core.environment.cdk.env_role_core_policies.service_policy import ServicePolicy
from dataall.core.environment.cdk.env_role_core_policies.service_policy import ServicePolicy
from dataall.modules.omics.services.omics_permissions import CREATE_OMICS_RUN


Expand All @@ -15,10 +15,10 @@ def get_statements(self, group_permissions, **kwargs):
return []

return [
iam.PolicyStatement(
actions=[
iam.PolicyStatement(
actions=[
"omics:*"
],
resources=['*'],
),
],
resources=['*'],
),
]
22 changes: 6 additions & 16 deletions backend/dataall/modules/omics/db/models.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
import enum

from sqlalchemy import Column, String, ForeignKey
from sqlalchemy.dialects.postgresql import JSON
from sqlalchemy.orm import query_expression, relationship

from dataall.base.db import Base
from dataall.base.db import Resource, utils


class OmicsWorkflowType(enum.Enum):
PRIVATE = "PRIVATE"
READY2RUN = "READY2RUN"

class OmicsWorkflow(Resource, Base):
__tablename__ = "omics_workflow"
workflowUri = Column(String, primary_key=True, default=utils.uuid("omicsWorkflowUri"))
arn = Column(String, nullable=False)
id = Column(String, nullable=False, primary_key=True, default=utils.uuid("omicsWorkflowUri"))
label = Column(String, nullable=False, default=utils.uuid("omicsWorkflowUri"))
owner = Column(String, nullable=False, default=utils.uuid("omicsWorkflowUri"))
name = Column(String, nullable=False)
status = Column(String, nullable=False)
id = Column(String, nullable=False)
type = Column(String, nullable=False)
description = Column(String, nullable=True)
environmentUri = Column(String, nullable=False)
environmentUri = Column(String, nullable=True)


class OmicsRun(Resource, Base):
__tablename__ = "omics_run"
runUri = Column(String, nullable=False, primary_key=True, default=utils.uuid("runUri"))
organizationUri = Column(String, nullable=False)
environmentUri = Column(String, ForeignKey("environment.environmentUri", ondelete="cascade"), nullable=False)
region = Column(String, default="eu-west-1")
AwsAccountId = Column(String, nullable=False)
workflowUri = Column(String, ForeignKey("omics_workflow.workflowUri", ondelete="cascade"), nullable=False)
SamlAdminGroupName = Column(String, nullable=False)
workflowId = Column(String, nullable=False)
parameterTemplate = Column(String, nullable=False)
outputUri = Column(String, nullable=True)
outputDatasetUri = Column(String, nullable=True)
17 changes: 5 additions & 12 deletions backend/dataall/modules/omics/db/omics_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,15 @@ def delete_omics_workflow(self, omics_workflow):
self._session.delete(omics_workflow)
self._session.commit()


def get_workflow(self, id: str):
return self._session.query(OmicsWorkflow).get(id)

def get_workflow(self, workflowUri: str):
return self._session.query(OmicsWorkflow).get(workflowUri)

def get_omics_run(self, runUri: str):
omics_run = self._session.query(OmicsRun).get(runUri)
if not omics_run:
raise exceptions.ObjectNotFound("OmicsRun", runUri)
return omics_run


def _query_workflows(self, filter) -> Query:
query = self._session.query(OmicsWorkflow)
if filter and filter.get("term"):
Expand All @@ -60,17 +57,15 @@ def _query_workflows(self, filter) -> Query:
OmicsWorkflow.name.ilike(filter.get("term") + "%%"),
)
)
print(query)
return query
def paginated_omics_workflows(self,filter=None) -> dict:

def paginated_omics_workflows(self, filter=None) -> dict:
return paginate(
query=self._query_workflows(filter),
page=filter.get('page', OmicsRepository._DEFAULT_PAGE),
page_size=filter.get('pageSize', OmicsRepository._DEFAULT_PAGE_SIZE),
).to_dict()


def _query_user_runs(self, username, groups, filter) -> Query:
query = self._session.query(OmicsRun).filter(
or_(
Expand All @@ -87,7 +82,6 @@ def _query_user_runs(self, username, groups, filter) -> Query:
)
return query


def paginated_user_runs(self, username, groups, filter=None) -> dict:
return paginate(
query=self._query_user_runs(username, groups, filter),
Expand All @@ -97,7 +91,6 @@ def paginated_user_runs(self, username, groups, filter=None) -> dict:

# TODO: IMPLEMENT COUNT_RESOUCES


# def count_resources(self, environment, group_uri):
# return (
# self._session.query(OmicsRun)
Expand All @@ -108,4 +101,4 @@ def paginated_user_runs(self, username, groups, filter=None) -> dict:
# )
# )
# .count()
# )
# )
6 changes: 6 additions & 0 deletions backend/dataall/modules/omics/services/omics_enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import enum


class OmicsWorkflowType(enum.Enum):
PRIVATE = "PRIVATE"
READY2RUN = "READY2RUN"
Loading

0 comments on commit 0f92390

Please sign in to comment.