| 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 "fmt" | 9 "fmt" |
| 10 "net/http" | 10 "net/http" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 getSwarmingResult(c context.Context, taskID string) (*swarming.SwarmingR
pcsTaskResult, error) | 82 getSwarmingResult(c context.Context, taskID string) (*swarming.SwarmingR
pcsTaskResult, error) |
| 83 getSwarmingRequest(c context.Context, taskID string) (*swarming.Swarming
RpcsTaskRequest, error) | 83 getSwarmingRequest(c context.Context, taskID string) (*swarming.Swarming
RpcsTaskRequest, error) |
| 84 getTaskOutput(c context.Context, taskID string) (string, error) | 84 getTaskOutput(c context.Context, taskID string) (string, error) |
| 85 } | 85 } |
| 86 | 86 |
| 87 type prodSwarmingService struct { | 87 type prodSwarmingService struct { |
| 88 host string | 88 host string |
| 89 client *swarming.Service | 89 client *swarming.Service |
| 90 } | 90 } |
| 91 | 91 |
| 92 func newProdService(c context.Context, host string) (*prodSwarmingService, error
) { | 92 func NewProdService(c context.Context, host string) (*prodSwarmingService, error
) { |
| 93 client, err := getSwarmingClient(c, host) | 93 client, err := getSwarmingClient(c, host) |
| 94 if err != nil { | 94 if err != nil { |
| 95 return nil, err | 95 return nil, err |
| 96 } | 96 } |
| 97 return &prodSwarmingService{ | 97 return &prodSwarmingService{ |
| 98 host: host, | 98 host: host, |
| 99 client: client, | 99 client: client, |
| 100 }, nil | 100 }, nil |
| 101 } | 101 } |
| 102 | 102 |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 } | 478 } |
| 479 // If this ever has more than one stream then memoryClient needs to beco
me | 479 // If this ever has more than one stream then memoryClient needs to beco
me |
| 480 // goroutine safe | 480 // goroutine safe |
| 481 if err := p.RunStreams([]*annotee.Stream{&is}); err != nil { | 481 if err := p.RunStreams([]*annotee.Stream{&is}); err != nil { |
| 482 return nil, err | 482 return nil, err |
| 483 } | 483 } |
| 484 p.Finish() | 484 p.Finish() |
| 485 return c.ToLogDogStreams() | 485 return c.ToLogDogStreams() |
| 486 } | 486 } |
| 487 | 487 |
| 488 // buildLoader represents the ability to load a Milo build from a Swarming task. | 488 // BuildLoader represents the ability to load a Milo build from a Swarming task. |
| 489 // | 489 // |
| 490 // It exists so that the internal build loading functionality can be stubbed out | 490 // It exists so that the internal build loading functionality can be stubbed out |
| 491 // for testing. | 491 // for testing. |
| 492 type buildLoader struct { | 492 type BuildLoader struct { |
| 493 // logdogClientFunc returns a coordinator Client instance for the suppli
ed | 493 // logdogClientFunc returns a coordinator Client instance for the suppli
ed |
| 494 // parameters. | 494 // parameters. |
| 495 // | 495 // |
| 496 // If nil, a production client will be generated. | 496 // If nil, a production client will be generated. |
| 497 logDogClientFunc func(c context.Context, host string) (*coordinator.Clie
nt, error) | 497 logDogClientFunc func(c context.Context, host string) (*coordinator.Clie
nt, error) |
| 498 } | 498 } |
| 499 | 499 |
| 500 func (bl *buildLoader) newEmptyAnnotationStream(c context.Context, addr *types.S
treamAddr) ( | 500 func (bl *BuildLoader) newEmptyAnnotationStream(c context.Context, addr *types.S
treamAddr) ( |
| 501 *rawpresentation.AnnotationStream, error) { | 501 *rawpresentation.AnnotationStream, error) { |
| 502 | 502 |
| 503 fn := bl.logDogClientFunc | 503 fn := bl.logDogClientFunc |
| 504 if fn == nil { | 504 if fn == nil { |
| 505 fn = rawpresentation.NewClient | 505 fn = rawpresentation.NewClient |
| 506 } | 506 } |
| 507 client, err := fn(c, addr.Host) | 507 client, err := fn(c, addr.Host) |
| 508 if err != nil { | 508 if err != nil { |
| 509 return nil, errors.Annotate(err, "failed to create LogDog client
").Err() | 509 return nil, errors.Annotate(err, "failed to create LogDog client
").Err() |
| 510 } | 510 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 539 infoComp := infoComponent(model.InfraFailure, | 539 infoComp := infoComponent(model.InfraFailure, |
| 540 "LogDog stream not found", "Job likely failed to start.") | 540 "LogDog stream not found", "Job likely failed to start.") |
| 541 infoComp.Started = build.Summary.Started | 541 infoComp.Started = build.Summary.Started |
| 542 infoComp.Finished = build.Summary.Finished | 542 infoComp.Finished = build.Summary.Finished |
| 543 infoComp.Duration = build.Summary.Duration | 543 infoComp.Duration = build.Summary.Duration |
| 544 infoComp.Verbosity = resp.Interesting | 544 infoComp.Verbosity = resp.Interesting |
| 545 build.Components = append(build.Components, infoComp) | 545 build.Components = append(build.Components, infoComp) |
| 546 return addTaskToBuild(c, host, res, build) | 546 return addTaskToBuild(c, host, res, build) |
| 547 } | 547 } |
| 548 | 548 |
| 549 func (bl *buildLoader) swarmingBuildImpl(c context.Context, svc swarmingService,
linkBase, taskID string) (*resp.MiloBuild, error) { | 549 func (bl *BuildLoader) SwarmingBuildImpl(c context.Context, svc swarmingService,
linkBase, taskID string) (*resp.MiloBuild, error) { |
| 550 // Fetch the data from Swarming | 550 // Fetch the data from Swarming |
| 551 var logDogStreamAddr *types.StreamAddr | 551 var logDogStreamAddr *types.StreamAddr |
| 552 | 552 |
| 553 fetchParams := swarmingFetchParams{ | 553 fetchParams := swarmingFetchParams{ |
| 554 fetchRes: true, | 554 fetchRes: true, |
| 555 fetchLog: true, | 555 fetchLog: true, |
| 556 | 556 |
| 557 // Cancel if LogDog annotation stream parameters are present in
the tag set. | 557 // Cancel if LogDog annotation stream parameters are present in
the tag set. |
| 558 taskResCallback: func(res *swarming.SwarmingRpcsTaskResult) (can
celLogs bool) { | 558 taskResCallback: func(res *swarming.SwarmingRpcsTaskResult) (can
celLogs bool) { |
| 559 // If the build hasn't started yet, then there is no Log
Dog log stream to | 559 // If the build hasn't started yet, then there is no Log
Dog log stream to |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 for _, tag := range v { | 768 for _, tag := range v { |
| 769 var value string | 769 var value string |
| 770 parts := strings.SplitN(tag, ":", 2) | 770 parts := strings.SplitN(tag, ":", 2) |
| 771 if len(parts) == 2 { | 771 if len(parts) == 2 { |
| 772 value = parts[1] | 772 value = parts[1] |
| 773 } | 773 } |
| 774 res[parts[0]] = value | 774 res[parts[0]] = value |
| 775 } | 775 } |
| 776 return res | 776 return res |
| 777 } | 777 } |
| OLD | NEW |