1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-25 23:21:29 +03:00

Merge branch 'feature-2143-api_call'

This commit is contained in:
Ruben S. Montero 2018-06-26 13:15:20 +02:00
commit 484e412b0a
7 changed files with 104 additions and 1 deletions

View File

@ -286,6 +286,12 @@ public:
*/
void delete_server(int follower_id);
/**
* Reset index for a follower.
* @param follower_id id of server
*/
void reset_index(int follower_id);
private:
friend void * raft_manager_loop(void *arg);

View File

@ -84,6 +84,22 @@ public:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
class ZoneResetServer : public RequestManagerZone
{
public:
ZoneResetServer():
RequestManagerZone("one.zone.resetserver", "Reset server log index",
"A:sis"){};
~ZoneResetServer(){};
void request_execute(xmlrpc_c::paramList const& _paramList,
RequestAttributes& att);
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
class ZoneReplicateLog : public RequestManagerZone
{
public:

View File

@ -128,6 +128,18 @@ cmd=CommandParser::CmdParser.new(ARGV) do
end
end
resetserver_desc = <<-EOT.unindent
Reset follower log index. This should be trigger when a follower DB has
been reset.
EOT
command :"server-reset", resetserver_desc, :zoneid, :serverid do
helper.perform_action(args[0], options, "server reset") do |o|
o.reset_server(args[1].to_i)
end
end
update_desc = <<-EOT.unindent
Update the template contents. If a path is not provided the editor will
be launched to modify the current content.

View File

@ -30,7 +30,8 @@ module OpenNebula
:rename => "zone.rename",
:delete => "zone.delete",
:addserver => "zone.addserver",
:delserver => "zone.delserver"
:delserver => "zone.delserver",
:resetserver => "zone.resetserver"
}
# Creates a Zone description with just its identifier
@ -168,6 +169,16 @@ module OpenNebula
return call(ZONE_METHODS[:delserver], @pe_id, server_id)
end
# Reset index for a follower
#
# @param id [Int] Server ID
#
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def reset_server(server_id)
return call(ZONE_METHODS[:resetserver], @pe_id, server_id)
end
private
# These methods adds elements to the given node of the zone

View File

@ -313,6 +313,7 @@ void RaftManager::add_server(int follower_id, const std::string& endpoint)
}
num_servers++;
servers.insert(std::make_pair(follower_id, endpoint));
next.insert(std::make_pair(follower_id, log_index + 1));
@ -1290,4 +1291,27 @@ std::string& RaftManager::to_xml(std::string& raft_xml)
return raft_xml;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void RaftManager::reset_index(int follower_id)
{
std::map<int, unsigned int>::iterator next_it;
unsigned int log_index, log_term;
LogDB * logdb = Nebula::instance().get_logdb();
logdb->get_last_record_index(log_index, log_term);
pthread_mutex_lock(&mutex);
next_it = next.find(follower_id);
if ( next_it != next.end() )
{
next_it->second = log_index + 1;
}
pthread_mutex_unlock(&mutex);
}

View File

@ -806,6 +806,7 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr zone_rename(zone_rename_pt);
xmlrpc_c::methodPtr zone_addserver(new ZoneAddServer());
xmlrpc_c::methodPtr zone_delserver(new ZoneDeleteServer());
xmlrpc_c::methodPtr zone_resetserver(new ZoneResetServer());
xmlrpc_c::methodPtr zone_replicatelog(new ZoneReplicateLog());
xmlrpc_c::methodPtr zone_voterequest(new ZoneVoteRequest());
xmlrpc_c::methodPtr zone_raftstatus(new ZoneRaftStatus());
@ -826,6 +827,7 @@ void RequestManager::register_xml_methods()
RequestManagerRegistry.addMethod("one.zone.addserver", zone_addserver);
RequestManagerRegistry.addMethod("one.zone.delserver", zone_delserver);
RequestManagerRegistry.addMethod("one.zone.resetserver", zone_resetserver);
RequestManagerRegistry.addMethod("one.zonepool.info",zonepool_info);

View File

@ -257,6 +257,38 @@ void ZoneDeleteServer::request_execute(xmlrpc_c::paramList const& paramList,
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void ZoneResetServer::request_execute(xmlrpc_c::paramList const& paramList,
RequestAttributes& att)
{
Nebula& nd = Nebula::instance();
int id = xmlrpc_c::value_int(paramList.getInt(1));
int zs_id = xmlrpc_c::value_int(paramList.getInt(2));
string error_str;
if ( id != nd.get_zone_id() )
{
att.resp_msg = "Servers have to be deleted through the target zone"
" endpoints";
failure_response(ACTION, att);
return;
}
if ( basic_authorization(id, att) == false )
{
return;
}
nd.get_raftm()->reset_index(zs_id);
success_response(id, att);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void ZoneReplicateLog::request_execute(xmlrpc_c::paramList const& paramList,
RequestAttributes& att)
{