T = TypeVar('T')
-class BaseScheduler(object):
- """
- Base Scheduler Interface
-
- * requires a ServiceSpec
-
- `place(host_pool)` needs to return a List[HostPlacementSpec, ..]
- """
-
- def __init__(self, spec):
- # type: (ServiceSpec) -> None
- self.spec = spec
-
- def place(self, host_pool, count=None):
- # type: (List[T], Optional[int]) -> List[T]
- raise NotImplementedError
-
-
-class SimpleScheduler(BaseScheduler):
- """
- The most simple way to pick/schedule a set of hosts.
- 1) Shuffle the provided host_pool
- 2) Select from list up to :count
- """
-
- def __init__(self, spec: ServiceSpec):
- super(SimpleScheduler, self).__init__(spec)
-
- def place(self, host_pool, count=None):
- # type: (List[T], Optional[int]) -> List[T]
- if not host_pool:
- return []
- host_pool = [x for x in host_pool]
- return host_pool[:count]
-
-
class HostAssignment(object):
def __init__(self,
hosts: List[orchestrator.HostSpec],
daemons: List[orchestrator.DaemonDescription],
filter_new_host=None, # type: Optional[Callable[[str],bool]]
- scheduler=None, # type: Optional[BaseScheduler]
allow_colo: bool = False,
):
assert spec
self.spec = spec # type: ServiceSpec
- self.scheduler = scheduler if scheduler else SimpleScheduler(self.spec)
self.hosts: List[orchestrator.HostSpec] = hosts
self.filter_new_host = filter_new_host
self.service_name = spec.service_name()
return existing_slots, [], to_remove
# ask the scheduler to select additional slots
- to_add = self.scheduler.place(others, need)
+ to_add = others[:need]
logger.debug('Combine hosts with existing daemons %s + new hosts %s' % (
existing, to_add))
return existing_slots + to_add, to_add, to_remove