def _check_chairmans_consistancy(self): """ Checks if chairman's in-memory view of the hierarchy is the same as the persisted view in zk. """ zk_root = get_hierarchy_from_zk(self.zk_client) chairmain_root = get_hierarchy_from_chairman(self.chairman_host, self.chairman_port, self.agent_host, self.agent_port) assert_that(zk_root, equal_to(chairmain_root))
def test_update_status(self): agent_host = 'localhost' agent_port1 = 20000 config = self.runtime.get_agent_config(agent_host, agent_port1, self.chairman_host, self.chairman_port) res = self.runtime.start_agent(config) _wait_for_configuration(self.root_sch_client, 1) root = get_hierarchy_from_zk(self.zk_client) # Update the hierarchy status root.update_status() # verify that the root scheduler and leaf are online assert_that(root.owner.status, is_(STATUS_ONLINE)) assert_that(len(root.children), is_(1)) assert_that(root.children.values()[0].owner.status, is_(STATUS_ONLINE)) # Kill both root scheduler and leaf host stop_service(self.runtime.root_procs[0]) self.runtime.stop_agent(res[0]) # Update the hierarchy status root.update_status() assert_that(root.owner.status, is_(STATUS_OFFLINE)) assert_that(root.children.values()[0].owner.status, is_(STATUS_OFFLINE)) # Start the root scheduler and leaf scheduler self.runtime.start_root_scheduler(self.root_conf) config = self.runtime.get_agent_config(agent_host, agent_port1, self.chairman_host, self.chairman_port) res = self.runtime.start_agent(config) (self.root_transport, self.root_sch_client) = create_root_client(self.root_port, self.root_host) # Wait for the root scheduler's leader election _wait_on_code(self.root_sch_client.get_schedulers, GetSchedulersResultCode.OK) # Check the status again root.update_status() # verify that the root scheduler and leaf are online assert_that(root.owner.status, is_(STATUS_ONLINE)) assert_that(root.children.values()[0].owner.status, is_(STATUS_ONLINE))
def _check_sim_state_with_chairman(self, root, hosts): """ Checks the pushed out hierarchy (simulator state) with chairman's view. """ # Mapping from root's config root_children = root.config.roles.schedulers[0].scheduler_children sim_leaf_host_mapping = set([(x.id, x.owner_host) for x in root_children]) # Mapping from zk state zk_root = get_hierarchy_from_zk(self.zk_client) zk_leaf_host_mapping = set([(leaf.id, leaf.owner.id) for leaf in zk_root.children.values()]) assert_that(sim_leaf_host_mapping, equal_to(zk_leaf_host_mapping)) (configured_hosts, missing, _) = self._sort_hosts(hosts) sim_leaf_owners = self._get_leaf_hosts(configured_hosts) # verify that the leaf schedulers have correct children for leaf in zk_root.children.values(): owner_host = leaf.owner.id sim_leaf_owner = configured_hosts.get(owner_host, None) if not sim_leaf_owner: if owner_host in missing and len(leaf.children): # Leaf has a single owner and its missing continue else: raise Exception("Leaf %s has a missing owner %s" % (leaf.id, owner_host)) if sim_leaf_owner.id not in sim_leaf_owners: raise Exception("chairman thinks host %s in a leaf, but" " hasn't been configured as a leaf" % (sim_leaf_owner.id)) # Verify that the leaf's child hosts are consistant sim_leaf_config = sim_leaf_owner.config.roles.schedulers[0] sim_leaf_child_hosts = set([x.id for x in sim_leaf_config.host_children]) zk_leaf_child_hosts = set(leaf.children.keys()) assert_that(sim_leaf_child_hosts, equal_to(zk_leaf_child_hosts))
def test_get_hierarchy_from_zk(self): agent_host = "localhost" agent_port1 = 20000 agent_port2 = 20001 agent_port3 = 20002 agent_ids = self._start_agents(agent_host, [agent_port1, agent_port2, agent_port3]) # The chairman will persist the schedulers then push the # configurations, thus after we detect that the root scheduler # has been configured we know that the leaf schedulers have already # been persisted to zk _wait_for_configuration(self.root_sch_client, 2) root = get_hierarchy_from_zk(self.zk_client) agent_list = [ (agent_ids[0], agent_host, agent_port1), (agent_ids[1], agent_host, agent_port2), (agent_ids[2], agent_host, agent_port3), ] # verify the hierarchy structure self._check_tree(root, self.root_host, self.root_port, self.leaf_fanout, agent_list)
def test_get_hierarchy_from_zk(self): agent_host = 'localhost' agent_port1 = 20000 agent_port2 = 20001 agent_port3 = 20002 agent_ids = self._start_agents(agent_host, [agent_port1, agent_port2, agent_port3]) # The chairman will persist the schedulers then push the # configurations, thus after we detect that the root scheduler # has been configured we know that the leaf schedulers have already # been persisted to zk _wait_for_configuration(self.root_sch_client, 2) root = get_hierarchy_from_zk(self.zk_client) agent_list = [(agent_ids[0], agent_host, agent_port1), (agent_ids[1], agent_host, agent_port2), (agent_ids[2], agent_host, agent_port3)] # verify the hierarchy structure self._check_tree(root, self.root_host, self.root_port, self.leaf_fanout, agent_list)
def test_update_status(self): agent_host = "localhost" agent_port1 = 20000 config = self.runtime.get_agent_config(agent_host, agent_port1, self.chairman_host, self.chairman_port) res = self.runtime.start_agent(config) _wait_for_configuration(self.root_sch_client, 1) root = get_hierarchy_from_zk(self.zk_client) # Update the hierarchy status root.update_status() # verify that the root scheduler and leaf are online assert_that(root.owner.status, is_(STATUS_ONLINE)) assert_that(len(root.children), is_(1)) assert_that(root.children.values()[0].owner.status, is_(STATUS_ONLINE)) # Kill both root scheduler and leaf host stop_service(self.runtime.root_procs[0]) self.runtime.stop_agent(res[0]) # Update the hierarchy status root.update_status() assert_that(root.owner.status, is_(STATUS_OFFLINE)) assert_that(root.children.values()[0].owner.status, is_(STATUS_OFFLINE)) # Start the root scheduler and leaf scheduler self.runtime.start_root_scheduler(self.root_conf) config = self.runtime.get_agent_config(agent_host, agent_port1, self.chairman_host, self.chairman_port) res = self.runtime.start_agent(config) (self.root_transport, self.root_sch_client) = create_root_client(self.root_port, self.root_host) # Wait for the root scheduler's leader election _wait_on_code(self.root_sch_client.get_schedulers, GetSchedulersResultCode.OK) # Check the status again root.update_status() # verify that the root scheduler and leaf are online assert_that(root.owner.status, is_(STATUS_ONLINE)) assert_that(root.children.values()[0].owner.status, is_(STATUS_ONLINE))