github.com/m3db/m3@v1.5.0/src/cluster/services/config.go (about) 1 // Copyright (c) 2017 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package services 22 23 import ( 24 "time" 25 ) 26 27 // OverrideConfiguration configs the override options. 28 type OverrideConfiguration struct { 29 Namespaces NamespacesConfiguration `yaml:"namespaces"` 30 } 31 32 // NewOptions creates a new override options. 33 func (cfg OverrideConfiguration) NewOptions() OverrideOptions { 34 return NewOverrideOptions(). 35 SetNamespaceOptions(cfg.Namespaces.NewOptions()) 36 } 37 38 // NamespacesConfiguration configs the NamespaceOptions. 39 type NamespacesConfiguration struct { 40 Placement string `yaml:"placement"` 41 Metadata string `yaml:"metadata"` 42 } 43 44 // NewOptions creates a new NamespaceOptions. 45 func (cfg NamespacesConfiguration) NewOptions() NamespaceOptions { 46 return NewNamespaceOptions(). 47 SetPlacementNamespace(cfg.Placement). 48 SetMetadataNamespace(cfg.Metadata) 49 } 50 51 // Configuration is the config for service options. 52 type Configuration struct { 53 InitTimeout *time.Duration `yaml:"initTimeout"` 54 } 55 56 // NewOptions creates an Option. 57 func (cfg Configuration) NewOptions() Options { 58 opts := NewOptions() 59 if cfg.InitTimeout != nil { 60 opts = opts.SetInitTimeout(*cfg.InitTimeout) 61 } 62 return opts 63 } 64 65 // ElectionConfiguration is for configuring election timeouts and TTLs 66 type ElectionConfiguration struct { 67 LeaderTimeout *time.Duration `yaml:"leaderTimeout"` 68 ResignTimeout *time.Duration `yaml:"resignTimeout"` 69 TTLSeconds *int `yaml:"TTLSeconds"` 70 } 71 72 // NewOptions creates an ElectionOptions. 73 func (cfg ElectionConfiguration) NewOptions() ElectionOptions { 74 opts := NewElectionOptions() 75 if cfg.LeaderTimeout != nil { 76 opts = opts.SetLeaderTimeout(*cfg.LeaderTimeout) 77 } 78 if cfg.ResignTimeout != nil { 79 opts = opts.SetResignTimeout(*cfg.ResignTimeout) 80 } 81 if cfg.TTLSeconds != nil { 82 opts = opts.SetTTLSecs(*cfg.TTLSeconds) 83 } 84 return opts 85 } 86 87 // ServiceIDConfiguration is for configuring serviceID. 88 type ServiceIDConfiguration struct { 89 Name string `yaml:"name"` 90 Environment string `yaml:"environment"` 91 Zone string `yaml:"zone"` 92 } 93 94 // NewServiceID creates a ServiceID. 95 func (cfg ServiceIDConfiguration) NewServiceID() ServiceID { 96 return NewServiceID(). 97 SetName(cfg.Name). 98 SetEnvironment(cfg.Environment). 99 SetZone(cfg.Zone) 100 }