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

Rename images

parent dfff40c4
No related branches found
No related tags found
1 merge request!990Rename images
Pipeline #5808 passed
Pipeline: workspaces

#5809

    ...@@ -15,7 +15,9 @@ ...@@ -15,7 +15,9 @@
    # #
    # You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
    # along with Workspaces. If not, see <https://www.gnu.org/licenses/>. # along with Workspaces. If not, see <https://www.gnu.org/licenses/>.
    import glob
    import logging import logging
    import os
    import shutil import shutil
    import subprocess import subprocess
    ...@@ -67,6 +69,9 @@ class ImageCollector(CollectorIF): ...@@ -67,6 +69,9 @@ class ImageCollector(CollectorIF):
    staging_dir = self.parameters["staging_area"] staging_dir = self.parameters["staging_area"]
    tar_name = self.create_artifacts_name() tar_name = self.create_artifacts_name()
    # rename image files to allow for duplicate ingestion
    self.rename_images()
    # run script # run script
    collector = subprocess.run( collector = subprocess.run(
    ["./image-product-collector.sh", workflow_dir, staging_dir, tar_name], ["./image-product-collector.sh", workflow_dir, staging_dir, tar_name],
    ...@@ -89,6 +94,27 @@ class ImageCollector(CollectorIF): ...@@ -89,6 +94,27 @@ class ImageCollector(CollectorIF):
    date = self.parameters["processingStart"] date = self.parameters["processingStart"]
    return name + date return name + date
    def rename_images(self):
    """
    Rename images to allow for duplicate ingestion
    :return:
    """
    self.logger.info("Renaming images...")
    sdm = self.parameters["sdmId"]
    ebMjd = sdm.split(".")[-2] + "." + sdm.split(".")[-1]
    prefix = self.parameters["project"] + ".MJD" + ebMjd
    path = self.parameters["spoolDir"] + "/products"
    images = glob.glob(path + "/*.fits")
    for image in images:
    newname = image.replace("oussid", prefix)
    self.logger.info(f"Renaming {image} to {newname}")
    os.rename(image, newname)
    class SECICollector(CollectorIF): class SECICollector(CollectorIF):
    """Collect SECI Image Products for Ingestion""" """Collect SECI Image Products for Ingestion"""
    ......
    ...@@ -143,6 +143,7 @@ class Solicitor: ...@@ -143,6 +143,7 @@ class Solicitor:
    """ """
    gen = { gen = {
    "sdmId": self.metadata["fileSetIds"],
    "requestId": self.metadata["systemId"], "requestId": self.metadata["systemId"],
    "telescope": self.metadata["projectMetadata"]["telescope"], # all, needed by manifest generator "telescope": self.metadata["projectMetadata"]["telescope"], # all, needed by manifest generator
    "project": self.metadata["projectMetadata"]["projectCode"], # needed for post ingestion messaging "project": self.metadata["projectMetadata"]["projectCode"], # needed for post ingestion messaging
    ...@@ -169,7 +170,6 @@ class Solicitor: ...@@ -169,7 +170,6 @@ class Solicitor:
    general = self.get_general_params() general = self.get_general_params()
    cal = { cal = {
    "sdmId": self.metadata["fileSetIds"], # calibration only
    "spl": self.metadata["productLocator"], # calibration only "spl": self.metadata["productLocator"], # calibration only
    } }
    ...@@ -183,7 +183,10 @@ class Solicitor: ...@@ -183,7 +183,10 @@ class Solicitor:
    """ """
    general = self.get_general_params() general = self.get_general_params()
    img = {"calSpl": self.metadata["calProductLocator"]} # image only img = {
    "calSpl": self.metadata["calProductLocator"], # image only
    "spoolDir": self.metadata["destinationDirectory"],
    }
    return {**general, **img} return {**general, **img}
    ......
    ...@@ -35,6 +35,8 @@ parameters = { ...@@ -35,6 +35,8 @@ parameters = {
    "calSpl": "uid://evla/calibration/c78ccfd6-fe4e-43c6-a5c5-70e5bcfde16b", "calSpl": "uid://evla/calibration/c78ccfd6-fe4e-43c6-a5c5-70e5bcfde16b",
    "staging_area": "/lustre/aoc/cluster/pipeline/docker/workspaces/staging", "staging_area": "/lustre/aoc/cluster/pipeline/docker/workspaces/staging",
    "storage_area": "/lustre/aoc/cluster/pipeline/docker/workspaces/storage", "storage_area": "/lustre/aoc/cluster/pipeline/docker/workspaces/storage",
    "project": "Operations",
    "spoolDir": "/lustre/aoc/cluster/pipeline/docker/workspaces/spool/tmprb1se376",
    } }
    image_collector = ImageCollector(parameters=parameters) image_collector = ImageCollector(parameters=parameters)
    ...@@ -56,7 +58,10 @@ def test_aux_file_to_staging(): ...@@ -56,7 +58,10 @@ def test_aux_file_to_staging():
    class TestImageCollector: class TestImageCollector:
    @patch("shutil.copy2") @patch("shutil.copy2")
    @patch("subprocess.run") @patch("subprocess.run")
    def test_collect_image_products(self, mock_run, mock_copy): @patch("glob.glob")
    @patch("os.rename")
    @patch("os.replace")
    def test_collect_image_products(self, mock_replace, mock_rename, mock_glob, mock_run, mock_copy):
    mock_run.return_value.returncode = 0 mock_run.return_value.returncode = 0
    image_collector.collect_products() image_collector.collect_products()
    assert mock_run.call_count == 1 assert mock_run.call_count == 1
    ......
    ...@@ -94,6 +94,7 @@ class TestSolicitor: ...@@ -94,6 +94,7 @@ class TestSolicitor:
    def test_solicit_parameters_image(self, image_solicitor: Solicitor): def test_solicit_parameters_image(self, image_solicitor: Solicitor):
    initial_version_dir = "iamthefirst" initial_version_dir = "iamthefirst"
    metadata = { metadata = {
    "sdmId": "brain_000.58099.67095825232",
    "telescope": "EVLA", "telescope": "EVLA",
    "workflowName": "std_cms_imaging", "workflowName": "std_cms_imaging",
    "processingStart": "2021_07_29T14_26_31", "processingStart": "2021_07_29T14_26_31",
    ...@@ -103,6 +104,7 @@ class TestSolicitor: ...@@ -103,6 +104,7 @@ class TestSolicitor:
    "calSpl": "uid://evla/calibration/c78ccfd6-fe4e-43c6-a5c5-70e5bcfde16b", "calSpl": "uid://evla/calibration/c78ccfd6-fe4e-43c6-a5c5-70e5bcfde16b",
    "project": "Operations", "project": "Operations",
    "requestId": "12", "requestId": "12",
    "spoolDir": "/lustre/aoc/cluster/pipeline/docker/workspaces/spool/tmprb1se376",
    } }
    with patch("ingest_envoy.solicitor.Solicitor.solicit_initial_directory_name", return_value=initial_version_dir): with patch("ingest_envoy.solicitor.Solicitor.solicit_initial_directory_name", return_value=initial_version_dir):
    parameters = image_solicitor.solicit_parameters() parameters = image_solicitor.solicit_parameters()
    ......
    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