| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package main | 5 package main |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "fmt" | 9 "fmt" |
| 10 "log" | 10 "log" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 func cmdArchive(defaultAuthOpts auth.Options) *subcommands.Command { | 27 func cmdArchive(defaultAuthOpts auth.Options) *subcommands.Command { |
| 28 return &subcommands.Command{ | 28 return &subcommands.Command{ |
| 29 UsageLine: "archive <options>", | 29 UsageLine: "archive <options>", |
| 30 ShortDesc: "creates a .isolated file and uploads the tree to an
isolate server.", | 30 ShortDesc: "creates a .isolated file and uploads the tree to an
isolate server.", |
| 31 LongDesc: "All the files listed in the .isolated file are put i
n the isolate server cache", | 31 LongDesc: "All the files listed in the .isolated file are put i
n the isolate server cache", |
| 32 CommandRun: func() subcommands.CommandRun { | 32 CommandRun: func() subcommands.CommandRun { |
| 33 c := archiveRun{} | 33 c := archiveRun{} |
| 34 c.commonServerFlags.Init(defaultAuthOpts) | 34 c.commonServerFlags.Init(defaultAuthOpts) |
| 35 c.isolateFlags.Init(&c.Flags) | 35 c.isolateFlags.Init(&c.Flags) |
| 36 c.loggingFlags.Init(&c.Flags) |
| 36 return &c | 37 return &c |
| 37 }, | 38 }, |
| 38 } | 39 } |
| 39 } | 40 } |
| 40 | 41 |
| 41 type archiveRun struct { | 42 type archiveRun struct { |
| 42 commonServerFlags | 43 commonServerFlags |
| 43 isolateFlags | 44 isolateFlags |
| 45 loggingFlags loggingFlags |
| 44 } | 46 } |
| 45 | 47 |
| 46 func (c *archiveRun) Parse(a subcommands.Application, args []string) error { | 48 func (c *archiveRun) Parse(a subcommands.Application, args []string) error { |
| 47 if err := c.commonServerFlags.Parse(); err != nil { | 49 if err := c.commonServerFlags.Parse(); err != nil { |
| 48 return err | 50 return err |
| 49 } | 51 } |
| 50 cwd, err := os.Getwd() | 52 cwd, err := os.Getwd() |
| 51 if err != nil { | 53 if err != nil { |
| 52 return err | 54 return err |
| 53 } | 55 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 98 |
| 97 archiveDetails := &logpb.IsolateClientEvent_ArchiveDetails{ | 99 archiveDetails := &logpb.IsolateClientEvent_ArchiveDetails{ |
| 98 HitCount: proto.Int64(int64(stats.TotalHits())), | 100 HitCount: proto.Int64(int64(stats.TotalHits())), |
| 99 MissCount: proto.Int64(int64(stats.TotalMisses())), | 101 MissCount: proto.Int64(int64(stats.TotalMisses())), |
| 100 HitBytes: proto.Int64(int64(stats.TotalBytesHits())), | 102 HitBytes: proto.Int64(int64(stats.TotalBytesHits())), |
| 101 MissBytes: proto.Int64(int64(stats.TotalBytesPushed())), | 103 MissBytes: proto.Int64(int64(stats.TotalBytesPushed())), |
| 102 } | 104 } |
| 103 if item.Error() != nil { | 105 if item.Error() != nil { |
| 104 archiveDetails.IsolateHash = []string{string(item.Digest())} | 106 archiveDetails.IsolateHash = []string{string(item.Digest())} |
| 105 } | 107 } |
| 106 » eventlogger := NewLogger(ctx, c.isolateFlags.EventlogEndpoint) | 108 » eventlogger := NewLogger(ctx, c.loggingFlags.EventlogEndpoint) |
| 107 op := logpb.IsolateClientEvent_LEGACY_ARCHIVE.Enum() | 109 op := logpb.IsolateClientEvent_LEGACY_ARCHIVE.Enum() |
| 108 if err := eventlogger.logStats(ctx, op, start, end, archiveDetails); err
!= nil { | 110 if err := eventlogger.logStats(ctx, op, start, end, archiveDetails); err
!= nil { |
| 109 log.Printf("Failed to log to eventlog: %v", err) | 111 log.Printf("Failed to log to eventlog: %v", err) |
| 110 } | 112 } |
| 111 return err | 113 return err |
| 112 } | 114 } |
| 113 | 115 |
| 114 func (c *archiveRun) Run(a subcommands.Application, args []string, _ subcommands
.Env) int { | 116 func (c *archiveRun) Run(a subcommands.Application, args []string, _ subcommands
.Env) int { |
| 115 if err := c.Parse(a, args); err != nil { | 117 if err := c.Parse(a, args); err != nil { |
| 116 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err) | 118 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err) |
| 117 return 1 | 119 return 1 |
| 118 } | 120 } |
| 119 cl, err := c.defaultFlags.StartTracing() | 121 cl, err := c.defaultFlags.StartTracing() |
| 120 if err != nil { | 122 if err != nil { |
| 121 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err) | 123 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err) |
| 122 return 1 | 124 return 1 |
| 123 } | 125 } |
| 124 defer cl.Close() | 126 defer cl.Close() |
| 125 if err := c.main(a, args); err != nil { | 127 if err := c.main(a, args); err != nil { |
| 126 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err) | 128 fmt.Fprintf(a.GetErr(), "%s: %s\n", a.GetName(), err) |
| 127 return 1 | 129 return 1 |
| 128 } | 130 } |
| 129 return 0 | 131 return 0 |
| 130 } | 132 } |
| OLD | NEW |