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

Side by Side Diff: logdog/appengine/coordinator/config/config.go

Issue 2626433004: Move "common/config" common types into cfgtypes. (Closed)
Patch Set: Created 3 years, 11 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 | « common/config/util.go ('k') | logdog/appengine/coordinator/config/projects.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 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 config 5 package config
6 6
7 import ( 7 import (
8 "fmt"
9 "net/url" 8 "net/url"
10 9
11 "github.com/golang/protobuf/proto" 10 "github.com/golang/protobuf/proto"
12 "github.com/luci/gae/service/info" 11 "github.com/luci/gae/service/info"
13 "github.com/luci/luci-go/common/config" 12 "github.com/luci/luci-go/common/config"
14 "github.com/luci/luci-go/common/errors" 13 "github.com/luci/luci-go/common/errors"
15 log "github.com/luci/luci-go/common/logging" 14 log "github.com/luci/luci-go/common/logging"
16 "github.com/luci/luci-go/logdog/api/config/svcconfig" 15 "github.com/luci/luci-go/logdog/api/config/svcconfig"
16 "github.com/luci/luci-go/luci_config/common/cfgtypes"
17
17 "golang.org/x/net/context" 18 "golang.org/x/net/context"
18 ) 19 )
19 20
20 var ( 21 var (
21 // ErrInvalidConfig is returned when the configuration exists, but is in valid. 22 // ErrInvalidConfig is returned when the configuration exists, but is in valid.
22 ErrInvalidConfig = errors.New("invalid configuration") 23 ErrInvalidConfig = errors.New("invalid configuration")
23 ) 24 )
24 25
25 // Config is the LogDog Coordinator service configuration. 26 // Config is the LogDog Coordinator service configuration.
26 type Config struct { 27 type Config struct {
27 svcconfig.Config 28 svcconfig.Config
28 // Settings are per-instance settings. 29 // Settings are per-instance settings.
29 Settings Settings 30 Settings Settings
30 31
31 // ConfigServiceURL is the config service's URL. 32 // ConfigServiceURL is the config service's URL.
32 ConfigServiceURL url.URL `json:"-"` 33 ConfigServiceURL url.URL `json:"-"`
33 // ConfigSet is the name of the service config set that is being used. 34 // ConfigSet is the name of the service config set that is being used.
34 ConfigSet string `json:"-"` 35 ConfigSet string `json:"-"`
35 // ServiceConfigPath is the path within ConfigSet of the service 36 // ServiceConfigPath is the path within ConfigSet of the service
36 // configuration. 37 // configuration.
37 ServiceConfigPath string `json:"-"` 38 ServiceConfigPath string `json:"-"`
38 } 39 }
39 40
40 // ServiceConfigPath returns the config set and path for this application's 41 // ServiceConfigPath returns the config set and path for this application's
41 // service configuration. 42 // service configuration.
42 func ServiceConfigPath(c context.Context) (string, string) { 43 func ServiceConfigPath(c context.Context) (cfgtypes.ConfigSet, string) {
43 appID := info.AppID(c) 44 appID := info.AppID(c)
44 » return fmt.Sprintf("services/%s", appID), svcconfig.ServiceConfigFilenam e 45 » return cfgtypes.ServiceConfigSet(appID), svcconfig.ServiceConfigFilename
45 } 46 }
46 47
47 // Load loads the service configuration. This includes: 48 // Load loads the service configuration. This includes:
48 // - The config service settings. 49 // - The config service settings.
49 // - The service configuration, loaded from the config service. 50 // - The service configuration, loaded from the config service.
50 // - Additional Settings data from datastore via settings. 51 // - Additional Settings data from datastore via settings.
51 // 52 //
52 // The service config is minimally validated prior to being returned. 53 // The service config is minimally validated prior to being returned.
53 func Load(c context.Context) (*Config, error) { 54 func Load(c context.Context) (*Config, error) {
54 configSet, configPath := ServiceConfigPath(c) 55 configSet, configPath := ServiceConfigPath(c)
55 » serviceCfg, err := config.GetConfig(c, configSet, configPath, false) 56 » serviceCfg, err := config.GetConfig(c, string(configSet), configPath, fa lse)
56 if err != nil { 57 if err != nil {
57 log.Fields{ 58 log.Fields{
58 log.ErrorKey: err, 59 log.ErrorKey: err,
59 "configSet": configSet, 60 "configSet": configSet,
60 "configPath": configPath, 61 "configPath": configPath,
61 }.Errorf(c, "Failed to load configuration from config service.") 62 }.Errorf(c, "Failed to load configuration from config service.")
62 return nil, err 63 return nil, err
63 } 64 }
64 65
65 // Unmarshal the config into service configuration. 66 // Unmarshal the config into service configuration.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 func validateServiceConfig(cc *svcconfig.Config) error { 102 func validateServiceConfig(cc *svcconfig.Config) error {
102 switch { 103 switch {
103 case cc == nil: 104 case cc == nil:
104 return errors.New("configuration is nil") 105 return errors.New("configuration is nil")
105 case cc.GetCoordinator() == nil: 106 case cc.GetCoordinator() == nil:
106 return errors.New("no Coordinator configuration") 107 return errors.New("no Coordinator configuration")
107 default: 108 default:
108 return nil 109 return nil
109 } 110 }
110 } 111 }
OLDNEW
« no previous file with comments | « common/config/util.go ('k') | logdog/appengine/coordinator/config/projects.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698