Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new fxn cromwell_labels #45

Merged
merged 7 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Package: rcromwell
Title: Convenience Tools for Managing WDL Workflows via Cromwell
Version: 3.2.2.91
Version: 3.2.4
Authors@R: c(
person("Amy", "Paguirigan", role = "aut",
comment = c(ORCID = "0000-0002-6819-9736")),
person("Scott", "Chamberlain", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-1444-9135")),
person("Fred Hutchinson Cancer Center", , , "[email protected]", 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:
Expand All @@ -24,7 +24,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,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 3 additions & 1 deletion R/cromwellOutputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 5 additions & 1 deletion R/cromwellSubmitBatch.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ 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
Expand Down
22 changes: 22 additions & 0 deletions R/labels.R
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ reference:
- cromwell_failures
- cromwell_glob
- cromwell_jobs
- cromwell_labels
- cromwell_logs
- cromwell_outputs
- cromwell_submit_batch
Expand Down
25 changes: 25 additions & 0 deletions man/cromwell_labels.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/rcromwell-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions tests/fixtures/cromwell_labels_data.yml
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions tests/fixtures/cromwell_labels_submit.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions tests/testthat/helper-vcr.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
24 changes: 24 additions & 0 deletions tests/testthat/test-cromwell_labels.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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")
})
2 changes: 2 additions & 0 deletions tests/testthat/test-error-handling.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading