Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1252)

Delta Between Two Patch Sets: state/apiserver/upgrader/upgrader.go

Issue 13380043: upgrader: add Upgrader.DesiredVersion
Left Patch Set: upgrader: add Upgrader.DesiredVersion Created 11 years, 7 months ago
Right Patch Set: upgrader: add Upgrader.DesiredVersion Created 11 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « state/api/upgrader/upgrader_test.go ('k') | state/apiserver/upgrader/upgrader_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2012, 2013 Canonical Ltd. 1 // Copyright 2012, 2013 Canonical Ltd.
2 // Licensed under the AGPLv3, see LICENCE file for details. 2 // Licensed under the AGPLv3, see LICENCE file for details.
3 3
4 package upgrader 4 package upgrader
5 5
6 import ( 6 import (
7 "errors" 7 "errors"
8 8
9 "launchpad.net/juju-core/environs" 9 "launchpad.net/juju-core/environs"
10 "launchpad.net/juju-core/environs/config"
10 envtools "launchpad.net/juju-core/environs/tools" 11 envtools "launchpad.net/juju-core/environs/tools"
11 "launchpad.net/juju-core/state" 12 "launchpad.net/juju-core/state"
12 "launchpad.net/juju-core/state/api/params" 13 "launchpad.net/juju-core/state/api/params"
13 "launchpad.net/juju-core/state/apiserver/common" 14 "launchpad.net/juju-core/state/apiserver/common"
14 "launchpad.net/juju-core/state/watcher" 15 "launchpad.net/juju-core/state/watcher"
15 agenttools "launchpad.net/juju-core/tools" 16 agenttools "launchpad.net/juju-core/tools"
16 "launchpad.net/juju-core/version" 17 "launchpad.net/juju-core/version"
17 ) 18 )
18 19
19 // UpgraderAPI provides access to the Upgrader API facade. 20 // UpgraderAPI provides access to the Upgrader API facade.
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 Number: agentVersion, 83 Number: agentVersion,
83 Series: existingTools.Version.Series, 84 Series: existingTools.Version.Series,
84 Arch: existingTools.Version.Arch, 85 Arch: existingTools.Version.Arch,
85 } 86 }
86 // TODO(jam): Avoid searching the provider for every machine 87 // TODO(jam): Avoid searching the provider for every machine
87 // that wants to upgrade. The information could just be cached 88 // that wants to upgrade. The information could just be cached
88 // in state, or even in the API servers 89 // in state, or even in the API servers
89 return envtools.FindExactTools(env, requested) 90 return envtools.FindExactTools(env, requested)
90 } 91 }
91 92
93 func (u *UpgraderAPI) getGlobalAgentVersion() (version.Number, *config.Config, e rror) {
rog 2013/08/29 14:48:50 Thanks for doing this - even though the values nee
94 // Get the Agent Version requested in the Environment Config
95 cfg, err := u.st.EnvironConfig()
96 if err != nil {
97 return version.Number{}, nil, err
98 }
99 agentVersion, ok := cfg.AgentVersion()
100 if !ok {
101 return version.Number{}, nil, errors.New("agent version not set in environment config")
102 }
103 return agentVersion, cfg, nil
104 }
105
92 // DesiredVersion reports the Agent Version that we want that agent to be runnin g 106 // DesiredVersion reports the Agent Version that we want that agent to be runnin g
93 func (u *UpgraderAPI) DesiredVersion(args params.Entities) (params.AgentVersionR esults, error) { 107 func (u *UpgraderAPI) DesiredVersion(args params.Entities) (params.AgentVersionR esults, error) {
94 results := make([]params.AgentVersionResult, len(args.Entities)) 108 results := make([]params.AgentVersionResult, len(args.Entities))
95 if len(args.Entities) == 0 { 109 if len(args.Entities) == 0 {
96 return params.AgentVersionResults{}, nil 110 return params.AgentVersionResults{}, nil
97 } 111 }
98 » // For now, all agents get the same proposed version 112 » agentVersion, _, err := u.getGlobalAgentVersion()
99 » cfg, err := u.st.EnvironConfig()
100 if err != nil { 113 if err != nil {
101 » » return params.AgentVersionResults{}, err 114 » » return params.AgentVersionResults{}, common.ServerError(err)
102 » }
103 » agentVersion, ok := cfg.AgentVersion()
104 » if !ok {
105 » » return params.AgentVersionResults{}, errors.New("agent version n ot set in environment config")
106 } 115 }
107 for i, entity := range args.Entities { 116 for i, entity := range args.Entities {
108 err := common.ErrPerm 117 err := common.ErrPerm
109 if u.authorizer.AuthOwner(entity.Tag) { 118 if u.authorizer.AuthOwner(entity.Tag) {
110 results[i].Version = &agentVersion 119 results[i].Version = &agentVersion
111 err = nil 120 err = nil
112 } 121 }
113 results[i].Error = common.ServerError(err) 122 results[i].Error = common.ServerError(err)
114 } 123 }
115 return params.AgentVersionResults{results}, nil 124 return params.AgentVersionResults{results}, nil
116 } 125 }
117 126
118 // Tools finds the Tools necessary for the given agents. 127 // Tools finds the Tools necessary for the given agents.
119 func (u *UpgraderAPI) Tools(args params.Entities) (params.AgentToolsResults, err or) { 128 func (u *UpgraderAPI) Tools(args params.Entities) (params.AgentToolsResults, err or) {
120 results := make([]params.AgentToolsResult, len(args.Entities)) 129 results := make([]params.AgentToolsResult, len(args.Entities))
121 if len(args.Entities) == 0 { 130 if len(args.Entities) == 0 {
122 return params.AgentToolsResults{}, nil 131 return params.AgentToolsResults{}, nil
123 } 132 }
124 » // For now, all agents get the same proposed version 133 » agentVersion, cfg, err := u.getGlobalAgentVersion()
125 » cfg, err := u.st.EnvironConfig()
126 if err != nil { 134 if err != nil {
127 » » return params.AgentToolsResults{}, err 135 » » return params.AgentToolsResults{}, common.ServerError(err)
128 » }
129 » agentVersion, ok := cfg.AgentVersion()
130 » if !ok {
131 » » return params.AgentToolsResults{}, errors.New("agent version not set in environment config")
132 } 136 }
133 env, err := environs.New(cfg) 137 env, err := environs.New(cfg)
134 if err != nil { 138 if err != nil {
135 return params.AgentToolsResults{}, err 139 return params.AgentToolsResults{}, err
136 } 140 }
137 for i, entity := range args.Entities { 141 for i, entity := range args.Entities {
138 agentTools, err := u.oneAgentTools(entity.Tag, agentVersion, env ) 142 agentTools, err := u.oneAgentTools(entity.Tag, agentVersion, env )
139 if err == nil { 143 if err == nil {
140 results[i].Tools = agentTools 144 results[i].Tools = agentTools
141 } 145 }
(...skipping 29 matching lines...) Expand all
171 entity0, err := u.st.FindEntity(tag) 175 entity0, err := u.st.FindEntity(tag)
172 if err != nil { 176 if err != nil {
173 return nil, err 177 return nil, err
174 } 178 }
175 entity, ok := entity0.(state.AgentTooler) 179 entity, ok := entity0.(state.AgentTooler)
176 if !ok { 180 if !ok {
177 return nil, common.NotSupportedError(tag, "agent tools") 181 return nil, common.NotSupportedError(tag, "agent tools")
178 } 182 }
179 return entity, nil 183 return entity, nil
180 } 184 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b