Project

General

Profile

Revision 693

- Separated constructor from initialization code in Manager
- Added dynamic loading of pricing policies

View differences:

branches/1.1/src/haizea/core/manager.py
52 52
from haizea.core.rpcserver import RPCServer
53 53
from haizea.common.utils import abstract, round_datetime, Singleton, import_class, OpenNebulaXMLRPCClientSingleton
54 54
from haizea.common.opennebula_xmlrpc import OpenNebulaXMLRPCClient
55
from haizea.pluggable.policies import admission_class_mappings, preemption_class_mappings, host_class_mappings 
55
from haizea.pluggable.policies import admission_class_mappings, preemption_class_mappings, host_class_mappings, pricing_mappings
56 56
from haizea.pluggable.accounting import probe_class_mappings
57 57

  
58 58
import operator
......
91 91
        pidfile -- When running as a daemon, file to save pid to
92 92
        """
93 93
        self.config = config
94
        
94
        self.daemon = daemon
95
        self.pidfile = pidfile
96

  
97
    # Has to be in a separate function since some pluggable modules need to
98
    # access the Manager singleton
99
    def __initialize(self):
95 100
        # Create the RM components
96 101
        
97
        mode = config.get("mode")
102
        mode = self.config.get("mode")
98 103
        
99
        self.daemon = daemon
100
        self.pidfile = pidfile
101 104

  
102 105
        if mode == "simulated":
103 106
            # Simulated-time simulations always run in the foreground
......
157 160
            else:
158 161
                site = Site.from_resources_string(resources)
159 162
    
160
            deploy_bandwidth = config.get("imagetransfer-bandwidth")
163
            deploy_bandwidth = self.config.get("imagetransfer-bandwidth")
161 164
            info_enact = SimulatedResourcePoolInfo(site)
162 165
            vm_enact = SimulatedVMEnactment()
163 166
            deploy_enact = SimulatedDeploymentEnactment(deploy_bandwidth)
......
205 208
        host_selection = import_class(host_selection)
206 209
        host_selection = host_selection(slottable)
207 210

  
208
        self.policy = PolicyManager(admission, preemption, host_selection)
211
        pricing = self.config.get("policy.pricing")
212
        pricing = pricing_mappings.get(pricing, pricing)
213
        pricing = import_class(pricing)
214
        pricing = pricing(slottable)
209 215

  
216
        self.policy = PolicyManager(admission, preemption, host_selection, pricing)
217

  
210 218
        # Preparation scheduler
211 219
        if preparation_type == constants.PREPARATION_UNMANAGED:
212 220
            preparation_scheduler = UnmanagedPreparationScheduler(slottable, resourcepool, deploy_enact)
......
339 347

  
340 348
    def start(self):
341 349
        """Starts the resource manager"""
350
        
351
        self.__initialize()
352

  
342 353
        self.logger.info("Starting resource manager")
343 354
        
344 355
        for frontend in self.frontends:
branches/1.1/src/haizea/core/log.py
29 29
    
30 30
    def makeRecord(self, name, lvl, fn, lno, msg, args, exc_info, func=None, extra=None):
31 31
        # Modify "extra" parameter keyword
32
        try:
33
            haizeatime = get_clock().get_time()
34
        except:
35
            # This is a kludge. Basically, calling get_clock will
36
            # fail if Manager is not yet fully constructed (since it's
37
            # a singleton). The more correct solution is to more cleanly
38
            # separate the initialization code in the Manager from the
39
            # initialization that actually involves interacting with
40
            # other components (which may want to use the logger)
41
            haizeatime = "                      "
32
        haizeatime = get_clock().get_time()
42 33
        extra = { "haizeatime" : haizeatime}
43 34
        if sys.version_info[1] <= 4:
44 35
            name = "[%s] %s" % (haizeatime, name)

Also available in: Unified diff