Skip to content
Snippets Groups Projects
Commit 3f7bdb4c authored by Nathan Bockisch's avatar Nathan Bockisch
Browse files

WS-1020: Added triggering utility for VLASS image ingestion

parent 3e258aec
No related branches found
No related tags found
1 merge request!915WS-1020: Added triggering utility for VLASS image ingestion
Pipeline #5063 passed
Pipeline: workspaces

#5066

    # iiwf_trigger:
    iiwf_trigger is a command line utility to initiate a workflow for a VLASS image set
    ## Usage
    `iiwf_trigger -path /path/to/VLASS/image/set [-prop CAPO_PATH]`
    module ssa/iiwf_trigger
    go 1.18
    require github.com/magiconair/properties v1.8.6
    github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo=
    github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
    /*
    * Copyright (C) 2022 Associated Universities, Inc. Washington DC, USA.
    *
    * This file is part of NRAO Workspaces.
    *
    * Workspaces is free software: you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation, either version 3 of the License, or
    * (at your option) any later version.
    *
    * Workspaces is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    * GNU General Public License for more details.
    *
    * You should have received a copy of the GNU General Public License
    * along with Workspaces. If not, see <https://www.gnu.org/licenses/>.
    */
    package main
    import (
    "flag"
    "ssa/iiwf_trigger/pkg/ingest"
    )
    func main() {
    var img_set_path string
    var capo_profile string
    flag.StringVar(&img_set_path, "path", "", "Path to a cached VLASS image set")
    flag.StringVar(&capo_profile, "prop", "/home/casa/capo/${CAPO_PROFILE}.properties", "Path to the CAPO properties file with the calibration lookup URL")
    flag.Parse()
    // Make sure a path was provided
    if len(img_set_path) == 0 {
    flag.Usage()
    return
    }
    locator := ingest.GetCalibrationLocator(img_set_path, capo_profile)
    ingest.CallIngestionEndpoint(img_set_path, locator, capo_profile)
    }
    /*
    * Copyright (C) 2022 Associated Universities, Inc. Washington DC, USA.
    *
    * This file is part of NRAO Workspaces.
    *
    * Workspaces is free software: you can redistribute it and/or modify
    * it under the terms of the GNU General Public License as published by
    * the Free Software Foundation, either version 3 of the License, or
    * (at your option) any later version.
    *
    * Workspaces is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    * GNU General Public License for more details.
    *
    * You should have received a copy of the GNU General Public License
    * along with Workspaces. If not, see <https://www.gnu.org/licenses/>.
    */
    package ingest
    import (
    "encoding/json"
    "fmt"
    "io/ioutil"
    "net/http"
    "path/filepath"
    "github.com/magiconair/properties"
    )
    type calibrationInfo struct {
    Locator string `json:"locator"`
    }
    /**
    * Check if an error happened and panic on it if so
    *
    * @param err An error object to report
    **/
    func checkError(err error) {
    if err != nil {
    panic(err)
    }
    }
    /**
    * Pull a property from a CAPO property file
    *
    * @param capo_profile A string with a path to the CAPO property file
    * @param property_name A string with the name of the property to be returned
    * @return a string with the property value
    **/
    func getCapoProperty(capo_profile string, property_name string) string {
    prop_file := properties.MustLoadFile(capo_profile, properties.UTF8)
    property := prop_file.GetString(property_name, "")
    if len(property) == 0 {
    panic(fmt.Sprintf("Unable to retrieve property %s from %s", property_name, capo_profile))
    }
    return property
    }
    /**
    * Get the locator for a VLASS image set
    *
    * @param img_set_path A string with the path to the image set
    * @param capo_profile A string with the path to the CAPO property file used to
    * get the calibration lookup URL
    * @return a string with the locator value
    **/
    func GetCalibrationLocator(img_set_path string, capo_profile string) string {
    lookup_url_prop := "edu.nrao.archive.workflow.config.IngestionWorkflowSettings.calibrationLookupUrl"
    workflow_endpoint := getCapoProperty(capo_profile, lookup_url_prop)
    img_set := filepath.Base(img_set_path)
    // Make the REST call
    lookup_url := workflow_endpoint + img_set
    resp, err := http.Get(lookup_url)
    checkError(err)
    defer resp.Body.Close()
    if resp.StatusCode != http.StatusOK {
    panic(fmt.Sprintf("Error making GET request to URL %s, got status code %d", lookup_url, resp.StatusCode))
    }
    resp_bytes, err := ioutil.ReadAll(resp.Body)
    checkError(err)
    // Get the json of the response body
    var calibration calibrationInfo
    json.Unmarshal(resp_bytes, &calibration)
    return calibration.Locator
    }
    package ingest
    import (
    "bytes"
    "encoding/json"
    "fmt"
    "io/ioutil"
    "log"
    "net/http"
    )
    type RequestPayload struct {
    CachePath string `json:"cache_path"`
    CalSpl string `json:"cal_spl"`
    }
    /**
    * Call the SECI ingestion endpoint to initiate the workflow
    *
    * @param img_set_path A string with the path to a VLASS image set
    * @param locator A string with the locator for the image set
    * @param capo_profile A string with the path to the CAPO property file used to
    * get the Workflow service URL
    **/
    func CallIngestionEndpoint(img_set_path string, locator string, capo_profile string) {
    payload := RequestPayload{
    CachePath: img_set_path,
    CalSpl: locator,
    }
    // Convert payload to json
    payload_json, err := json.Marshal(payload)
    checkError(err)
    fmt.Println(string(payload_json))
    // Get post request
    workflow_url_prop := "edu.nrao.workspaces.WorkflowSettings.serviceUrl"
    workflow_url := getCapoProperty(capo_profile, workflow_url_prop)
    post_url := workflow_url + "/workflows/requests/vlass_ingest/seci"
    resp, err := http.Post(post_url, "application/json", bytes.NewBuffer(payload_json))
    checkError(err)
    defer resp.Body.Close()
    if resp.StatusCode != http.StatusOK {
    panic(fmt.Sprintf("Error making POST request to URL %s, got status code %d", post_url, resp.StatusCode))
    }
    resp_header := resp.Header
    resp_body, err := ioutil.ReadAll(resp.Body)
    checkError(err)
    log.Println("POST Request Made")
    log.Println("Response Headers: ", resp_header)
    log.Println("Response Body: ", resp_body)
    }
    # mod_analyst:
    mod_analyst is a command line utility to add/remove DAs and AODs from the qa_staff table in the database
    ## Usage
    `mod_analyst -name "First Last" [-aod] [-email EMAIL] [-rm] [-ssl] [-port PORT] [-dbname DATABASE_NAME] [-host DATABASE_HOST] [-prop CAPO_PATH]`
    ## Examples
    ### To add Nathan Bockisch as an aod
    1. ssh to the machine hosting the database
    2. `mod_analyst -name "Nathan Bockisch" -aod -email "nbockisc@nrao.edu"`
    ### To remove Nathan Bockisch as an aod
    1. ssh to the machine hosting the database
    2. `mod_analyst -name "Nathan Bockisch" -rm`
    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