Skip to content

Commit

Permalink
Revert "changes according to new catalogue db structure"
Browse files Browse the repository at this point in the history
This reverts commit 6f21d76.
  • Loading branch information
alex75 committed Oct 31, 2023
1 parent 6f21d76 commit 4826e74
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 30 deletions.
13 changes: 5 additions & 8 deletions cads_processing_api_service/adaptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

def get_adaptor_properties(
dataset: cads_catalogue.database.Resource,
dataset_data: cads_catalogue.database.ResourceData,
) -> dict[str, Any]:
config: dict[str, Any] = dataset.adaptor_configuration
if config:
Expand All @@ -36,18 +35,18 @@ def get_adaptor_properties(
setup_code = dataset.adaptor
resources = config.pop("resources", {})

constraints = dataset_data.constraints_data
constraints = dataset.constraints_data
if constraints is not None:
config["constraints"] = constraints
mapping = dataset_data.mapping
mapping = dataset.mapping
if mapping is not None:
config["mapping"] = mapping
licences: list[cads_catalogue.database.Licence] = dataset.licences
if licences is not None:
config["licences"] = [
(licence.licence_uid, licence.revision) for licence in licences
]
form = dataset_data.form_data
form = dataset.form_data
hash = dataset.adaptor_properties_hash

adaptor_properties: dict[str, Any] = {
Expand All @@ -64,11 +63,10 @@ def get_adaptor_properties(

def make_system_job_kwargs(
dataset: cads_catalogue.database.Resource,
dataset_data: cads_catalogue.database.ResourceData,
request: dict[str, Any],
adaptor_resources: dict[str, int],
) -> dict[str, Any]:
adaptor_properties = get_adaptor_properties(dataset, dataset_data)
adaptor_properties = get_adaptor_properties(dataset)
# merge adaptor and dataset resources
resources = dict(adaptor_resources, **adaptor_properties["resources"])
system_job_kwargs = {
Expand All @@ -85,9 +83,8 @@ def make_system_job_kwargs(

def instantiate_adaptor(
dataset: cads_catalogue.database.Resource,
dataset_data: cads_catalogue.database.ResourceData,
) -> cads_adaptors.AbstractAdaptor:
adaptor_properties = get_adaptor_properties(dataset, dataset_data)
adaptor_properties = get_adaptor_properties(dataset)
adaptor_class = cads_adaptors.get_adaptor_class(
entry_point=adaptor_properties["entry_point"],
setup_code=adaptor_properties["setup_code"],
Expand Down
17 changes: 6 additions & 11 deletions cads_processing_api_service/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ class DatabaseClient(ogc_api_processes_fastapi.clients.BaseClient):
job_table: type[cads_broker.database.SystemRequest] = attrs.field(
default=cads_broker.database.SystemRequest
)
process_data_table: type[cads_catalogue.database.ResourceData] = attrs.field(
default=cads_catalogue.database.ResourceData
)

def get_processes(
self,
Expand Down Expand Up @@ -143,14 +140,12 @@ def get_process(
db_utils.ConnectionMode.read
)
with catalogue_sessionmaker() as catalogue_session:
resource, resource_data = utils.lookup_resource_by_id(
resource = utils.lookup_resource_by_id(
resource_id=process_id,
table=self.process_table,
session=catalogue_session,
)
process_description = serializers.serialize_process_description(
resource, resource_data
)
process_description = serializers.serialize_process_description(resource)
process_description.outputs = {
"asset": ogc_api_processes_fastapi.models.OutputDescription(
title="Asset",
Expand Down Expand Up @@ -204,18 +199,18 @@ def post_process_execution(
db_utils.ConnectionMode.read
)
with catalogue_sessionmaker() as catalogue_session:
resource, resource_data = utils.lookup_resource_by_id(
resource: cads_catalogue.database.Resource = utils.lookup_resource_by_id(
resource_id=process_id,
table=self.process_table,
session=catalogue_session,
)
adaptor = adaptors.instantiate_adaptor(resource, resource_data)
adaptor = adaptors.instantiate_adaptor(resource)
licences = adaptor.get_licences(execution_content)
auth.validate_licences(execution_content, stored_accepted_licences, licences)
job_id = str(uuid.uuid4())
structlog.contextvars.bind_contextvars(job_id=job_id)
job_kwargs = adaptors.make_system_job_kwargs(
resource, resource_data, execution_content, adaptor.resources
resource, execution_content, adaptor.resources
)
compute_sessionmaker = db_utils.get_compute_sessionmaker(
mode=db_utils.ConnectionMode.write
Expand Down Expand Up @@ -407,7 +402,7 @@ def get_job(
(form_data,) = utils.get_resource_properties(
resource_id=job.process_id,
properties="form_data",
table=self.process_data_table,
table=self.process_table,
session=catalogue_session,
)
kwargs["request"] = {
Expand Down
6 changes: 2 additions & 4 deletions cads_processing_api_service/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ def apply_constraints(
db_utils.ConnectionMode.read
)
with catalogue_sessionmaker() as catalogue_session:
dataset, dataset_data = utils.lookup_resource_by_id(
dataset = utils.lookup_resource_by_id(
resource_id=process_id, table=table, session=catalogue_session
)
adaptor: cads_adaptors.AbstractAdaptor = adaptors.instantiate_adaptor(
dataset, dataset_data
)
adaptor: cads_adaptors.AbstractAdaptor = adaptors.instantiate_adaptor(dataset)
try:
constraints: dict[str, Any] = adaptor.apply_constraints(request=request)
except cads_adaptors.constraints.ParameterError as exc:
Expand Down
3 changes: 1 addition & 2 deletions cads_processing_api_service/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def serialize_process_summary(

def serialize_process_description(
db_model: cads_catalogue.database.Resource,
db_data_model: cads_catalogue.database.ResourceData,
) -> ogc_api_processes_fastapi.models.ProcessDescription:
"""Convert provided database entry into a representation of the related process description.
Expand All @@ -68,7 +67,7 @@ def serialize_process_description(
Process description representation.
"""
process_summary = serialize_process_summary(db_model)
cds_form = db_data_model.form_data
cds_form = db_model.form_data
process_inputs = {}
if cds_form:
process_inputs = translators.translate_cds_form(cds_form)
Expand Down
7 changes: 2 additions & 5 deletions cads_processing_api_service/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,10 @@ def lookup_resource_by_id(
row: cads_catalogue.database.Resource = (
session.execute(statement).unique().scalar_one()
)
row_data: cads_catalogue.database.ResourceData = row.resource_data
except sqlalchemy.exc.NoResultFound:
raise ogc_api_processes_fastapi.exceptions.NoSuchProcess()
session.expunge(row)
session.expunge(row_data)
return row, row_data
return row


@cachetools.cached( # type: ignore
Expand All @@ -111,8 +109,7 @@ def lookup_resource_by_id(
def get_resource_properties(
resource_id: str,
properties: str | tuple[str],
table: type[cads_catalogue.database.Resource]
| type[cads_catalogue.database.ResourceData],
table: type[cads_catalogue.database.Resource],
session: sqlalchemy.orm.Session,
) -> tuple[Any, ...]:
"""Look for the resource identified by `id` into the Catalogue database.
Expand Down

0 comments on commit 4826e74

Please sign in to comment.