1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-11 04:58:16 +03:00

F #5353: Zone standby mode. DB version number to 6.2.0

Includes the following commits from f-5353:

  - 62d3d38d7fb135b82874a5076a7f06c23675e0b7
  - 52f3f066603c478061891175c008a58cfed3dc43
  - 0e82f9e5471c3cf0e21969393299279c6e739138
  - 8c32050940f528ea876e8293e6fbbf56a373bd54
This commit is contained in:
Pavel Czerny 2021-04-20 13:40:44 +02:00 committed by Ruben S. Montero
parent d051a383e8
commit 69e83eb161
No known key found for this signature in database
GPG Key ID: A0CEA6FA880A1D87
20 changed files with 334 additions and 19 deletions

View File

@ -22,6 +22,7 @@
#include "DefaultQuotas.h"
#include "UserPool.h"
#include "Zone.h"
#include "NebulaLog.h"
class LogDB;
@ -403,7 +404,7 @@ public:
*/
static std::string shared_db_version()
{
return "6.0.0";
return "6.2.0";
}
/**
@ -412,7 +413,7 @@ public:
*/
static std::string local_db_version()
{
return "6.0.0";
return "6.2.0";
}
/**
@ -468,6 +469,21 @@ public:
return master_oned;
};
void set_zone_state(Zone::ZoneState state)
{
zone_state = state;
}
Zone::ZoneState get_zone_state() const
{
return zone_state;
}
/**
* Update actual zone state from the DB
*/
void update_zone_state();
// -----------------------------------------------------------------------
// Configuration attributes (read from oned.conf)
// -----------------------------------------------------------------------
@ -808,6 +824,7 @@ private:
int zone_id;
int server_id;
std::string master_oned;
Zone::ZoneState zone_state = Zone::ENABLED;
// ---------------------------------------------------------------
// Default quotas

View File

@ -149,7 +149,7 @@ public:
*/
static std::string shared_db_version()
{
return "6.0.0";
return "6.2.0";
}
/**
@ -158,7 +158,7 @@ public:
*/
static std::string local_db_version()
{
return "6.0.0";
return "6.2.0";
}
// -----------------------------------------------------------------------

View File

@ -304,9 +304,12 @@ protected:
std::set<int> hidden_params;
bool log_method_call;
//Method can be only execute by leaders or solo servers
// Method can be only execute by leaders or solo servers
bool leader_only;
// Method can be executed in disabled state
bool zone_disabled;
/* ---------------------------------------------------------------------- */
/* Class Constructors */
/* ---------------------------------------------------------------------- */
@ -325,6 +328,7 @@ protected:
log_method_call = true;
leader_only = true;
zone_disabled = false;
vm_action = VMActions::NONE_ACTION;
};

View File

@ -52,6 +52,7 @@ protected:
auth_op = AuthRequest::USE_NO_LCK;
leader_only = false;
zone_disabled = true;
};
/* -------------------------------------------------------------------- */

View File

@ -67,6 +67,7 @@ protected:
{
leader_only = false;
extended = false;
zone_disabled = true;
};
void request_execute(

View File

@ -52,7 +52,10 @@ public:
SystemVersion():
RequestManagerSystem("one.system.version",
"Returns the OpenNebula version",
"A:s") {}
"A:s")
{
zone_disabled = true;
}
~SystemVersion(){};
@ -69,7 +72,10 @@ public:
SystemConfig():
RequestManagerSystem("one.system.config",
"Returns the OpenNebula configuration",
"A:s") {}
"A:s")
{
zone_disabled = true;
}
~SystemConfig(){};
@ -139,7 +145,10 @@ public:
UserQuotaInfo():
RequestManagerSystem("one.userquota.info",
"Returns the default user quota limits",
"A:s") { }
"A:s")
{
zone_disabled = true;
}
~UserQuotaInfo(){};
@ -156,7 +165,10 @@ public:
GroupQuotaInfo():
RequestManagerSystem("one.groupquota.info",
"Returns the default group quota limits",
"A:s") { }
"A:s")
{
zone_disabled = true;
}
~GroupQuotaInfo(){};

View File

@ -108,6 +108,7 @@ public:
{
log_method_call = false;
leader_only = false;
zone_disabled = true;
};
~ZoneReplicateLog(){};
@ -126,6 +127,7 @@ public:
"Request vote from a candidate", "A:siiii")
{
leader_only = false;
zone_disabled = true;
};
~ZoneVoteRequest(){};
@ -144,6 +146,7 @@ public:
"Returns Raft status", "A:s")
{
leader_only = false;
zone_disabled = true;
};
~ZoneRaftStatus(){};
@ -163,6 +166,7 @@ public:
"A:sis")
{
log_method_call = false;
zone_disabled = true;
};
~ZoneReplicateFedLog(){};
@ -171,4 +175,22 @@ public:
RequestAttributes& att) override;
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
class ZoneEnable : public RequestManagerZone
{
public:
ZoneEnable():
RequestManagerZone("one.zone.enable", "Enable or disable zone",
"A:sii")
{
log_method_call = true;
zone_disabled = true;
}
void request_execute(xmlrpc_c::paramList const& _paramList,
RequestAttributes& att) override;
};
#endif

View File

@ -28,6 +28,51 @@ class ZoneServer;
class Zone : public PoolObjectSQL
{
public:
enum ZoneState
{
ENABLED = 0, /**< Enabled */
DISABLED = 1, /**< Disabled, only read-only commmands are executed */
};
/**
* Functions to convert to/from string the Host states
*/
static int str_to_state(std::string& st, ZoneState& state)
{
one_util::toupper(st);
state = ENABLED;
if ( st == "ENABLED" ) {
state = ENABLED;
} else if ( st == "DISABLED" ) {
state = DISABLED;
}
else
{
return -1;
}
return 0;
}
static std::string state_to_str(ZoneState state)
{
std::string st = "";
switch (state)
{
case ENABLED:
st = "ENABLED";
break;
case DISABLED:
st = "DISABLED";
break;
}
return st;
}
virtual ~Zone();
/**
@ -78,12 +123,33 @@ public:
* @param server_id
* @return the server
*/
ZoneServer * get_server(int server_id);
ZoneServer * get_server(int server_id) const;
/**
* @return the number of servers in this zone
*/
unsigned int servers_size();
unsigned int servers_size() const;
ZoneState get_state() const
{
return state;
}
/**
* Enable the zone
*/
void enable()
{
state = ENABLED;
}
/**
* Disable the zone, only read_only commands are allowed
*/
void disable()
{
state = DISABLED;
}
private:
// -------------------------------------------------------------------------
@ -96,6 +162,8 @@ private:
// -------------------------------------------------------------------------
Zone(int id, std::unique_ptr<Template> zone_template);
ZoneState state;
// -------------------------------------------------------------------------
// Zone servers
// -------------------------------------------------------------------------

View File

@ -6,6 +6,7 @@
<xs:sequence>
<xs:element name="ID" type="xs:integer"/>
<xs:element name="NAME" type="xs:string"/>
<xs:element name="STATE" type="xs:integer"/>
<xs:element name="TEMPLATE">
<xs:complexType>
<xs:sequence>

View File

@ -7,6 +7,7 @@
<xs:sequence>
<xs:element name="ID" type="xs:integer"/>
<xs:element name="NAME" type="xs:string"/>
<xs:element name="STATE" type="xs:integer"/>
<xs:element name="TEMPLATE">
<xs:complexType>
<xs:sequence>

View File

@ -22,9 +22,15 @@
:desc: Federation index
:size: 10
:STAT:
:desc: Zone status
:size: 4
:left: true
:default:
- :CURRENT
- :ID
- :NAME
- :ENDPOINT
- :FED_INDEX
- :STAT

View File

@ -491,6 +491,13 @@ class OneZoneHelper < OpenNebulaHelper::OneHelper
"onezone.yaml"
end
def self.state_to_str(id)
id = id.to_i
state_str = Zone::ZONE_STATES[id]
Zone::SHORT_ZONE_STATES[state_str]
end
def format_pool(options)
config_file = self.class.table_conf
@ -516,7 +523,11 @@ class OneZoneHelper < OpenNebulaHelper::OneHelper
helper.get_fed_index(d["TEMPLATE"]['ENDPOINT'])
end
default :CURRENT, :ID, :NAME, :ENDPOINT, :FED_INDEX
column :STAT, 'Zone status', :left, :size => 6 do |d|
OneZoneHelper.state_to_str(d['STATE'])
end
default :CURRENT, :ID, :NAME, :ENDPOINT, :FED_INDEX, :STAT
end
table
@ -583,6 +594,7 @@ class OneZoneHelper < OpenNebulaHelper::OneHelper
CLIHelper.print_header(str_h1 % "ZONE #{zone['ID']} INFORMATION")
puts str % ["ID", zone.id.to_s]
puts str % ["NAME", zone.name]
puts str % ["STATE",zone.state_str]
puts
zone_hash=zone.to_hash

View File

@ -258,4 +258,24 @@ CommandParser::CmdParser.new(ARGV) do
0
end
enable_desc = <<-EOT.unindent
Enable zone
EOT
command :enable, enable_desc, :zoneid do
helper.perform_action(args[0], options, 'enable zone') do |o|
o.enable()
end
end
disable_desc = <<-EOT.unindent
Disable zone, disabled zones can execute only readonly commands
EOT
command :disable, disable_desc, :zoneid do
helper.perform_action(args[0], options, 'disable zone') do |o|
o.disable()
end
end
end

View File

@ -800,6 +800,8 @@ void Nebula::start(bool bootstrap_only)
default_user_quota.select();
default_group_quota.select();
update_zone_state();
}
catch (exception&)
{
@ -1238,6 +1240,22 @@ error_mad:
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void Nebula::update_zone_state()
{
if (auto zone = zonepool->get_ro(get_zone_id()))
{
set_zone_state(zone->get_state());
}
else
{
NebulaLog::warn("ONE", "Unable to find zone id: "
+ to_string(get_zone_id()));
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -31,7 +31,15 @@ module OpenNebula
:delete => "zone.delete",
:addserver => "zone.addserver",
:delserver => "zone.delserver",
:resetserver => "zone.resetserver"
:resetserver => "zone.resetserver",
:enable => "zone.enable"
}
ZONE_STATES=%w{ENABLED DISABLED}
SHORT_ZONE_STATES={
"ENABLED" => "on",
"DISABLED" => "off"
}
# Creates a Zone description with just its identifier
@ -179,6 +187,37 @@ module OpenNebula
return call(ZONE_METHODS[:resetserver], @pe_id, server_id)
end
# Enable zone
#
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def enable()
return call(ZONE_METHODS[:enable], @pe_id, true)
end
# Disable zone, only readonly commands can be executed in disabled
# state
#
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def disable()
return call(ZONE_METHODS[:enable], @pe_id, false)
end
#######################################################################
# Helpers to get Zone information
#######################################################################
# Returns the state of the Zone (numeric value)
def state
self['STATE'].to_i
end
# Returns the state of the Zone (string value)
def state_str
ZONE_STATES[state]
end
private
# These methods adds elements to the given node of the zone

View File

@ -405,6 +405,8 @@ void RaftManager::leader()
im->raft_status(state);
}
nd.update_zone_state();
aclm->reload_rules();
if ( nd.is_federation_master() )

View File

@ -22,6 +22,7 @@
#include "HookAPI.h"
#include "HookManager.h"
#include "RaftManager.h"
#include "ZonePool.h"
#include <xmlrpc-c/abyss.h>
@ -439,6 +440,16 @@ void Request::execute(
}
else //leader or solo or !leader_only
{
if ( !zone_disabled && nd.get_zone_state() == Zone::DISABLED )
{
att.resp_msg = "Cannot process request, zone disabled";
failure_response(INTERNAL, att);
log_result(att, method_name);
return;
}
request_execute(_paramList, att);
}

View File

@ -884,6 +884,7 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr zone_update(zone_update_pt);
xmlrpc_c::methodPtr zone_delete(zone_delete_pt);
xmlrpc_c::methodPtr zone_rename(zone_rename_pt);
xmlrpc_c::methodPtr zone_enable(new ZoneEnable());
xmlrpc_c::methodPtr zone_addserver(new ZoneAddServer());
xmlrpc_c::methodPtr zone_delserver(new ZoneDeleteServer());
xmlrpc_c::methodPtr zone_resetserver(new ZoneResetServer());
@ -900,6 +901,7 @@ void RequestManager::register_xml_methods()
RequestManagerRegistry.addMethod("one.zone.delete", zone_delete);
RequestManagerRegistry.addMethod("one.zone.info", zone_info);
RequestManagerRegistry.addMethod("one.zone.rename", zone_rename);
RequestManagerRegistry.addMethod("one.zone.enable", zone_enable);
RequestManagerRegistry.addMethod("one.zone.replicate",zone_replicatelog);
RequestManagerRegistry.addMethod("one.zone.fedreplicate",zone_fedreplicatelog);
RequestManagerRegistry.addMethod("one.zone.voterequest",zone_voterequest);

View File

@ -124,8 +124,6 @@ void ZoneAddServer::request_execute(xmlrpc_c::paramList const& paramList,
if ( nd.is_federation_master() || !nd.is_federation_enabled() )
{
std::vector<int> zids;
pool->update(zone.get());
}
else
@ -224,8 +222,6 @@ void ZoneDeleteServer::request_execute(xmlrpc_c::paramList const& paramList,
if ( nd.is_federation_master() || !nd.is_federation_enabled() )
{
std::vector<int> zids;
pool->update(zone.get());
}
else
@ -651,3 +647,69 @@ void ZoneReplicateFedLog::request_execute(xmlrpc_c::paramList const& paramList,
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void ZoneEnable::request_execute(xmlrpc_c::paramList const& paramList,
RequestAttributes& att)
{
Nebula& nd = Nebula::instance();
int id = xmlrpc_c::value_int(paramList.getInt(1));
bool enable = xmlrpc_c::value_boolean(paramList.getBoolean(2));
Zone::ZoneState state;
string error_str;
if ( id != nd.get_zone_id() )
{
att.resp_msg = "Enable/disable mode have to be set through the target"
" zone endpoints";
failure_response(ACTION, att);
return;
}
if ( basic_authorization(id, att) == false )
{
return;
}
auto zone = pool->get<Zone>(id);
if ( enable )
{
zone->enable();
state = Zone::ENABLED;
}
else
{
zone->disable();
state = Zone::DISABLED;
}
if ( nd.is_federation_master() || !nd.is_federation_enabled() )
{
pool->update(zone.get());
}
else
{
std::string tmpl_xml;
zone->to_xml(tmpl_xml);
ErrorCode ec = master_update_zone(id, tmpl_xml, att);
if ( ec != SUCCESS )
{
NebulaLog::error("ReM", att.resp_msg);
failure_response(ec, att);
return;
}
}
nd.set_zone_state(state);
success_response(id, att);
}

View File

@ -32,6 +32,7 @@ const char * ZoneServers::SERVER_ID_NAME = "ID";
Zone::Zone(int id, unique_ptr<Template> zone_template):
PoolObjectSQL(id, ZONE, "", -1, -1, "", "", one_db::zone_table),
state(ENABLED),
servers_template(false, '=', "SERVER_POOL"),
servers(0)
{
@ -217,6 +218,7 @@ string& Zone::to_xml(string& xml) const
"<ZONE>" <<
"<ID>" << oid << "</ID>" <<
"<NAME>" << name << "</NAME>" <<
"<STATE>" << state << "</STATE>" <<
obj_template->to_xml(template_xml) <<
servers_template.to_xml(server_xml) <<
"</ZONE>";
@ -234,12 +236,17 @@ int Zone::from_xml(const string& xml)
vector<xmlNodePtr> content;
int rc = 0;
int int_state;
// Initialize the internal XML object
update_from_str(xml);
// Get class base attributes
rc += xpath(oid, "/ZONE/ID", -1);
rc += xpath(name,"/ZONE/NAME", "not_found");
rc += xpath(int_state, "/ZONE/STATE", 0);
state = static_cast<ZoneState>( int_state );
// -------------------------------------------------------------------------
// Zone template
@ -335,6 +342,9 @@ int Zone::add_server(Template& tmpl, int& sid, string& xmlep, string& error)
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int Zone::delete_server(int id, string& error)
{
ZoneServer * zs;
@ -354,12 +364,18 @@ int Zone::delete_server(int id, string& error)
return 0;
}
unsigned int Zone::servers_size()
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
unsigned int Zone::servers_size() const
{
return servers->size();
}
ZoneServer * Zone::get_server(int server_id)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
ZoneServer * Zone::get_server(int server_id) const
{
return servers->get_server(server_id);
}