logger = logging.getLogger(__name__)
T = TypeVar('T')
+
class BaseScheduler(object):
"""
Base Scheduler Interface
1) Shuffle the provided host_pool
2) Select from list up to :count
"""
+
def __init__(self, spec):
super(SimpleScheduler, self).__init__(spec)
def __init__(self,
spec, # type: ServiceSpec
get_hosts_func, # type: Callable
- get_daemons_func, # type: Callable[[str],List[orchestrator.DaemonDescription]]
- filter_new_host=None, # type: Optional[Callable[[str],bool]]
+ get_daemons_func, # type: Callable[[str],List[orchestrator.DaemonDescription]]
+ filter_new_host=None, # type: Optional[Callable[[str],bool]]
scheduler=None, # type: Optional[BaseScheduler]
):
assert spec and get_hosts_func and get_daemons_func
# if a host already has the anticipated daemon, merge it with the candidates
# to get a list of HostPlacementSpec that can be deployed on.
return list(merge_hostspecs(hosts_with_daemons, others))
-
+
def get_hosts_with_active_daemon(self, hosts: List[HostPlacementSpec]) -> List[HostPlacementSpec]:
active_hosts: List['HostPlacementSpec'] = []
for daemon in self.daemons:
active_hosts.append(h)
# remove duplicates before returning
return list(dict.fromkeys(active_hosts))
-
+
def prefer_hosts_with_active_daemons(self, hosts: List[HostPlacementSpec], count) -> List[HostPlacementSpec]:
# try to prefer host with active daemon if possible
active_hosts = self.get_hosts_with_active_daemon(hosts)
return self.scheduler.place(active_hosts, count)
else:
return list(merge_hostspecs(self.scheduler.place(active_hosts, count),
- self.scheduler.place(hosts, count - len(active_hosts))))
+ self.scheduler.place(hosts, count - len(active_hosts))))
# ask the scheduler to return a set of hosts with a up to the value of <count>
return self.scheduler.place(hosts, count)
]
# If none of the above and also no <count>
if self.spec.placement.count is None:
- raise OrchestratorValidationError("placement spec is empty: no hosts, no label, no pattern, no count")
+ raise OrchestratorValidationError(
+ "placement spec is empty: no hosts, no label, no pattern, no count")
# backward compatibility: consider an empty placements to be the same pattern = *
return [
HostPlacementSpec(x, '', '')
"""
r_names = {h.hostname for h in r}
return [h for h in l if h.hostname not in r_names]
-