@@ -34,11 +34,43 @@ type InternalClient struct {
3434 RPCClient * rpc.Client
3535}
3636
37+ const (
38+ RPCServiceNameV0 = `RpcServerDriver`
39+ RPCServiceNameV1 = `RPCServerDriver`
40+
41+ HeartbeatMethod = `.Heartbeat`
42+ GetVersionMethod = `.GetVersion`
43+ CloseMethod = `.Close`
44+ GetCreateFlagsMethod = `.GetCreateFlags`
45+ SetConfigRawMethod = `.SetConfigRaw`
46+ GetConfigRawMethod = `.GetConfigRaw`
47+ DriverNameMethod = `.DriverName`
48+ SetConfigFromFlagsMethod = `.SetConfigFromFlags`
49+ GetURLMethod = `.GetURL`
50+ GetMachineNameMethod = `.GetMachineName`
51+ GetIPMethod = `.GetIP`
52+ GetSSHHostnameMethod = `.GetSSHHostname`
53+ GetSSHKeyPathMethod = `.GetSSHKeyPath`
54+ GetSSHPortMethod = `.GetSSHPort`
55+ GetSSHUsernameMethod = `.GetSSHUsername`
56+ GetStateMethod = `.GetState`
57+ PreCreateCheckMethod = `.PreCreateCheck`
58+ CreateMethod = `.Create`
59+ RemoveMethod = `.Remove`
60+ StartMethod = `.Start`
61+ StopMethod = `.Stop`
62+ RestartMethod = `.Restart`
63+ KillMethod = `.Kill`
64+ UpgradeMethod = `.Upgrade`
65+ LocalArtifactPathMethod = `.LocalArtifactPath`
66+ GlobalArtifactPathMethod = `.GlobalArtifactPath`
67+ )
68+
3769func (ic * InternalClient ) Call (serviceMethod string , args interface {}, reply interface {}) error {
38- if serviceMethod != "RPCServerDriver.Heartbeat" {
70+ if serviceMethod != HeartbeatMethod {
3971 log .Debugf ("(%s) Calling %+v" , ic .MachineName , serviceMethod )
4072 }
41- return ic .RPCClient .Call (serviceMethod , args , reply )
73+ return ic .RPCClient .Call (RPCServiceNameV1 + serviceMethod , args , reply )
4274}
4375
4476func NewInternalClient (rpcclient * rpc.Client ) * InternalClient {
@@ -84,7 +116,7 @@ func NewRPCClientDriver(rawDriverData []byte, driverName string) (*RPCClientDriv
84116 case <- c .heartbeatDoneCh :
85117 return
86118 default :
87- if err := c .Client .Call ("RPCServerDriver.Heartbeat" , struct {}{}, nil ); err != nil {
119+ if err := c .Client .Call (HeartbeatMethod , struct {}{}, nil ); err != nil {
88120 log .Warnf ("Error attempting heartbeat call to plugin server: %s" , err )
89121 c .Close ()
90122 return
@@ -95,7 +127,7 @@ func NewRPCClientDriver(rawDriverData []byte, driverName string) (*RPCClientDriv
95127 }(c )
96128
97129 var serverVersion int
98- if err := c .Client .Call ("RPCServerDriver.GetVersion" , struct {}{}, & serverVersion ); err != nil {
130+ if err := c .Client .Call (GetVersionMethod , struct {}{}, & serverVersion ); err != nil {
99131 return nil , err
100132 }
101133
@@ -136,7 +168,7 @@ func (c *RPCClientDriver) Close() error {
136168
137169 log .Debug ("Making call to close driver server" )
138170
139- if err := c .Client .Call ("RPCServerDriver.Close" , struct {}{}, nil ); err != nil {
171+ if err := c .Client .Call (CloseMethod , struct {}{}, nil ); err != nil {
140172 return err
141173 }
142174
@@ -160,21 +192,21 @@ func (c *RPCClientDriver) rpcStringCall(method string) (string, error) {
160192func (c * RPCClientDriver ) GetCreateFlags () []mcnflag.Flag {
161193 var flags []mcnflag.Flag
162194
163- if err := c .Client .Call ("RPCServerDriver.GetCreateFlags" , struct {}{}, & flags ); err != nil {
195+ if err := c .Client .Call (GetCreateFlagsMethod , struct {}{}, & flags ); err != nil {
164196 log .Warnf ("Error attempting call to get create flags: %s" , err )
165197 }
166198
167199 return flags
168200}
169201
170202func (c * RPCClientDriver ) SetConfigRaw (data []byte ) error {
171- return c .Client .Call ("RPCServerDriver.SetConfigRaw" , data , nil )
203+ return c .Client .Call (SetConfigRawMethod , data , nil )
172204}
173205
174206func (c * RPCClientDriver ) GetConfigRaw () ([]byte , error ) {
175207 var data []byte
176208
177- if err := c .Client .Call ("RPCServerDriver.GetConfigRaw" , struct {}{}, & data ); err != nil {
209+ if err := c .Client .Call (GetConfigRawMethod , struct {}{}, & data ); err != nil {
178210 return nil , err
179211 }
180212
@@ -183,7 +215,7 @@ func (c *RPCClientDriver) GetConfigRaw() ([]byte, error) {
183215
184216// DriverName returns the name of the driver
185217func (c * RPCClientDriver ) DriverName () string {
186- driverName , err := c .rpcStringCall ("RPCServerDriver.DriverName" )
218+ driverName , err := c .rpcStringCall (DriverNameMethod )
187219 if err != nil {
188220 log .Warnf ("Error attempting call to get driver name: %s" , err )
189221 }
@@ -192,15 +224,15 @@ func (c *RPCClientDriver) DriverName() string {
192224}
193225
194226func (c * RPCClientDriver ) SetConfigFromFlags (flags drivers.DriverOptions ) error {
195- return c .Client .Call ("RPCServerDriver.SetConfigFromFlags" , & flags , nil )
227+ return c .Client .Call (SetConfigFromFlagsMethod , & flags , nil )
196228}
197229
198230func (c * RPCClientDriver ) GetURL () (string , error ) {
199- return c .rpcStringCall ("RPCServerDriver.GetURL" )
231+ return c .rpcStringCall (GetURLMethod )
200232}
201233
202234func (c * RPCClientDriver ) GetMachineName () string {
203- name , err := c .rpcStringCall ("RPCServerDriver.GetMachineName" )
235+ name , err := c .rpcStringCall (GetMachineNameMethod )
204236 if err != nil {
205237 log .Warnf ("Error attempting call to get machine name: %s" , err )
206238 }
@@ -209,17 +241,17 @@ func (c *RPCClientDriver) GetMachineName() string {
209241}
210242
211243func (c * RPCClientDriver ) GetIP () (string , error ) {
212- return c .rpcStringCall ("RPCServerDriver.GetIP" )
244+ return c .rpcStringCall (GetIPMethod )
213245}
214246
215247func (c * RPCClientDriver ) GetSSHHostname () (string , error ) {
216- return c .rpcStringCall ("RPCServerDriver.GetSSHHostname" )
248+ return c .rpcStringCall (GetSSHHostnameMethod )
217249}
218250
219251// GetSSHKeyPath returns the key path
220252// TODO: This method doesn't even make sense to have with RPC.
221253func (c * RPCClientDriver ) GetSSHKeyPath () string {
222- path , err := c .rpcStringCall ("RPCServerDriver.GetSSHKeyPath" )
254+ path , err := c .rpcStringCall (GetSSHKeyPathMethod )
223255 if err != nil {
224256 log .Warnf ("Error attempting call to get SSH key path: %s" , err )
225257 }
@@ -230,15 +262,15 @@ func (c *RPCClientDriver) GetSSHKeyPath() string {
230262func (c * RPCClientDriver ) GetSSHPort () (int , error ) {
231263 var port int
232264
233- if err := c .Client .Call ("RPCServerDriver.GetSSHPort" , struct {}{}, & port ); err != nil {
265+ if err := c .Client .Call (GetSSHPortMethod , struct {}{}, & port ); err != nil {
234266 return 0 , err
235267 }
236268
237269 return port , nil
238270}
239271
240272func (c * RPCClientDriver ) GetSSHUsername () string {
241- username , err := c .rpcStringCall ("RPCServerDriver.GetSSHUsername" )
273+ username , err := c .rpcStringCall (GetSSHUsernameMethod )
242274 if err != nil {
243275 log .Warnf ("Error attempting call to get SSH username: %s" , err )
244276 }
@@ -249,53 +281,53 @@ func (c *RPCClientDriver) GetSSHUsername() string {
249281func (c * RPCClientDriver ) GetState () (state.State , error ) {
250282 var s state.State
251283
252- if err := c .Client .Call ("RPCServerDriver.GetState" , struct {}{}, & s ); err != nil {
284+ if err := c .Client .Call (GetStateMethod , struct {}{}, & s ); err != nil {
253285 return state .Error , err
254286 }
255287
256288 return s , nil
257289}
258290
259291func (c * RPCClientDriver ) PreCreateCheck () error {
260- return c .Client .Call ("RPCServerDriver.PreCreateCheck" , struct {}{}, nil )
292+ return c .Client .Call (PreCreateCheckMethod , struct {}{}, nil )
261293}
262294
263295func (c * RPCClientDriver ) Create () error {
264- return c .Client .Call ("RPCServerDriver.Create" , struct {}{}, nil )
296+ return c .Client .Call (CreateMethod , struct {}{}, nil )
265297}
266298
267299func (c * RPCClientDriver ) Remove () error {
268- return c .Client .Call ("RPCServerDriver.Remove" , struct {}{}, nil )
300+ return c .Client .Call (RemoveMethod , struct {}{}, nil )
269301}
270302
271303func (c * RPCClientDriver ) Start () error {
272- return c .Client .Call ("RPCServerDriver.Start" , struct {}{}, nil )
304+ return c .Client .Call (StartMethod , struct {}{}, nil )
273305}
274306
275307func (c * RPCClientDriver ) Stop () error {
276- return c .Client .Call ("RPCServerDriver.Stop" , struct {}{}, nil )
308+ return c .Client .Call (StopMethod , struct {}{}, nil )
277309}
278310
279311func (c * RPCClientDriver ) Restart () error {
280- return c .Client .Call ("RPCServerDriver.Restart" , struct {}{}, nil )
312+ return c .Client .Call (RestartMethod , struct {}{}, nil )
281313}
282314
283315func (c * RPCClientDriver ) Kill () error {
284- return c .Client .Call ("RPCServerDriver.Kill" , struct {}{}, nil )
316+ return c .Client .Call (KillMethod , struct {}{}, nil )
285317}
286318
287319func (c * RPCClientDriver ) LocalArtifactPath (file string ) string {
288320 var path string
289321
290- if err := c .Client .Call ("RPCServerDriver.LocalArtifactPath" , file , & path ); err != nil {
322+ if err := c .Client .Call (LocalArtifactPathMethod , file , & path ); err != nil {
291323 log .Warnf ("Error attempting call to get LocalArtifactPath: %s" , err )
292324 }
293325
294326 return path
295327}
296328
297329func (c * RPCClientDriver ) GlobalArtifactPath () string {
298- globalArtifactPath , err := c .rpcStringCall ("RPCServerDriver.GlobalArtifactPath" )
330+ globalArtifactPath , err := c .rpcStringCall (GlobalArtifactPathMethod )
299331 if err != nil {
300332 log .Warnf ("Error attempting call to get GlobalArtifactPath: %s" , err )
301333 }
@@ -304,5 +336,5 @@ func (c *RPCClientDriver) GlobalArtifactPath() string {
304336}
305337
306338func (c * RPCClientDriver ) Upgrade () error {
307- return c .Client .Call ("RPCServerDriver.Upgrade" , struct {}{}, nil )
339+ return c .Client .Call (UpgradeMethod , struct {}{}, nil )
308340}
0 commit comments