From b6766466568edeefcc3c243b34ac4b5f0b39ea84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Tue, 22 Jan 2013 14:24:36 +0100 Subject: [PATCH] Feature #1554: Scheduler adds a new element, CLUSTER_TEMPLATE, to each Host after the pool is refreshed --- src/scheduler/include/ClusterPoolXML.h | 56 +++++++++++++++++++++ src/scheduler/include/ClusterXML.h | 52 ++++++++++++++++++++ src/scheduler/include/HostPoolXML.h | 9 ++++ src/scheduler/include/HostXML.h | 6 +++ src/scheduler/include/Scheduler.h | 8 +++ src/scheduler/src/pool/ClusterPoolXML.cc | 62 ++++++++++++++++++++++++ src/scheduler/src/pool/HostPoolXML.cc | 40 ++++++++++++++- src/scheduler/src/pool/HostXML.cc | 1 + src/scheduler/src/pool/SConstruct | 3 +- src/scheduler/src/sched/Scheduler.cc | 19 ++++++++ 10 files changed, 254 insertions(+), 2 deletions(-) create mode 100644 src/scheduler/include/ClusterPoolXML.h create mode 100644 src/scheduler/include/ClusterXML.h create mode 100644 src/scheduler/src/pool/ClusterPoolXML.cc diff --git a/src/scheduler/include/ClusterPoolXML.h b/src/scheduler/include/ClusterPoolXML.h new file mode 100644 index 0000000000..31915c0d78 --- /dev/null +++ b/src/scheduler/include/ClusterPoolXML.h @@ -0,0 +1,56 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + + +#ifndef CLUSTER_POOL_XML_H_ +#define CLUSTER_POOL_XML_H_ + +#include "PoolXML.h" +#include "ClusterXML.h" + +using namespace std; + +class ClusterPoolXML : public PoolXML +{ +public: + + ClusterPoolXML(Client* client):PoolXML(client) + {}; + + /** + * Gets an object from the pool + * @param oid the object unique identifier + * + * @return a pointer to the object, 0 in case of failure + */ + ClusterXML * get(int oid) const + { + return static_cast(PoolXML::get(oid)); + }; + +protected: + + int get_suitable_nodes(vector& content) + { + return get_nodes("/CLUSTER_POOL/CLUSTER", content); + }; + + void add_object(xmlNodePtr node); + + int load_info(xmlrpc_c::value &result); +}; + +#endif /* CLUSTER_POOL_XML_H_ */ diff --git a/src/scheduler/include/ClusterXML.h b/src/scheduler/include/ClusterXML.h new file mode 100644 index 0000000000..01ef1604f0 --- /dev/null +++ b/src/scheduler/include/ClusterXML.h @@ -0,0 +1,52 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + + +#ifndef CLUSTER_XML_H_ +#define CLUSTER_XML_H_ + +#include "ObjectXML.h" + +using namespace std; + +class ClusterXML : public ObjectXML +{ +public: + ClusterXML(const string &xml_doc):ObjectXML(xml_doc) + { + init_attributes(); + }; + + ClusterXML(const xmlNodePtr node):ObjectXML(node) + { + init_attributes(); + }; + + int get_oid() const + { + return oid; + }; + +private: + int oid; + + void init_attributes() + { + oid = atoi(((*this)["/CLUSTER/ID"] )[0].c_str() ); + }; +}; + +#endif /* CLUSTER_XML_H_ */ diff --git a/src/scheduler/include/HostPoolXML.h b/src/scheduler/include/HostPoolXML.h index 78c1c308d8..7307d29929 100644 --- a/src/scheduler/include/HostPoolXML.h +++ b/src/scheduler/include/HostPoolXML.h @@ -20,6 +20,7 @@ #include "PoolXML.h" #include "HostXML.h" +#include "ClusterPoolXML.h" using namespace std; @@ -45,6 +46,14 @@ public: return static_cast(PoolXML::get(oid)); }; + /** + * For each Host in a cluster, adds the cluster template as a new + * Host xml element + * + * @param clpool Cluster pool + */ + void merge_clusters(ClusterPoolXML * clpool); + protected: int get_suitable_nodes(vector& content) diff --git a/src/scheduler/include/HostXML.h b/src/scheduler/include/HostXML.h index a9171ac146..8fd4c75f8e 100644 --- a/src/scheduler/include/HostXML.h +++ b/src/scheduler/include/HostXML.h @@ -40,6 +40,11 @@ public: return oid; }; + int get_cid() const + { + return cluster_id; + }; + /** * Tests whether a new VM can be hosted by the host or not * @param cpu needed by the VM (percentage) @@ -82,6 +87,7 @@ public: private: int oid; + int cluster_id; // Host share values int disk_usage; /**< Disk allocated to VMs (in Mb). */ diff --git a/src/scheduler/include/Scheduler.h b/src/scheduler/include/Scheduler.h index 54add04616..bc5f1e7b56 100644 --- a/src/scheduler/include/Scheduler.h +++ b/src/scheduler/include/Scheduler.h @@ -19,6 +19,7 @@ #include "Log.h" #include "HostPoolXML.h" +#include "ClusterPoolXML.h" #include "VirtualMachinePoolXML.h" #include "SchedulerPolicy.h" #include "ActionManager.h" @@ -47,6 +48,7 @@ protected: Scheduler(): hpool(0), + clpool(0), vmpool(0), acls(0), timer(0), @@ -67,6 +69,11 @@ protected: delete hpool; } + if ( clpool != 0) + { + delete clpool; + } + if ( vmpool != 0) { delete vmpool; @@ -88,6 +95,7 @@ protected: // --------------------------------------------------------------- HostPoolXML * hpool; + ClusterPoolXML * clpool; VirtualMachinePoolXML * vmpool; AclXML * acls; diff --git a/src/scheduler/src/pool/ClusterPoolXML.cc b/src/scheduler/src/pool/ClusterPoolXML.cc new file mode 100644 index 0000000000..aef376d4e2 --- /dev/null +++ b/src/scheduler/src/pool/ClusterPoolXML.cc @@ -0,0 +1,62 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +#include "ClusterPoolXML.h" + +void ClusterPoolXML::add_object(xmlNodePtr node) +{ + if ( node == 0 || node->children == 0 ) + { + NebulaLog::log("CLUSTER",Log::ERROR, + "XML Node does not represent a valid Cluster"); + + return; + } + + ClusterXML* cluster = new ClusterXML( node ); + + objects.insert( pair(cluster->get_oid(), cluster) ); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int ClusterPoolXML::load_info(xmlrpc_c::value &result) +{ + try + { + client->call( client->get_endpoint(), // serverUrl + "one.clusterpool.info", // methodName + "s", // arguments format + &result, // resultP + client->get_oneauth().c_str() // argument + ); + return 0; + } + catch (exception const& e) + { + ostringstream oss; + oss << "Exception raised: " << e.what(); + + NebulaLog::log("CLUSTER", Log::ERROR, oss); + + return -1; + } +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + diff --git a/src/scheduler/src/pool/HostPoolXML.cc b/src/scheduler/src/pool/HostPoolXML.cc index 316cca5a2d..6c7ba1e87c 100644 --- a/src/scheduler/src/pool/HostPoolXML.cc +++ b/src/scheduler/src/pool/HostPoolXML.cc @@ -16,7 +16,6 @@ #include "HostPoolXML.h" - int HostPoolXML::set_up() { ostringstream oss; @@ -89,3 +88,42 @@ int HostPoolXML::load_info(xmlrpc_c::value &result) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +void HostPoolXML::merge_clusters(ClusterPoolXML * clpool) +{ + map::iterator it; + + ClusterXML* cluster; + HostXML* host; + + int cluster_id; + vector nodes; + + for (it=objects.begin(); it!=objects.end(); it++) + { + host = static_cast(it->second); + + cluster_id = host->get_cid(); + + if(cluster_id != -1) //ClusterPool::NONE_CLUSTER_ID + { + cluster = clpool->get(cluster_id); + + if(cluster != 0) + { + nodes.clear(); + + cluster->get_nodes("/CLUSTER/TEMPLATE", nodes); + + if (!nodes.empty()) + { + host->add_node("/HOST", nodes[0], "CLUSTER_TEMPLATE"); + } + + cluster->free_nodes(nodes); + } + } + } +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ diff --git a/src/scheduler/src/pool/HostXML.cc b/src/scheduler/src/pool/HostXML.cc index 6ed7a562f4..58c65fdffe 100644 --- a/src/scheduler/src/pool/HostXML.cc +++ b/src/scheduler/src/pool/HostXML.cc @@ -26,6 +26,7 @@ float HostXML::hypervisor_mem; void HostXML::init_attributes() { oid = atoi(((*this)["/HOST/ID"] )[0].c_str() ); + cluster_id = atoi(((*this)["/HOST/CLUSTER_ID"] )[0].c_str() ); disk_usage = atoi(((*this)["/HOST/HOST_SHARE/DISK_USAGE"])[0].c_str()); mem_usage = atoi(((*this)["/HOST/HOST_SHARE/MEM_USAGE"])[0].c_str()); diff --git a/src/scheduler/src/pool/SConstruct b/src/scheduler/src/pool/SConstruct index b8ade4e4f6..f9b88433e3 100644 --- a/src/scheduler/src/pool/SConstruct +++ b/src/scheduler/src/pool/SConstruct @@ -25,7 +25,8 @@ source_files=[ 'HostPoolXML.cc', 'HostXML.cc', 'VirtualMachinePoolXML.cc', - 'VirtualMachineXML.cc'] + 'VirtualMachineXML.cc', + 'ClusterPoolXML.cc'] # Build library sched_env.StaticLibrary(lib_name, source_files) diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index 9ed5254d5f..afa9e4bbf3 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -175,6 +175,7 @@ void Scheduler::start() // ----------------------------------------------------------- hpool = new HostPoolXML(client, hypervisor_mem); + clpool = new ClusterPoolXML(client); vmpool = new VirtualMachinePoolXML(client, machines_limit, (live_rescheds == 1)); @@ -275,6 +276,24 @@ int Scheduler::set_up_pools() return rc; } + //-------------------------------------------------------------------------- + //Cleans the cache and get the cluster information + //-------------------------------------------------------------------------- + + rc = clpool->set_up(); + + if ( rc != 0 ) + { + return rc; + } + + //-------------------------------------------------------------------------- + //Add to each host the corresponding cluster template + //-------------------------------------------------------------------------- + + hpool->merge_clusters(clpool); + + //-------------------------------------------------------------------------- //Cleans the cache and get the pending VMs //--------------------------------------------------------------------------