mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-19 11:22:55 +09:00
Feature #1554: Scheduler adds a new element, CLUSTER_TEMPLATE, to each Host after the pool is refreshed
This commit is contained in:
1 parent
afc4cddfd5
commit
b676646656
10 files changed
+254
-2
No files matched your search
@@ -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<ClusterXML *>(PoolXML::get(oid));
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
int get_suitable_nodes(vector<xmlNodePtr>& 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_ */
|
||||
@@ -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_ */
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
#include "PoolXML.h"
|
||||
#include "HostXML.h"
|
||||
#include "ClusterPoolXML.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -45,6 +46,14 @@ public:
|
||||
return static_cast<HostXML *>(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<xmlNodePtr>& content)
|
||||
|
||||
@@ -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). */
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<int,ObjectXML*>(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;
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
@@ -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<int,ObjectXML*>::iterator it;
|
||||
|
||||
ClusterXML* cluster;
|
||||
HostXML* host;
|
||||
|
||||
int cluster_id;
|
||||
vector<xmlNodePtr> nodes;
|
||||
|
||||
for (it=objects.begin(); it!=objects.end(); it++)
|
||||
{
|
||||
host = static_cast<HostXML*>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
@@ -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());
|
||||
|
||||
@@ -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)
|
||||
@@ -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
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
Reference in new issue
Block a user