| 4040 | } |
| 4041 | |
| 4042 | void HandleClientChangeRole(const std::vector<std::string> parts, |
| 4043 | ::fedb::client::TabletClient* client) { |
| 4044 | if (parts.size() < 4) { |
| 4045 | std::cout << "Bad changerole format" << std::endl; |
| 4046 | return; |
| 4047 | } |
| 4048 | try { |
| 4049 | uint64_t termid = 0; |
| 4050 | if (parts.size() > 4) { |
| 4051 | termid = boost::lexical_cast<uint64_t>(parts[4]); |
| 4052 | } |
| 4053 | if (parts[3].compare("leader") == 0) { |
| 4054 | bool ok = client->ChangeRole( |
| 4055 | boost::lexical_cast<uint32_t>(parts[1]), |
| 4056 | boost::lexical_cast<uint32_t>(parts[2]), true, termid); |
| 4057 | if (ok) { |
| 4058 | std::cout << "ChangeRole ok" << std::endl; |
| 4059 | } else { |
| 4060 | std::cout << "Fail to change leader" << std::endl; |
| 4061 | } |
| 4062 | } else if (parts[3].compare("follower") == 0) { |
| 4063 | bool ok = client->ChangeRole( |
| 4064 | boost::lexical_cast<uint32_t>(parts[1]), |
| 4065 | boost::lexical_cast<uint32_t>(parts[2]), false, termid); |
| 4066 | if (ok) { |
| 4067 | std::cout << "ChangeRole ok" << std::endl; |
| 4068 | } else { |
| 4069 | std::cout << "Fail to change follower" << std::endl; |
| 4070 | } |
| 4071 | } else { |
| 4072 | std::cout << "role must be leader or follower" << std::endl; |
| 4073 | } |
| 4074 | } catch (boost::bad_lexical_cast& e) { |
| 4075 | std::cout << "Bad changerole format" << std::endl; |
| 4076 | } |
| 4077 | } |
| 4078 | |
| 4079 | void HandleClientPreview(const std::vector<std::string>& parts, |
| 4080 | ::fedb::client::TabletClient* client) { |
no test coverage detected