[ARVADOS] updated: 1.1.2-50-gec836ed

Git user git at public.curoverse.com
Fri Dec 22 10:46:03 EST 2017


Summary of changes:
 sdk/R/R/Arvados.R        | 84 +++++++++++++++++++++++++++++++++++++++++-------
 sdk/R/R/ArvadosFile.R    | 20 ++++++++----
 sdk/R/R/Collection.R     | 58 +++++++++++++++++++++++++++++----
 sdk/R/R/CollectionTree.R |  1 -
 sdk/R/R/HttpParser.R     |  4 ++-
 sdk/R/R/HttpRequest.R    |  6 ++--
 sdk/R/R/Subcollection.R  | 30 ++++++++++-------
 sdk/R/README             | 17 ++++------
 8 files changed, 167 insertions(+), 53 deletions(-)

       via  ec836ed648758619ed35153e52016079adce99b7 (commit)
       via  91801cb4c303db0fbf701aa34e646e0dc4187f05 (commit)
       via  76c2e8d11e3c644f1603adbef3222afaacd6a279 (commit)
       via  d645f41a7f082e92288cb07cfa4527ff3edb408a (commit)
       via  f4da35a4dc44a18c8371c9e42a03fa5dc96c53d3 (commit)
      from  99bec637f6d4384a8d6f3c2cb27eb32d13c14f21 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit ec836ed648758619ed35153e52016079adce99b7
Author: Fuad Muhic <fmuhic at capeannenterprises.com>
Date:   Fri Dec 22 16:43:45 2017 +0100

    Added methods listAllCollections and listAllProjects.
    
    Arvados-DCO-1.1-Signed-off-by: Fuad Muhic <fmuhic at capeannenterprises.com>

diff --git a/sdk/R/R/Arvados.R b/sdk/R/R/Arvados.R
index e337cb9..e08ce61 100644
--- a/sdk/R/R/Arvados.R
+++ b/sdk/R/R/Arvados.R
@@ -83,12 +83,21 @@ Arvados <- R6::R6Class(
             serverResponse <- private$http$GET(collectionURL, headers, filters,
                                                limit, offset)
 
-            collection <- private$httpParser$parseJSONResponse(serverResponse)
+            collections <- private$httpParser$parseJSONResponse(serverResponse)
 
-            if(!is.null(collection$errors))
-                stop(collection$errors)       
+            if(!is.null(collections$errors))
+                stop(collections$errors)       
 
-            collection
+            collections
+        },
+
+        listAllCollections = function(filters = NULL)
+        {
+            if(!is.null(filters))
+                names(filters) <- c("collection")
+
+            collectionURL <- paste0(private$host, "collections")
+            private$fetchAllItems(collectionURL, filters)
         },
 
         deleteCollection = function(uuid) 
@@ -229,6 +238,18 @@ Arvados <- R6::R6Class(
             projects
         },
 
+        listAllProjects = function(filters = NULL)
+        {
+            if(!is.null(filters))
+                names(filters) <- c("groups")
+
+            filters[[length(filters) + 1]] <- list("group_class", "=", "project")
+
+            projectURL <- paste0(private$host, "groups")
+
+            private$fetchAllItems(projectURL, filters)
+        },
+
         deleteProject = function(uuid) 
         {
             projectURL <- paste0(private$host, "groups/", uuid)
@@ -252,7 +273,35 @@ Arvados <- R6::R6Class(
         host           = NULL,
         webDavHostName = NULL,
         http           = NULL,
-        httpParser     = NULL
+        httpParser     = NULL,
+
+        fetchAllItems = function(resourceURL, filters)
+        {
+            headers <- list(Authorization = paste("OAuth2", private$token))
+
+            offset <- 0
+            itemsAvailable <- .Machine$integer.max
+            items <- c()
+            while(length(items) < itemsAvailable)
+            {
+                serverResponse <- private$http$GET(url          = resourceURL,
+                                                   headers      = headers,
+                                                   queryFilters = filters,
+                                                   limit        = NULL,
+                                                   offset       = offset)
+
+                parsedResponse <- private$httpParser$parseJSONResponse(serverResponse)
+
+                if(!is.null(parsedResponse$errors))
+                    stop(parsedResponse$errors)       
+
+                items          <- c(items, parsedResponse$items)
+                offset         <- length(items)
+                itemsAvailable <- parsedResponse$items_available
+            }
+
+            items
+        }
     ),
     
     cloneable = FALSE
diff --git a/sdk/R/R/HttpRequest.R b/sdk/R/R/HttpRequest.R
index 20ad7ea..a1e1f61 100644
--- a/sdk/R/R/HttpRequest.R
+++ b/sdk/R/R/HttpRequest.R
@@ -139,9 +139,10 @@ HttpRequest <- R6::R6Class(
             if(length(finalQuery) > 1)
             {
                 finalQuery <- paste0(finalQuery, collapse = "&")
-                finalQuery <- paste0("?", finalQuery)
             }
 
+            finalQuery <- paste0("/?", finalQuery)
+
             finalQuery
         }
     ),

commit 91801cb4c303db0fbf701aa34e646e0dc4187f05
Author: Fuad Muhic <fmuhic at capeannenterprises.com>
Date:   Fri Dec 22 14:01:05 2017 +0100

    Added code to notify user when API is unable to locate webDAV server.
    
    Arvados-DCO-1.1-Signed-off-by: Fuad Muhic <fmuhic at capeannenterprises.com>

diff --git a/sdk/R/R/Arvados.R b/sdk/R/R/Arvados.R
index c051313..e337cb9 100644
--- a/sdk/R/R/Arvados.R
+++ b/sdk/R/R/Arvados.R
@@ -47,6 +47,9 @@ Arvados <- R6::R6Class(
 
             discoveryDocument <- private$httpParser$parseJSONResponse(serverResponse)
             private$webDavHostName <- discoveryDocument$keepWebServiceUrl
+
+            if(is.null(private$webDavHostName))
+                stop("Unable to find WebDAV server.")
         },
 
         getToken    = function() private$token,

commit 76c2e8d11e3c644f1603adbef3222afaacd6a279
Author: Fuad Muhic <fmuhic at capeannenterprises.com>
Date:   Fri Dec 22 12:32:39 2017 +0100

    Split Collectin's add method to add and create methods.
    
    Arvados-DCO-1.1-Signed-off-by: Fuad Muhic <fmuhic at capeannenterprises.com>

diff --git a/sdk/R/R/Collection.R b/sdk/R/R/Collection.R
index fb9af11..8e6895e 100644
--- a/sdk/R/R/Collection.R
+++ b/sdk/R/R/Collection.R
@@ -50,17 +50,61 @@ Collection <- R6::R6Class(
             if(is.null(subcollection))
                 stop(paste("Subcollection", relativePath, "doesn't exist."))
 
-            if(is.character(content))
+            if("ArvadosFile"   %in% class(content) ||
+               "Subcollection" %in% class(content))
             {
-                sapply(content, function(fileName)
+                subcollection$add(content)
+
+                content
+            }
+            else
+            {
+                contentClass <- paste(class(content), collapse = ", ")
+                stop(paste("Expected AravodsFile or Subcollection object, got",
+                           paste0("(", contentClass, ")"), "."))
+            }
+        },
+
+        create = function(fileNames, relativePath = "")
+        {
+            if(relativePath == "" ||
+               relativePath == "." ||
+               relativePath == "./")
+            {
+                subcollection <- private$tree$.__enclos_env__$private$tree
+            }
+            else
+            {
+                if(endsWith(relativePath, "/") && nchar(relativePath) > 0)
+                    relativePath <- substr(relativePath, 1, nchar(relativePath) - 1)
+
+                subcollection <- self$get(relativePath)
+            }
+
+            if(is.null(subcollection))
+                stop(paste("Subcollection", relativePath, "doesn't exist."))
+
+            if(is.character(fileNames))
+            {
+                arvadosFiles <- NULL
+                sapply(fileNames, function(fileName)
                 {
-                    subcollection$add(ArvadosFile$new(fileName))
+                    newFile <- ArvadosFile$new(fileName)
+                    subcollection$add(newFile)
+
+                    arvadosFiles <<- c(arvadosFiles, newFile)
                 })
+
+                if(length(arvadosFiles) == 1)
+                    return(arvadosFiles[[1]])
+                else
+                    return(arvadosFiles)
             }
-            else if("ArvadosFile"   %in% class(content) ||
-                    "Subcollection" %in% class(content))
+            else 
             {
-                subcollection$add(content)
+                contentClass <- paste(class(fileNames), collapse = ", ")
+                stop(paste("Expected character vector, got",
+                           paste0("(", contentClass, ")"), "."))
             }
         },
 
diff --git a/sdk/R/README b/sdk/R/README
index 0c43473..3d100f4 100644
--- a/sdk/R/README
+++ b/sdk/R/README
@@ -108,15 +108,16 @@ size <- arvadosSubcollection$getSizeInBytes()
 
 #Create new file in a collection
 
-#Call structure
-
-collection$add(arvadosFileOrSubcollectionOrFileName, optionalRelativePath)
+collection$create(fileNames, optionalRelativePath)
 
 #Example
 
-collection$add("main.cpp", "cpp/src/")
+mainFile <- collection$create("main.cpp", "cpp/src/")
+fileList <- collection$create(c("main.cpp", lib.dll), "cpp/src/")
 
-#or
+--------------------------------------------------------------------------------------------------------------------------------
+
+#Add existing ArvadosFile or Subcollection to a collection
 
 folder <- Subcollection$new("src")
 file <- ArvadosFile$new("main.cpp")
@@ -124,13 +125,9 @@ folder$add(file)
 
 collection$add(folder, "cpp")
 
-#Both examples will add file "main.cpp" in "./cpp/src/" folder if folder exists.
+#This examples will add file "main.cpp" in "./cpp/src/" folder if folder exists.
 #If subcollection contains more files or folders they will be added recursively.
 
-#You can also add multiple files
-
-collection$add(c("path/to/my/file.cpp", "path/to/other/file.cpp"))
-
 --------------------------------------------------------------------------------------------------------------------------------
 
 #Write to existing file (Override current content of the file)

commit d645f41a7f082e92288cb07cfa4527ff3edb408a
Author: Fuad Muhic <fmuhic at capeannenterprises.com>
Date:   Fri Dec 22 11:44:14 2017 +0100

    Collections getFileContent method renamed to getFileListing.
    
    Arvados-DCO-1.1-Signed-off-by: Fuad Muhic <fmuhic at capeannenterprises.com>

diff --git a/sdk/R/R/ArvadosFile.R b/sdk/R/R/ArvadosFile.R
index c5fa183..3be24c4 100644
--- a/sdk/R/R/ArvadosFile.R
+++ b/sdk/R/R/ArvadosFile.R
@@ -18,7 +18,7 @@ ArvadosFile <- R6::R6Class(
 
         getName = function() private$name,
 
-        getFileList = function(fullpath = TRUE)
+        getFileListing = function(fullpath = TRUE)
         {
             self$getName()
         },
diff --git a/sdk/R/R/Collection.R b/sdk/R/R/Collection.R
index ca26082..fb9af11 100644
--- a/sdk/R/R/Collection.R
+++ b/sdk/R/R/Collection.R
@@ -105,7 +105,7 @@ Collection <- R6::R6Class(
             elementToMove$move(newLocation)
         },
 
-        getFileContent = function() private$getCollectionContent(),
+        getFileListing = function() private$getCollectionContent(),
 
         get = function(relativePath)
         {
diff --git a/sdk/R/R/Subcollection.R b/sdk/R/R/Subcollection.R
index 62c62d4..296cb92 100644
--- a/sdk/R/R/Subcollection.R
+++ b/sdk/R/R/Subcollection.R
@@ -32,7 +32,7 @@ Subcollection <- R6::R6Class(
                 if(!is.null(private$collection))
                 {       
                     contentPath <- paste0(self$getRelativePath(),
-                                          "/", content$getFileList())
+                                          "/", content$getFileListing())
 
                     private$collection$.__enclos_env__$private$createFilesOnREST(contentPath)
                     content$.__enclos_env__$private$addToCollection(private$collection)
@@ -59,7 +59,7 @@ Subcollection <- R6::R6Class(
                 stop("Unable to delete root folder.")
 
             collectionList <- paste0(self$getRelativePath(),
-                                     "/", self$getFileList(fullpath = FALSE))
+                                     "/", self$getFileListing(fullpath = FALSE))
             sapply(collectionList, function(file)
             {
                 private$collection$.__enclos_env__$private$deleteFromREST(file)
@@ -71,14 +71,14 @@ Subcollection <- R6::R6Class(
             "Content removed successfully."
         },
 
-        getFileList = function(fullpath = TRUE)
+        getFileListing = function(fullpath = TRUE)
         {
             content <- NULL
 
             if(fullpath)
             {
                 for(child in private$children)
-                    content <- c(content, child$getFileList())
+                    content <- c(content, child$getFileListing())
 
                 if(private$name != "")
                     content <- unlist(paste0(private$name, "/", content))

commit f4da35a4dc44a18c8371c9e42a03fa5dc96c53d3
Author: Fuad Muhic <fmuhic at capeannenterprises.com>
Date:   Fri Dec 22 11:12:39 2017 +0100

    Methods listCollections and listProjects now work properly
    when called without parameters. Removed old comments.
    
    Arvados-DCO-1.1-Signed-off-by: Fuad Muhic <fmuhic at capeannenterprises.com>

diff --git a/sdk/R/R/Arvados.R b/sdk/R/R/Arvados.R
index 3236ab7..c051313 100644
--- a/sdk/R/R/Arvados.R
+++ b/sdk/R/R/Arvados.R
@@ -27,9 +27,11 @@ Arvados <- R6::R6Class(
             token <- Sys.getenv("ARVADOS_API_TOKEN");
 
             if(host == "" | token == "")
-                stop("Please provide host name and authentification token or set ARVADOS_API_HOST and ARVADOS_API_TOKEN environmental variables.")
+                stop("Please provide host name and authentification token or set
+                     ARVADOS_API_HOST and ARVADOS_API_TOKEN environmental variables.")
 
-            discoveryDocumentURL <- paste0("https://", host, "/discovery/v1/apis/arvados/v1/rest")
+            discoveryDocumentURL <- paste0("https://", host,
+                                           "/discovery/v1/apis/arvados/v1/rest")
 
             version <- "v1"
             host  <- paste0("https://", host, "/arvados/", version, "/")
@@ -50,7 +52,6 @@ Arvados <- R6::R6Class(
         getToken    = function() private$token,
         getHostName = function() private$host,
 
-        #Todo(Fudo): Hardcoded credentials to WebDAV server. Remove them later
         getWebDavHostName = function() private$webDavHostName,
 
         getCollection = function(uuid) 
@@ -73,9 +74,12 @@ Arvados <- R6::R6Class(
             collectionURL <- paste0(private$host, "collections")
             headers <- list(Authorization = paste("OAuth2", private$token))
 
-            names(filters) <- c("collection")
+            if(!is.null(filters))
+                names(filters) <- c("collection")
+
+            serverResponse <- private$http$GET(collectionURL, headers, filters,
+                                               limit, offset)
 
-            serverResponse <- private$http$GET(collectionURL, headers, filters, limit, offset)
             collection <- private$httpParser$parseJSONResponse(serverResponse)
 
             if(!is.null(collection$errors))
@@ -206,10 +210,14 @@ Arvados <- R6::R6Class(
             projectURL <- paste0(private$host, "groups")
             headers <- list(Authorization = paste("OAuth2", private$token))
 
-            names(filters) <- c("groups")
+            if(!is.null(filters))
+                names(filters) <- c("groups")
+
             filters[[length(filters) + 1]] <- list("group_class", "=", "project")
 
-            serverResponse <- private$http$GET(projectURL, headers, filters, limit, offset)
+            serverResponse <- private$http$GET(projectURL, headers, filters,
+                                               limit, offset)
+
             projects <- private$httpParser$parseJSONResponse(serverResponse)
 
             if(!is.null(projects$errors))
diff --git a/sdk/R/R/ArvadosFile.R b/sdk/R/R/ArvadosFile.R
index 84e76af..c5fa183 100644
--- a/sdk/R/R/ArvadosFile.R
+++ b/sdk/R/R/ArvadosFile.R
@@ -25,7 +25,8 @@ ArvadosFile <- R6::R6Class(
 
         getSizeInBytes = function()
         {
-            collectionURL <- URLencode(paste0(private$collection$api$getWebDavHostName(), "c=", private$collection$uuid))
+            collectionURL <- URLencode(paste0(private$collection$api$getWebDavHostName(),
+                                              "c=", private$collection$uuid))
             fileURL <- paste0(collectionURL, "/", self$getRelativePath());
 
             headers = list("Authorization" = paste("OAuth2", private$collection$api$getToken()))
@@ -82,11 +83,13 @@ ArvadosFile <- R6::R6Class(
             if(length > 0)
                 range = paste0(range, offset + length - 1)
             
-            fileURL = paste0(private$collection$api$getWebDavHostName(), "c=", private$collection$uuid, "/", self$getRelativePath());
+            fileURL = paste0(private$collection$api$getWebDavHostName(),
+                             "c=", private$collection$uuid, "/", self$getRelativePath());
 
             if(offset == 0 && length == 0)
             {
-                headers <- list(Authorization = paste("OAuth2", private$collection$api$getToken())) 
+                headers <- list(Authorization = paste("OAuth2",
+                                                      private$collection$api$getToken())) 
             }
             else
             {
@@ -108,7 +111,8 @@ ArvadosFile <- R6::R6Class(
             if(is.null(private$collection))
                 stop("ArvadosFile doesn't belong to any collection.")
 
-            fileURL = paste0(private$collection$api$getWebDavHostName(), "c=", private$collection$uuid, "/", self$getRelativePath());
+            fileURL = paste0(private$collection$api$getWebDavHostName(), 
+                             "c=", private$collection$uuid, "/", self$getRelativePath());
             headers <- list(Authorization = paste("OAuth2", private$collection$api$getToken()), 
                             "Content-Type" = contentType)
             body <- content
@@ -129,7 +133,8 @@ ArvadosFile <- R6::R6Class(
 
             if(endsWith(newLocation, paste0(private$name, "/")))
             {
-                newLocation <- substr(newLocation, 0, nchar(newLocation) - nchar(paste0(private$name, "/")))
+                newLocation <- substr(newLocation, 0,
+                                      nchar(newLocation) - nchar(paste0(private$name, "/")))
             }
             else if(endsWith(newLocation, private$name))
             {
@@ -147,7 +152,8 @@ ArvadosFile <- R6::R6Class(
                 stop("Unable to get destination subcollection.")
             }
 
-            status <- private$collection$.__enclos_env__$private$moveOnREST(self$getRelativePath(), paste0(newParent$getRelativePath(), "/", self$getName()))
+            status <- private$collection$.__enclos_env__$private$moveOnREST(self$getRelativePath(),
+                                                                            paste0(newParent$getRelativePath(), "/", self$getName()))
 
             private$attachToParent(newParent)
 
diff --git a/sdk/R/R/CollectionTree.R b/sdk/R/R/CollectionTree.R
index 82c6eb8..3bf89e5 100644
--- a/sdk/R/R/CollectionTree.R
+++ b/sdk/R/R/CollectionTree.R
@@ -88,7 +88,6 @@ CollectionTree <- R6::R6Class(
             if(is.null(child))
             {
                 container$add(node)
-                #todo add it to collection
             }
             else
             {
diff --git a/sdk/R/R/HttpParser.R b/sdk/R/R/HttpParser.R
index e7407b1..82b7109 100644
--- a/sdk/R/R/HttpParser.R
+++ b/sdk/R/R/HttpParser.R
@@ -11,7 +11,9 @@ HttpParser <- R6::R6Class(
 
         parseJSONResponse = function(serverResponse) 
         {
-            parsed_response <- httr::content(serverResponse, as = "parsed", type = "application/json")
+            parsed_response <- httr::content(serverResponse,
+                                             as = "parsed",
+                                             type = "application/json")
         },
 
         parseWebDAVResponse = function(response, uri)
diff --git a/sdk/R/R/HttpRequest.R b/sdk/R/R/HttpRequest.R
index 2f17268..20ad7ea 100644
--- a/sdk/R/R/HttpRequest.R
+++ b/sdk/R/R/HttpRequest.R
@@ -71,8 +71,6 @@ HttpRequest <- R6::R6Class(
 
     private = list(
 
-        #Todo(Fudo): Refactor this and find a better way to build
-        # Python array from R list (recursion?)
         createQuery = function(filters, limit, offset)
         {
             finalQuery <- NULL
@@ -115,7 +113,6 @@ HttpRequest <- R6::R6Class(
 
                 encodedQuery <- URLencode(filters, reserved = T, repeated = T)
 
-                #Todo(Fudo): This is a hack for now. Find a proper solution.
                 encodedQuery <- stringr::str_replace_all(encodedQuery, "%2B", "+")
 
                 finalQuery <- c(finalQuery, paste0("filters=", encodedQuery))
diff --git a/sdk/R/R/Subcollection.R b/sdk/R/R/Subcollection.R
index 76bec2e..62c62d4 100644
--- a/sdk/R/R/Subcollection.R
+++ b/sdk/R/R/Subcollection.R
@@ -26,11 +26,14 @@ Subcollection <- R6::R6Class(
 
                 childWithSameName <- private$getChild(content$getName())
                 if(!is.null(childWithSameName))
-                stop("Subcollection already contains ArvadosFile or Subcollection with same name.")
+                    stop("Subcollection already contains ArvadosFile
+                          or Subcollection with same name.")
 
                 if(!is.null(private$collection))
                 {       
-                    contentPath <- paste0(self$getRelativePath(), "/", content$getFileList())
+                    contentPath <- paste0(self$getRelativePath(),
+                                          "/", content$getFileList())
+
                     private$collection$.__enclos_env__$private$createFilesOnREST(contentPath)
                     content$.__enclos_env__$private$addToCollection(private$collection)
                 }
@@ -42,7 +45,8 @@ Subcollection <- R6::R6Class(
             }
             else
             {
-                stop(paste("Expected AravodsFile or Subcollection object, got", class(content), "."))
+                stop(paste("Expected AravodsFile or Subcollection object, got",
+                           class(content), "."))
             }
         },
 
@@ -54,7 +58,8 @@ Subcollection <- R6::R6Class(
             if(private$name == "")
                 stop("Unable to delete root folder.")
 
-            collectionList <- paste0(self$getRelativePath(), "/", self$getFileList(fullpath = FALSE))
+            collectionList <- paste0(self$getRelativePath(),
+                                     "/", self$getFileList(fullpath = FALSE))
             sapply(collectionList, function(file)
             {
                 private$collection$.__enclos_env__$private$deleteFromREST(file)
@@ -89,7 +94,8 @@ Subcollection <- R6::R6Class(
 
         getSizeInBytes = function()
         {
-            collectionURL <- URLencode(paste0(private$collection$api$getWebDavHostName(), "c=", private$collection$uuid))
+            collectionURL <- URLencode(paste0(private$collection$api$getWebDavHostName(),
+                                              "c=", private$collection$uuid))
             subcollectionURL <- paste0(collectionURL, "/", self$getRelativePath(), "/");
 
             headers = list("Authorization" = paste("OAuth2", private$collection$api$getToken()))
@@ -109,7 +115,6 @@ Subcollection <- R6::R6Class(
             relativePath <- c(private$name)
             parent <- private$parent
 
-            #Recurse back to root
             while(!is.null(parent))
             {
                 relativePath <- c(parent$getName(), relativePath)
@@ -127,11 +132,13 @@ Subcollection <- R6::R6Class(
 
             if(endsWith(newLocation, paste0(private$name, "/")))
             {
-                newLocation <- substr(newLocation, 0, nchar(newLocation) - nchar(paste0(private$name, "/")))
+                newLocation <- substr(newLocation, 0,
+                                      nchar(newLocation) - nchar(paste0(private$name, "/")))
             }
             else if(endsWith(newLocation, private$name))
             {
-                newLocation <- substr(newLocation, 0, nchar(newLocation) - nchar(private$name))
+                newLocation <- substr(newLocation, 0,
+                                      nchar(newLocation) - nchar(private$name))
             }
             else
             {
@@ -145,7 +152,8 @@ Subcollection <- R6::R6Class(
                 stop("Unable to get destination subcollection.")
             }
 
-            status <- private$collection$.__enclos_env__$private$moveOnREST(self$getRelativePath(), paste0(newParent$getRelativePath(), "/", self$getName()))
+            status <- private$collection$.__enclos_env__$private$moveOnREST(self$getRelativePath(),
+                                                                            paste0(newParent$getRelativePath(), "/", self$getName()))
 
             private$attachToParent(newParent)
 

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list