1 /* Keep Datamanager. Responsible for checking on and reporting on Keep Storage */
7 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
8 "git.curoverse.com/arvados.git/sdk/go/util"
9 "git.curoverse.com/arvados.git/services/datamanager/collection"
10 "git.curoverse.com/arvados.git/services/datamanager/keep"
17 arv, err := arvadosclient.MakeArvadosClient()
19 log.Fatalf("Error setting up arvados client %s", err.Error())
22 if is_admin, err := util.UserIsAdmin(arv); err != nil {
23 log.Fatalf("Error querying current arvados user %s", err.Error())
25 log.Fatalf("Current user is not an admin. Datamanager can only be run by admins.")
28 // TODO(misha): Read Collections and Keep Contents concurrently as goroutines.
30 // readCollections := collection.GetCollections(
31 // collection.GetCollectionsParams{
32 // Client: arv, BatchSize: 500})
34 // UserUsage := ComputeSizeOfOwnedCollections(readCollections)
35 // log.Printf("Uuid to Size used: %v", UserUsage)
37 // // TODO(misha): Add a "readonly" flag. If we're in readonly mode,
38 // // lots of behaviors can become warnings (and obviously we can't
39 // // write anything).
40 // // if !readCollections.ReadAllCollections {
41 // // log.Fatalf("Did not read all collections")
44 // log.Printf("Read and processed %d collections",
45 // len(readCollections.UuidToCollection))
47 readServers := keep.GetKeepServers(
48 keep.GetKeepServersParams{Client: arv, Limit: 1000})
50 log.Printf("Returned %d keep disks", len(readServers.ServerToContents))
52 blockReplicationCounts := make(map[int]int)
53 for _, infos := range readServers.BlockToServers {
54 replication := len(infos)
55 blockReplicationCounts[replication] += 1
58 log.Printf("Replication level distribution: %v", blockReplicationCounts)
61 func ComputeSizeOfOwnedCollections(readCollections collection.ReadCollections) (
62 results map[string]int) {
63 results = make(map[string]int)
64 for _, coll := range readCollections.UuidToCollection {
65 results[coll.OwnerUuid] = results[coll.OwnerUuid] + coll.TotalSize