def test_resource_constraints_negative_two_select_one(self): # Test that child 4 is the only one picked as # child 5 has only one host ("host4") which is included # in the negative constraints strategy = RandomSubsetStrategy(0.5, 2) strategy._get_constraints = self._get_constraints constraints = [ResourceConstraint(ResourceConstraintType.HOST, ['host1'], True), ResourceConstraint(ResourceConstraintType.HOST, ['host4'], True)] result = strategy.filter_child( [self.child_4, self.child_5], self.request, constraints) assert_that(result, has_length(1)) assert_that(result, contains_inanyorder(self.child_4)) constraints = [ResourceConstraint(ResourceConstraintType.HOST, ['host1', 'host4'], True)] result = strategy.filter_child( [self.child_4, self.child_5], self.request, constraints) assert_that(result, has_length(1)) assert_that(result, contains_inanyorder(self.child_4))
def test_resource_constraints_zero_constraints_min_fanout(self): strategy = RandomSubsetStrategy(0.5, 2) strategy._get_constraints = self._get_constraints result = strategy.filter_child( [self.child_1, self.child_2, self.child_3], self.request, []) assert_that(result, has_length(2))
def test_resource_constraints_negative_two_select_two(self): # Test that both children are picked as # child 4 has more than just "host1" # while child 5 has "host4" which is # not included in the negative constraints strategy = RandomSubsetStrategy(0.5, 2) strategy._get_constraints = self._get_constraints constraints = [ResourceConstraint(ResourceConstraintType.HOST, ['host1'], True), ResourceConstraint(ResourceConstraintType.HOST, ['host7'], True)] result = strategy.filter_child( [self.child_4, self.child_5], self.request, constraints) assert_that(result, has_length(2)) assert_that(result, contains_inanyorder(self.child_4, self.child_5)) # Now try with a single constraint constraints = [ResourceConstraint(ResourceConstraintType.HOST, ['host1', 'host7'], True)] result = strategy.filter_child( [self.child_4, self.child_5], self.request, constraints) assert_that(result, has_length(2)) assert_that(result, contains_inanyorder(self.child_4, self.child_5))
def get_placement_strategy(self, root_config): """ For now this method only accepts root configuration. This can later be extended to get config for branch and leaf schedulers as well. """ return RandomSubsetStrategy(root_config["fanout_ratio"], root_config["min_fanout"], root_config["max_fanout"])
def test_resource_constraints_no_match(self): strategy = RandomSubsetStrategy(0.5, 2) strategy._get_constraints = self._get_constraints result = strategy.filter_child( [self.child_1, self.child_2, self.child_3], self.request, [ResourceConstraint(ResourceConstraintType.DATASTORE, ['never_found'])]) assert_that(result, has_length(0))
def test_resource_constraints_one_constraints(self): strategy = RandomSubsetStrategy(0.5, 2) strategy._get_constraints = self._get_constraints result = strategy.filter_child( [self.child_1, self.child_2, self.child_3], self.request, [ResourceConstraint(ResourceConstraintType.DATASTORE, ['datastore1'])]) assert_that(result, has_length(2)) assert_that(result, contains_inanyorder(self.child_1, self.child_2))
def test_resource_constraints_negative_all_match(self): strategy = RandomSubsetStrategy(0.5, 2) strategy._get_constraints = self._get_constraints constraints = [ResourceConstraint(ResourceConstraintType.HOST, ['host6', 'host7'], True)] result = strategy.filter_child( [self.child_4, self.child_5], self.request, constraints) assert_that(result, has_length(2)) assert_that(result, contains_inanyorder(self.child_4, self.child_5))
def test_resource_constraints_negative_no_match(self): strategy = RandomSubsetStrategy(0.5, 2) strategy._get_constraints = self._get_constraints constraints = [ResourceConstraint( ResourceConstraintType.HOST, ['host1', 'host2', 'host3', 'host4'], True)] result = strategy.filter_child( [self.child_4, self.child_5], self.request, constraints) assert_that(result, has_length(0))
def test_resource_constraints_availability_zone_no_match(self): strategy = RandomSubsetStrategy(0.5, 2) strategy._get_constraints = self._get_constraints constraints = [ ResourceConstraint(ResourceConstraintType.AVAILABILITY_ZONE, ['zone1'], False), ResourceConstraint(ResourceConstraintType.DATASTORE, ['datastore2'], False)] result = strategy.filter_child( [self.child_1, self.child_6, self.child_7], self.request, constraints) assert_that(result, has_length(0))
def __init__(self, scheduler_id, ut_ratio, enable_health_checker=True): """Create a new branch scheduler. :param scheduler_id: scheduler id :type scheduler_id: str """ self._logger = logging.getLogger(__name__) self._logger.info("Creating branch scheduler: %s" % scheduler_id) self._place_strategy = RandomSubsetStrategy(PLACE_FAN_OUT_RATIO, MIN_PLACE_FAN_OUT) self._scheduler_id = scheduler_id self._schedulers = [] self._scorer = DefaultScorer(ut_ratio) self._threadpool = None self._scheduler_client = None self._initialize_services(scheduler_id)
def __init__(self, scheduler_id, ut_ratio, enable_health_checker=True): """Create a new leaf scheduler. :param scheduler_id: scheduler id :type scheduler_id: str :type enable_health_checker: enables health checking of children. """ self._logger = logging.getLogger(__name__) self._logger.info("Creating leaf scheduler: %s" % scheduler_id) self.lock = threading.RLock() self._latch = CountUpDownLatch() self._place_strategy = RandomSubsetStrategy(PLACE_FAN_OUT_RATIO, MIN_PLACE_FAN_OUT, MAX_PLACE_FAN_OUT) self._scheduler_id = scheduler_id self._hosts = [] self._scorer = DefaultScorer(ut_ratio) self._threadpool = None self._initialize_services(scheduler_id) self._health_checker = None self._enable_health_checker = enable_health_checker self._configured = ConfigStates.UNINITIALIZED