| 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 "context" | 8 "context" |
| 9 "encoding/json" | 9 "encoding/json" |
| 10 "errors" | 10 "errors" |
| 11 "fmt" | 11 "fmt" |
| 12 "io/ioutil" | 12 "io/ioutil" |
| 13 "log" | 13 "log" |
| 14 "os" | 14 "os" |
| 15 "path/filepath" | 15 "path/filepath" |
| 16 "strings" |
| 16 | 17 |
| 17 "time" | 18 "time" |
| 18 | 19 |
| 19 humanize "github.com/dustin/go-humanize" | 20 humanize "github.com/dustin/go-humanize" |
| 20 | 21 |
| 21 "github.com/golang/protobuf/proto" | 22 "github.com/golang/protobuf/proto" |
| 22 "github.com/luci/luci-go/client/isolate" | 23 "github.com/luci/luci-go/client/isolate" |
| 23 "github.com/luci/luci-go/common/eventlog" | 24 "github.com/luci/luci-go/common/eventlog" |
| 24 logpb "github.com/luci/luci-go/common/eventlog/proto" | 25 logpb "github.com/luci/luci-go/common/eventlog/proto" |
| 25 "github.com/luci/luci-go/common/isolated" | 26 "github.com/luci/luci-go/common/isolated" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 42 ) | 43 ) |
| 43 | 44 |
| 44 var cmdExpArchive = &subcommands.Command{ | 45 var cmdExpArchive = &subcommands.Command{ |
| 45 UsageLine: "exparchive <options>", | 46 UsageLine: "exparchive <options>", |
| 46 ShortDesc: "EXPERIMENTAL parses a .isolate file to create a .isolated fi
le, and uploads it and all referenced files to an isolate server", | 47 ShortDesc: "EXPERIMENTAL parses a .isolate file to create a .isolated fi
le, and uploads it and all referenced files to an isolate server", |
| 47 LongDesc: "All the files listed in the .isolated file are put in the is
olate server cache. Small files are combined together in a tar archive before up
loading.", | 48 LongDesc: "All the files listed in the .isolated file are put in the is
olate server cache. Small files are combined together in a tar archive before up
loading.", |
| 48 CommandRun: func() subcommands.CommandRun { | 49 CommandRun: func() subcommands.CommandRun { |
| 49 c := &expArchiveRun{} | 50 c := &expArchiveRun{} |
| 50 c.commonServerFlags.Init() | 51 c.commonServerFlags.Init() |
| 51 c.isolateFlags.Init(&c.Flags) | 52 c.isolateFlags.Init(&c.Flags) |
| 53 c.Flags.StringVar(&c.dumpJSON, "dump-json", "", |
| 54 "Write isolated digests of archived trees to this file a
s JSON") |
| 52 return c | 55 return c |
| 53 }, | 56 }, |
| 54 } | 57 } |
| 55 | 58 |
| 56 // expArchiveRun contains the logic for the experimental archive subcommand. | 59 // expArchiveRun contains the logic for the experimental archive subcommand. |
| 57 // It implements subcommand.CommandRun | 60 // It implements subcommand.CommandRun |
| 58 type expArchiveRun struct { | 61 type expArchiveRun struct { |
| 59 commonServerFlags // Provides the GetFlags method. | 62 commonServerFlags // Provides the GetFlags method. |
| 60 isolateFlags isolateFlags | 63 isolateFlags isolateFlags |
| 64 dumpJSON string |
| 61 } | 65 } |
| 62 | 66 |
| 63 // Item represents a file or symlink referenced by an isolate file. | 67 // Item represents a file or symlink referenced by an isolate file. |
| 64 type Item struct { | 68 type Item struct { |
| 65 Path string | 69 Path string |
| 66 RelPath string | 70 RelPath string |
| 67 Size int64 | 71 Size int64 |
| 68 Mode os.FileMode | 72 Mode os.FileMode |
| 69 | 73 |
| 70 Digest isolated.HexDigest | 74 Digest isolated.HexDigest |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 if err := uploader.Close(); err != nil { | 250 if err := uploader.Close(); err != nil { |
| 247 return err | 251 return err |
| 248 } | 252 } |
| 249 | 253 |
| 250 // Write the isolated file, and emit its digest to stdout. | 254 // Write the isolated file, and emit its digest to stdout. |
| 251 if err := ioutil.WriteFile(archiveOpts.Isolated, isolJSON, 0644); err !=
nil { | 255 if err := ioutil.WriteFile(archiveOpts.Isolated, isolJSON, 0644); err !=
nil { |
| 252 return err | 256 return err |
| 253 } | 257 } |
| 254 fmt.Printf("%s\t%s\n", isolItem.Digest, filepath.Base(archiveOpts.Isolat
ed)) | 258 fmt.Printf("%s\t%s\n", isolItem.Digest, filepath.Base(archiveOpts.Isolat
ed)) |
| 255 | 259 |
| 260 // Optionally, write the digest of the isolated file as JSON (in the sam
e |
| 261 // format as batch_archive). |
| 262 if c.dumpJSON != "" { |
| 263 // The name is the base name of the isolated file, extension str
ipped. |
| 264 name := filepath.Base(archiveOpts.Isolated) |
| 265 if i := strings.LastIndex(name, "."); i != -1 { |
| 266 name = name[:i] |
| 267 } |
| 268 j, err := json.Marshal(map[string]isolated.HexDigest{ |
| 269 name: isolItem.Digest, |
| 270 }) |
| 271 if err != nil { |
| 272 return err |
| 273 } |
| 274 if err := ioutil.WriteFile(c.dumpJSON, j, 0644); err != nil { |
| 275 return err |
| 276 } |
| 277 } |
| 278 |
| 256 end := time.Now() | 279 end := time.Now() |
| 257 | 280 |
| 258 if endpoint := eventlogEndpoint(c.isolateFlags.EventlogEndpoint); endpoi
nt != "" { | 281 if endpoint := eventlogEndpoint(c.isolateFlags.EventlogEndpoint); endpoi
nt != "" { |
| 259 logger := eventlog.NewClient(ctx, endpoint) | 282 logger := eventlog.NewClient(ctx, endpoint) |
| 260 | 283 |
| 261 // TODO(mcgreevy): fill out more stats in archiveDetails. | 284 // TODO(mcgreevy): fill out more stats in archiveDetails. |
| 262 archiveDetails := &logpb.IsolateClientEvent_ArchiveDetails{ | 285 archiveDetails := &logpb.IsolateClientEvent_ArchiveDetails{ |
| 263 HitCount: proto.Int64(int64(checker.Hit.Count)), | 286 HitCount: proto.Int64(int64(checker.Hit.Count)), |
| 264 MissCount: proto.Int64(int64(checker.Miss.Count)), | 287 MissCount: proto.Int64(int64(checker.Miss.Count)), |
| 265 HitBytes: &checker.Hit.Bytes, | 288 HitBytes: &checker.Hit.Bytes, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 func eventlogEndpoint(endpointFlag string) string { | 359 func eventlogEndpoint(endpointFlag string) string { |
| 337 switch endpointFlag { | 360 switch endpointFlag { |
| 338 case "test": | 361 case "test": |
| 339 return eventlog.TestEndpoint | 362 return eventlog.TestEndpoint |
| 340 case "prod": | 363 case "prod": |
| 341 return eventlog.ProdEndpoint | 364 return eventlog.ProdEndpoint |
| 342 default: | 365 default: |
| 343 return endpointFlag | 366 return endpointFlag |
| 344 } | 367 } |
| 345 } | 368 } |
| OLD | NEW |