From 3a944bea99b743f9bd26f2c98ed017f1a079d7b3 Mon Sep 17 00:00:00 2001 From: pvictor Date: Tue, 7 Jun 2022 10:05:51 +0200 Subject: [PATCH] runSimulation: API OK --- R/API.R | 11 ++++++++++- R/runSimulation.R | 21 ++++++++++++++++++--- inst/API/dev-api-online.R | 8 ++++---- man/getJobLogs.Rd | 9 ++++++++- man/runSimulation.Rd | 8 ++++++-- 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/R/API.R b/R/API.R index 371f3cb4..6bc4441b 100644 --- a/R/API.R +++ b/R/API.R @@ -231,13 +231,22 @@ getJobs <- function(opts = antaresRead::simOptions()) { #' @examples #' \dontrun{ #' -#' getJobLogs("37afff54-3a8b-40fa-8841-e1dae8854f5f") +#' antaresRead::setSimulationPathAPI( +#' host = "http://localhost:8080", +#' study_id = "39c604fc-687f-46c4-9fa6-59b57ff9c8d1", +#' token = NULL, +#' simulation = "input" +#' ) +#' job <- runSimulation() +#' getJobLogs(job) #' #' } getJobLogs <- function(job_id, opts = antaresRead::simOptions()) { assertthat::assert_that(inherits(opts, "simOptions")) if (!is_api_study(opts)) stop("getJobLogs can only be used with Antares API.", call. = FALSE) + if (is.list(job_id) && !is.null(job_id$job_id)) + job_id <- job_id$job_id logs <- api_get(opts = opts, paste0("launcher/jobs/", job_id, "/logs"), default_endpoint = "v1") class(logs) <- c(class(logs), "antares.api.logs") return(logs) diff --git a/R/runSimulation.R b/R/runSimulation.R index 17b9ce1c..5db559e1 100644 --- a/R/runSimulation.R +++ b/R/runSimulation.R @@ -1,6 +1,10 @@ #' @title Run an Antares Simulation #' -#' @description Run an ANTARES study +#' @description +#' `r antaresEditObject::badge_api_ok()` +#' +#' Run an ANTARES study +#' #' #' @param name #' Name of the simulation. @@ -23,8 +27,10 @@ #' [antaresRead::setSimulationPath()] #' #' @return -#' The function does not return anything. It is used to launch an -#' ANTARES simulation +#' In API mode it return a `list` with either the job id in case of success of +#' the command or details about the error produce. +#' In non-API mode the function does not return anything, it is used to launch an +#' ANTARES simulation. #' #' @importFrom assertthat assert_that #' @importFrom antaresRead simOptions @@ -38,6 +44,15 @@ runSimulation <- function(name, show_output_on_console = FALSE, parallel = TRUE, opts = antaresRead::simOptions()) { + assertthat::assert_that(inherits(opts, "simOptions")) + + if (is_api_study(opts)) { + + run <- api_post(opts = opts, url = paste0("launcher/run/", opts$study_id), default_endpoint = "v1") + return(run) + + } + if (is.null(path_solver)) { path_solver <- setSolverPath() } diff --git a/inst/API/dev-api-online.R b/inst/API/dev-api-online.R index 7e00ec6c..a80a8153 100644 --- a/inst/API/dev-api-online.R +++ b/inst/API/dev-api-online.R @@ -10,14 +10,14 @@ library(antaresEditObject) # Path to our study opts <- antaresRead::setSimulationPathAPI( host = "http://localhost:8080", - study_id = "0b26b7e9-57d3-47cb-82c6-d118427eaf7d", + study_id = "39c604fc-687f-46c4-9fa6-59b57ff9c8d1", token = NULL, simulation = "input" ) # temp (implemented in dev version of antaresRead) -opts$host <- "http://localhost:8080" -opts$study_id <- "0b26b7e9-57d3-47cb-82c6-d118427eaf7d" -options(antares = opts) +# opts$host <- "http://localhost:8080" +# opts$study_id <- "0b26b7e9-57d3-47cb-82c6-d118427eaf7d" +# options(antares = opts) diff --git a/man/getJobLogs.Rd b/man/getJobLogs.Rd index 3bc2dbbc..1246b6c3 100644 --- a/man/getJobLogs.Rd +++ b/man/getJobLogs.Rd @@ -21,7 +21,14 @@ Retrieve job log from API \examples{ \dontrun{ -getJobLogs("37afff54-3a8b-40fa-8841-e1dae8854f5f") +antaresRead::setSimulationPathAPI( + host = "http://localhost:8080", + study_id = "39c604fc-687f-46c4-9fa6-59b57ff9c8d1", + token = NULL, + simulation = "input" +) +job <- runSimulation() +getJobLogs(job) } } diff --git a/man/runSimulation.Rd b/man/runSimulation.Rd index eced02e2..6fa75154 100644 --- a/man/runSimulation.Rd +++ b/man/runSimulation.Rd @@ -35,9 +35,13 @@ is the one set in advanced_settings/simulation_cores (see ANTARES interface).} \code{\link[antaresRead:setSimulationPath]{antaresRead::setSimulationPath()}}} } \value{ -The function does not return anything. It is used to launch an -ANTARES simulation +In API mode it return a \code{list} with either the job id in case of success of +the command or details about the error produce. +In non-API mode the function does not return anything, it is used to launch an +ANTARES simulation. } \description{ +\ifelse{html}{\figure{badge_api_ok.svg}{options: alt='Antares API OK'}}{Antares API: \strong{OK}} + Run an ANTARES study }