Skip to content

Commit

Permalink
F #2427: Added new functionality to scheduler
Browse files Browse the repository at this point in the history
  • Loading branch information
juanmont committed Oct 4, 2018
1 parent 5a839f1 commit bdea707
Show file tree
Hide file tree
Showing 7 changed files with 364 additions and 20 deletions.
11 changes: 11 additions & 0 deletions src/scheduler/include/Scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "ClusterPoolXML.h"
#include "DatastorePoolXML.h"
#include "VirtualMachinePoolXML.h"
#include "VirtualNetworkPoolXML.h"
#include "SchedulerPolicy.h"
#include "ActionManager.h"
#include "AclXML.h"
Expand Down Expand Up @@ -74,6 +75,7 @@ class Scheduler: public ActionListener
img_dspool(0),
vmpool(0),
vm_roles_pool(0),
vnetpool(0),
vmgpool(0),
vmapool(0),
timer(0),
Expand All @@ -93,6 +95,7 @@ class Scheduler: public ActionListener

delete vmpool;
delete vm_roles_pool;
delete vnetpool;
delete vmapool;

delete dspool;
Expand All @@ -119,6 +122,8 @@ class Scheduler: public ActionListener
VirtualMachinePoolXML * vmpool;
VirtualMachineRolePoolXML * vm_roles_pool;

VirtualNetworkPoolXML * vnetpool;

VMGroupPoolXML * vmgpool;

VirtualMachineActionsPoolXML* vmapool;
Expand All @@ -142,6 +147,11 @@ class Scheduler: public ActionListener
vm_policies.push_back(policy);
}

void add_net_policy(SchedulerPolicy *policy)
{
net_policies.push_back(policy);
}

// ---------------------------------------------------------------
// Scheduler main methods
// ---------------------------------------------------------------
Expand Down Expand Up @@ -182,6 +192,7 @@ class Scheduler: public ActionListener
vector<SchedulerPolicy *> host_policies;
vector<SchedulerPolicy *> ds_policies;
vector<SchedulerPolicy *> vm_policies;
vector<SchedulerPolicy *> net_policies;

// ---------------------------------------------------------------
// Configuration attributes
Expand Down
3 changes: 2 additions & 1 deletion src/scheduler/include/VirtualMachinePoolXML.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ class VirtualMachinePoolXML : public PoolXML
* @param vid the VM id
* @param hid the id of the target host
* @param resched the machine is going to be rescheduled
* @param extra template with result nics
*/
int dispatch(int vid, int hid, int dsid, bool resched) const;
int dispatch(int vid, int hid, int dsid, bool resched, string extra_template) const;

/**
* Update the VM template
Expand Down
49 changes: 49 additions & 0 deletions src/scheduler/include/VirtualMachineXML.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ class VirtualMachineXML : public ObjectXML
return ds_requirements;
}

const string& get_nic_requirements(int nic_id)
{
return nic_requirements[nic_id];
}

/**
* Return VM usage requirments
*/
Expand Down Expand Up @@ -204,6 +209,15 @@ class VirtualMachineXML : public ObjectXML
match_datastores.add_resource(oid);
}

/**
* Adds a matching network
* @param oid of the network
*/
void add_match_network(int oid)
{
match_networks.add_resource(oid);
}

/**
* Returns a vector of matched hosts
*/
Expand All @@ -220,6 +234,14 @@ class VirtualMachineXML : public ObjectXML
return match_datastores.get_resources();
}

/**
* Returns a vector of matched datastores
*/
const vector<Resource *> get_match_networks()
{
return match_networks.get_resources();
}

/**
* Sort the matched hosts for the VM
*/
Expand All @@ -236,6 +258,14 @@ class VirtualMachineXML : public ObjectXML
match_datastores.sort_resources();
}

/**
* Sort the matched networks for the VM
*/
void sort_match_networks()
{
match_networks.sort_resources();
}

/**
* Removes the matched hosts
*/
Expand All @@ -252,6 +282,14 @@ class VirtualMachineXML : public ObjectXML
match_datastores.clear();
}

/**
* Removes the matched networks
*/
void clear_match_networks()
{
match_networks.clear();
}

/**
* Marks the VM to be only deployed on public cloud hosts
*/
Expand Down Expand Up @@ -368,6 +406,11 @@ class VirtualMachineXML : public ObjectXML
*/
bool clear_log();

set<int> get_nics_ids()
{
return nics_ids_auto;
}

protected:

/**
Expand All @@ -383,6 +426,8 @@ class VirtualMachineXML : public ObjectXML

ResourceMatch match_datastores;

ResourceMatch match_networks;

bool only_public_cloud;

set<int> affined_vms;
Expand Down Expand Up @@ -415,6 +460,10 @@ class VirtualMachineXML : public ObjectXML
string ds_requirements;
string ds_rank;

map<int, string> nic_requirements;

set<int> nics_ids_auto;

VirtualMachineTemplate * vm_template; /**< The VM template */
VirtualMachineTemplate * user_template; /**< The VM user template */

Expand Down
4 changes: 3 additions & 1 deletion src/scheduler/src/pool/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ source_files=[
'VMGroupPoolXML.cc',
'VMGroupXML.cc',
'DatastorePoolXML.cc',
'DatastoreXML.cc']
'DatastoreXML.cc',
'VirtualNetworkPoolXML.cc',
'VirtualNetworkXML.cc']

# Build library
sched_env.StaticLibrary(lib_name, source_files)
7 changes: 4 additions & 3 deletions src/scheduler/src/pool/VirtualMachinePoolXML.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ int VirtualMachinePoolXML::load_info(xmlrpc_c::value &result)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

int VirtualMachinePoolXML::dispatch(int vid, int hid, int dsid, bool resched) const
int VirtualMachinePoolXML::dispatch(int vid, int hid, int dsid, bool resched, string extra_template) const
{
xmlrpc_c::value deploy_result;

Expand All @@ -174,12 +174,13 @@ int VirtualMachinePoolXML::dispatch(int vid, int hid, int dsid, bool resched) co
else
{
client->call("one.vm.deploy", // methodName
"iibi", // arguments format
"iibis", // arguments format
&deploy_result, // resultP
vid, // argument 1 (VM)
hid, // argument 2 (HOST)
false, // argument 3 (ENFORCE)
dsid); // argument 5 (SYSTEM SD)
dsid, // argument 5 (SYSTEM SD)
extra_template); // argument 6 (EXTRA TEMPLATE)
}
}
catch (exception const& e)
Expand Down
38 changes: 38 additions & 0 deletions src/scheduler/src/pool/VirtualMachineXML.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,32 @@ void VirtualMachineXML::init_attributes()
ds_requirements = automatic_ds_requirements;
}

// ------------------- NIC REQUIREMENTS -------------------------------------

vector<string> nics_ids;
vector<string> nics_requirement;

xpaths(nics_ids,"/VM/TEMPLATE/NIC[NETWORK_MODE='auto']/NIC_ID");
xpaths(nics_requirement,"/VM/TEMPLATE/NIC[NETWORK_MODE='auto']/REQUIREMENTS");

int nic_id;
string requirements;

for (size_t i = 0; i < nics_ids.size(); i++)
{
nic_id = atoi(nics_ids[i].c_str());

nics_ids_auto.insert(nic_id);
}

for (size_t i = 0; i < nics_ids.size() && i < nics_requirement.size(); i++)
{
nic_id = atoi(nics_ids[i].c_str());
requirements = nics_requirement[i];

nic_requirements[nic_id] = requirements;
}

// ---------------- HISTORY HID, DSID, RESCHED & TEMPLATE ------------------

xpath(hid, "/VM/HISTORY_RECORDS/HISTORY/HID", -1);
Expand Down Expand Up @@ -200,6 +226,18 @@ ostream& operator<<(ostream& os, VirtualMachineXML& vm)

os << endl;

os << "\tPRI\tID - NETWORKS"<< endl
<< "\t------------------------" << endl;

const vector<Resource *> net_resources = vm.match_networks.get_resources();

for (i = net_resources.rbegin(); i != net_resources.rend() ; i++)
{
os << "\t" << (*i)->priority << "\t" << (*i)->oid << endl;
}

os << endl;

return os;
};

Expand Down
Loading

0 comments on commit bdea707

Please sign in to comment.