| OLD | NEW |
| 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 distributor | 5 package distributor |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "fmt" | 9 "fmt" |
| 10 "reflect" | 10 "reflect" |
| 11 | 11 |
| 12 "github.com/golang/protobuf/proto" | |
| 13 "github.com/luci/gae/service/info" | 12 "github.com/luci/gae/service/info" |
| 14 "github.com/luci/luci-go/common/config" | |
| 15 "github.com/luci/luci-go/common/logging" | 13 "github.com/luci/luci-go/common/logging" |
| 16 "github.com/luci/luci-go/dm/api/distributor" | 14 "github.com/luci/luci-go/dm/api/distributor" |
| 17 "github.com/luci/luci-go/dm/api/service/v1" | 15 "github.com/luci/luci-go/dm/api/service/v1" |
| 16 "github.com/luci/luci-go/luci_config/server/cfgclient" |
| 17 "github.com/luci/luci-go/luci_config/server/cfgclient/textproto" |
| 18 "github.com/luci/luci-go/tumble" | 18 "github.com/luci/luci-go/tumble" |
| 19 |
| 20 "github.com/golang/protobuf/proto" |
| 21 |
| 19 "golang.org/x/net/context" | 22 "golang.org/x/net/context" |
| 20 ) | 23 ) |
| 21 | 24 |
| 22 var regKey = "holds a DM Distributor Registry" | 25 var regKey = "holds a DM Distributor Registry" |
| 23 | 26 |
| 24 // WithRegistry adds the registry to the Context. | 27 // WithRegistry adds the registry to the Context. |
| 25 func WithRegistry(c context.Context, r Registry) context.Context { | 28 func WithRegistry(c context.Context, r Registry) context.Context { |
| 26 if r == nil { | 29 if r == nil { |
| 27 panic(errors.New("you may not use WithRegistry on a nil Registry
")) | 30 panic(errors.New("you may not use WithRegistry on a nil Registry
")) |
| 28 } | 31 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 return nil, "", fmt.Errorf("unknown distributor type %T", cfg.Co
ntent) | 118 return nil, "", fmt.Errorf("unknown distributor type %T", cfg.Co
ntent) |
| 116 } | 119 } |
| 117 | 120 |
| 118 d, err = fn(c, cfg) | 121 d, err = fn(c, cfg) |
| 119 return | 122 return |
| 120 } | 123 } |
| 121 | 124 |
| 122 // loadConfig loads the named distributor configuration from luci-config, | 125 // loadConfig loads the named distributor configuration from luci-config, |
| 123 // possibly using the in-memory or memcache version. | 126 // possibly using the in-memory or memcache version. |
| 124 func loadConfig(c context.Context, cfgName string) (ret *Config, err error) { | 127 func loadConfig(c context.Context, cfgName string) (ret *Config, err error) { |
| 125 » aid := info.TrimmedAppID(c) | 128 » configSet := cfgclient.CurrentServiceConfigSet(c) |
| 126 » distCfgObj, err := config.GetConfig(c, fmt.Sprintf("services/%s", aid),
"distributors.cfg", false) | 129 |
| 127 » if err != nil { | 130 » var ( |
| 131 » » distCfg distributor.Config |
| 132 » » meta cfgclient.Meta |
| 133 » ) |
| 134 » if err = cfgclient.Get(c, cfgclient.AsService, configSet, "distributors.
cfg", textproto.Message(&distCfg), &meta); err != nil { |
| 128 return | 135 return |
| 129 } | 136 } |
| 130 | 137 |
| 131 » cfgVersion := distCfgObj.Revision | 138 » cfgVersion := meta.Revision |
| 132 » distCfg := &distributor.Config{} | |
| 133 » if err = proto.UnmarshalText(distCfgObj.Content, distCfg); err != nil { | |
| 134 » » return | |
| 135 » } | |
| 136 | |
| 137 cfg, ok := distCfg.DistributorConfigs[cfgName] | 139 cfg, ok := distCfg.DistributorConfigs[cfgName] |
| 138 if !ok { | 140 if !ok { |
| 139 err = fmt.Errorf("unknown distributor configuration: %q", cfgNam
e) | 141 err = fmt.Errorf("unknown distributor configuration: %q", cfgNam
e) |
| 140 return | 142 return |
| 141 } | 143 } |
| 142 if alias := cfg.GetAlias(); alias != nil { | 144 if alias := cfg.GetAlias(); alias != nil { |
| 143 cfg, ok = distCfg.DistributorConfigs[alias.OtherConfig] | 145 cfg, ok = distCfg.DistributorConfigs[alias.OtherConfig] |
| 144 if !ok { | 146 if !ok { |
| 145 err = fmt.Errorf("unknown distributor configuration: %q
(via alias %q)", cfgName, alias.OtherConfig) | 147 err = fmt.Errorf("unknown distributor configuration: %q
(via alias %q)", cfgName, alias.OtherConfig) |
| 146 return | 148 return |
| (...skipping 16 matching lines...) Expand all Loading... |
| 163 implConfig := dVal.Elem().Field(0).Interface().(proto.Message) | 165 implConfig := dVal.Elem().Field(0).Interface().(proto.Message) |
| 164 | 166 |
| 165 ret = &Config{ | 167 ret = &Config{ |
| 166 info.DefaultVersionHostname(c), | 168 info.DefaultVersionHostname(c), |
| 167 cfgName, | 169 cfgName, |
| 168 cfgVersion, | 170 cfgVersion, |
| 169 implConfig, | 171 implConfig, |
| 170 } | 172 } |
| 171 return | 173 return |
| 172 } | 174 } |
| OLD | NEW |