Statistics
| Branch: | Tag: | Revision:

one / src / scheduler / include / Scheduler.h @ 1f571426

History | View | Annotate | Download (6.09 KB)

1
/* -------------------------------------------------------------------------- */
2
/* Copyright 2002-2017, OpenNebula Project, OpenNebula Systems                */
3
/*                                                                            */
4
/* Licensed under the Apache License, Version 2.0 (the "License"); you may    */
5
/* not use this file except in compliance with the License. You may obtain    */
6
/* a copy of the License at                                                   */
7
/*                                                                            */
8
/* http://www.apache.org/licenses/LICENSE-2.0                                 */
9
/*                                                                            */
10
/* Unless required by applicable law or agreed to in writing, software        */
11
/* distributed under the License is distributed on an "AS IS" BASIS,          */
12
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   */
13
/* See the License for the specific language governing permissions and        */
14
/* limitations under the License.                                             */
15
/* -------------------------------------------------------------------------- */
16

    
17
#ifndef SCHEDULER_H_
18
#define SCHEDULER_H_
19

    
20
#include "Log.h"
21
#include "HostPoolXML.h"
22
#include "VMGroupPoolXML.h"
23
#include "UserPoolXML.h"
24
#include "ClusterPoolXML.h"
25
#include "DatastorePoolXML.h"
26
#include "VirtualMachinePoolXML.h"
27
#include "SchedulerPolicy.h"
28
#include "ActionManager.h"
29
#include "AclXML.h"
30

    
31
using namespace std;
32

    
33
/* -------------------------------------------------------------------------- */
34
/* -------------------------------------------------------------------------- */
35

    
36
extern "C" void * scheduler_action_loop(void *arg);
37
class  SchedulerTemplate;
38
/**
39
 *  The Scheduler class. It represents the scheduler ...
40
 */
41

    
42
class Scheduler: public ActionListener
43
{
44
public:
45

    
46
    void start();
47

    
48
    virtual void register_policies(const SchedulerTemplate& conf) = 0;
49

    
50
protected:
51

    
52
    Scheduler():
53
        acls(0),
54
        upool(0),
55
        hpool(0),
56
        clpool(0),
57
        dspool(0),
58
        img_dspool(0),
59
        vmpool(0),
60
        vm_roles_pool(0),
61
        vmgpool(0),
62
        vmapool(0),
63
        timer(0),
64
        one_xmlrpc(""),
65
        machines_limit(0),
66
        dispatch_limit(0),
67
        host_dispatch_limit(0)
68
    {
69
        am.addListener(this);
70
    };
71

    
72
    virtual ~Scheduler()
73
    {
74
        delete hpool;
75
        delete clpool;
76

    
77
        delete vmpool;
78
        delete vm_roles_pool;
79
        delete vmapool;
80

    
81
        delete dspool;
82
        delete img_dspool;
83

    
84
        delete upool;
85
        delete vmgpool;
86

    
87
        delete acls;
88
    };
89

    
90
    // ---------------------------------------------------------------
91
    // Pools
92
    // ---------------------------------------------------------------
93
    AclXML *      acls;
94
    UserPoolXML * upool;
95

    
96
    HostPoolXML *    hpool;
97
    ClusterPoolXML * clpool;
98

    
99
    SystemDatastorePoolXML * dspool;
100
    ImageDatastorePoolXML *  img_dspool;
101

    
102
    VirtualMachinePoolXML *     vmpool;
103
    VirtualMachineRolePoolXML * vm_roles_pool;
104

    
105
    VMGroupPoolXML * vmgpool;
106

    
107
    VirtualMachineActionsPoolXML* vmapool;
108

    
109
    // ---------------------------------------------------------------
110
    // Scheduler Policies
111
    // ---------------------------------------------------------------
112

    
113
    void add_host_policy(SchedulerPolicy *policy)
114
    {
115
        host_policies.push_back(policy);
116
    }
117

    
118
    void add_ds_policy(SchedulerPolicy *policy)
119
    {
120
        ds_policies.push_back(policy);
121
    }
122

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

    
128
    // ---------------------------------------------------------------
129
    // Scheduler main methods
130
    // ---------------------------------------------------------------
131

    
132
    /**
133
     *  Gets the hosts that match the requirements of the pending VMs, also
134
     *  the capacity of the host is checked. If there is enough room to host the
135
     *  VM a share vector is added to the VM.
136
     */
137
    virtual void match_schedule();
138

    
139
    virtual void dispatch();
140

    
141
    /**
142
     * Retrieves the pools
143
     *
144
     * @return   0 on success
145
     *          -1 on error
146
     *          -2 if no VMs need to be scheduled
147
     */
148
    virtual int set_up_pools();
149

    
150
    virtual int do_scheduled_actions();
151

    
152
    virtual void do_vm_groups();
153

    
154
private:
155
    Scheduler(Scheduler const&){};
156

    
157
    Scheduler& operator=(Scheduler const&){return *this;};
158

    
159
    friend void * scheduler_action_loop(void *arg);
160

    
161
    // ---------------------------------------------------------------
162
    // Scheduling Policies
163
    // ---------------------------------------------------------------
164

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

    
169
    // ---------------------------------------------------------------
170
    // Configuration attributes
171
    // ---------------------------------------------------------------
172

    
173
    time_t  timer;
174

    
175
    string  one_xmlrpc;
176

    
177
    /**
178
     *  Limit of pending virtual machines to process from the pool.
179
     */
180
    unsigned int machines_limit;
181

    
182
    /**
183
     *  Limit of virtual machines to ask OpenNebula core to deploy.
184
     */
185
    unsigned int dispatch_limit;
186

    
187
    /**
188
     *  Limit of virtual machines to be deployed simultaneously to a given host.
189
     */
190
    unsigned int host_dispatch_limit;
191

    
192
    /**
193
     *  OpenNebula zone id.
194
     */
195
    int zone_id;
196

    
197
    /**
198
     * oned runtime configuration values
199
     */
200
     Template oned_conf;
201

    
202
    // ---------------------------------------------------------------
203
    // Timer to periodically schedule and dispatch VMs
204
    // ---------------------------------------------------------------
205

    
206
    pthread_t       sched_thread;
207
    ActionManager   am;
208

    
209
    // -------------------------------------------------------------------------
210
    // Action Listener interface
211
    // -------------------------------------------------------------------------
212
    void timer_action(const ActionRequest& ar);
213

    
214
    void finalize_action(const ActionRequest& ar)
215
    {
216
        NebulaLog::log("SCHED",Log::INFO,"Stopping the scheduler...");
217
    };
218
};
219

    
220
#endif /*SCHEDULER_H_*/