Arvados class now accepts additional parameter which specifies max
[arvados.git] / sdk / R / R / Arvados.R
index a22ff73bef300ff409496d4246636a9b37e6ab42..ea4384b5b47ecb97d9b2aaa0348b79738ae2e180 100644 (file)
@@ -16,7 +16,7 @@ Arvados <- R6::R6Class(
 
     public = list(
 
-        initialize = function(authToken = NULL, hostName = NULL)
+        initialize = function(authToken = NULL, hostName = NULL, numRetries = 0)
         {
             if(!is.null(hostName))
                Sys.setenv(ARVADOS_API_HOST = hostName)
@@ -25,15 +25,18 @@ Arvados <- R6::R6Class(
                 Sys.setenv(ARVADOS_API_TOKEN = authToken)
 
             hostName  <- Sys.getenv("ARVADOS_API_HOST");
-            token <- Sys.getenv("ARVADOS_API_TOKEN");
+            token     <- Sys.getenv("ARVADOS_API_TOKEN");
 
             if(hostName == "" | token == "")
-                stop(paste0("Please provide host name and authentification token",
-                            " or set ARVADOS_API_HOST and ARVADOS_API_TOKEN",
-                            " environment variables."))
+                stop(paste("Please provide host name and authentification token",
+                           "or set ARVADOS_API_HOST and ARVADOS_API_TOKEN",
+                           "environment variables."))
+
+            private$numRetries  <- numRetries
+            private$REST  <- RESTService$new(token, hostName,
+                                             HttpRequest$new(), HttpParser$new(),
+                                             numRetries)
 
-            private$REST  <- RESTService$new(token, hostName, NULL,
-                                             HttpRequest$new(), HttpParser$new())
             private$token <- private$REST$token
             private$host  <- private$REST$hostName
         },
@@ -44,6 +47,12 @@ Arvados <- R6::R6Class(
         getRESTService    = function() private$REST,
         setRESTService    = function(newRESTService) private$REST <- newRESTService,
 
+        getNumRetries = function() private$REST$numRetries,
+        setNumRetries = function(newNumOfRetries)
+        {
+            private$REST$setNumRetries(newNumOfRetries)
+        },
+
         getCollection = function(uuid)
         {
             collection <- private$REST$getResource("collections", uuid)
@@ -119,8 +128,7 @@ Arvados <- R6::R6Class(
             names(body) <- c("group")
             body$group <- newContent
 
-            updatedProject <- private$REST$updateResource("groups",
-                                                          uuid, body)
+            updatedProject <- private$REST$updateResource("groups", uuid, body)
             updatedProject
         },
 
@@ -131,8 +139,7 @@ Arvados <- R6::R6Class(
 
             filters[[length(filters) + 1]] <- list("group_class", "=", "project")
 
-            projects <- private$REST$listResources("groups", filters,
-                                                   limit, offset)
+            projects <- private$REST$listResources("groups", filters, limit, offset)
             projects
         },
 
@@ -158,10 +165,19 @@ Arvados <- R6::R6Class(
 
     private = list(
 
-        token          = NULL,
-        host           = NULL,
-        REST           = NULL
+        token      = NULL,
+        host       = NULL,
+        REST       = NULL,
+        numRetries = NULL
     ),
 
     cloneable = FALSE
 )
+
+#' @export print.Arvados
+print.Arvados = function(arvados)
+{
+    cat(paste0("Type:  ", "\"", "Arvados",             "\""), sep = "\n")
+    cat(paste0("Host:  ", "\"", arvados$getHostName(), "\""), sep = "\n")
+    cat(paste0("Token: ", "\"", arvados$getToken(),    "\""), sep = "\n")
+}