| 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 "net/http" | 8 "net/http" |
| 9 "os" | 9 "os" |
| 10 | 10 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 Message: "unregistered Swarming host", | 46 Message: "unregistered Swarming host", |
| 47 Code: http.StatusNotFound, | 47 Code: http.StatusNotFound, |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 // Log is for fetching logs from swarming. | 52 // Log is for fetching logs from swarming. |
| 53 type Log struct{} | 53 type Log struct{} |
| 54 | 54 |
| 55 // Build is for deciphering recipe builds from swarming based off of logs. | 55 // Build is for deciphering recipe builds from swarming based off of logs. |
| 56 type Build struct{} | 56 type Build struct { |
| 57 » // bl is the buildLoader to use. A zero value is suitable for production
, but |
| 58 » // this can be overridden for testing. |
| 59 » bl buildLoader |
| 60 } |
| 57 | 61 |
| 58 // GetTemplateName for Log returns the template name for log pages. | 62 // GetTemplateName for Log returns the template name for log pages. |
| 59 func (l Log) GetTemplateName(t settings.Theme) string { | 63 func (l Log) GetTemplateName(t settings.Theme) string { |
| 60 return "log.html" | 64 return "log.html" |
| 61 } | 65 } |
| 62 | 66 |
| 63 // Render writes the build log to the given response writer. | 67 // Render writes the build log to the given response writer. |
| 64 func (l Log) Render(c context.Context, r *http.Request, p httprouter.Params) (*t
emplates.Args, error) { | 68 func (l Log) Render(c context.Context, r *http.Request, p httprouter.Params) (*t
emplates.Args, error) { |
| 65 id := p.ByName("id") | 69 id := p.ByName("id") |
| 66 if id == "" { | 70 if id == "" { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 Message: "No id", | 112 Message: "No id", |
| 109 Code: http.StatusBadRequest, | 113 Code: http.StatusBadRequest, |
| 110 } | 114 } |
| 111 } | 115 } |
| 112 | 116 |
| 113 sf, err := getSwarmingService(c, getSwarmingHost(r)) | 117 sf, err := getSwarmingService(c, getSwarmingHost(r)) |
| 114 if err != nil { | 118 if err != nil { |
| 115 return nil, convertErr(err) | 119 return nil, convertErr(err) |
| 116 } | 120 } |
| 117 | 121 |
| 118 » result, err := swarmingBuildImpl(c, sf, r.URL.String(), id) | 122 » result, err := b.bl.swarmingBuildImpl(c, sf, r.URL.String(), id) |
| 119 if err != nil { | 123 if err != nil { |
| 120 return nil, convertErr(err) | 124 return nil, convertErr(err) |
| 121 } | 125 } |
| 122 | 126 |
| 123 // Render into the template | 127 // Render into the template |
| 124 args := &templates.Args{ | 128 args := &templates.Args{ |
| 125 "Build": result, | 129 "Build": result, |
| 126 } | 130 } |
| 127 return args, nil | 131 return args, nil |
| 128 } | 132 } |
| 129 | 133 |
| 130 func convertErr(err error) error { | 134 func convertErr(err error) error { |
| 131 if isAPINotFound(err) || os.IsNotExist(err) { | 135 if isAPINotFound(err) || os.IsNotExist(err) { |
| 132 return &miloerror.Error{ | 136 return &miloerror.Error{ |
| 133 Message: err.Error(), | 137 Message: err.Error(), |
| 134 Code: http.StatusNotFound, | 138 Code: http.StatusNotFound, |
| 135 } | 139 } |
| 136 } | 140 } |
| 137 return err | 141 return err |
| 138 } | 142 } |
| 139 | 143 |
| 140 // isAPINotFound returns true if err is a HTTP 404 API response. | 144 // isAPINotFound returns true if err is a HTTP 404 API response. |
| 141 func isAPINotFound(err error) bool { | 145 func isAPINotFound(err error) bool { |
| 142 if apiErr, ok := err.(*googleapi.Error); ok && apiErr.Code == http.Statu
sNotFound { | 146 if apiErr, ok := err.(*googleapi.Error); ok && apiErr.Code == http.Statu
sNotFound { |
| 143 return true | 147 return true |
| 144 } | 148 } |
| 145 | 149 |
| 146 return false | 150 return false |
| 147 } | 151 } |
| OLD | NEW |