github.com/m3db/m3@v1.5.0/src/aggregator/tools/deploy/planner_options.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 deploy 22 23 import ( 24 "github.com/m3db/m3/src/cluster/services" 25 xsync "github.com/m3db/m3/src/x/sync" 26 ) 27 28 const ( 29 defaultPlannerWorkerPoolSize = 16 30 defaultElectionKeyFmt = "/shardset/%s/lock" 31 defaultMaxStepSize = 0 32 ) 33 34 // PlannerOptions provide a set of options for the deployment planner. 35 type PlannerOptions interface { 36 // SetLeaderService sets the leader service. 37 SetLeaderService(value services.LeaderService) PlannerOptions 38 39 // LeaderService returns the leader service. 40 LeaderService() services.LeaderService 41 42 // SetWorkerPool sets the worker pool. 43 SetWorkerPool(value xsync.WorkerPool) PlannerOptions 44 45 // WorkerPool returns the worker pool. 46 WorkerPool() xsync.WorkerPool 47 48 // SetElectionKeyFmt sets the election key format. 49 SetElectionKeyFmt(value string) PlannerOptions 50 51 // ElectionKeyFmt returns the election key format. 52 ElectionKeyFmt() string 53 54 // SetMaxStepSize sets the maximum step size (i.e., number of instances per step). 55 SetMaxStepSize(value int) PlannerOptions 56 57 // MaxStepSize returns the maximum step size (i.e., number of instances per step). 58 MaxStepSize() int 59 } 60 61 type plannerOptions struct { 62 leaderService services.LeaderService 63 workerPool xsync.WorkerPool 64 electionKeyFmt string 65 maxStepSize int 66 } 67 68 // NewPlannerOptions create a new set of options for the deployment planner. 69 func NewPlannerOptions() PlannerOptions { 70 workers := xsync.NewWorkerPool(defaultPlannerWorkerPoolSize) 71 workers.Init() 72 return &plannerOptions{ 73 workerPool: workers, 74 electionKeyFmt: defaultElectionKeyFmt, 75 maxStepSize: defaultMaxStepSize, 76 } 77 } 78 79 func (o *plannerOptions) SetLeaderService(value services.LeaderService) PlannerOptions { 80 opts := *o 81 opts.leaderService = value 82 return &opts 83 } 84 85 func (o *plannerOptions) LeaderService() services.LeaderService { 86 return o.leaderService 87 } 88 89 func (o *plannerOptions) SetWorkerPool(value xsync.WorkerPool) PlannerOptions { 90 opts := *o 91 opts.workerPool = value 92 return &opts 93 } 94 95 func (o *plannerOptions) WorkerPool() xsync.WorkerPool { 96 return o.workerPool 97 } 98 99 func (o *plannerOptions) SetElectionKeyFmt(value string) PlannerOptions { 100 opts := *o 101 opts.electionKeyFmt = value 102 return &opts 103 } 104 105 func (o *plannerOptions) ElectionKeyFmt() string { 106 return o.electionKeyFmt 107 } 108 109 func (o *plannerOptions) SetMaxStepSize(value int) PlannerOptions { 110 opts := *o 111 opts.maxStepSize = value 112 return &opts 113 } 114 115 func (o *plannerOptions) MaxStepSize() int { 116 return o.maxStepSize 117 }