rpc.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // Copyright 2015 CoreOS, Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package main
  15. import (
  16. "net"
  17. "net/http"
  18. "net/rpc"
  19. "github.com/coreos/etcd/tools/functional-tester/etcd-agent/client"
  20. )
  21. func (a *Agent) serveRPC(port string) {
  22. rpc.Register(a)
  23. rpc.HandleHTTP()
  24. l, e := net.Listen("tcp", port)
  25. if e != nil {
  26. plog.Fatal(e)
  27. }
  28. plog.Println("agent listening on", port)
  29. go http.Serve(l, nil)
  30. }
  31. func (a *Agent) RPCStart(args []string, pid *int) error {
  32. plog.Printf("start etcd with args %v", args)
  33. err := a.start(args...)
  34. if err != nil {
  35. plog.Println("error starting etcd", err)
  36. return err
  37. }
  38. *pid = a.cmd.Process.Pid
  39. return nil
  40. }
  41. func (a *Agent) RPCStop(args struct{}, reply *struct{}) error {
  42. plog.Printf("stop etcd")
  43. err := a.stop()
  44. if err != nil {
  45. plog.Println("error stopping etcd", err)
  46. return err
  47. }
  48. return nil
  49. }
  50. func (a *Agent) RPCRestart(args struct{}, pid *int) error {
  51. plog.Printf("restart etcd")
  52. err := a.restart()
  53. if err != nil {
  54. plog.Println("error restarting etcd", err)
  55. return err
  56. }
  57. *pid = a.cmd.Process.Pid
  58. return nil
  59. }
  60. func (a *Agent) RPCCleanup(args struct{}, reply *struct{}) error {
  61. plog.Printf("cleanup etcd")
  62. err := a.cleanup()
  63. if err != nil {
  64. plog.Println("error cleaning up etcd", err)
  65. return err
  66. }
  67. return nil
  68. }
  69. func (a *Agent) RPCTerminate(args struct{}, reply *struct{}) error {
  70. plog.Printf("terminate etcd")
  71. err := a.terminate()
  72. if err != nil {
  73. plog.Println("error terminating etcd", err)
  74. }
  75. return nil
  76. }
  77. func (a *Agent) RPCDropPort(port int, reply *struct{}) error {
  78. plog.Printf("drop port %d", port)
  79. err := a.dropPort(port)
  80. if err != nil {
  81. plog.Println("error dropping port", err)
  82. }
  83. return nil
  84. }
  85. func (a *Agent) RPCRecoverPort(port int, reply *struct{}) error {
  86. plog.Printf("recover port %d", port)
  87. err := a.recoverPort(port)
  88. if err != nil {
  89. plog.Println("error recovering port", err)
  90. }
  91. return nil
  92. }
  93. func (a *Agent) RPCStatus(args struct{}, status *client.Status) error {
  94. *status = a.status()
  95. return nil
  96. }