| OLD | NEW |
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. | 1 // Copyright 2017 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 "strconv" | 8 "strconv" |
| 9 "strings" | 9 "strings" |
| 10 "unicode/utf8" | 10 "unicode/utf8" |
| 11 | 11 |
| 12 swarming "github.com/luci/luci-go/common/api/swarming/swarming/v1" | 12 swarming "github.com/luci/luci-go/common/api/swarming/swarming/v1" |
| 13 "github.com/luci/luci-go/common/errors" | 13 "github.com/luci/luci-go/common/errors" |
| 14 "github.com/luci/luci-go/common/logging" | 14 "github.com/luci/luci-go/common/logging" |
| 15 miloProto "github.com/luci/luci-go/common/proto/milo" | 15 miloProto "github.com/luci/luci-go/common/proto/milo" |
| 16 "github.com/luci/luci-go/grpc/grpcutil" | 16 "github.com/luci/luci-go/grpc/grpcutil" |
| 17 "github.com/luci/luci-go/logdog/common/types" | 17 "github.com/luci/luci-go/logdog/common/types" |
| 18 "github.com/luci/luci-go/luci_config/common/cfgtypes" | 18 "github.com/luci/luci-go/luci_config/common/cfgtypes" |
| 19 milo "github.com/luci/luci-go/milo/api/proto" | 19 milo "github.com/luci/luci-go/milo/api/proto" |
| 20 "github.com/luci/luci-go/swarming/tasktemplate" | 20 "github.com/luci/luci-go/swarming/tasktemplate" |
| 21 | 21 |
| 22 "golang.org/x/net/context" | 22 "golang.org/x/net/context" |
| 23 ) | 23 ) |
| 24 | 24 |
| 25 // BuildInfoProvider provides build information. | 25 // BuildInfoProvider provides build information. |
| 26 // | 26 // |
| 27 // In a production system, this will be completely defaults. For testing, the | 27 // In a production system, this will be completely defaults. For testing, the |
| 28 // various services and data sources may be substituted for testing stubs. | 28 // various services and data sources may be substituted for testing stubs. |
| 29 type BuildInfoProvider struct { | 29 type BuildInfoProvider struct { |
| 30 » bl buildLoader | 30 » bl BuildLoader |
| 31 | 31 |
| 32 // swarmingServiceFunc returns a swarmingService instance for the suppli
ed | 32 // swarmingServiceFunc returns a swarmingService instance for the suppli
ed |
| 33 // parameters. | 33 // parameters. |
| 34 // | 34 // |
| 35 // If nil, a production fetcher will be generated. | 35 // If nil, a production fetcher will be generated. |
| 36 swarmingServiceFunc func(c context.Context, host string) (swarmingServic
e, error) | 36 swarmingServiceFunc func(c context.Context, host string) (swarmingServic
e, error) |
| 37 } | 37 } |
| 38 | 38 |
| 39 func (p *BuildInfoProvider) newSwarmingService(c context.Context, host string) (
swarmingService, error) { | 39 func (p *BuildInfoProvider) newSwarmingService(c context.Context, host string) (
swarmingService, error) { |
| 40 if p.swarmingServiceFunc == nil { | 40 if p.swarmingServiceFunc == nil { |
| 41 » » return newProdService(c, host) | 41 » » return NewProdService(c, host) |
| 42 } | 42 } |
| 43 return p.swarmingServiceFunc(c, host) | 43 return p.swarmingServiceFunc(c, host) |
| 44 } | 44 } |
| 45 | 45 |
| 46 // GetBuildInfo resolves a Milo protobuf Step for a given Swarming task. | 46 // GetBuildInfo resolves a Milo protobuf Step for a given Swarming task. |
| 47 func (p *BuildInfoProvider) GetBuildInfo(c context.Context, req *milo.BuildInfoR
equest_Swarming, | 47 func (p *BuildInfoProvider) GetBuildInfo(c context.Context, req *milo.BuildInfoR
equest_Swarming, |
| 48 projectHint cfgtypes.ProjectName) (*milo.BuildInfoResponse, error) { | 48 projectHint cfgtypes.ProjectName) (*milo.BuildInfoResponse, error) { |
| 49 | 49 |
| 50 // Load the Swarming task (no log content). | 50 // Load the Swarming task (no log content). |
| 51 sf, err := p.newSwarmingService(c, req.Host) | 51 sf, err := p.newSwarmingService(c, req.Host) |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 } | 260 } |
| 261 | 261 |
| 262 lastChar, lastCharSize := utf8.DecodeLastRuneInString(taskID) | 262 lastChar, lastCharSize := utf8.DecodeLastRuneInString(taskID) |
| 263 v, err := strconv.ParseUint(string(lastChar), 16, 8) | 263 v, err := strconv.ParseUint(string(lastChar), 16, 8) |
| 264 if err != nil { | 264 if err != nil { |
| 265 return "", errors.Annotate(err, "failed to parse hex from rune:
%r", lastChar).Err() | 265 return "", errors.Annotate(err, "failed to parse hex from rune:
%r", lastChar).Err() |
| 266 } | 266 } |
| 267 | 267 |
| 268 return taskID[:len(taskID)-lastCharSize] + strconv.FormatUint((v|uint64(
tryNumber)), 16), nil | 268 return taskID[:len(taskID)-lastCharSize] + strconv.FormatUint((v|uint64(
tryNumber)), 16), nil |
| 269 } | 269 } |
| OLD | NEW |