def _configure_host(self, client, scheduler_id, host_id): config_request = ConfigureRequest( self._stable_uuid(scheduler_id), Roles(), host_id=host_id) return client.configure(config_request)
def test_demote_agent_from_leaf_scheduler(self): request = GetSchedulersRequest() response = self.control_client.get_schedulers(request) # Agent starts without any schedulers assert_that(len(response.schedulers), is_(0)) # Configure the agent with a leaf scheduler leafId1 = stable_uuid("leaf scheduler") config_req = Host.GetConfigRequest() host_config = self.client.get_host_config(config_req).hostConfig leaf_scheduler = SchedulerRole(leafId1) leaf_scheduler.parent_id = stable_uuid("parent scheduler") leaf_scheduler.hosts = [host_config.agent_id] leaf_scheduler.host_children = [ChildInfo(id=host_config.agent_id, address="localhost", port=8835)] config_request = ConfigureRequest( leafId1, Roles([leaf_scheduler])) self.client.configure(config_request) request = GetSchedulersRequest() response = self.control_client.get_schedulers(request) # Verify that the agent has been configured assert_that(len(response.schedulers), is_(1)) assert_that(response.schedulers[0].role.id, is_(leafId1)) # Demote agent from leaf scheduler config_request = ConfigureRequest( leafId1, Roles([])) self.client.configure(config_request) # Verify that the agent isn't a scheduler request = GetSchedulersRequest() response = self.control_client.get_schedulers(request) assert_that(len(response.schedulers), is_(0))
def get_hierarchy_from_zk(zk_client): """ This function will read /hosts and /roles and try to construct a hierarchy. """ try: res = get_service_leader(zk_client, ROOT_SCHEDULER_SERVICE) if not res: log.debug("Couldn't find a root scheduler leader!") res = (None, None) if not zk_client.exists(ROLES_PREFIX): log.error("%s doesn't exist" % (ROLES_PREFIX, )) return root_host = Host(ROOT_SCHEDULER_ID, res[0], res[1]) root_sch = Scheduler(ROOT_SCHEDULER_ID, ROOT_SCHEDULER_TYPE, root_host) if not zk_client.exists(ROLES_PREFIX): log.debug("%s doesn't exist" % (ROLES_PREFIX, )) return # TODO(Maithem): cross reference with /hosts scheduler_hosts = zk_client.get_children(ROLES_PREFIX) for sch_host in scheduler_hosts: try: path = "%s/%s" % (ROLES_PREFIX, sch_host) (value, stat) = zk_client.get(path) role = Roles() deserialize(role, value) if (not role or not role.schedulers or len(role.schedulers) != 1): log.debug("Incorrect role for scheduler host %s" % (sch_host, )) continue leaf_role = role.schedulers[0] leaf = Scheduler(leaf_role.id, LEAF_SCHEDULER_TYPE, None, root_sch) for childHost in (leaf_role.host_children or []): host = Host(childHost.id, childHost.address, childHost.port, leaf) if childHost.id == sch_host: leaf.owner = host leaf.add_child(host) root_sch.add_child(leaf) except NoNodeError: log.debug("Scheduler host %s not found" % (sch_host, )) continue return root_sch except Exception, e: log.exception(e)
def configure_host(self): config_req = Host.GetConfigRequest() host_config = self.host_client.get_host_config(config_req).hostConfig leaf_scheduler = SchedulerRole(stable_uuid("leaf scheduler")) leaf_scheduler.parent_id = stable_uuid("parent scheduler") leaf_scheduler.hosts = [host_config.agent_id] config_request = ConfigureRequest(stable_uuid("leaf scheduler"), Roles([leaf_scheduler])) self.host_client.configure(config_request)
def test_get_leaf_scheduler(self): """Test agent introspection""" agent_host = 'localhost' agent_port = 20000 # Agent not online leaf = get_leaf_scheduler(agent_host, agent_port) assert_that(leaf, is_(None)) # Start an agent with an invalid chairman, so that it doesn't # get configured, because we want to configure it manually config = self.runtime.get_agent_config(agent_host, agent_port, "localhost", 24234) res = self.runtime.start_agent(config) agent_client = res[1] # Agent is online but not a leaf scheduler leaf = get_leaf_scheduler(agent_host, agent_port) assert_that(leaf, is_(None)) leafId1 = stable_uuid("leaf scheduler") config_req = THost.GetConfigRequest() host_config = agent_client.get_host_config(config_req).hostConfig leaf_scheduler = SchedulerRole(leafId1) leaf_scheduler.parent_id = stable_uuid("parent scheduler") leaf_scheduler.hosts = [host_config.agent_id] leaf_scheduler.host_children = [ ChildInfo(id=host_config.agent_id, address=agent_host, port=agent_port) ] config_request = ConfigureRequest(leafId1, Roles([leaf_scheduler])) resp = agent_client.configure(config_request) assert_that(resp.result, is_(ConfigureResultCode.OK)) leaf = get_leaf_scheduler(agent_host, agent_port) assert_that(leaf.id, not_none()) assert_that(leaf.type, is_(LEAF_SCHEDULER_TYPE)) assert_that(len(leaf.children), is_(1)) # Verify the owner host owner_host = leaf.owner assert_that(owner_host, not_none()) assert_that(owner_host.id, is_(host_config.agent_id)) assert_that(owner_host.address, is_(agent_host)) assert_that(owner_host.port, is_(agent_port)) assert_that(owner_host.parent, is_(leaf))
def configure_host(self, leaf_scheduler, roles=Roles()): config = HostConfiguration(self._agent_id, self._availability_zone_id, leaf_scheduler, roles) for observer in self._configuration_observers: observer(config)