From 0e10eb2efca8d33cd2765550205a3a56bdef5cfd Mon Sep 17 00:00:00 2001 From: Scott Chamberlain Date: Fri, 26 Jul 2024 12:44:34 -0700 Subject: [PATCH 1/6] bump roxygen version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index a96a3d8..615ee98 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,7 +25,7 @@ License: MIT + file LICENSE Depends: R (>= 3.6.0) Roxygen: list(markdown = TRUE, roclets = c("collate", "namespace", "rd", "roxyglobals::global_roclet")) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 Encoding: UTF-8 Suggests: curl, From 6c24c78272c7bfe6dbb62d7a7b25d8961bfcc652 Mon Sep 17 00:00:00 2001 From: Scott Chamberlain Date: Fri, 26 Jul 2024 12:46:27 -0700 Subject: [PATCH 2/6] #43 add new fxn cromwell_labels for /labels route - and add tests and fixtures for cromwell_labels - and change handling of labels data in the post request for cromwell_submit_batch, post from a file rather than data --- DESCRIPTION | 2 +- NAMESPACE | 1 + R/cromwellSubmitBatch.R | 5 +++- R/labels.R | 22 +++++++++++++++++ man/cromwell_labels.Rd | 25 +++++++++++++++++++ tests/fixtures/cromwell_labels_data.yml | 26 ++++++++++++++++++++ tests/fixtures/cromwell_labels_submit.yml | 30 +++++++++++++++++++++++ tests/testthat/test-cromwell_labels.R | 22 +++++++++++++++++ 8 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 R/labels.R create mode 100644 man/cromwell_labels.Rd create mode 100644 tests/fixtures/cromwell_labels_data.yml create mode 100644 tests/fixtures/cromwell_labels_submit.yml create mode 100644 tests/testthat/test-cromwell_labels.R diff --git a/DESCRIPTION b/DESCRIPTION index 615ee98..7b47a1e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rcromwell Title: Convenience Tools for Managing WDL Workflows via Cromwell -Version: 3.2.2.91 +Version: 3.2.2.93 Authors@R: c( person("Amy", "Paguirigan", role = "aut", comment = c(ORCID = "0000-0002-6819-9736")), diff --git a/NAMESPACE b/NAMESPACE index 35875ec..dd9d319 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -8,6 +8,7 @@ export(cromwell_config) export(cromwell_failures) export(cromwell_glob) export(cromwell_jobs) +export(cromwell_labels) export(cromwell_logs) export(cromwell_outputs) export(cromwell_submit_batch) diff --git a/R/cromwellSubmitBatch.R b/R/cromwellSubmitBatch.R index a0678b8..1677917 100644 --- a/R/cromwellSubmitBatch.R +++ b/R/cromwellSubmitBatch.R @@ -66,8 +66,11 @@ cromwell_submit_batch_query <- function( ) } if (!is.null(labels)) { + labels_temp_file <- tempfile(pattern = "rcromwell_", fileext = ".json") + cat(jsonlite::toJSON(as.list(labels), auto_unbox = TRUE), + file = labels_temp_file) body <- c(body, - labels = list(jsonlite::toJSON(as.list(labels), auto_unbox = TRUE)) + labels = lst_upload_file(labels_temp_file) ) } body diff --git a/R/labels.R b/R/labels.R new file mode 100644 index 0000000..b8a4899 --- /dev/null +++ b/R/labels.R @@ -0,0 +1,22 @@ +#' Cromwell labels for a workflow +#' +#' @export +#' @template workflowid +#' @template serverdeets +#' @return a named list of workflow labels +cromwell_labels <- function(workflow_id, url = cw_url(), token = NULL) { + check_url(url) + response <- http_get( + url = make_url( + url, + "api/workflows/v1", + workflow_id, + "labels" + ), + as = "parsed", + token = token + ) + labels <- response$labels + names(labels)[grep("cromwell-workflow-id", names(labels))] <- "workflow_id" + labels +} diff --git a/man/cromwell_labels.Rd b/man/cromwell_labels.Rd new file mode 100644 index 0000000..a9bc7e3 --- /dev/null +++ b/man/cromwell_labels.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/labels.R +\name{cromwell_labels} +\alias{cromwell_labels} +\title{Cromwell labels for a workflow} +\usage{ +cromwell_labels(workflow_id, url = cw_url(), token = NULL) +} +\arguments{ +\item{workflow_id}{(character) A single workflow ID} + +\item{url}{(character) base url for your Cromwell server. optional. if not +supplied set the url as the env var \code{CROMWELLURL}} + +\item{token}{(character) we do not recommend passing your token +here as a string. Either pass it using \code{\link[=Sys.getenv]{Sys.getenv()}} or save your +token as the env var \code{PROOF_TOKEN} and then passing nothing to this +param and we'll find it} +} +\value{ +a named list of workflow labels +} +\description{ +Cromwell labels for a workflow +} diff --git a/tests/fixtures/cromwell_labels_data.yml b/tests/fixtures/cromwell_labels_data.yml new file mode 100644 index 0000000..dba5c23 --- /dev/null +++ b/tests/fixtures/cromwell_labels_data.yml @@ -0,0 +1,26 @@ +http_interactions: +- request: + method: get + uri: http://localhost:8000/api/workflows/v1/287c7902-abc0-49ab-a6ec-0ce0c097b4d2/labels + body: + encoding: '' + string: '' + headers: + Accept: application/json, text/xml, application/xml, */* + response: + status: + status_code: 200 + category: Success + reason: OK + message: 'Success: (200) OK' + headers: + server: akka-http/10.1.15 + date: Fri, 26 Jul 2024 19:26:12 GMT + content-type: application/json + content-length: '200' + body: + encoding: '' + file: no + string: '{"id":"287c7902-abc0-49ab-a6ec-0ce0c097b4d2","labels":{"Label":"Apple","secondaryLabel":"Orange","workflowType":"AppSubmission","cromwell-workflow-id":"cromwell-287c7902-abc0-49ab-a6ec-0ce0c097b4d2"}}' + recorded_at: 2024-07-26 19:26:12 GMT + recorded_with: vcr/1.6.0, webmockr/1.0.0 diff --git a/tests/fixtures/cromwell_labels_submit.yml b/tests/fixtures/cromwell_labels_submit.yml new file mode 100644 index 0000000..a639388 --- /dev/null +++ b/tests/fixtures/cromwell_labels_submit.yml @@ -0,0 +1,30 @@ +http_interactions: +- request: + method: post + uri: http://localhost:8000/api/workflows/v1 + body: + encoding: '' + string: workflowSource=list(path = "/Users/schambe3/github/getwilds/rcromwell/inst/examples/hello.wdl", + type = "application/octet-stream", name = NULL),workflowInputs=list(path = + "/Users/schambe3/github/getwilds/rcromwell/inst/examples/inputs.json", type + = "application/json", name = NULL),labels=list(path = "/private/var/folders/qt/fzq1m_bj2yb_7b2jz57s9q7c0000gp/T/Rtmp21huqY/rcromwell_1609933b0cbaf.json", + type = "application/json", name = NULL) + headers: + Accept: application/json, text/xml, application/xml, */* + response: + status: + status_code: 201 + category: Success + reason: Created + message: 'Success: (201) Created' + headers: + server: akka-http/10.1.15 + date: Fri, 26 Jul 2024 19:25:52 GMT + content-type: application/json + content-length: '66' + body: + encoding: '' + file: no + string: '{"id":"287c7902-abc0-49ab-a6ec-0ce0c097b4d2","status":"Submitted"}' + recorded_at: 2024-07-26 19:25:52 GMT + recorded_with: vcr/1.6.0, webmockr/1.0.0 diff --git a/tests/testthat/test-cromwell_labels.R b/tests/testthat/test-cromwell_labels.R new file mode 100644 index 0000000..dfe4321 --- /dev/null +++ b/tests/testthat/test-cromwell_labels.R @@ -0,0 +1,22 @@ +test_that("cromwell_labels", { + my_labels <- data.frame( + "workflowType" = "AppSubmission", + "Label" = "Apple", + "secondaryLabel" = "Orange" + ) + + vcr::use_cassette("cromwell_labels_submit", { + res <- cromwell_submit_batch(wdl = file_hello, params = file_inputs, + labels = my_labels) + }) + + # Sys.sleep(20) # Needed only for recording new fixture #nolint + + vcr::use_cassette("cromwell_labels_data", { + labels_from_workflow <- cromwell_labels(res$id) + }) + + expect_length(labels_from_workflow, 4) + expect_equal(labels_from_workflow$Label, "Apple") + expect_equal(labels_from_workflow$secondaryLabel, "Orange") +}) From bafaa0b20f5ed997c62021d9e1a662eda3e3cc91 Mon Sep 17 00:00:00 2001 From: Scott Chamberlain Date: Fri, 26 Jul 2024 13:09:54 -0700 Subject: [PATCH 3/6] small fix to tests: skip tests that do not use vcr when localhost 8000 cromwell server is not available --- tests/testthat/helper-vcr.R | 8 ++++++++ tests/testthat/test-error-handling.R | 2 ++ 2 files changed, 10 insertions(+) diff --git a/tests/testthat/helper-vcr.R b/tests/testthat/helper-vcr.R index ec894d1..f33b0f1 100644 --- a/tests/testthat/helper-vcr.R +++ b/tests/testthat/helper-vcr.R @@ -15,3 +15,11 @@ file_workflow_opts <- sys_file("examples/workflow_options.json") # suppress messages for the test run cromwell_config(verbose = FALSE) + +cromwell_localhost_up <- function() { + try8000 <- tryCatch( + curl::curl_fetch_memory("localhost:8000"), + error = function(e) e + ) + !inherits(try8000, "error") +} diff --git a/tests/testthat/test-error-handling.R b/tests/testthat/test-error-handling.R index f5de0ed..a2a1939 100644 --- a/tests/testthat/test-error-handling.R +++ b/tests/testthat/test-error-handling.R @@ -1,3 +1,5 @@ +skip_if_not(cromwell_localhost_up()) + test_that("proof api or DIY cromwell server down", { # This should happen whether proof or DIY if not on # campus or VPN for Fred Hutch at least From a12dd895f2af5ad7c670079bddcbe98153e4383a Mon Sep 17 00:00:00 2001 From: Scott Chamberlain Date: Fri, 26 Jul 2024 13:10:49 -0700 Subject: [PATCH 4/6] styling --- R/cromwellOutputs.R | 4 +++- R/cromwellSubmitBatch.R | 3 ++- tests/testthat/test-cromwell_labels.R | 6 ++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/R/cromwellOutputs.R b/R/cromwellOutputs.R index 856028c..124bf84 100644 --- a/R/cromwellOutputs.R +++ b/R/cromwellOutputs.R @@ -34,7 +34,9 @@ cromwell_outputs_query <- function(workflow_id, url = cw_url(), token = NULL) { #' @autoglobal cromwell_outputs_process <- function(resp, workflow_id) { - if (length(resp$outputs) == 0) return(dplyr::tibble()) + if (length(resp$outputs) == 0) { + return(dplyr::tibble()) + } # grab only the outputs list and unlist into a dataframe df <- purrr::map_dfr(resp$outputs, function(x) { z <- dplyr::tibble("pathToOutput" = unlist(x)) diff --git a/R/cromwellSubmitBatch.R b/R/cromwellSubmitBatch.R index 1677917..d5796fc 100644 --- a/R/cromwellSubmitBatch.R +++ b/R/cromwellSubmitBatch.R @@ -68,7 +68,8 @@ cromwell_submit_batch_query <- function( if (!is.null(labels)) { labels_temp_file <- tempfile(pattern = "rcromwell_", fileext = ".json") cat(jsonlite::toJSON(as.list(labels), auto_unbox = TRUE), - file = labels_temp_file) + file = labels_temp_file + ) body <- c(body, labels = lst_upload_file(labels_temp_file) ) diff --git a/tests/testthat/test-cromwell_labels.R b/tests/testthat/test-cromwell_labels.R index dfe4321..8119125 100644 --- a/tests/testthat/test-cromwell_labels.R +++ b/tests/testthat/test-cromwell_labels.R @@ -6,8 +6,10 @@ test_that("cromwell_labels", { ) vcr::use_cassette("cromwell_labels_submit", { - res <- cromwell_submit_batch(wdl = file_hello, params = file_inputs, - labels = my_labels) + res <- cromwell_submit_batch( + wdl = file_hello, params = file_inputs, + labels = my_labels + ) }) # Sys.sleep(20) # Needed only for recording new fixture #nolint From 08213a7b191685b5e80f922b30d051c81f4eb71e Mon Sep 17 00:00:00 2001 From: Scott Chamberlain Date: Fri, 26 Jul 2024 13:12:57 -0700 Subject: [PATCH 5/6] add labels fxn to pkgdown config file --- _pkgdown.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/_pkgdown.yml b/_pkgdown.yml index 54ae98f..3014c9c 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -27,6 +27,7 @@ reference: - cromwell_failures - cromwell_glob - cromwell_jobs + - cromwell_labels - cromwell_logs - cromwell_outputs - cromwell_submit_batch From 4c3a2103b57328c348b51ff5ddd0833401f82a37 Mon Sep 17 00:00:00 2001 From: Scott Chamberlain Date: Tue, 6 Aug 2024 13:30:03 -0700 Subject: [PATCH 6/6] bump pkg version, update news --- DESCRIPTION | 4 ++-- NEWS.md | 4 ++++ man/rcromwell-package.Rd | 3 ++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 31227cf..a641f55 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rcromwell Title: Convenience Tools for Managing WDL Workflows via Cromwell -Version: 3.2.2.93 +Version: 3.2.4 Authors@R: c( person("Amy", "Paguirigan", role = "aut", comment = c(ORCID = "0000-0002-6819-9736")), @@ -8,7 +8,7 @@ Authors@R: c( comment = c(ORCID = "0000-0003-1444-9135")), person("Fred Hutchinson Cancer Center", , , "wilds@fredhutch.org", role = "fnd") ) -URL: https://getwilds.org/rcromwell/, https://github.com/getwilds/rcromwell +URL: https://getwilds.org/rcromwell, https://github.com/getwilds/rcromwell BugReports: https://github.com/getwilds/rcromwell/issues Description: A repo containing a basic R package for using Cromwell with WDL workflows via R. Imports: diff --git a/NEWS.md b/NEWS.md index f5e295a..5e117a7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# rcromwell 3.2.4 + +* gains new function `cromwell_labels` that hits the `/labels` route (#43) (#45) + # rcromwell 3.2.1 * fix `cromwell_submit_batch` - internally changed `workflow_options` to `workflowOptions` (#32) diff --git a/man/rcromwell-package.Rd b/man/rcromwell-package.Rd index 9ced8b2..dcfebc6 100644 --- a/man/rcromwell-package.Rd +++ b/man/rcromwell-package.Rd @@ -11,7 +11,8 @@ A repo containing a basic R package for using Cromwell with WDL workflows via R. \seealso{ Useful links: \itemize{ - \item \url{http://getwilds.org/rcromwell/ (website) https://github.com/getwilds/rcromwell (devel)} + \item \url{https://getwilds.org/rcromwell} + \item \url{https://github.com/getwilds/rcromwell} \item Report bugs at \url{https://github.com/getwilds/rcromwell/issues} }