From af28d07d151ac2af6ec11f2c65ae26d856244822 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Sun, 26 Jan 2014 00:24:36 +0100 Subject: [PATCH] Feature #2653: Get zone id using xml-rpc api --- src/scheduler/include/Scheduler.h | 55 ++++++++------------ src/scheduler/src/sched/Scheduler.cc | 76 +++++++++++++++++++++++++--- 2 files changed, 90 insertions(+), 41 deletions(-) diff --git a/src/scheduler/include/Scheduler.h b/src/scheduler/include/Scheduler.h index 591a4aab3f..1a659f28d0 100644 --- a/src/scheduler/include/Scheduler.h +++ b/src/scheduler/include/Scheduler.h @@ -52,6 +52,8 @@ protected: clpool(0), vmpool(0), vmapool(0), + dspool(0), + img_dspool(0), acls(0), timer(0), url(""), @@ -66,45 +68,18 @@ protected: virtual ~Scheduler() { - if ( hpool != 0) - { - delete hpool; - } + delete hpool; + delete clpool; - if ( clpool != 0) - { - delete clpool; - } + delete vmpool; + delete vmapool; - if ( vmpool != 0) - { - delete vmpool; - } + delete dspool; + delete img_dspool; - if ( vmapool != 0) - { - delete vmapool; - } + delete acls; - if ( dspool != 0) - { - delete dspool; - } - - if ( img_dspool != 0) - { - delete img_dspool; - } - - if ( acls != 0) - { - delete acls; - } - - if ( client != 0) - { - delete client; - } + delete client; }; // --------------------------------------------------------------- @@ -201,11 +176,21 @@ private: */ float hypervisor_mem; + /** + * OpenNebula zone id. + */ + int zone_id; + /** * XML_RPC client */ Client * client; + /** + * oned runtime configuration values + */ + Template oned_conf; + // --------------------------------------------------------------- // Timer to periodically schedule and dispatch VMs // --------------------------------------------------------------- diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index e321fda2ee..65b8ef797a 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -215,9 +215,77 @@ void Scheduler::start() xmlInitParser(); - // ----------------------------------------------------------- + // ------------------------------------------------------------------------- + // Get oned configuration, and init zone_id + // ------------------------------------------------------------------------- + int tries = 0; + + while (tries < 3) + { + try + { + xmlrpc_c::value result; + + client->call(client->get_endpoint(), // serverUrl + "one.system.config", // methodName + "s", // arguments format + &result, // resultP + client->get_oneauth().c_str());// auth string + + vector values = + xmlrpc_c::value_array(result).vectorValueValue(); + + bool success = xmlrpc_c::value_boolean(values[0]); + string message = xmlrpc_c::value_string(values[1]); + + if (!success ||(oned_conf.from_xml(message) != 0)) + { + ostringstream oss; + oss << "Wrong oned response: " << message; + + NebulaLog::log("SCHED", Log::WARNING, message); + + tries++; + } + + break; + } + catch (exception const& e) + { + tries++; + NebulaLog::log("SCHED", Log::WARNING, e.what()); + } + + sleep(2); + } + + if (tries >= 3) + { + throw runtime_error("Error contacting oned, check sched.log"); + } + + vector fed; + + zone_id = 0; + + if (oned_conf.get("FEDERATION", fed) > 0) + { + const VectorAttribute * va=static_cast(fed[0]); + + if (va->vector_value("ZONE_ID", zone_id) != 0) + { + zone_id = 0; + } + } + + oss.str(""); + oss << "Configuring scheduler for Zone ID: " << zone_id; + + NebulaLog::log("SCHED", Log::INFO, oss); + + // ------------------------------------------------------------------------- // Pools - // ----------------------------------------------------------- + // ------------------------------------------------------------------------- hpool = new HostPoolXML(client, hypervisor_mem); clpool = new ClusterPoolXML(client); @@ -228,10 +296,6 @@ void Scheduler::start() dspool = new SystemDatastorePoolXML(client); img_dspool = new ImageDatastorePoolXML(client); - // TODO: In stand alone mode, Nebula.cc inits zone_id to 0. But we need - // to know the local zone id in the sched. Either from sched.conf, or - // from one.system.config - int zone_id = 0; acls = new AclXML(client, zone_id); // -----------------------------------------------------------