From 32d3651136bcd174d5d0511bf5ab82e25664d978 Mon Sep 17 00:00:00 2001 From: Matthias Mohr Date: Fri, 26 Jul 2024 22:14:33 +0200 Subject: [PATCH] Add additional parameters for custom property injection #125 --- NEWS.md | 6 ++++++ R/jobs.R | 19 ++++++++++++++++--- R/services.R | 14 ++++++++++++-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index a51e1612..0a2ea866 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# Version 1.4.0 + +## Added + +* compute_result, create_job, update_job, create_service and update_service have an additional parameter to inject custom properties into the request (e.g., to set memory or CPU limits) + # Version 1.3.1 ## Added diff --git a/R/jobs.R b/R/jobs.R index 27f4f477..aef1136d 100644 --- a/R/jobs.R +++ b/R/jobs.R @@ -63,6 +63,7 @@ setClass("Job") #' @param as_stars logical to indicate if the data shall be interpreted as a stars object #' @param format character or `FileFormat` specifying the File format for the output, if 'save_result' is not #' set in the process then it will be added otherwise the value stated here will replace the original value. +#' @param additional Additional, non-standardized job settings to send to the back-end #' @param con connected and authenticated openEO client (optional) otherwise [active_connection()] #' is used. #' @param ... additional parameters passed to jsonlite::toJSON() (like 'digits') or additional arguments that shall @@ -72,7 +73,7 @@ setClass("Job") #' #' @importFrom methods as #' @export -compute_result = function(graph, output_file = NULL, budget=NULL, plan=NULL, as_stars=FALSE, format = NULL, con=NULL, ...) { +compute_result = function(graph, output_file = NULL, budget=NULL, plan=NULL, as_stars=FALSE, format = NULL, additional = NULL, con=NULL, ...) { tryCatch({ con = .assure_connection(con) output = list() @@ -151,6 +152,10 @@ compute_result = function(graph, output_file = NULL, budget=NULL, plan=NULL, as_ job$plan = plan } + if (!is.null(additional)) { + job = c(job, additional) + } + is_tempfile = ifelse(length(output_file) == 0,TRUE,FALSE) tag = "execute_sync" @@ -213,13 +218,14 @@ compute_result = function(graph, output_file = NULL, budget=NULL, plan=NULL, as_ #' @param description Optional detailed information about a job #' @param plan An optional execution plan offered by the back-end, determining how the job will be executed #' @param budget An optional budget, which sets the maximum amount of credits to be used by the job +#' @param additional Additional, non-standardized job settings to send to the back-end #' @param con connected and authenticated openEO client (optional) otherwise [active_connection()] #' is used. #' @param ... additional parameters passed to jsonlite::toJSON() (like 'digits') #' #' @return the id of the job #' @export -create_job = function(graph = NULL, title = NULL, description = NULL, plan = NULL, budget = NULL, con=NULL, ...) { +create_job = function(graph = NULL, title = NULL, description = NULL, plan = NULL, budget = NULL, additional = NULL, con=NULL, ...) { tryCatch({ con = .assure_connection(con) @@ -233,6 +239,8 @@ create_job = function(graph = NULL, title = NULL, description = NULL, plan = NUL job$plan = plan if (!is.null(budget)) job$budget = budget + if (!is.null(additional)) + job = c(job, additional) # build an empty process if (!is.null(graph)) { @@ -320,12 +328,13 @@ start_job = function(job, log=FALSE, con=NULL) { #' will return the results or a self defined [Process()] #' @param plan replaces plan with the set value #' @param budget replaces or sets the credits that can be spent at maximum +#' @param additional Additional, non-standardized job settings to send to the back-end #' @param con connected and authenticated openEO client (optional) otherwise [active_connection()] #' is used. #' @param ... additional parameters passed to jsonlite::toJSON() (like 'digits') #' #' @export -update_job = function(id, title = NULL, description = NULL, process = NULL, plan = NULL, budget = NULL, con=NULL, ...) { +update_job = function(id, title = NULL, description = NULL, process = NULL, plan = NULL, budget = NULL, additional = NULL, con=NULL, ...) { tryCatch({ con = .assure_connection(con) @@ -362,6 +371,10 @@ update_job = function(id, title = NULL, description = NULL, process = NULL, plan patch$budget = budget } + if (!is.null(additional)) { + patch = c(patch, additional) + } + tag = "jobs_update" res = con$request(tag = tag, parameters = list(id), authorized = TRUE, encodeType = "json", data = patch, ...) message(paste("Job '", id, "' was successfully updated.", sep = "")) diff --git a/R/services.R b/R/services.R index 43e3aef5..62cc67ad 100644 --- a/R/services.R +++ b/R/services.R @@ -46,13 +46,14 @@ list_services = function(con=NULL) { #' @param configuration a named list specifying the configuration parameter #' @param plan character - the billing plan #' @param budget numeric - the amount of credits that can be spent on this service +#' @param additional Additional, non-standardized service settings to send to the back-end #' @param con connected and authenticated openEO client object (optional) otherwise [active_connection()] #' is used. #' @param ... additional parameters passed to jsonlite::toJSON() (like 'digits') #' #' @return Service object #' @export -create_service = function(type, graph, title = NULL, description = NULL, enabled = NULL, configuration = NULL, plan = NULL, budget = NULL, con=NULL, ...) { +create_service = function(type, graph, title = NULL, description = NULL, enabled = NULL, configuration = NULL, plan = NULL, budget = NULL, additional = NULL, con=NULL, ...) { tryCatch({ if (is.null(type)) { stop("No type specified.") @@ -68,6 +69,10 @@ create_service = function(type, graph, title = NULL, description = NULL, enabled plan = plan, budget = budget) + if (!is.null(additional)) { + service_request_object = c(service_request_object, additional) + } + # build an empty process if (!is.null(graph)) { process = Process$new(id=NA,description = NA, @@ -118,6 +123,7 @@ create_service = function(type, graph, title = NULL, description = NULL, enabled #' @param configuration a list of service creation configuration #' @param plan character - the billing plan #' @param budget numeric - the amount of credits that can be spent for this service +#' @param additional Additional, non-standardized service settings to send to the back-end #' @param con connected and authorized openEO client object (optional) otherwise [active_connection()] #' is used. #' @param ... additional parameters passed to jsonlite::toJSON() (like 'digits') @@ -125,7 +131,7 @@ create_service = function(type, graph, title = NULL, description = NULL, enabled #' @return Service object #' #' @export -update_service = function(service, type = NULL, graph = NULL, title = NULL, description = NULL, enabled = NULL, configuration = NULL, plan = NULL, budget = NULL, con=NULL, ...) { +update_service = function(service, type = NULL, graph = NULL, title = NULL, description = NULL, enabled = NULL, configuration = NULL, plan = NULL, budget = NULL, additional = NULL, con=NULL, ...) { tryCatch({ patch = list() @@ -220,6 +226,10 @@ update_service = function(service, type = NULL, graph = NULL, title = NULL, desc } } + if (!is.null(additional)) { + patch = c(patch, additional) + } + tag = "services_update" res = con$request(tag = tag, parameters = list(service), authorized = TRUE, encodeType = "json", data = patch, ...) message(paste("Service '", service, "' was successfully updated.", sep = ""))