mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-28 14:50:08 +03:00
F #4809: Method to query raft status one servers. Updated CLI to make
use of it
This commit is contained in:
parent
9e1fd142c3
commit
c14d648e32
@ -99,6 +99,12 @@ public:
|
||||
// -------------------------------------------------------------------------
|
||||
// Raft state query functions
|
||||
// -------------------------------------------------------------------------
|
||||
/**
|
||||
* Return the Raft status in XML format
|
||||
* @return xml document with the raft state
|
||||
*/
|
||||
std::string& to_xml(std::string& state_xml);
|
||||
|
||||
/**
|
||||
* Makes this server follower. Stop associated replication facilities
|
||||
*/
|
||||
|
@ -112,4 +112,20 @@ public:
|
||||
RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
class ZoneRaftStatus : public RequestManagerZone
|
||||
{
|
||||
public:
|
||||
ZoneRaftStatus():
|
||||
RequestManagerZone("ZoneRaftInformation", "Returns Raft status",
|
||||
"A:s"){};
|
||||
|
||||
~ZoneRaftStatus(){};
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
RequestAttributes& att);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -117,6 +117,42 @@ class OneZoneHelper < OpenNebulaHelper::OneHelper
|
||||
zone_hash=zone.to_hash
|
||||
|
||||
if zone.has_elements?("/ZONE/SERVER_POOL/SERVER")
|
||||
servers = zone_hash["ZONE"]["SERVER_POOL"]["SERVER"]
|
||||
|
||||
servers.each { |s|
|
||||
endpoint = s["ENDPOINT"]
|
||||
|
||||
next if endpoint.nil?
|
||||
|
||||
client = OpenNebula::Client.new(nil, endpoint)
|
||||
|
||||
xml_doc = client.call("zone.raftstatus")
|
||||
|
||||
if OpenNebula::is_error?(xml_doc)
|
||||
s["STATE"] = "error"
|
||||
s["TERM"] = "-"
|
||||
s["VOTEDFOR"] = "-"
|
||||
s["COMMIT" ] = "-"
|
||||
s["LOG_INDEX"] = "-"
|
||||
|
||||
next
|
||||
end
|
||||
|
||||
xml_doc = Nokogiri::XML(xml_doc)
|
||||
|
||||
s["STATE"] = case xml_doc.root.at_xpath("STATE").text
|
||||
when "0" then "solo"
|
||||
when "1" then "candidate"
|
||||
when "2" then "follower"
|
||||
when "3" then "leader"
|
||||
else "-"
|
||||
end
|
||||
s["TERM"] = xml_doc.root.at_xpath("TERM").text
|
||||
s["VOTEDFOR"] = xml_doc.root.at_xpath("VOTEDFOR").text
|
||||
s["COMMIT"] = xml_doc.root.at_xpath("COMMIT").text
|
||||
s["LOG_INDEX"] = xml_doc.root.at_xpath("LOG_INDEX").text
|
||||
}
|
||||
|
||||
puts
|
||||
CLIHelper.print_header(str_h1 % "SERVERS",false)
|
||||
|
||||
@ -130,10 +166,29 @@ class OneZoneHelper < OpenNebulaHelper::OneHelper
|
||||
d["NAME"] if !d.nil?
|
||||
end
|
||||
|
||||
column :"ENDPOINT", "", :left, :size=>30 do |d|
|
||||
d["ENDPOINT"] if !d.nil?
|
||||
column :"STATE", "", :left, :size=>10 do |d|
|
||||
d["STATE"] if !d.nil?
|
||||
end
|
||||
|
||||
column :"TERM", "", :left, :size=>10 do |d|
|
||||
d["TERM"] if !d.nil?
|
||||
end
|
||||
|
||||
column :"INDEX", "", :left, :size=>10 do |d|
|
||||
d["LOG_INDEX"] if !d.nil?
|
||||
end
|
||||
|
||||
column :"COMMIT", "", :left, :size=>10 do |d|
|
||||
d["COMMIT"] if !d.nil?
|
||||
end
|
||||
|
||||
column :"VOTE", "", :left, :size=>5 do |d|
|
||||
d["VOTEDFOR"] if !d.nil?
|
||||
end
|
||||
|
||||
column :"ENDPOINT", "", :left, :size=>18 do |d|
|
||||
d["ENDPOINT"] if !d.nil?
|
||||
end
|
||||
end.show([zone_hash['ZONE']['SERVER_POOL']['SERVER']].flatten, {})
|
||||
end
|
||||
|
||||
|
@ -1112,3 +1112,37 @@ int RaftManager::xmlrpc_request_vote(int follower_id, unsigned int lindex,
|
||||
return xml_rc;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
std::string& RaftManager::to_xml(std::string& raft_xml)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
LogDB * logdb = nd.get_logdb();
|
||||
|
||||
unsigned int lindex, lterm;
|
||||
|
||||
std::ostringstream oss;
|
||||
|
||||
logdb->get_last_record_index(lindex, lterm);
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
|
||||
oss << "<RAFT>"
|
||||
<< "<SERVER_ID>" << server_id << "</SERVER_ID>"
|
||||
<< "<STATE>" << state << "</STATE>"
|
||||
<< "<TERM>" << term << "</TERM>"
|
||||
<< "<VOTEDFOR>" << votedfor << "</VOTEDFOR>"
|
||||
<< "<COMMIT>" << commit << "</COMMIT>"
|
||||
<< "<LOG_INDEX>" << lindex << "</LOG_INDEX>"
|
||||
<< "<LOG_TERM>" << lterm << "</LOG_TERM>"
|
||||
<< "</RAFT>";
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
raft_xml = oss.str();
|
||||
|
||||
return raft_xml;
|
||||
}
|
||||
|
||||
|
||||
|
@ -789,6 +789,7 @@ void RequestManager::register_xml_methods()
|
||||
xmlrpc_c::methodPtr zone_delserver(zone_delserver_pt);
|
||||
xmlrpc_c::methodPtr zone_replicatelog(new ZoneReplicateLog());
|
||||
xmlrpc_c::methodPtr zone_voterequest(new ZoneVoteRequest());
|
||||
xmlrpc_c::methodPtr zone_raftstatus(new ZoneRaftStatus());
|
||||
|
||||
xmlrpc_c::methodPtr zone_info(new ZoneInfo());
|
||||
xmlrpc_c::methodPtr zonepool_info(new ZonePoolInfo());
|
||||
@ -800,6 +801,7 @@ void RequestManager::register_xml_methods()
|
||||
RequestManagerRegistry.addMethod("one.zone.rename", zone_rename);
|
||||
RequestManagerRegistry.addMethod("one.zone.replicate",zone_replicatelog);
|
||||
RequestManagerRegistry.addMethod("one.zone.voterequest",zone_voterequest);
|
||||
RequestManagerRegistry.addMethod("one.zone.raftstatus", zone_raftstatus);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.zone.addserver", zone_addserver);
|
||||
RequestManagerRegistry.addMethod("one.zone.delserver", zone_delserver);
|
||||
|
@ -303,4 +303,25 @@ void ZoneVoteRequest::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
success_response(static_cast<int>(current_term), att);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void ZoneRaftStatus::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
RaftManager * raftm = nd.get_raftm();
|
||||
|
||||
std::string raft_xml;
|
||||
|
||||
if ( basic_authorization(nd.get_zone_id(), att) == false )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
raftm->to_xml(raft_xml);
|
||||
|
||||
success_response(raft_xml, att);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user