Skip to content

Commit

Permalink
Add test output to validate function
Browse files Browse the repository at this point in the history
  • Loading branch information
afwillia committed Feb 19, 2024
1 parent a584e92 commit f0446dd
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 34 deletions.
41 changes: 24 additions & 17 deletions R/schematic_rest_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate",
schema_url="https://raw.githubusercontent.com/ncihtan/data-models/main/HTAN.model.jsonld", #nolint
data_type, file_name = NULL, restrict_rules=FALSE, project_scope = NULL,
access_token, asset_view = NULL, json_str = NULL) {

a <- paste0(sample(1000, 1), "-")
cat(paste0(a, "-validate func ", data_type, " ", file_name, "\n"))
flattenbody <- function(x) {
# A form/query can only have one value per name, so take
# any values that contain vectors length >1 and
Expand All @@ -137,8 +138,15 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate",
}

if (is.null(json_str)) {
req <- httr2::request(url)
resp <- req %>%
reqs <- httr2::request(url) |>
httr2::req_retry(
max_tries = 3,
is_transient = \(reqs) httr2::resp_status(reqs) %in% c(429, 500, 503, 504)
) |>
httr2::req_error(is_error = \(reqs) FALSE) |>
httr2::req_throttle(1)
cat(paste0(a, "-validate func requesting", unlist(reqs), "\n"))
resp <- reqs %>%
httr2::req_headers(Authorization = sprintf("Bearer %s", access_token)) |>
httr2::req_url_query(
schema_url=schema_url,
Expand All @@ -148,14 +156,11 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate",
asset_view = asset_view
) |>
httr2::req_body_multipart(file_name=curl::form_file(file_name)) |>
httr2::req_retry(
max_tries = 3,
is_transient = \(resp) httr2::resp_status(resp) %in% c(429, 500, 503, 504)
) |>
httr2::req_error(is_error = \(resp) FALSE) |>
httr2::req_perform()
cat(paste0(a, "-validate func response", unlist(resp), "\n"))
} else {
req <- httr2::request(url)
req <- httr2::request(url) |>
httr2::req_throttle(1)
resp <- req %>%
httr2::req_headers(Authorization = sprintf("Bearer %s", access_token)) |>
httr2::req_url_query(
Expand All @@ -166,15 +171,16 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate",
asset_view = asset_view,
json_str = json_str
) |>
httr2::req_retry(
max_tries = 3,
is_transient = \(resp) httr2::resp_status(resp) %in% c(429, 500, 503, 504)
) |>
httr2::req_error(is_error = \(resp) FALSE) |>
#httr2::req_retry(
# max_tries = 3,
# is_transient = \(resp) httr2::resp_status(resp) %in% c(429, 500, 503, 504)
#) |>
#httr2::req_error(is_error = \(resp) FALSE) |>
httr2::req_perform()
}

# Format server error in a way validationResult can handle
cat(a, "-validate func response", "\n")
if (httr2::resp_is_error(resp)) {
return(
list(
Expand Down Expand Up @@ -243,14 +249,15 @@ model_component_requirements <- function(url="http://localhost:3001/v1/model/com
schema_url, source_component,
as_graph = FALSE) {

req <- httr2::request(url)
resp <- req |>
reqs <- httr2::request(url) |>
httr2::req_throttle(1)
resp <- reqs |>
httr2::req_url_query(
schema_url = schema_url,
source_component = source_component,
as_graph = as_graph
) |>
httr2::req_retry(max_tries = 3) |>
#httr2::req_retry(max_tries = 3) |>
httr2::req_perform()
resp |>
httr2::resp_body_json()
Expand Down
41 changes: 24 additions & 17 deletions functions/schematic_rest_api.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate",
schema_url="https://raw.githubusercontent.com/ncihtan/data-models/main/HTAN.model.jsonld", #nolint
data_type, file_name = NULL, restrict_rules=FALSE, project_scope = NULL,
access_token, asset_view = NULL, json_str = NULL) {

a <- paste0(sample(1000, 1), "-")
cat(paste0(a, "-validate func ", data_type, " ", file_name, "\n"))
flattenbody <- function(x) {
# A form/query can only have one value per name, so take
# any values that contain vectors length >1 and
Expand All @@ -137,8 +138,15 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate",
}

if (is.null(json_str)) {
req <- httr2::request(url)
resp <- req %>%
reqs <- httr2::request(url) |>
httr2::req_retry(
max_tries = 3,
is_transient = \(reqs) httr2::resp_status(reqs) %in% c(429, 500, 503, 504)
) |>
httr2::req_error(is_error = \(reqs) FALSE) |>
httr2::req_throttle(1)
cat(paste0(a, "-validate func requesting", unlist(reqs), "\n"))
resp <- reqs %>%
httr2::req_headers(Authorization = sprintf("Bearer %s", access_token)) |>
httr2::req_url_query(
schema_url=schema_url,
Expand All @@ -148,14 +156,11 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate",
asset_view = asset_view
) |>
httr2::req_body_multipart(file_name=curl::form_file(file_name)) |>
httr2::req_retry(
max_tries = 3,
is_transient = \(resp) httr2::resp_status(resp) %in% c(429, 500, 503, 504)
) |>
httr2::req_error(is_error = \(resp) FALSE) |>
httr2::req_perform()
cat(paste0(a, "-validate func response", unlist(resp), "\n"))
} else {
req <- httr2::request(url)
req <- httr2::request(url) |>
httr2::req_throttle(1)
resp <- req %>%
httr2::req_headers(Authorization = sprintf("Bearer %s", access_token)) |>
httr2::req_url_query(
Expand All @@ -166,15 +171,16 @@ manifest_validate <- function(url="http://localhost:3001/v1/model/validate",
asset_view = asset_view,
json_str = json_str
) |>
httr2::req_retry(
max_tries = 3,
is_transient = \(resp) httr2::resp_status(resp) %in% c(429, 500, 503, 504)
) |>
httr2::req_error(is_error = \(resp) FALSE) |>
#httr2::req_retry(
# max_tries = 3,
# is_transient = \(resp) httr2::resp_status(resp) %in% c(429, 500, 503, 504)
#) |>
#httr2::req_error(is_error = \(resp) FALSE) |>
httr2::req_perform()
}

# Format server error in a way validationResult can handle
cat(a, "-validate func response", "\n")
if (httr2::resp_is_error(resp)) {
return(
list(
Expand Down Expand Up @@ -243,14 +249,15 @@ model_component_requirements <- function(url="http://localhost:3001/v1/model/com
schema_url, source_component,
as_graph = FALSE) {

req <- httr2::request(url)
resp <- req |>
reqs <- httr2::request(url) |>
httr2::req_throttle(1)
resp <- reqs |>
httr2::req_url_query(
schema_url = schema_url,
source_component = source_component,
as_graph = as_graph
) |>
httr2::req_retry(max_tries = 3) |>
#httr2::req_retry(max_tries = 3) |>
httr2::req_perform()
resp |>
httr2::resp_body_json()
Expand Down

0 comments on commit f0446dd

Please sign in to comment.