Skip to content

Commit

Permalink
refactor(proto): devices now explict rename as targets (#2280)
Browse files Browse the repository at this point in the history
* refactor(proto): devices now explict rename as targets
  • Loading branch information
hanxiao authored Apr 4, 2021
1 parent 9c9ad17 commit 1fa761f
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 39 deletions.
10 changes: 5 additions & 5 deletions jina/clients/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,25 +171,25 @@ def delete(

def reload(
self,
devices: Union[str, List[str]],
targets: Union[str, List[str]],
on_done: CallbackFnType = None,
on_error: CallbackFnType = None,
on_always: CallbackFnType = None,
**kwargs
):
"""Send 'reload' request to the Flow.
:param devices: the regex string or list of regex strings to match the pea/pod names.
:param targets: the regex string or list of regex strings to match the pea/pod names.
:param on_done: the function to be called when the :class:`Request` object is resolved.
:param on_error: the function to be called when the :class:`Request` object is rejected.
:param on_always: the function to be called when the :class:`Request` object is is either resolved or rejected.
:param kwargs: additional parameters
:return: None
"""

if isinstance(devices, str):
devices = [devices]
kwargs['devices'] = devices
if isinstance(targets, str):
targets = [targets]
kwargs['targets'] = targets

self.mode = RequestType.CONTROL
return run_async(
Expand Down
10 changes: 5 additions & 5 deletions jina/clients/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,25 +199,25 @@ async def update(

async def reload(
self,
devices: Union[str, List[str]],
targets: Union[str, List[str]],
on_done: CallbackFnType = None,
on_error: CallbackFnType = None,
on_always: CallbackFnType = None,
**kwargs
):
"""Send 'reload' request to the Flow.
:param devices: the regex string or list of regex strings to match the pea/pod names.
:param targets: the regex string or list of regex strings to match the pea/pod names.
:param on_done: the function to be called when the :class:`Request` object is resolved.
:param on_error: the function to be called when the :class:`Request` object is rejected.
:param on_always: the function to be called when the :class:`Request` object is is either resolved or rejected.
:param kwargs: additional parameters
:yield: result
"""

if isinstance(devices, str):
devices = [devices]
kwargs['devices'] = devices
if isinstance(targets, str):
targets = [targets]
kwargs['targets'] = targets

self.mode = RequestType.CONTROL
async for r in self._get_results([], on_done, on_error, on_always, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion jina/clients/request/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,5 @@ def _add_control_propagate(req, kwargs):
raise ValueError(
f'command "{command}" is not supported, must be one of {_available_commands}'
)
req.args.update(extra_kwargs)
req.targets.extend(extra_kwargs.get('targets', []))
req.control.propagate = True
7 changes: 2 additions & 5 deletions jina/drivers/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,8 @@ def __call__(self, *args, **kwargs):
elif self.req.command == 'CANCEL':
pass
elif self.req.command == 'RELOAD':
if (
'devices' in self.req.args
and self.runtime.__class__.__name__ == 'ZEDRuntime'
):
patterns = self.req.args['devices']
if self.req.targets and self.runtime.__class__.__name__ == 'ZEDRuntime':
patterns = self.req.targets
if isinstance(patterns, str):
patterns = [patterns]
for p in patterns:
Expand Down
6 changes: 3 additions & 3 deletions jina/flow/mixin/async_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AsyncControlFlowMixin:

async def reload(
self,
devices: Union[str, Sequence[str]],
targets: Union[str, Sequence[str]],
on_done: CallbackFnType = None,
on_error: CallbackFnType = None,
on_always: CallbackFnType = None,
Expand All @@ -17,14 +17,14 @@ async def reload(
"""Reload the executor of certain peas/pods in the Flow
It will start a :py:class:`CLIClient` and call :py:func:`reload`.
:param devices: the regex string or list of regex strings to match the pea/pod names.
:param targets: the regex string or list of regex strings to match the pea/pod names.
:param on_done: the function to be called when the :class:`Request` object is resolved.
:param on_error: the function to be called when the :class:`Request` object is rejected.
:param on_always: the function to be called when the :class:`Request` object is is either resolved or rejected.
:param kwargs: accepts all keyword arguments of `jina client` CLI
:yield: result
"""
async for r in self._get_client(**kwargs).reload(
devices, on_done, on_error, on_always, **kwargs
targets, on_done, on_error, on_always, **kwargs
):
yield r
6 changes: 3 additions & 3 deletions jina/flow/mixin/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ControlFlowMixin:

def reload(
self,
devices: Union[str, Sequence[str]],
targets: Union[str, Sequence[str]],
on_done: CallbackFnType = None,
on_error: CallbackFnType = None,
on_always: CallbackFnType = None,
Expand All @@ -17,13 +17,13 @@ def reload(
"""Reload the executor of certain peas/pods in the Flow
It will start a :py:class:`CLIClient` and call :py:func:`reload`.
:param devices: the regex string or list of regex strings to match the pea/pod names.
:param targets: the regex string or list of regex strings to match the pea/pod names.
:param on_done: the function to be called when the :class:`Request` object is resolved.
:param on_error: the function to be called when the :class:`Request` object is rejected.
:param on_always: the function to be called when the :class:`Request` object is is either resolved or rejected.
:param kwargs: accepts all keyword arguments of `jina client` CLI
:return: results
"""
return self._get_client(**kwargs).reload(
devices, on_done, on_error, on_always, **kwargs
targets, on_done, on_error, on_always, **kwargs
)
4 changes: 3 additions & 1 deletion jina/proto/jina.proto
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ message RequestProto {

google.protobuf.Struct args = 2; // the pea arguments, useful in STATUS

bool propagate = 3; // when set, then this request is propagate over the Flow topology just like a data request
bool propagate = 3; // if set, then this request is propagate over the Flow topology just like a data request

repeated string targets = 4; // if set, the control request is targeted to certain peas/pods, regex strings
}

StatusProto status = 6; // status info
Expand Down
Loading

0 comments on commit 1fa761f

Please sign in to comment.