From 1a860f66cbd481f4aa35b70b40f5464f06f12afd Mon Sep 17 00:00:00 2001
From: chausman <chausman@nrao.edu>
Date: Mon, 28 Jun 2021 16:55:39 -0600
Subject: [PATCH] WS-271: CMS imaging templates

---
 ...2fcb74a8c_add_std_cms_imaging_templates.py | 144 ++++++++++++++++++
 1 file changed, 144 insertions(+)
 create mode 100644 schema/versions/a832fcb74a8c_add_std_cms_imaging_templates.py

diff --git a/schema/versions/a832fcb74a8c_add_std_cms_imaging_templates.py b/schema/versions/a832fcb74a8c_add_std_cms_imaging_templates.py
new file mode 100644
index 000000000..5c54a4a3d
--- /dev/null
+++ b/schema/versions/a832fcb74a8c_add_std_cms_imaging_templates.py
@@ -0,0 +1,144 @@
+"""add std_cms_imaging templates
+
+Revision ID: a832fcb74a8c
+Revises: 6ce7b4b8a9ea
+Create Date: 2021-06-28 15:51:12.733523
+
+"""
+from alembic import op
+import sqlalchemy as sa
+
+
+# revision identifiers, used by Alembic.
+revision = 'a832fcb74a8c'
+down_revision = '6ce7b4b8a9ea'
+branch_labels = None
+depends_on = None
+
+condor_content = """executable = std_cms_imaging.sh
+arguments = {{product_locator}} metadata.json PPR.xml
+
+output = imaging.out
+error = imaging.err
+log = condor.log
+
+SBIN_PATH = /lustre/aoc/cluster/pipeline/$ENV(CAPO_PROFILE)/workspaces/sbin
+should_transfer_files = yes
+transfer_input_files = $(SBIN_PATH)/.matplotlib, $(SBIN_PATH)/pycapo, $(SBIN_PATH)/framework.sh, $(SBIN_PATH)/productfetcher, $(SBIN_PATH)/casa_envoy, $(SBIN_PATH)/vela, $(SBIN_PATH)/conveyor, ./PPR.xml, ./metadata.json
+
+request_memory = {{ramInGb}}
+getenv = True
+environment = "CAPO_PATH=/home/casa/capo"
+
+queue
+
+"""
+
+script_content = """#!/bin/sh
+
+export HOME=$TMPDIR
+
+./framework.sh -d .
+chmod 770 .
+cd rawdata/
+../productfetcher --product-locator $1
+cd ../
+./casa_envoy --standard-cmsimage $2 $3
+#  find out expected behavior for standard type image delivery
+# ./conveyor --deliver $2
+
+"""
+
+metadata_content = """{
+  "fileSetIds": "{{sdmId}}",
+  "workflowName": "std_cms_imaging",
+  "systemId": "{{request_id}}",
+  "productLocator": "{{product_locator}}",
+  "projectMetadata": {
+    "projectCode": "{{projectCode}}",
+    "title": "{{title}}",
+    "startTime": "{{startTime}}",
+    "observer": "{{observer}}"
+  },
+  "destinationDirectory": "{{root_directory}}/{{relative_path}}"
+}
+"""
+
+ppr_content = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<ns2:SciPipeRequest xmlns:ns2="Common/pipelinescience/SciPipeRequest">
+    <ProjectSummary>
+        <ProposalCode>VLA/null</ProposalCode>
+        <Observatory>NRAO</Observatory>
+        <Telescope>VLA</Telescope>
+        <ProcessingSite>Socorro</ProcessingSite>
+        <Operator>vlapipe</Operator>
+        <Mode>SCIENCE</Mode>
+        <Version>NGRH-ALMA-10_8</Version>
+        <CreationTime>{{created_at}}</CreationTime>
+    </ProjectSummary>
+    <ProjectStructure>TBD</ProjectStructure>
+    <ProcessingRequests>
+        <RootDirectory>{{root_directory}}</RootDirectory>
+        <ProcessingRequest>
+            <ProcessingIntents>
+                <Intents>
+                    <Keyword>VLA_INTERFEROMETRY_STANDARD_OBSERVING_MODE</Keyword>
+                    <Value>Undefined</Value>
+                </Intents>
+            </ProcessingIntents>
+
+            <!--TODO: find correct procedure!-->
+
+            <DataSet>
+                <RelativePath>{{relative_path}}</RelativePath>
+                <SdmIdentifier>{{sdmId}}.ms</SdmIdentifier>
+                <DataType>asdm</DataType>
+            </DataSet>
+        </ProcessingRequest>
+    </ProcessingRequests>
+    <ResultsProcessing>
+        <ArchiveResults>false</ArchiveResults>
+        <CleanUpDisk>false</CleanUpDisk>
+        <UpdateProjectLifeCycle>false</UpdateProjectLifeCycle>
+        <NotifyOperatorWhenDone>false</NotifyOperatorWhenDone>
+        <SDMall>false</SDMall>
+        <SDMonly>false</SDMonly>
+        <PipelineOperatorAddress>Unknown</PipelineOperatorAddress>
+    </ResultsProcessing>
+</ns2:SciPipeRequest>
+"""
+
+
+def upgrade():
+    op.execute(
+        f"""
+        INSERT INTO workflow_templates (filename, content, workflow_name) 
+        VALUES('std_cms_imaging.condor', E'{condor_content}', 'std_cms_imaging') 
+        """
+    )
+    op.execute(
+        f"""
+        INSERT INTO workflow_templates (filename, content, workflow_name) 
+        VALUES ('std_cms_imaging.sh', E'{script_content}', 'std_cms_imaging') 
+        """
+    )
+    op.execute(
+        f"""
+        INSERT INTO workflow_templates (filename, content, workflow_name) 
+        VALUES ('metadata.json', E'{metadata_content}', 'std_cms_imaging') 
+        """
+    )
+    op.execute(
+        f"""
+        INSERT INTO workflow_templates (filename, content, workflow_name) 
+        VALUES ('PPR.xml', E'{ppr_content}', 'std_cms_imaging') 
+        """
+    )
+
+
+def downgrade():
+    op.execute(
+        """
+        DELETE FROM workflow_templates WHERE workflow_name='std_cms_imaging'
+        """
+    )
-- 
GitLab