Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: deploytool/cmd/luci_deploy/deploy.go

Issue 2963503003: [errors] Greatly simplify common/errors package. (Closed)
Patch Set: fix nits Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « deploytool/cmd/luci_deploy/config.go ('k') | deploytool/cmd/luci_deploy/deploy_appengine.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The LUCI Authors. All rights reserved. 1 // Copyright 2016 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 "sort" 8 "sort"
9 9
10 "github.com/luci/luci-go/common/cli" 10 "github.com/luci/luci-go/common/cli"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // If a manual version was specified, use it. 102 // If a manual version was specified, use it.
103 if cmd.manualVersion != "" { 103 if cmd.manualVersion != "" {
104 cmd.dp.params.forceVersion = makeStringCloudProjectVersion(cmd.m anualVersion) 104 cmd.dp.params.forceVersion = makeStringCloudProjectVersion(cmd.m anualVersion)
105 } 105 }
106 106
107 err := a.runWork(c, func(w *work) error { 107 err := a.runWork(c, func(w *work) error {
108 // Perform our planned checkout. 108 // Perform our planned checkout.
109 if cmd.checkout { 109 if cmd.checkout {
110 // Perform a full checkout. 110 // Perform a full checkout.
111 if err := checkout(w, &a.layout, false); err != nil { 111 if err := checkout(w, &a.layout, false); err != nil {
112 » » » » return errors.Annotate(err).Reason("failed to ch eckout sources").Err() 112 » » » » return errors.Annotate(err, "failed to checkout sources").Err()
113 } 113 }
114 } 114 }
115 115
116 // Load our frozen checkout. 116 // Load our frozen checkout.
117 if err := a.layout.loadFrozenLayout(w); err != nil { 117 if err := a.layout.loadFrozenLayout(w); err != nil {
118 » » » return errors.Annotate(err).Reason("failed to load froze n checkout").Err() 118 » » » return errors.Annotate(err, "failed to load frozen check out").Err()
119 } 119 }
120 return nil 120 return nil
121 }) 121 })
122 if err != nil { 122 if err != nil {
123 logError(c, err, "Failed to perform checkout.") 123 logError(c, err, "Failed to perform checkout.")
124 return 1 124 return 1
125 } 125 }
126 126
127 // Figure out what we're going to deploy. 127 // Figure out what we're going to deploy.
128 for _, arg := range args { 128 for _, arg := range args {
(...skipping 14 matching lines...) Expand all
143 if !matched { 143 if !matched {
144 log.Fields{ 144 log.Fields{
145 "target": arg, 145 "target": arg,
146 }.Errorf(c, "Deploy target did not match any configured deployments or components.") 146 }.Errorf(c, "Deploy target did not match any configured deployments or components.")
147 return 1 147 return 1
148 } 148 }
149 } 149 }
150 150
151 err = a.runWork(c, func(w *work) error { 151 err = a.runWork(c, func(w *work) error {
152 if err := cmd.dp.initialize(w, &a.layout); err != nil { 152 if err := cmd.dp.initialize(w, &a.layout); err != nil {
153 » » » return errors.Annotate(err).Reason("failed to initialize ").Err() 153 » » » return errors.Annotate(err, "failed to initialize").Err( )
154 } 154 }
155 155
156 return cmd.dp.deploy(w) 156 return cmd.dp.deploy(w)
157 }) 157 })
158 if err != nil { 158 if err != nil {
159 logError(c, err, "Failed to perform deployment.") 159 logError(c, err, "Failed to perform deployment.")
160 return 1 160 return 1
161 } 161 }
162 return 0 162 return 0
163 } 163 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 // order in which they are defined in the Application's protobuf . 224 // order in which they are defined in the Application's protobuf .
225 for _, compName := range dep.componentNames { 225 for _, compName := range dep.componentNames {
226 comp := dep.components[compName] 226 comp := dep.components[compName]
227 227
228 // Only pass the registrar if this component is being de ployed. 228 // Only pass the registrar if this component is being de ployed.
229 var pReg componentRegistrar 229 var pReg componentRegistrar
230 if _, ok := dp.comps[comp.String()]; ok { 230 if _, ok := dp.comps[comp.String()]; ok {
231 pReg = &dp.reg 231 pReg = &dp.reg
232 } 232 }
233 if err := comp.loadSourceComponent(pReg); err != nil { 233 if err := comp.loadSourceComponent(pReg); err != nil {
234 » » » » return errors.Annotate(err).Reason("failed to lo ad component %(comp)q"). 234 » » » » return errors.Annotate(err, "failed to load comp onent %q", comp).Err()
235 » » » » » D("comp", comp.String()).Err()
236 } 235 }
237 } 236 }
238 } 237 }
239 238
240 return nil 239 return nil
241 } 240 }
242 241
243 func (dp *deploymentPlan) deploy(w *work) error { 242 func (dp *deploymentPlan) deploy(w *work) error {
244 // Create our working root and staging/build subdirectories. 243 // Create our working root and staging/build subdirectories.
245 fs, err := dp.layout.workingFilesystem() 244 fs, err := dp.layout.workingFilesystem()
246 if err != nil { 245 if err != nil {
247 » » return errors.Annotate(err).Reason("failed to create working dir ectory").Err() 246 » » return errors.Annotate(err, "failed to create working directory" ).Err()
248 } 247 }
249 248
250 stagingDir, err := fs.Base().EnsureDirectory("staging") 249 stagingDir, err := fs.Base().EnsureDirectory("staging")
251 if err != nil { 250 if err != nil {
252 » » return errors.Annotate(err).Reason("failed to create staging dir ectory").Err() 251 » » return errors.Annotate(err, "failed to create staging directory" ).Err()
253 } 252 }
254 253
255 // Stage: Staging 254 // Stage: Staging
256 if err := dp.reg.stage(w, stagingDir, &dp.params); err != nil { 255 if err := dp.reg.stage(w, stagingDir, &dp.params); err != nil {
257 » » return errors.Annotate(err).Reason("failed to stage").Err() 256 » » return errors.Annotate(err, "failed to stage").Err()
258 } 257 }
259 if dp.params.stage <= deployStaging { 258 if dp.params.stage <= deployStaging {
260 return nil 259 return nil
261 } 260 }
262 261
263 // Stage: Local Build 262 // Stage: Local Build
264 if err := dp.reg.localBuild(w); err != nil { 263 if err := dp.reg.localBuild(w); err != nil {
265 » » return errors.Annotate(err).Reason("failed to perform local buil d").Err() 264 » » return errors.Annotate(err, "failed to perform local build").Err ()
266 } 265 }
267 if dp.params.stage <= deployLocalBuild { 266 if dp.params.stage <= deployLocalBuild {
268 return nil 267 return nil
269 } 268 }
270 269
271 // Stage: Push 270 // Stage: Push
272 if err := dp.reg.push(w); err != nil { 271 if err := dp.reg.push(w); err != nil {
273 » » return errors.Annotate(err).Reason("failed to push components"). Err() 272 » » return errors.Annotate(err, "failed to push components").Err()
274 } 273 }
275 if dp.params.stage <= deployPush { 274 if dp.params.stage <= deployPush {
276 return nil 275 return nil
277 } 276 }
278 277
279 // Stage: Commit 278 // Stage: Commit
280 if err := dp.reg.commit(w); err != nil { 279 if err := dp.reg.commit(w); err != nil {
281 » » return errors.Annotate(err).Reason("failed to commit").Err() 280 » » return errors.Annotate(err, "failed to commit").Err()
282 } 281 }
283 return nil 282 return nil
284 } 283 }
285 284
286 // deploymentRegistry is the registry of all prepared deployments. 285 // deploymentRegistry is the registry of all prepared deployments.
287 // 286 //
288 // While deployment is specified and staged at a component level, actual 287 // While deployment is specified and staged at a component level, actual
289 // deployment is allowed to happen at a practical level (e.g., a single 288 // deployment is allowed to happen at a practical level (e.g., a single
290 // cloud project's AppEngine configuration, a single Google Container Engine 289 // cloud project's AppEngine configuration, a single Google Container Engine
291 // cluster, etc.). 290 // cluster, etc.).
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 // All components can be independently staged in parallel. 379 // All components can be independently staged in parallel.
381 // 380 //
382 // We will still enumerate over them in sorted order for determinism. 381 // We will still enumerate over them in sorted order for determinism.
383 return w.RunMulti(func(workC chan<- func() error) { 382 return w.RunMulti(func(workC chan<- func() error) {
384 // AppEngine Projects 383 // AppEngine Projects
385 for _, name := range reg.gaeProjectNames { 384 for _, name := range reg.gaeProjectNames {
386 proj := reg.gaeProjects[name] 385 proj := reg.gaeProjects[name]
387 workC <- func() error { 386 workC <- func() error {
388 depDir, err := stageDir.EnsureDirectory(string(p roj.project.dep.title), "appengine") 387 depDir, err := stageDir.EnsureDirectory(string(p roj.project.dep.title), "appengine")
389 if err != nil { 388 if err != nil {
390 » » » » » return errors.Annotate(err).Reason("fail ed to create deployment directory for %(deployment)q"). 389 » » » » » return errors.Annotate(err, "failed to c reate deployment directory for %q", proj.project.dep.title).Err()
391 » » » » » » D("deployment", proj.project.dep .title).Err()
392 } 390 }
393 return proj.stage(w, depDir, params) 391 return proj.stage(w, depDir, params)
394 } 392 }
395 } 393 }
396 394
397 // Container Engine Projects 395 // Container Engine Projects
398 for _, name := range reg.gkeProjectNames { 396 for _, name := range reg.gkeProjectNames {
399 proj := reg.gkeProjects[name] 397 proj := reg.gkeProjects[name]
400 workC <- func() error { 398 workC <- func() error {
401 depDir, err := stageDir.EnsureDirectory(string(p roj.project.dep.title), "container_engine") 399 depDir, err := stageDir.EnsureDirectory(string(p roj.project.dep.title), "container_engine")
402 if err != nil { 400 if err != nil {
403 » » » » » return errors.Annotate(err).Reason("fail ed to create deployment directory for %(deployment)q"). 401 » » » » » return errors.Annotate(err, "failed to c reate deployment directory for %q", proj.project.dep.title).Err()
404 » » » » » » D("deployment", proj.project.dep .title).Err()
405 } 402 }
406 return proj.stage(w, depDir, params) 403 return proj.stage(w, depDir, params)
407 } 404 }
408 } 405 }
409 }) 406 })
410 } 407 }
411 408
412 // build performs the build stage on staged components. 409 // build performs the build stage on staged components.
413 func (reg *deploymentRegistry) localBuild(w *work) error { 410 func (reg *deploymentRegistry) localBuild(w *work) error {
414 // Enumerate over them in sorted order for determinism. 411 // Enumerate over them in sorted order for determinism.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 469
473 // Container Engine Projects 470 // Container Engine Projects
474 for _, name := range reg.gkeProjectNames { 471 for _, name := range reg.gkeProjectNames {
475 proj := reg.gkeProjects[name] 472 proj := reg.gkeProjects[name]
476 workC <- func() error { 473 workC <- func() error {
477 return proj.commit(w) 474 return proj.commit(w)
478 } 475 }
479 } 476 }
480 }) 477 })
481 } 478 }
OLDNEW
« no previous file with comments | « deploytool/cmd/luci_deploy/config.go ('k') | deploytool/cmd/luci_deploy/deploy_appengine.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698