Commit 4783e1b7 authored by S. Lackner's avatar S. Lackner

[sched] extend resource management in compute resources and special resources

parent 788949b8
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
""" """
import sys import sys
from .resource import Resources, Resource from .resource import Resources, Resource, ComputeResource
from .utils import ListView from .utils import ListView
...@@ -23,6 +23,7 @@ class Allocation: ...@@ -23,6 +23,7 @@ class Allocation:
def __init__(self, start_time, walltime=None, resources=[], job=None): def __init__(self, start_time, walltime=None, resources=[], job=None):
self._job = None self._job = None
self._resources = [] self._resources = []
self._special_resources = []
self._scheduler = None self._scheduler = None
...@@ -57,6 +58,11 @@ class Allocation: ...@@ -57,6 +58,11 @@ class Allocation:
"""The list of assigned resources.""" """The list of assigned resources."""
return ListView(self._resources) return ListView(self._resources)
@property
def special_resources(self):
"""The list of assigned special resources."""
return ListView(self._special_resources)
@property @property
def allocated(self): def allocated(self):
"""Whether or not this allocation is currently allocated (active).""" """Whether or not this allocation is currently allocated (active)."""
...@@ -199,7 +205,10 @@ class Allocation: ...@@ -199,7 +205,10 @@ class Allocation:
""" """
assert not self.allocated and not self.previously_allocated, "Allocation is in invalid state" assert not self.allocated and not self.previously_allocated, "Allocation is in invalid state"
resource._do_add_allocation(self) resource._do_add_allocation(self)
self._resources.append(resource) if not isinstance(resource, ComputeResource):
self._special_resources.append(resource)
else:
self._resources.append(resource)
def remove_resource(self, resource): def remove_resource(self, resource):
"""Removes a resource from this allocation. """Removes a resource from this allocation.
...@@ -208,13 +217,18 @@ class Allocation: ...@@ -208,13 +217,18 @@ class Allocation:
""" """
assert not self.allocated and not self.previously_allocated, "Allocation is in invalid state" assert not self.allocated and not self.previously_allocated, "Allocation is in invalid state"
resource._do_remove_allocation(self) resource._do_remove_allocation(self)
self._resources.remove(resource) if not isinstance(resource, ComputeResource):
self._special_resources.remove(resource)
else:
self._resources.remove(resource)
def remove_all_resources(self): def remove_all_resources(self):
"""Removes all resources from this allocation.""" """Removes all resources from this allocation."""
assert not self.allocated and not self.previously_allocated, "Allocation is in invalid state" assert not self.allocated and not self.previously_allocated, "Allocation is in invalid state"
for r in self._resources.copy(): for r in self._resources.copy():
self.remove_resource(r) self.remove_resource(r)
for r in self._special_resources.copy():
self.remove_resource(r)
def allocate(self, scheduler, range1, *more_ranges): def allocate(self, scheduler, range1, *more_ranges):
"""Mark node ranges from this allocation as `computing` and set the allocation """Mark node ranges from this allocation as `computing` and set the allocation
......
This diff is collapsed.
...@@ -11,7 +11,7 @@ from abc import ABCMeta, abstractmethod ...@@ -11,7 +11,7 @@ from abc import ABCMeta, abstractmethod
from batsim.batsim import BatsimScheduler, Batsim from batsim.batsim import BatsimScheduler, Batsim
from .resource import Resources, Resource from .resource import Resources, ComputeResource
from .job import Job, Jobs from .job import Job, Jobs
from .reply import ConsumedEnergyReply from .reply import ConsumedEnergyReply
from .utils import DictWrapper from .utils import DictWrapper
...@@ -241,6 +241,8 @@ class Scheduler(metaclass=ABCMeta): ...@@ -241,6 +241,8 @@ class Scheduler(metaclass=ABCMeta):
self._jobs = Jobs() self._jobs = Jobs()
self._resources = Resources() self._resources = Resources()
self._find_resource_handler = []
self._workload_map = {} self._workload_map = {}
self._dynamic_workload = WorkloadDescription(name="DYNAMIC_WORKLOAD") self._dynamic_workload = WorkloadDescription(name="DYNAMIC_WORKLOAD")
...@@ -303,6 +305,33 @@ class Scheduler(metaclass=ABCMeta): ...@@ -303,6 +305,33 @@ class Scheduler(metaclass=ABCMeta):
"""Whether or not time sharing is enabled.""" """Whether or not time sharing is enabled."""
return self._batsim.time_sharing return self._batsim.time_sharing
@property
def get_find_resource_handlers(self):
"""The functions to find resource requirements for jobs."""
return self._find_resource_handler
def register_find_resource_handler(self, handler):
"""Adds a resource handler for searching resource requirements for jobs.
:param handler: a function which should return an iterable
(or generator) containing `ResourceRequirement`
objects. The function should determine
absolutely necessary resource requirements
needed by this job. For example, when all jobs
should always allocate a specific external
special resource like allocating I/O nodes
not managed by Batsim.
Signature: scheduler, job
"""
self._find_resource_handler.append(handler)
def unregister_find_resource_handler(self, handler):
"""Removes a resource handler.
:param handler: the function to be removed
"""
self._find_resource_handler.remove(handler)
def run_scheduler_at(self, time): def run_scheduler_at(self, time):
"""Wake the scheduler at the given point in time (of the simulation).""" """Wake the scheduler at the given point in time (of the simulation)."""
self._batsim.wake_me_up_at(time) self._batsim.wake_me_up_at(time)
...@@ -421,12 +450,12 @@ class Scheduler(metaclass=ABCMeta): ...@@ -421,12 +450,12 @@ class Scheduler(metaclass=ABCMeta):
`super()._pre_init()` `super()._pre_init()`
""" """
for r in self._batsim.resources: for r in self._batsim.resources:
self._resources.add(Resource(self, self._resources.add(ComputeResource(self,
r["id"], id=r["id"],
r["name"], name=r["name"],
r["state"], resources_list=self.resources,
r["properties"], state=r["state"],
self.resources)) properties=r["properties"]))
self.info( self.info(
"{num_resources} resources registered", "{num_resources} resources registered",
num_resources=len( num_resources=len(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment