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

Side by Side Diff: deploytool/api/deploy/util.go

Issue 2580213002: luci_depkoy: Add instance class, params. (Closed)
Patch Set: Created 4 years 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/component.pb.go ('k') | deploytool/cmd/luci_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 deploy 5 package deploy
6 6
7 import ( 7 import (
8 "fmt" 8 "fmt"
9 "strings"
10 "time"
9 11
10 "github.com/luci/luci-go/common/errors" 12 "github.com/luci/luci-go/common/errors"
11 ) 13 )
12 14
15 // AppYAMLString returns the GAE app.yaml string for this Duration.
16 func (d *Duration) AppYAMLString() string { return strings.Join(d.appYAMLStringP arts(), " ") }
17
18 func (d *Duration) appYAMLStringParts() (parts []string) {
19 if d != nil {
20 parts = []string{fmt.Sprintf("%d%s", d.Value, d.Unit.appYAMLSuff ix())}
21 for _, plus := range d.Plus {
22 parts = append(parts, plus.appYAMLStringParts()...)
23 }
24 }
25 return
26 }
27
28 // Duration returns the time.Duration that this Duration describes.
29 func (d *Duration) Duration() time.Duration {
30 if d == nil {
31 return 0
32 }
33
34 dv := time.Duration(d.Value) * d.Unit.durationUnit()
35 for _, plus := range d.Plus {
36 dv += plus.Duration()
37 }
38 return dv
39 }
40
41 func (u Duration_Unit) appYAMLSuffix() string {
42 switch u {
43 case Duration_MILLISECONDS:
44 return "ms"
45 case Duration_SECONDS:
46 return "s"
47 case Duration_MINUTES:
48 return "m"
49 case Duration_HOURS:
50 return "h"
51 case Duration_DAYS:
52 return "d"
53 default:
54 panic(fmt.Errorf("unknown Duration.Unit: %v", u))
55 }
56 }
57
58 func (u Duration_Unit) durationUnit() time.Duration {
59 switch u {
60 case Duration_MILLISECONDS:
61 return time.Millisecond
62 case Duration_SECONDS:
63 return time.Second
64 case Duration_MINUTES:
65 return time.Minute
66 case Duration_HOURS:
67 return time.Hour
68 case Duration_DAYS:
69 return 24 * time.Hour
70 default:
71 panic(fmt.Errorf("unknown Duration.Unit: %v", u))
72 }
73 }
74
75 // AppYAMLString returns the "app.yaml" string for this instance class.
76 //
77 // The supplied prefix is prepended to the instance class string. This prefix
78 // will differ based on the type of AppEngine module that the instance class
79 // is describing (e.g., for "F_1", the prefix is "F_").
80 func (v AppEngineModule_ClassicParams_InstanceClass) AppYAMLString(prefix string ) string {
81 var name string
82 switch v {
83 case AppEngineModule_ClassicParams_IC_DEFAULT:
84 return ""
85
86 case AppEngineModule_ClassicParams_IC_1:
87 name = "1"
88 case AppEngineModule_ClassicParams_IC_2:
89 name = "2"
90 case AppEngineModule_ClassicParams_IC_4:
91 name = "4"
92 case AppEngineModule_ClassicParams_IC_4_1G:
93 name = "4_1G"
94 case AppEngineModule_ClassicParams_IC_8:
95 name = "8"
96 default:
97 panic(fmt.Errorf("unknown InstanceClass: %v", v))
98 }
99
100 return prefix + name
101 }
102
13 // AppYAMLString returns the "app.yaml" string for this option. 103 // AppYAMLString returns the "app.yaml" string for this option.
14 func (v AppEngineModule_Handler_LoginOption) AppYAMLString() string { 104 func (v AppEngineModule_Handler_LoginOption) AppYAMLString() string {
15 switch v { 105 switch v {
16 case AppEngineModule_Handler_LOGIN_OPTIONAL: 106 case AppEngineModule_Handler_LOGIN_OPTIONAL:
17 return "optional" 107 return "optional"
18 case AppEngineModule_Handler_LOGIN_REQUIRED: 108 case AppEngineModule_Handler_LOGIN_REQUIRED:
19 return "required" 109 return "required"
20 case AppEngineModule_Handler_LOGIN_ADMIN: 110 case AppEngineModule_Handler_LOGIN_ADMIN:
21 return "admin" 111 return "admin"
22 default: 112 default:
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 return "Ti" 205 return "Ti"
116 case KubernetesPod_Container_Resources_PEBIBYTE: 206 case KubernetesPod_Container_Resources_PEBIBYTE:
117 return "Pi" 207 return "Pi"
118 case KubernetesPod_Container_Resources_EXBIBYTE: 208 case KubernetesPod_Container_Resources_EXBIBYTE:
119 return "Ei" 209 return "Ei"
120 210
121 default: 211 default:
122 panic(fmt.Errorf("unknown resource unit (%v)", v)) 212 panic(fmt.Errorf("unknown resource unit (%v)", v))
123 } 213 }
124 } 214 }
OLDNEW
« no previous file with comments | « deploytool/api/deploy/component.pb.go ('k') | deploytool/cmd/luci_deploy/appengine.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698