def get_schedulers(self, request): """Return the list of current schedulers. :type request: GetSchedulersRequest: :rtype: GetSchedulersResponse """ scheduler_handler = common.services.get(Scheduler.Iface) _schedulers = scheduler_handler.get_schedulers response = GetSchedulersResponse() response.schedulers = [] for schId in _schedulers: scheduler = _schedulers[schId] schEntry = SchedulerEntry() schRole = SchedulerRole() schRole.host_children = [] schRole.id = schId for host in scheduler._get_hosts(): childHost = ChildInfo() childHost.id = host.id childHost.address = host.address childHost.port = host.port schRole.host_children.append(childHost) schEntry.role = schRole response.schedulers.append(schEntry) response.result = GetSchedulersResultCode.OK return response
def get_schedulers(self, request): """Return the list of current schedulers. :type request: GetSchedulersRequest: :rtype: GetSchedulersResponse """ scheduler_handler = common.services.get(Scheduler.Iface) _schedulers = scheduler_handler.get_schedulers response = GetSchedulersResponse() response.schedulers = [] for schId in _schedulers: scheduler = _schedulers[schId] schEntry = SchedulerEntry() schRole = SchedulerRole() schRole.host_children = [] schRole.id = schId for host in scheduler._get_hosts(): childHost = ChildInfo() childHost.id = host.id childHost.address = host.address childHost.port = host.port schRole.host_children.append(childHost) schEntry.role = schRole response.schedulers.append(schEntry) response.result = GetSchedulersResultCode.OK return response
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))