1 /* Computes Summary based on data read from API server. */
9 "git.curoverse.com/arvados.git/sdk/go/logger"
10 "git.curoverse.com/arvados.git/services/datamanager/collection"
11 "git.curoverse.com/arvados.git/services/datamanager/keep"
12 "git.curoverse.com/arvados.git/services/datamanager/loggerutil"
18 // These are just used for development, to save network i/o
23 type serializedData struct {
24 ReadCollections collection.ReadCollections
25 KeepServerInfo keep.ReadServers
29 flag.StringVar(&writeDataTo,
32 "Write summary of data received to this file. Used for development only.")
33 flag.StringVar(&readDataFrom,
36 "Avoid network i/o and read summary data from this file instead. Used for development only.")
39 // Writes data we've read to a file.
41 // This is useful for development, so that we don't need to read all our data from the network every time we tweak something.
43 // This should not be used outside of development, since you'll be
44 // working with stale data.
45 func MaybeWriteData(arvLogger *logger.Logger,
46 readCollections collection.ReadCollections,
47 keepServerInfo keep.ReadServers) bool {
48 if writeDataTo == "" {
51 summaryFile, err := os.Create(writeDataTo)
53 loggerutil.FatalWithMessage(arvLogger,
54 fmt.Sprintf("Failed to open %s: %v", writeDataTo, err))
56 defer summaryFile.Close()
58 enc := gob.NewEncoder(summaryFile)
59 data := serializedData{
60 ReadCollections: readCollections,
61 KeepServerInfo: keepServerInfo}
62 err = enc.Encode(data)
64 loggerutil.FatalWithMessage(arvLogger,
65 fmt.Sprintf("Failed to write summary data: %v", err))
67 log.Printf("Wrote summary data to: %s", writeDataTo)
72 // Reads data that we've read to a file.
74 // This is useful for development, so that we don't need to read all our data from the network every time we tweak something.
76 // This should not be used outside of development, since you'll be
77 // working with stale data.
78 func MaybeReadData(arvLogger *logger.Logger,
79 readCollections *collection.ReadCollections,
80 keepServerInfo *keep.ReadServers) bool {
81 if readDataFrom == "" {
84 summaryFile, err := os.Open(readDataFrom)
86 loggerutil.FatalWithMessage(arvLogger,
87 fmt.Sprintf("Failed to open %s: %v", readDataFrom, err))
89 defer summaryFile.Close()
91 dec := gob.NewDecoder(summaryFile)
92 data := serializedData{}
93 err = dec.Decode(&data)
95 loggerutil.FatalWithMessage(arvLogger,
96 fmt.Sprintf("Failed to read summary data: %v", err))
98 log.Printf("Read summary data from: %s", readDataFrom)