def chronos_services_running_here(): """See what chronos services are being run by a mesos-slave on this host. :returns: A list of triples of (service, instance, port)""" return mesos_services_running_here( framework_filter=lambda fw: fw['name'].startswith('chronos'), parse_service_instance_from_executor_id=lambda task_id: decompose_job_id(task_id.split(MESOS_TASK_SPACER)[3]), )
def marathon_services_running_here(): """See what marathon services are being run by a mesos-slave on this host. :returns: A list of triples of (service, instance, port)""" return mesos_services_running_here( framework_filter=lambda fw: fw['name'].startswith('marathon'), parse_service_instance_from_executor_id= parse_service_instance_from_executor_id, )
def paasta_native_services_running_here(hostname=None, framework_id=None): """See what paasta_native services are being run by a mesos-slave on this host. :returns: A list of triples of (service, instance, port) :param hostname: query the mesos slave on this hostname. :param framework_id: If specified, return info only for tasks belonging to this framework id. """ def framework_filter(fw): return fw['name'].startswith('paasta_native ') and ( framework_id is None or fw['id'] == framework_id) return mesos_tools.mesos_services_running_here( framework_filter=framework_filter, parse_service_instance_from_executor_id= parse_service_instance_from_executor_id, hostname=hostname)
def test_mesos_services_running_here(): with mock.patch("paasta_tools.mesos_tools.get_local_slave_state", autospec=True) as mock_get_local_slave_state: mock_state = { "frameworks": [ { "name": "marathon2", "executors": [ { "id": "thing.main", "resources": { "ports": "[31062-31062]" }, "tasks": [{ "state": "TASK_RUNNING" }], }, { "id": "thing.another", "tasks": [{ "state": "TASK_LOST" }] }, ], }, { "name": "tron", "executors": [ { "id": "c.main", "resources": {}, "tasks": [{ "state": "TASK_RUNNING" }], }, { "id": "c.another", "resources": {}, "tasks": [{ "state": "TASK_RUNNING" }], }, ], }, ] } mock_get_local_slave_state.return_value = {} assert (mesos_tools.mesos_services_running_here( lambda _: True, lambda id_str: id_str.split(".")) == []) mock_get_local_slave_state.return_value = mock_state expected = [ ("thing", "main", 31062), ("c", "main", None), ("c", "another", None), ] assert (mesos_tools.mesos_services_running_here( lambda _: True, lambda id_str: id_str.split(".")) == expected) mock_fw_filter = mock.Mock(side_effect=[True, False]) expected = [("thing", "main", 31062)] assert (mesos_tools.mesos_services_running_here( mock_fw_filter, lambda id_str: id_str.split(".")) == expected) mock_parse_service_instance_from_executor_id = mock.Mock( side_effect=[("thing", "main"), ValueError, ("c", "another")]) expected = [("thing", "main", 31062), ("c", "another", None)] assert (mesos_tools.mesos_services_running_here( lambda _: True, mock_parse_service_instance_from_executor_id) == expected)
def tron_jobs_running_here() -> List[Tuple[str, str, int]]: return mesos_services_running_here( framework_filter=lambda fw: fw["name"].startswith("tron"), parse_service_instance_from_executor_id= parse_service_instance_from_executor_id, )
def test_mesos_services_running_here(): with mock.patch( 'paasta_tools.mesos_tools.get_local_slave_state', autospec=True, ) as mock_get_local_slave_state: mock_state = { "frameworks": [ { "name": "marathon2", "executors": [ { "id": "thing.main", "resources": { "ports": "[31062-31062]", }, "tasks": [ { "state": "TASK_RUNNING", }, ], }, { "id": "thing.another", "tasks": [ { "state": "TASK_LOST", }, ], }, ], }, { "name": "chronos", "executors": [ { "id": "c.main", "resources": {}, "tasks": [ { "state": "TASK_RUNNING", }, ], }, { "id": "c.another", "resources": {}, "tasks": [ { "state": "TASK_RUNNING", }, ], }, ], }, ], } mock_get_local_slave_state.return_value = {} assert mesos_tools.mesos_services_running_here( lambda _: True, lambda id_str: id_str.split('.')) == [] mock_get_local_slave_state.return_value = mock_state expected = [('thing', 'main', 31062), ('c', 'main', None), ('c', 'another', None)] assert mesos_tools.mesos_services_running_here( lambda _: True, lambda id_str: id_str.split('.')) == expected mock_fw_filter = mock.Mock(side_effect=[True, False]) expected = [('thing', 'main', 31062)] assert mesos_tools.mesos_services_running_here( mock_fw_filter, lambda id_str: id_str.split('.')) == expected mock_parse_service_instance_from_executor_id = mock.Mock(side_effect=[ ('thing', 'main'), ValueError, ('c', 'another'), ]) expected = [('thing', 'main', 31062), ('c', 'another', None)] assert mesos_tools.mesos_services_running_here( lambda _: True, mock_parse_service_instance_from_executor_id, ) == expected