ZooKeeperQuorumServer.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. #ifndef ZOOKEEPER_QUORUM_SERVER_H
  18. #define ZOOKEEPER_QUORUM_SERVER_H
  19. #include <stdint.h>
  20. #include <string>
  21. #include <vector>
  22. #include <utility>
  23. class ZooKeeperQuorumServer {
  24. public:
  25. ~ZooKeeperQuorumServer();
  26. typedef std::vector<std::pair<std::string, std::string> > tConfigPairs;
  27. static std::vector<ZooKeeperQuorumServer*> getCluster(uint32_t numServers);
  28. static std::vector<ZooKeeperQuorumServer*> getCluster(uint32_t numServers,
  29. tConfigPairs configs, /* Additional config options as a list of key/value pairs. */
  30. std::string env /* Additional environment variables when starting zkServer.sh. */);
  31. std::string getHostPort();
  32. uint32_t getClientPort();
  33. void start();
  34. void stop();
  35. bool isLeader();
  36. bool isFollower();
  37. std::string getServerString();
  38. private:
  39. ZooKeeperQuorumServer();
  40. ZooKeeperQuorumServer(uint32_t id, uint32_t numServers, std::string config = "",
  41. std::string env = "");
  42. ZooKeeperQuorumServer(const ZooKeeperQuorumServer& that);
  43. const ZooKeeperQuorumServer& operator=(const ZooKeeperQuorumServer& that);
  44. void createConfigFile(std::string config = "");
  45. std::string getConfigFileName();
  46. void createDataDirectory();
  47. std::string getDataDirectory();
  48. static std::string getServerString(uint32_t id);
  49. std::string getMode();
  50. static const uint32_t SERVER_PORT_BASE = 2000;
  51. static const uint32_t ELECTION_PORT_BASE = 3000;
  52. static const uint32_t CLIENT_PORT_BASE = 4000;
  53. uint32_t id_;
  54. std::string env_;
  55. uint32_t numServers_;
  56. std::string root_;
  57. };
  58. #endif // ZOOKEEPER_QUORUM_SERVER_H