Skip to content
Snippets Groups Projects
Commit 647ebf89 authored by Charlotte Hausman's avatar Charlotte Hausman
Browse files

aat_wrest restore info

parent 7c3e0ba4
No related branches found
No related tags found
2 merge requests!344Refactor aat_wrest,!340restore capability and workflow
......@@ -69,13 +69,13 @@ def arg_parser() -> argparse.ArgumentParser:
"--restore",
required=False,
action="store_true",
help="run the restore measurement set CASA pipeline",
help="run the restore measurement set CASA pipeline, use in conjunction with '-c'",
)
parser.add_argument(
"--integrated",
required=False,
action="store_true",
help="run an integrated calibration-imaging pipeline",
help="run an integrated calibration-imaging pipeline, use in conjunction with '-i'",
)
return parser
......
......@@ -7,10 +7,10 @@ import logging
import sys
import pendulum
import psycopg2 as pg
from typing import List
from aat_wrest.observation_wrester import ObservationWrester
from aat_wrest.utilities import PENDULUM_FORMAT, TIME_ZONE, MDDBConnector
from pycapo import CapoConfig
logger = logging.getLogger("aat_wrest")
logger.setLevel(logging.INFO)
......@@ -23,7 +23,11 @@ class WrestWorkflowMetadata:
"""
def __init__(
self, connection: MDDBConnector, spl: str = None, fileset_id: str = None, sdm_id: str = None
self,
connection: MDDBConnector,
spl: List[str] = None,
fileset_id: str = None,
sdm_id: str = None,
):
self.logger = logging.getLogger("aat_wrest")
self.conn = connection
......@@ -58,7 +62,7 @@ class WrestWorkflowMetadata:
make_json = {}
try:
cursor = self.conn.cursor()
cursor.execute(sql, {"spl": self.spl})
cursor.execute(sql, {"spl": self.spl[0]})
data = cursor.fetchall()
if data:
make_json = json.dumps(
......@@ -77,7 +81,7 @@ class WrestWorkflowMetadata:
else:
self.logger.error(
f"ERROR: aat-wrest query returned no results!"
f" The database appears to be missing information for SPL {self.spl}!"
f" The database appears to be missing information for SPL {self.spl[0]}!"
)
finally:
self.conn.close()
......@@ -130,6 +134,62 @@ class WrestWorkflowMetadata:
self.conn.close()
return make_json
def wrest_restore_info(self) -> json:
"""
Given an execution block science product locator and calibration science product locator, returns
the required metadata to run the restore CMS workflow
:return:
"""
eb_sql = f"""
SELECT ngas_fileset_id as filesetId,
e.project_code as projectCode,
p.title as title,
e.starttime as startTime,
(a.firstname || ' ' || a.lastname) as observer,
telescope as telescope
FROM execution_blocks e
JOIN projects p on e.project_code = p.project_code
JOIN authors a on p.project_code = a.project_code
WHERE science_product_locator = %(spl)s AND a.is_pi = true
"""
cal_sql = f"""
SELECT external_name as calSdmId
from science_products WHERE science_product_locator = %(cal_spl)s
"""
make_json = {}
try:
cursor = self.conn.cursor()
cursor.execute(eb_sql, {"spl": self.spl[0]})
data = cursor.fetchall()
cursor.execute(cal_sql, {"cal_spl": self.spl[1]})
cal_data = cursor.fetchall()
if data and cal_data:
make_json = json.dumps(
{
"sdmId": data[0][0],
"calSdmId": cal_data[0][0],
"projectCode": data[0][1],
"title": data[0][2],
"startTime": data[0][3],
"observer": data[0][4],
"telescope": data[0][5],
"created_at": str(
pendulum.now().in_timezone(TIME_ZONE).format(PENDULUM_FORMAT)
),
}
)
else:
self.logger.error(
f"ERROR: aat-wrest query returned no results!"
f" The database appears to be missing information for either SPL {self.spl[0]} or Cal SPL {self.spl[1]}!"
)
finally:
self.conn.close()
return make_json
def wrest_obs_metadata_from_fileset_id(self, fileset_id: str) -> str:
"""
Given a fileset_id, query the Metadata DB and return the corresponding science_product_locator
......@@ -182,6 +242,14 @@ def parser() -> argparse.ArgumentParser:
required=False,
help="Find workflow metadata for standard CMS imaging with provided SDM id",
)
arg_parser.add_argument(
"-r",
"--restore",
nargs=2,
action="store",
required=False,
help="Find workflow metadata for Restores with provided EB product locator and Cal product locator",
)
arg_parser.add_argument(
"-obs",
"--observation",
......@@ -198,6 +266,8 @@ def determine_wrester(connection: MDDBConnector, args: argparse.Namespace):
data = WrestWorkflowMetadata(connection, spl=args.stdcals[0]).wrest_standard_cal_info()
if args.stdimg:
data = WrestWorkflowMetadata(connection, sdm_id=args.stdimg[0]).wrest_standard_image_info()
if args.restore:
data = WrestWorkflowMetadata(connection, spl=args.restore[0]).wrest_restore_info()
if args.observation:
data = ObservationWrester(connection, spl=args.observation[0]).wrest_observation_info()
......
......@@ -235,6 +235,9 @@ class WorkflowService(WorkflowServiceIF):
if "calibration" in name:
wrest_type = "-sc"
argument = wf_request.argument["product_locator"]
elif "restore" in name:
wrest_type = "-r"
argument = [wf_request.argument["product_locator"], wf_request.argument["cal_locator"]]
elif "imaging" in name:
wrest_type = "-si"
argument = wf_request.argument["sdmId"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment