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

Side by Side Diff: deploytool/cmd/luci_deploy/appengine.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/api/deploy/util.go ('k') | deploytool/cmd/luci_deploy/build.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 "io/ioutil" 8 "io/ioutil"
9 "path/filepath" 9 "path/filepath"
10 "strings" 10 "strings"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 case *deploy.AppEngineModule_StaticModule_: 186 case *deploy.AppEngineModule_StaticModule_:
187 // A static module presents itself as an empty Python AppEngine module. This 187 // A static module presents itself as an empty Python AppEngine module. This
188 // doesn't actually need any Python code to support it. 188 // doesn't actually need any Python code to support it.
189 appYAML.Runtime = "python27" 189 appYAML.Runtime = "python27"
190 appYAML.APIVersion = "1" 190 appYAML.APIVersion = "1"
191 threadSafe := true 191 threadSafe := true
192 appYAML.ThreadSafe = &threadSafe 192 appYAML.ThreadSafe = &threadSafe
193 isStub = true 193 isStub = true
194 194
195 default: 195 default:
196 » » return nil, errors.Reason("unsupported runtime %(runtime)q").D(" runtime", aem.Runtime).Err() 196 » » return nil, errors.Reason("unsupported runtime %q", aem.Runtime) .Err()
197 } 197 }
198 198
199 // Classic / Managed VM Properties 199 // Classic / Managed VM Properties
200 switch p := aem.GetParams().(type) { 200 switch p := aem.GetParams().(type) {
201 case *deploy.AppEngineModule_Classic: 201 case *deploy.AppEngineModule_Classic:
202 var icPrefix string 202 var icPrefix string
203 switch sc := p.Classic.GetScaling().(type) { 203 switch sc := p.Classic.GetScaling().(type) {
204 case nil: 204 case nil:
205 // (Automatic, default). 205 // (Automatic, default).
206 icPrefix = "F" 206 icPrefix = "F"
(...skipping 18 matching lines...) Expand all
225 icPrefix = "B" 225 icPrefix = "B"
226 226
227 case *deploy.AppEngineModule_ClassicParams_ManualScaling_: 227 case *deploy.AppEngineModule_ClassicParams_ManualScaling_:
228 ms := sc.ManualScaling 228 ms := sc.ManualScaling
229 appYAML.ManualScaling = &gaeAppManualScalingParams{ 229 appYAML.ManualScaling = &gaeAppManualScalingParams{
230 Instances: int(ms.Instances), 230 Instances: int(ms.Instances),
231 } 231 }
232 icPrefix = "B" 232 icPrefix = "B"
233 233
234 default: 234 default:
235 » » » return nil, errors.Reason("unknown scaling type %(type)T ").D("type", sc).Err() 235 » » » return nil, errors.Reason("unknown scaling type %T", sc) .Err()
236 } 236 }
237 appYAML.InstanceClass = p.Classic.InstanceClass.AppYAMLString(ic Prefix) 237 appYAML.InstanceClass = p.Classic.InstanceClass.AppYAMLString(ic Prefix)
238 238
239 case *deploy.AppEngineModule_ManagedVm: 239 case *deploy.AppEngineModule_ManagedVm:
240 if scopes := p.ManagedVm.Scopes; len(scopes) > 0 { 240 if scopes := p.ManagedVm.Scopes; len(scopes) > 0 {
241 appYAML.BetaSettings = &gaeAppYAMLBetaSettings{ 241 appYAML.BetaSettings = &gaeAppYAMLBetaSettings{
242 ServiceAccountScopes: strings.Join(scopes, ","), 242 ServiceAccountScopes: strings.Join(scopes, ","),
243 } 243 }
244 } 244 }
245 } 245 }
(...skipping 22 matching lines...) Expand all
268 entry.StaticDir = staticMap[t.StaticBuildDir] 268 entry.StaticDir = staticMap[t.StaticBuildDir]
269 269
270 case *deploy.AppEngineModule_Handler_StaticFiles_: 270 case *deploy.AppEngineModule_Handler_StaticFiles_:
271 sf := t.StaticFiles 271 sf := t.StaticFiles
272 272
273 relDir := staticMap[sf.GetBuild()] 273 relDir := staticMap[sf.GetBuild()]
274 entry.Upload = filepath.Join(relDir, sf.Upload) 274 entry.Upload = filepath.Join(relDir, sf.Upload)
275 entry.StaticFiles = filepath.Join(relDir, sf.Url Map) 275 entry.StaticFiles = filepath.Join(relDir, sf.Url Map)
276 276
277 default: 277 default:
278 » » » » return nil, errors.Reason("don't know how to han dle content %(content)T"). 278 » » » » return nil, errors.Reason("don't know how to han dle content %T", t).
279 » » » » » D("content", t).D("url", handler.Url).Er r() 279 » » » » » InternalReason("url(%q)", handler.Url).E rr()
280 } 280 }
281 281
282 if entry.Script != "" && isStub { 282 if entry.Script != "" && isStub {
283 return nil, errors.Reason("stub module cannot ha ve entry script").Err() 283 return nil, errors.Reason("stub module cannot ha ve entry script").Err()
284 } 284 }
285 285
286 appYAML.Handlers[i] = &entry 286 appYAML.Handlers[i] = &entry
287 } 287 }
288 } 288 }
289 289
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 331
332 for _, m := range cp.appEngineModules { 332 for _, m := range cp.appEngineModules {
333 for _, url := range m.resources.Dispatch { 333 for _, url := range m.resources.Dispatch {
334 dispatchYAML.Dispatch = append(dispatchYAML.Dispatch, &g aeDispatchYAMLEntry{ 334 dispatchYAML.Dispatch = append(dispatchYAML.Dispatch, &g aeDispatchYAMLEntry{
335 Module: m.ModuleName, 335 Module: m.ModuleName,
336 URL: url, 336 URL: url,
337 }) 337 })
338 } 338 }
339 } 339 }
340 if count := len(dispatchYAML.Dispatch); count > 10 { 340 if count := len(dispatchYAML.Dispatch); count > 10 {
341 » » return nil, errors.Reason("dispatch file has more than 10 routin g rules (%(count)d)"). 341 » » return nil, errors.Reason("dispatch file has more than 10 routin g rules (%d)", count).Err()
342 » » » D("count", count).Err()
343 } 342 }
344 return &dispatchYAML, nil 343 return &dispatchYAML, nil
345 } 344 }
346 345
347 func gaeBuildQueueYAML(cp *layoutDeploymentCloudProject) (*gaeQueueYAML, error) { 346 func gaeBuildQueueYAML(cp *layoutDeploymentCloudProject) (*gaeQueueYAML, error) {
348 var queueYAML gaeQueueYAML 347 var queueYAML gaeQueueYAML
349 348
350 for _, m := range cp.appEngineModules { 349 for _, m := range cp.appEngineModules {
351 for _, queue := range m.resources.TaskQueue { 350 for _, queue := range m.resources.TaskQueue {
352 entry := gaeQueueYAMLEntry{ 351 entry := gaeQueueYAMLEntry{
353 Name: queue.Name, 352 Name: queue.Name,
354 } 353 }
355 switch t := queue.GetType().(type) { 354 switch t := queue.GetType().(type) {
356 case *deploy.AppEngineResources_TaskQueue_Push_: 355 case *deploy.AppEngineResources_TaskQueue_Push_:
357 push := t.Push 356 push := t.Push
358 357
359 entry.Target = m.ModuleName 358 entry.Target = m.ModuleName
360 entry.Mode = "push" 359 entry.Mode = "push"
361 entry.Rate = push.Rate 360 entry.Rate = push.Rate
362 entry.BucketSize = int(push.BucketSize) 361 entry.BucketSize = int(push.BucketSize)
363 entry.MaxConcurrentRequests = int(push.MaxConcur rentRequests) 362 entry.MaxConcurrentRequests = int(push.MaxConcur rentRequests)
364 entry.RetryParameters = &gaeQueueYAMLEntryRetryP arameters{ 363 entry.RetryParameters = &gaeQueueYAMLEntryRetryP arameters{
365 TaskAgeLimit: push.RetryTaskAgeLimi t, 364 TaskAgeLimit: push.RetryTaskAgeLimi t,
366 MinBackoffSeconds: int(push.RetryMinBack offSeconds), 365 MinBackoffSeconds: int(push.RetryMinBack offSeconds),
367 MaxBackoffSeconds: int(push.RetryMaxBack offSeconds), 366 MaxBackoffSeconds: int(push.RetryMaxBack offSeconds),
368 MaxDoublings: int(push.RetryMaxDoub lings), 367 MaxDoublings: int(push.RetryMaxDoub lings),
369 } 368 }
370 369
371 default: 370 default:
372 » » » » return nil, errors.Reason("unknown task queue ty pe %(type)T").D("type", t).Err() 371 » » » » return nil, errors.Reason("unknown task queue ty pe %T", t).Err()
373 } 372 }
374 373
375 queueYAML.Queue = append(queueYAML.Queue, &entry) 374 queueYAML.Queue = append(queueYAML.Queue, &entry)
376 } 375 }
377 } 376 }
378 return &queueYAML, nil 377 return &queueYAML, nil
379 } 378 }
380 379
381 // loadIndexYAMLResource loads an AppEngine "index.yaml" file from the specified 380 // loadIndexYAMLResource loads an AppEngine "index.yaml" file from the specified
382 // filesystem path and translates it into AppEngineResources Index entries. 381 // filesystem path and translates it into AppEngineResources Index entries.
383 func loadIndexYAMLResource(path string) (*deploy.AppEngineResources, error) { 382 func loadIndexYAMLResource(path string) (*deploy.AppEngineResources, error) {
384 data, err := ioutil.ReadFile(path) 383 data, err := ioutil.ReadFile(path)
385 if err != nil { 384 if err != nil {
386 » » return nil, errors.Annotate(err).Reason("failed to load [%(path) s]").D("path", path).Err() 385 » » return nil, errors.Annotate(err, "failed to load [%s]", path).Er r()
387 } 386 }
388 387
389 var indexYAML gaeIndexYAML 388 var indexYAML gaeIndexYAML
390 if err := yaml.Unmarshal(data, &indexYAML); err != nil { 389 if err := yaml.Unmarshal(data, &indexYAML); err != nil {
391 » » return nil, errors.Annotate(err).Reason("could not load 'index.y aml' from [%(path)s]"). 390 » » return nil, errors.Annotate(err, "could not load 'index.yaml' fr om [%s]", path).Err()
392 » » » D("path", path).Err()
393 } 391 }
394 392
395 var res deploy.AppEngineResources 393 var res deploy.AppEngineResources
396 if len(indexYAML.Indexes) > 0 { 394 if len(indexYAML.Indexes) > 0 {
397 res.Index = make([]*deploy.AppEngineResources_Index, len(indexYA ML.Indexes)) 395 res.Index = make([]*deploy.AppEngineResources_Index, len(indexYA ML.Indexes))
398 for i, idx := range indexYAML.Indexes { 396 for i, idx := range indexYAML.Indexes {
399 entry := deploy.AppEngineResources_Index{ 397 entry := deploy.AppEngineResources_Index{
400 Kind: idx.Kind, 398 Kind: idx.Kind,
401 Ancestor: yesOrBoolToBool(idx.Ancestor), 399 Ancestor: yesOrBoolToBool(idx.Ancestor),
402 Property: make([]*deploy.AppEngineResources_Inde x_Property, len(idx.Properties)), 400 Property: make([]*deploy.AppEngineResources_Inde x_Property, len(idx.Properties)),
403 } 401 }
404 for pidx, idxProp := range idx.Properties { 402 for pidx, idxProp := range idx.Properties {
405 dir, err := deploy.IndexDirectionFromAppYAMLStri ng(idxProp.Direction) 403 dir, err := deploy.IndexDirectionFromAppYAMLStri ng(idxProp.Direction)
406 if err != nil { 404 if err != nil {
407 » » » » » return nil, errors.Annotate(err).Reason( "could not identify direction for entry"). 405 » » » » » return nil, errors.Annotate(err, "could not identify direction for entry").
408 » » » » » » D("index", i).D("propertyIndex", pidx).Err() 406 » » » » » » InternalReason("index(%d)/proper tyIndex(%d)", i, pidx).Err()
409 } 407 }
410 408
411 entry.Property[pidx] = &deploy.AppEngineResource s_Index_Property{ 409 entry.Property[pidx] = &deploy.AppEngineResource s_Index_Property{
412 Name: idxProp.Name, 410 Name: idxProp.Name,
413 Direction: dir, 411 Direction: dir,
414 } 412 }
415 } 413 }
416 414
417 res.Index[i] = &entry 415 res.Index[i] = &entry
418 } 416 }
(...skipping 13 matching lines...) Expand all
432 func yesOrBoolToBool(v interface{}) bool { 430 func yesOrBoolToBool(v interface{}) bool {
433 switch t := v.(type) { 431 switch t := v.(type) {
434 case string: 432 case string:
435 return (t == "yes") 433 return (t == "yes")
436 case bool: 434 case bool:
437 return t 435 return t
438 default: 436 default:
439 return false 437 return false
440 } 438 }
441 } 439 }
OLDNEW
« no previous file with comments | « deploytool/api/deploy/util.go ('k') | deploytool/cmd/luci_deploy/build.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698