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 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 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 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))