diff --git a/apps/cli/executables/go/iiwf_trigger/README.md b/apps/cli/executables/go/iiwf_trigger/README.md new file mode 100644 index 0000000000000000000000000000000000000000..f1221f397e91d452c40db83269e7ffaf1f9e8142 --- /dev/null +++ b/apps/cli/executables/go/iiwf_trigger/README.md @@ -0,0 +1,6 @@ +# 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]` diff --git a/apps/cli/executables/go/iiwf_trigger/go.mod b/apps/cli/executables/go/iiwf_trigger/go.mod new file mode 100644 index 0000000000000000000000000000000000000000..fd0725ed5507bf8f5e6e8cba6a1fabf11a42d59f --- /dev/null +++ b/apps/cli/executables/go/iiwf_trigger/go.mod @@ -0,0 +1,5 @@ +module ssa/iiwf_trigger + +go 1.18 + +require github.com/magiconair/properties v1.8.6 diff --git a/apps/cli/executables/go/iiwf_trigger/go.sum b/apps/cli/executables/go/iiwf_trigger/go.sum new file mode 100644 index 0000000000000000000000000000000000000000..606c7ba8fda67bda1355c333d630bb132fe9adc5 --- /dev/null +++ b/apps/cli/executables/go/iiwf_trigger/go.sum @@ -0,0 +1,2 @@ +github.com/magiconair/properties v1.8.6 h1:5ibWZ6iY0NctNGWo87LalDlEZ6R41TqbbDamhfG/Qzo= +github.com/magiconair/properties v1.8.6/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= diff --git a/apps/cli/executables/go/iiwf_trigger/main.go b/apps/cli/executables/go/iiwf_trigger/main.go new file mode 100644 index 0000000000000000000000000000000000000000..9ae0e418a9629fa7518befc0327ff4bac4c208ee --- /dev/null +++ b/apps/cli/executables/go/iiwf_trigger/main.go @@ -0,0 +1,43 @@ +/* + * 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) +} diff --git a/apps/cli/executables/go/iiwf_trigger/pkg/ingest/get_info.go b/apps/cli/executables/go/iiwf_trigger/pkg/ingest/get_info.go new file mode 100644 index 0000000000000000000000000000000000000000..b79599747f7c60a7e6d2b0c42a9f46a122b117b7 --- /dev/null +++ b/apps/cli/executables/go/iiwf_trigger/pkg/ingest/get_info.go @@ -0,0 +1,98 @@ +/* + * 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 +} diff --git a/apps/cli/executables/go/iiwf_trigger/pkg/ingest/send_info.go b/apps/cli/executables/go/iiwf_trigger/pkg/ingest/send_info.go new file mode 100644 index 0000000000000000000000000000000000000000..76788a65a0a56820cbb5bc44a24658fe0e40828b --- /dev/null +++ b/apps/cli/executables/go/iiwf_trigger/pkg/ingest/send_info.go @@ -0,0 +1,58 @@ +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) +} diff --git a/apps/cli/executables/go/mod_analyst/README.md b/apps/cli/executables/go/mod_analyst/README.md new file mode 100644 index 0000000000000000000000000000000000000000..a05602e8e7b057715740dfc59b997455eb8aa6d5 --- /dev/null +++ b/apps/cli/executables/go/mod_analyst/README.md @@ -0,0 +1,16 @@ +# 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`