Created helper method to deal with iterating through list returned by SDK.
[arvados.git] / services / datamanager / datamanager.go
1 /* Keep Datamanager. Responsible for checking on and reporting on Keep Storage */
2
3 package main
4
5 import (
6         //"git.curoverse.com/arvados.git/sdk/go/keepclient"
7         "fmt"
8         "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
9         "git.curoverse.com/arvados.git/services/datamanager/collection"
10         "log"
11 )
12
13 // Helper type so we don't have to write out 'map[string]interface{}' every time.
14 type Dict map[string]interface{}
15
16 func UserIsAdmin(arv arvadosclient.ArvadosClient) (is_admin bool, err error) {
17         type user struct {
18                 IsAdmin bool `json:"is_admin"`
19         }
20         var u user
21         err = arv.Call("GET", "users", "", "current", nil, &u)
22         return u.IsAdmin, err
23 }
24
25 func main() {
26         fmt.Println("Hello, world\n")
27
28         arv, err := arvadosclient.MakeArvadosClient()
29         if err != nil {
30                 log.Fatalf("Error setting up arvados client %s", err.Error())
31         }
32
33         if is_admin, err := UserIsAdmin(arv); err != nil {
34                 log.Fatalf("Error querying current arvados user %s", err.Error())
35         } else if !is_admin {
36                 log.Fatalf("Current user is not an admin. Datamanager can only be run by admins.")
37         }
38
39         readCollections := collection.GetCollections(
40                 collection.GetCollectionsParams{
41                         Client: arv, Limit: 50, LogEveryNthCollectionProcessed: 10})
42
43         //log.Printf("Read Collections: %v", readCollections)
44
45         // TODO(misha): Add a "readonly" flag. If we're in readonly mode,
46         // lots of behaviors can become warnings (and obviously we can't
47         // write anything).
48         // if !readCollections.ReadAllCollections {
49         //      log.Fatalf("Did not read all collections")
50         // }
51
52         log.Printf("Read and processed %d collections",
53                 len(readCollections.UuidToCollection))
54
55         // TODO(misha): Send SDK and Keep requests in parallel
56 }