Chromium Code Reviews| 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 swarming | 5 package swarming |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "encoding/json" | 9 "encoding/json" |
| 10 "fmt" | 10 "fmt" |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 390 } | 390 } |
| 391 // If this ever has more than one stream then memoryClient needs to beco me | 391 // If this ever has more than one stream then memoryClient needs to beco me |
| 392 // goroutine safe | 392 // goroutine safe |
| 393 if err := p.RunStreams([]*annotee.Stream{&is}); err != nil { | 393 if err := p.RunStreams([]*annotee.Stream{&is}); err != nil { |
| 394 return nil, err | 394 return nil, err |
| 395 } | 395 } |
| 396 p.Finish() | 396 p.Finish() |
| 397 return c.ToLogDogStreams() | 397 return c.ToLogDogStreams() |
| 398 } | 398 } |
| 399 | 399 |
| 400 func swarmingBuildImpl(c context.Context, linkBase, server, taskID string) (*res p.MiloBuild, error) { | 400 // swarmingBuildImpl fetches a swarming task from a swarming server, parses |
| 401 // the logs via Annotee, and returns a build response, along with a list of | |
| 402 // URLs to prefetch. | |
|
agable
2016/08/18 21:44:11
Any reason the list of urls isn't part of an "inte
Ryan Tseng
2016/08/18 22:09:45
Originally the thought was that this would manifes
| |
| 403 func swarmingBuildImpl(c context.Context, linkBase, server, taskID string) (*res p.MiloBuild, []string, error) { | |
| 401 // Fetch the data from Swarming | 404 // Fetch the data from Swarming |
| 402 sr, body, err := getSwarming(c, server, taskID) | 405 sr, body, err := getSwarming(c, server, taskID) |
| 403 if err != nil { | 406 if err != nil { |
| 404 » » return nil, err | 407 » » return nil, nil, err |
| 405 } | 408 } |
| 406 | 409 |
| 407 allowMilo := false | 410 allowMilo := false |
| 408 for _, t := range sr.Tags { | 411 for _, t := range sr.Tags { |
| 409 if t == "allow_milo:1" { | 412 if t == "allow_milo:1" { |
| 410 allowMilo = true | 413 allowMilo = true |
| 411 break | 414 break |
| 412 } | 415 } |
| 413 } | 416 } |
| 414 if !allowMilo { | 417 if !allowMilo { |
| 415 » » return nil, fmt.Errorf("Not A Milo Job") | 418 » » return nil, nil, fmt.Errorf("Not A Milo Job") |
| 416 } | 419 } |
| 417 | 420 |
| 418 var build resp.MiloBuild | 421 var build resp.MiloBuild |
| 419 | 422 |
| 420 // Decode the data using annotee. The logdog stream returned here is ass umed | 423 // Decode the data using annotee. The logdog stream returned here is ass umed |
| 421 // to be consistent, which is why the following block of code are not | 424 // to be consistent, which is why the following block of code are not |
| 422 // expected to ever err out. | 425 // expected to ever err out. |
| 423 if body != "" { | 426 if body != "" { |
| 424 lds, err := streamsFromAnnotatedLog(c, body) | 427 lds, err := streamsFromAnnotatedLog(c, body) |
| 425 if err != nil { | 428 if err != nil { |
| 426 build.Components = []*resp.BuildComponent{{ | 429 build.Components = []*resp.BuildComponent{{ |
| 427 Type: resp.Summary, | 430 Type: resp.Summary, |
| 428 Label: "Milo annotation parser", | 431 Label: "Milo annotation parser", |
| 429 Text: []string{err.Error()}, | 432 Text: []string{err.Error()}, |
| 430 Status: resp.InfraFailure, | 433 Status: resp.InfraFailure, |
| 431 SubLink: []*resp.Link{{ | 434 SubLink: []*resp.Link{{ |
| 432 Label: "swarming task", | 435 Label: "swarming task", |
| 433 URL: taskPageURL(server, taskID), | 436 URL: taskPageURL(server, taskID), |
| 434 }}, | 437 }}, |
| 435 }} | 438 }} |
| 436 } else { | 439 } else { |
| 437 if lds.MainStream == nil || lds.MainStream.Data == nil { | 440 if lds.MainStream == nil || lds.MainStream.Data == nil { |
| 438 panic("no main build step stream") | 441 panic("no main build step stream") |
| 439 } | 442 } |
| 440 | 443 |
| 441 if err := addTaskToMiloStep(c, server, sr, lds.MainStrea m.Data); err != nil { | 444 if err := addTaskToMiloStep(c, server, sr, lds.MainStrea m.Data); err != nil { |
| 442 » » » » return nil, err | 445 » » » » return nil, nil, err |
| 443 } | 446 } |
| 444 logdog.AddLogDogToBuild(c, swarmingURLBuilder(linkBase), lds, &build) | 447 logdog.AddLogDogToBuild(c, swarmingURLBuilder(linkBase), lds, &build) |
| 445 } | 448 } |
| 446 } | 449 } |
| 447 | 450 |
| 448 if err := addTaskToBuild(c, server, sr, &build); err != nil { | 451 if err := addTaskToBuild(c, server, sr, &build); err != nil { |
| 449 » » return nil, err | 452 » » return nil, nil, err |
| 450 } | 453 } |
| 451 | 454 |
| 452 » return &build, nil | 455 » // Extract links that are failures or exceptions for prefetching. |
| 456 » prefetch := []string{} | |
| 457 » for _, step := range build.Components { | |
| 458 » » if len(prefetch) > 3 { | |
| 459 » » » break // Don't prefetch more than 3 things. | |
| 460 » » } | |
| 461 » » switch step.Status { | |
| 462 » » case resp.Failure, resp.InfraFailure: | |
| 463 » » » prefetch = append(prefetch, step.MainLink.URL) | |
| 464 » » } | |
| 465 » } | |
| 466 | |
| 467 » return &build, prefetch, nil | |
| 453 } | 468 } |
| 454 | 469 |
| 455 // taskPageURL returns a URL to a human-consumable page of a swarming task. | 470 // taskPageURL returns a URL to a human-consumable page of a swarming task. |
| 456 // Supports server aliases. | 471 // Supports server aliases. |
| 457 func taskPageURL(swarmingHostname, taskID string) string { | 472 func taskPageURL(swarmingHostname, taskID string) string { |
| 458 return fmt.Sprintf("https://%s/user/task/%s", swarmingHostname, taskID) | 473 return fmt.Sprintf("https://%s/user/task/%s", swarmingHostname, taskID) |
| 459 } | 474 } |
| 460 | 475 |
| 461 // botPageURL returns a URL to a human-consumable page of a swarming bot. | 476 // botPageURL returns a URL to a human-consumable page of a swarming bot. |
| 462 // Supports server aliases. | 477 // Supports server aliases. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 case *miloProto.Link_Url: | 513 case *miloProto.Link_Url: |
| 499 return &resp.Link{ | 514 return &resp.Link{ |
| 500 Label: l.Label, | 515 Label: l.Label, |
| 501 URL: t.Url, | 516 URL: t.Url, |
| 502 } | 517 } |
| 503 | 518 |
| 504 default: | 519 default: |
| 505 return nil | 520 return nil |
| 506 } | 521 } |
| 507 } | 522 } |
| OLD | NEW |