Skip to content

Commit

Permalink
Rename master -> head
Browse files Browse the repository at this point in the history
  • Loading branch information
刘宝 committed Jul 16, 2020
1 parent 87a7b8c commit 52460a3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
10 changes: 5 additions & 5 deletions dashboard/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import ray
import ray.new_dashboard.consts as dashboard_consts
import ray.new_dashboard.master as dashboard_master
import ray.new_dashboard.head as dashboard_head
import ray.new_dashboard.utils as dashboard_utils
import ray.ray_constants as ray_constants
import ray.services
Expand Down Expand Up @@ -77,7 +77,7 @@ def __init__(self,
self.port = port
self.temp_dir = temp_dir
self.dashboard_id = str(uuid.uuid4())
self.dashboard_master = dashboard_master.DashboardMaster(
self.dashboard_head = dashboard_head.DashboardHead(
redis_address=redis_address, redis_password=redis_password)

self.app = aiohttp.web.Application()
Expand All @@ -104,13 +104,13 @@ async def get_favicon(self, req) -> aiohttp.web.FileResponse:

async def run(self):
coroutines = [
self.dashboard_master.run(),
self.dashboard_head.run(),
aiohttp.web._run_app(self.app, host=self.host, port=self.port)
]
ip = ray.services.get_node_ip_address()
aioredis_client = await aioredis.create_redis_pool(
address=self.dashboard_master.redis_address,
password=self.dashboard_master.redis_password)
address=self.dashboard_head.redis_address,
password=self.dashboard_head.redis_password)
await aioredis_client.set(dashboard_consts.REDIS_KEY_DASHBOARD,
ip + ":" + str(self.port))
await asyncio.gather(*coroutines)
Expand Down
2 changes: 1 addition & 1 deletion dashboard/datacenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class DataSource:
class DataOrganizer:
@staticmethod
async def purge():
# These data sources are maintained by master,
# These data sources are maintained by DashboardHead,
# we do not needs to purge them:
# * agents
# * nodes
Expand Down
16 changes: 8 additions & 8 deletions dashboard/master.py → dashboard/head.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ def gcs_node_info_to_dict(message):
message, {"nodeId"}, including_default_value_fields=True)


class DashboardMaster:
class DashboardHead:
def __init__(self, redis_address, redis_password):
# Scan and import master modules for collecting http routes.
self._master_cls_list = dashboard_utils.get_all_modules(
dashboard_utils.DashboardMasterModule)
# Scan and import head modules for collecting http routes.
self._head_cls_list = dashboard_utils.get_all_modules(
dashboard_utils.DashboardHeadModule)
ip, port = redis_address.split(":")
# NodeInfoGcsService
self._gcs_node_info_stub = None
self._gcs_rpc_error_counter = 0
# Public attributes are accessible for all master modules.
# Public attributes are accessible for all head modules.
self.redis_address = (ip, int(port))
self.redis_password = redis_password
self.aioredis_client = None
Expand Down Expand Up @@ -109,11 +109,11 @@ async def _update_nodes(self):
dashboard_consts.UPDATE_NODES_INTERVAL_SECONDS)

def _load_modules(self):
"""Load dashboard master modules."""
"""Load dashboard head modules."""
modules = []
for cls in self._master_cls_list:
for cls in self._head_cls_list:
logger.info("Load %s: %s",
dashboard_utils.DashboardMasterModule.__name__, cls)
dashboard_utils.DashboardHeadModule.__name__, cls)
c = cls(self)
dashboard_utils.ClassMethodRouteTable.bind(c)
modules.append(c)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
routes = dashboard_utils.ClassMethodRouteTable


class ReportMaster(dashboard_utils.DashboardMasterModule):
def __init__(self, dashboard_master):
super().__init__(dashboard_master)
class ReportHead(dashboard_utils.DashboardHeadModule):
def __init__(self, dashboard_head):
super().__init__(dashboard_head)
self._stubs = {}
self._profiling_stats = {}
DataSource.agents.signal.append(self._update_stubs)
Expand Down Expand Up @@ -86,7 +86,7 @@ def _get_profiling_info(self, profiling_id):
return json.loads(profiling_stats.profiling_stats)

async def run(self):
p = self._dashboard_master.aioredis_client
p = self._dashboard_head.aioredis_client
mpsc = Receiver()

reporter_key = "{}*".format(reporter_consts.REPORTER_PREFIX)
Expand Down
16 changes: 8 additions & 8 deletions dashboard/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ async def run(self, server):
"""


class DashboardMasterModule(abc.ABC):
def __init__(self, dashboard_master):
class DashboardHeadModule(abc.ABC):
def __init__(self, dashboard_head):
"""
Initialize current module when DashboardMaster loading modules.
Initialize current module when DashboardHead loading modules.
:param dashboard_master: The DashboardMaster instance.
:param dashboard_head: The DashboardHead instance.
"""
self._dashboard_master = dashboard_master
self._dashboard_head = dashboard_head

@abc.abstractmethod
async def run(self):
Expand Down Expand Up @@ -136,17 +136,17 @@ def view(cls, path, **kwargs):
return cls._register_route(hdrs.METH_ANY, path, **kwargs)

@classmethod
def bind(cls, master_instance):
def bind(cls, instance):
def predicate(o):
if inspect.ismethod(o):
return hasattr(o, "__route_method__") and hasattr(
o, "__route_path__")
return False

handler_routes = inspect.getmembers(master_instance, predicate)
handler_routes = inspect.getmembers(instance, predicate)
for _, h in handler_routes:
cls._bind_map[h.__func__.__route_method__][
h.__func__.__route_path__].instance = master_instance
h.__func__.__route_path__].instance = instance


def get_all_modules(module_type):
Expand Down

0 comments on commit 52460a3

Please sign in to comment.