Revision 1f571426

View differences:

share/etc/oned.conf
927 927
VM_RESTRICTED_ATTR = "DISK_COST"
928 928
VM_RESTRICTED_ATTR = "PCI"
929 929
VM_RESTRICTED_ATTR = "EMULATOR"
930
VM_RESTRICTED_ATTR = "USER_PRIORITY"
930 931
#VM_RESTRICTED_ATTR = "USER_INPUTS/CPU"
931 932
#VM_RESTRICTED_ATTR = "USER_INPUTS/MEMORY"
932 933
#VM_RESTRICTED_ATTR = "USER_INPUTS/VCPU"
src/scheduler/include/Scheduler.h
120 120
        ds_policies.push_back(policy);
121 121
    }
122 122

  
123
    void add_vm_policy(SchedulerPolicy *policy)
124
    {
125
        vm_policies.push_back(policy);
126
    }
127

  
123 128
    // ---------------------------------------------------------------
124 129
    // Scheduler main methods
125 130
    // ---------------------------------------------------------------
......
159 164

  
160 165
    vector<SchedulerPolicy *> host_policies;
161 166
    vector<SchedulerPolicy *> ds_policies;
167
    vector<SchedulerPolicy *> vm_policies;
162 168

  
163 169
    // ---------------------------------------------------------------
164 170
    // Configuration attributes
src/scheduler/include/SchedulerPolicy.h
55 55
        policy(obj, priority);
56 56

  
57 57
        //2. Scale priorities
58
        sw.max =fabs(*max_element(priority.begin(), priority.end(), abs_cmp));
58
        sw.max = fabs(*max_element(priority.begin(), priority.end(), abs_cmp));
59 59

  
60 60
        transform(priority.begin(), priority.end(), priority.begin(), sw);
61 61

  
src/scheduler/include/VirtualMachinePoolXML.h
85 85
    };
86 86

  
87 87
    /**
88
     *
89
     *
88
     *  Returns a vector of matched hosts
89
     */
90
    const vector<Resource *> get_vm_resources()
91
    {
92
        return vm_resources.get_resources();
93
    }
94

  
95
    /**
96
     *  Sort the VMs in the pool
90 97
     */
91
    void clear()
98
    void sort_vm_resources()
92 99
    {
93
        flush();
100
        vm_resources.sort_resources();
94 101
    }
95 102

  
96 103
protected:
......
110 117
     * Do live migrations to resched VMs
111 118
     */
112 119
    bool live_resched;
120

  
121
private:
122
    /**
123
     *  Stores the list of vms, and it associated user prioty vm_resources.
124
     */
125
    ResourceMatch vm_resources;
113 126
};
114 127

  
115 128
/* -------------------------------------------------------------------------- */
src/scheduler/src/pool/VirtualMachinePoolXML.cc
26 26

  
27 27
    if ( rc == 0 )
28 28
    {
29
        map<int, ObjectXML*>::iterator it;
30

  
29 31
        if (objects.empty())
30 32
        {
31 33
            return -2;
32 34
        }
33 35

  
36
        vm_resources.clear();
37

  
38
        for ( it = objects.begin(); it != objects.end(); ++it )
39
        {
40
            vm_resources.add_resource(it->first);
41
        } 
42

  
34 43
        if (NebulaLog::log_level() >= Log::DDDEBUG)
35 44
        {
36
            map<int,ObjectXML*>::iterator it;
37 45

  
38 46
            oss << "Pending/rescheduling VM and capacity requirements:" << endl;
39 47

  
src/scheduler/src/sched/Scheduler.cc
1077 1077
    bool dispatched, matched;
1078 1078
    char * estr;
1079 1079

  
1080
    map<int, ObjectXML*>::const_iterator vm_it;
1080
    vector<Resource *>::const_reverse_iterator i, j, k;
1081 1081

  
1082
    vector<Resource *>::const_reverse_iterator i, j;
1082
    vector<SchedulerPolicy *>::iterator sp_it;
1083 1083

  
1084
    const map<int, ObjectXML*> pending_vms = vmpool->get_objects();
1084
    //--------------------------------------------------------------------------
1085
    // Schedule pending VMs according to the VM policies (e.g. User priority)
1086
    //--------------------------------------------------------------------------
1087
    for (sp_it = vm_policies.begin() ; sp_it != vm_policies.end() ; ++sp_it)
1088
    {
1089
        (*sp_it)->schedule(0);
1090
    }
1091

  
1092
    vmpool->sort_vm_resources();
1085 1093

  
1086
    dss << "Dispatching VMs to hosts:\n" << "\tVMID\tHost\tSystem DS\n"
1087
        << "\t-------------------------\n";
1094
    const vector<Resource *> vm_rs = vmpool->get_vm_resources();
1088 1095

  
1089 1096
    //--------------------------------------------------------------------------
1090
    // Dispatch each VM till we reach the dispatch limit
1097
    dss << "Dispatching VMs to hosts:\n" 
1098
        << "\tVMID\tPriority\tHost\tSystem DS\n"
1099
        << "\t--------------------------------------------------------------\n";
1091 1100
    //--------------------------------------------------------------------------
1092 1101

  
1093
    for (vm_it = pending_vms.begin();
1094
         vm_it != pending_vms.end() &&
1095
            ( dispatch_limit <= 0 || dispatched_vms < dispatch_limit );
1096
         vm_it++)
1102
    //--------------------------------------------------------------------------
1103
    // Dispatch each VM till we reach the dispatch limit
1104
    //--------------------------------------------------------------------------
1105
    for (k = vm_rs.rbegin(); k != vm_rs.rend() &&
1106
            ( dispatch_limit <= 0 || dispatched_vms < dispatch_limit ); ++k)
1097 1107
    {
1098 1108
        dispatched = false;
1099 1109

  
1100
        vm = static_cast<VirtualMachineXML*>(vm_it->second);
1110
        vm = vmpool->get((*k)->oid);
1101 1111

  
1102 1112
        const vector<Resource *> resources = vm->get_match_hosts();
1103 1113

  
......
1273 1283
            //------------------------------------------------------------------
1274 1284
            // Dispatch and update host and DS capacity, and dispatch counters
1275 1285
            //------------------------------------------------------------------
1276
            if (vmpool->dispatch(vm_it->first, hid, dsid, vm->is_resched()) != 0)
1286
            if (vmpool->dispatch((*k)->oid, hid, dsid, vm->is_resched()) != 0)
1277 1287
            {
1278 1288
                continue;
1279 1289
            }
1280 1290

  
1281
            dss << "\t" << vm_it->first << "\t" << hid << "\t" << dsid << "\n";
1291
            //------------------------------------------------------------------
1292
            dss << "\t" << (*k)->oid << "\t" << (*k)->priority << "\t\t" << hid
1293
                << "\t" << dsid << "\n";
1294
            //------------------------------------------------------------------
1282 1295

  
1283 1296
            // DS capacity skip VMs deployed in public cloud hosts
1284 1297
            if (!host->is_public_cloud())
......
1347 1360
        }
1348 1361
    }
1349 1362

  
1350
    if (vm_it != pending_vms.end())
1363
    if (k != vm_rs.rend())
1351 1364
    {
1352 1365
        dss << endl << "MAX_DISPATCH limit of " << dispatch_limit << " reached, "
1353
            << std::distance(vm_it, pending_vms.end())
1366
            << std::distance(k, vm_rs.rend())
1354 1367
            << " VMs were not dispatched";
1355 1368
    }
1356 1369

  
src/scheduler/src/sched/mm_sched.cc
17 17
#include "Scheduler.h"
18 18
#include "SchedulerTemplate.h"
19 19
#include "RankPolicy.h"
20
#include "UserPriorityPolicy.h"
20 21
#include <unistd.h>
21 22
#include <sys/types.h>
22 23
#include <sys/stat.h>
......
32 33
{
33 34
public:
34 35

  
35
    RankScheduler():Scheduler(),rp_host(0),rp_ds(0){};
36
    RankScheduler():Scheduler(),rp_host(0),rp_ds(0),rp_vm(0){};
36 37

  
37 38
    ~RankScheduler()
38 39
    {
39
        if ( rp_host != 0 )
40
        {
41
            delete rp_host;
42
        }
43

  
44
        if ( rp_ds != 0 )
45
        {
46
            delete rp_ds;
47
        }
40
        delete rp_host;
41
        delete rp_ds;
42

  
43
        delete rp_vm;
48 44
    };
49 45

  
50 46
    void register_policies(const SchedulerTemplate& conf)
......
56 52
        rp_ds = new RankDatastorePolicy(dspool, conf.get_ds_policy(), 1.0);
57 53

  
58 54
        add_ds_policy(rp_ds);
55

  
56
        rp_vm = new UserPriorityPolicy(vmpool, 1.0);
57

  
58
        add_vm_policy(rp_vm);
59 59
    };
60 60

  
61 61
private:
62 62
    RankPolicy * rp_host;
63 63
    RankPolicy * rp_ds;
64

  
65
    UserPriorityPolicy * rp_vm;
64 66
};
65 67

  
66 68
int main(int argc, char **argv)

Also available in: Unified diff