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. "log"
  17. "net"
  18. "net/http"
  19. "net/rpc"
  20. "github.com/coreos/etcd/tools/functional-tester/etcd-agent/client"
  21. )
  22. func (a *Agent) serveRPC() {
  23. rpc.Register(a)
  24. rpc.HandleHTTP()
  25. l, e := net.Listen("tcp", ":9027")
  26. if e != nil {
  27. log.Fatal("agent:", e)
  28. }
  29. go http.Serve(l, nil)
  30. }
  31. func (a *Agent) RPCStart(args []string, pid *int) error {
  32. log.Printf("rpc: start etcd with args %v", args)
  33. err := a.start(args...)
  34. if err != nil {
  35. log.Println("rpc: 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. log.Printf("rpc: stop etcd")
  43. err := a.stop()
  44. if err != nil {
  45. log.Println("rpc: error stopping etcd", err)
  46. return err
  47. }
  48. return nil
  49. }
  50. func (a *Agent) RPCRestart(args struct{}, pid *int) error {
  51. log.Printf("rpc: restart etcd")
  52. err := a.restart()
  53. if err != nil {
  54. log.Println("rpc: 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. log.Printf("rpc: cleanup etcd")
  62. err := a.cleanup()
  63. if err != nil {
  64. log.Println("rpc: error cleaning up etcd", err)
  65. return err
  66. }
  67. return nil
  68. }
  69. func (a *Agent) RPCTerminate(args struct{}, reply *struct{}) error {
  70. log.Printf("rpc: terminate etcd")
  71. err := a.terminate()
  72. if err != nil {
  73. log.Println("rpc: error terminating etcd", err)
  74. }
  75. return nil
  76. }
  77. func (a *Agent) RPCDropPort(port int, reply *struct{}) error {
  78. log.Printf("rpc: drop port %d", port)
  79. err := a.dropPort(port)
  80. if err != nil {
  81. log.Println("rpc: error dropping port", err)
  82. }
  83. return nil
  84. }
  85. func (a *Agent) RPCRecoverPort(port int, reply *struct{}) error {
  86. log.Printf("rpc: recover port %d", port)
  87. err := a.recoverPort(port)
  88. if err != nil {
  89. log.Println("rpc: 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. }