Skip to content

Commit

Permalink
refactor: create orchestrate and serve modules (#4168)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoanFM committed Jan 20, 2022
1 parent 62745a7 commit 21e5daf
Show file tree
Hide file tree
Showing 198 changed files with 296 additions and 300 deletions.
12 changes: 6 additions & 6 deletions cli/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from jina.peapods.runtimes.head import HeadRuntime
from jina.serve.runtimes.head import HeadRuntime

if False:
from argparse import Namespace
Expand All @@ -10,7 +10,7 @@ def pod(args: 'Namespace'):
:param args: arguments coming from the CLI.
"""
from jina.peapods.pods import Pod
from jina.orchestrate.pods import Pod

try:
with Pod(args) as p:
Expand All @@ -25,7 +25,7 @@ def pea(args: 'Namespace'):
:param args: arguments coming from the CLI.
"""
from jina.peapods.peas.factory import PeaFactory
from jina.orchestrate.peas.factory import PeaFactory

try:
with PeaFactory.build_pea(args) as p:
Expand All @@ -40,7 +40,7 @@ def executor_native(args: 'Namespace'):
:param args: arguments coming from the CLI.
"""
from jina.peapods.runtimes.worker import WorkerRuntime
from jina.serve.runtimes.worker import WorkerRuntime

if args.runtime_cls == 'WorkerRuntime':
runtime_cls = WorkerRuntime
Expand Down Expand Up @@ -81,7 +81,7 @@ def worker_runtime(args: 'Namespace'):
:param args: arguments coming from the CLI.
"""
from jina.peapods.runtimes.worker import WorkerRuntime
from jina.serve.runtimes.worker import WorkerRuntime

with WorkerRuntime(args) as runtime:
runtime.logger.success(
Expand All @@ -97,7 +97,7 @@ def gateway(args: 'Namespace'):
:param args: arguments coming from the CLI.
"""
from jina.enums import GatewayProtocolType
from jina.peapods.runtimes import get_runtime
from jina.serve.runtimes import get_runtime

gateway_runtime_dict = {
GatewayProtocolType.GRPC: 'GRPCGatewayRuntime',
Expand Down
4 changes: 2 additions & 2 deletions daemon/api/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from pydantic import FilePath
from pydantic.errors import PathNotAFileError

from jina.peapods.peas.container_helper import get_gpu_device_requests
from jina.peapods.peas.helper import update_runtime_cls
from jina.orchestrate.peas.container_helper import get_gpu_device_requests
from jina.orchestrate.peas.helper import update_runtime_cls
from jina import Flow
from jina.enums import (
RemoteWorkspaceState,
Expand Down
8 changes: 4 additions & 4 deletions daemon/stores/partial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from typing import Dict, Optional, Type, Union

from jina.helper import colored, random_port
from jina.peapods.pods import Pod
from jina.peapods.peas.factory import PeaFactory
from jina.peapods import BasePod, BasePea
from jina.peapods.peas.helper import update_runtime_cls
from jina.orchestrate.pods import Pod, BasePod
from jina.orchestrate.peas.factory import PeaFactory
from jina.orchestrate.peas import BasePea
from jina.orchestrate.peas.helper import update_runtime_cls
from jina import Flow, __docker_host__
from jina.logging.logger import JinaLogger

Expand Down
8 changes: 4 additions & 4 deletions jina/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ def _set_nofile(nofile_atleast=4096):
from docarray import Document, DocumentArray

# Executor
from jina.executors import BaseExecutor as Executor
from jina.executors.decorators import requests
from jina.serve.executors import BaseExecutor as Executor
from jina.serve.executors.decorators import requests

# Flow
from jina.flow.base import Flow
from jina.flow.asyncio import AsyncFlow
from jina.orchestrate.flow.base import Flow
from jina.orchestrate.flow.asyncio import AsyncFlow

__all__ = [_s for _s in dir() if not _s.startswith('_')]
__all__.extend(_names_with_underscore)
2 changes: 1 addition & 1 deletion jina/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, args: 'argparse.Namespace'):
"""

from jina.logging.profile import TimeContext
from jina.peapods.runtimes.worker import WorkerRuntime
from jina.serve.runtimes.worker import WorkerRuntime
import time

ctrl_addr = f'{args.host}:{args.port}'
Expand Down
2 changes: 1 addition & 1 deletion jina/clients/base/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from jina.excepts import BadClient, BadClientInput
from jina.logging.profile import ProgressBar
from jina.proto import jina_pb2_grpc
from jina.peapods.networking import GrpcConnectionPool
from jina.serve.networking import GrpcConnectionPool

if TYPE_CHECKING:
from jina.clients.base import InputType, CallbackFnType
Expand Down
2 changes: 1 addition & 1 deletion jina/clients/base/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from jina.importer import ImportExtensions
from jina.logging.profile import ProgressBar
from jina.types.request import Request
from jina.peapods.stream import RequestStreamer
from jina.serve.stream import RequestStreamer
from jina.types.request.data import DataRequest

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion jina/clients/base/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from jina.clients.helper import callback_exec
from jina.importer import ImportExtensions
from jina.logging.profile import ProgressBar
from jina.peapods.stream import RequestStreamer
from jina.serve.stream import RequestStreamer
from jina.helper import get_or_reuse_loop

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion jina/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class FlowBuildLevel(BetterEnum):
"""
The enum for representing a flow's build level.
Some :class:`jina.flow.Flow` class functions require certain build level to run.
Some :class:`jina.orchestrate.flow.Flow` class functions require certain build level to run.
"""

EMPTY = 0 #: Nothing is built
Expand Down
2 changes: 1 addition & 1 deletion jina/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ def kwargs2list(kwargs: Dict) -> List[str]:
:return: argument list
"""
args = []
from jina.executors import BaseExecutor
from jina.serve.executors import BaseExecutor

for k, v in kwargs.items():
k = k.replace('_', '-')
Expand Down
2 changes: 1 addition & 1 deletion jina/jaml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ def _delitem(
else None,
)

from jina.flow.base import Flow
from jina.orchestrate.flow.base import Flow

if issubclass(cls, Flow):
no_tag_yml_copy = copy.copy(no_tag_yml)
Expand Down
4 changes: 2 additions & 2 deletions jina/jaml/parsers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def _get_all_parser(cls: Type['JAMLCompatible']):
:param cls: target class
:return: a tuple of two elements; first is a list of all parsers, second is the legacy parser for default fallback
"""
from jina.executors import BaseExecutor
from jina.flow.base import Flow
from jina.serve.executors import BaseExecutor
from jina.orchestrate.flow.base import Flow

if issubclass(cls, Flow):
return _get_flow_parser()
Expand Down
4 changes: 2 additions & 2 deletions jina/jaml/parsers/base.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import Dict, Union, TYPE_CHECKING

if TYPE_CHECKING:
from jina.flow.base import Flow
from jina.executors import BaseExecutor
from jina.orchestrate.flow.base import Flow
from jina.serve.executors import BaseExecutor


class VersionedYAMLParser:
Expand Down
4 changes: 2 additions & 2 deletions jina/jaml/parsers/executor/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from typing import Dict, Type, Set

from jina.jaml.parsers.base import VersionedYAMLParser
from jina.executors import BaseExecutor
from jina.executors.metas import get_default_metas
from jina.serve.executors import BaseExecutor
from jina.serve.executors.metas import get_default_metas


class LegacyParser(VersionedYAMLParser):
Expand Down
2 changes: 1 addition & 1 deletion jina/jaml/parsers/flow/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from jina.jaml.parsers.base import VersionedYAMLParser
from jina.enums import PodRoleType
from jina.flow.base import Flow
from jina.orchestrate.flow.base import Flow
from jina.helper import expand_env_var, ArgNamespace
from jina.parsers import set_gateway_parser, set_pod_parser

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion jina/flow/asyncio.py → jina/orchestrate/flow/asyncio.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from jina.flow.base import Flow
from jina.orchestrate.flow.base import Flow
from jina.clients.mixin import AsyncPostMixin


Expand Down
23 changes: 11 additions & 12 deletions jina/flow/base.py → jina/orchestrate/flow/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
TYPE_CHECKING,
)

from jina.flow.builder import allowed_levels, _hanging_pods
from jina.orchestrate.flow.builder import allowed_levels, _hanging_pods
from jina import __default_host__, helper
from jina.clients import Client
from jina.clients.mixin import AsyncPostMixin, PostMixin
Expand All @@ -33,7 +33,6 @@
PodRoleType,
FlowInspectType,
GatewayProtocolType,
PollingType,
)
from jina.excepts import FlowTopologyError, FlowMissingPodError, RuntimeFailToStart
from jina.helper import (
Expand All @@ -49,7 +48,7 @@
from jina.logging.logger import JinaLogger
from jina.parsers import set_gateway_parser, set_pod_parser, set_client_cli_parser
from jina.parsers.flow import set_flow_parser
from jina.peapods import Pod
from jina.orchestrate.pods import Pod

__all__ = ['Flow']

Expand All @@ -63,9 +62,9 @@ class FlowType(type(ExitStack), type(JAMLCompatible)):
_regex_port = r'(.*?):([0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])$'

if TYPE_CHECKING:
from jina.executors import BaseExecutor
from jina.serve.executors import BaseExecutor
from jina.clients.base import BaseClient
from jina.flow.asyncio import AsyncFlow
from jina.orchestrate.flow.asyncio import AsyncFlow

GATEWAY_NAME = 'gateway'
FALLBACK_PARSERS = [
Expand Down Expand Up @@ -349,7 +348,7 @@ def _update_args(self, args, **kwargs):
if self._common_kwargs.get('asyncio', False) and not isinstance(
self, AsyncPostMixin
):
from jina.flow.asyncio import AsyncFlow
from jina.orchestrate.flow.asyncio import AsyncFlow

self.__class__ = AsyncFlow

Expand Down Expand Up @@ -448,8 +447,8 @@ def _get_pod_addresses(self) -> Dict[str, List[str]]:

def _get_k8s_pod_addresses(self, k8s_namespace: str) -> Dict[str, List[str]]:
graph_dict = {}
from jina.peapods.networking import K8sGrpcConnectionPool
from jina.peapods.pods.config.helper import to_compatible_name
from jina.serve.networking import K8sGrpcConnectionPool
from jina.orchestrate.pods.config.helper import to_compatible_name

for node, v in self._pod_nodes.items():
if node == 'gateway':
Expand All @@ -465,8 +464,8 @@ def _get_k8s_pod_addresses(self, k8s_namespace: str) -> Dict[str, List[str]]:

def _get_docker_compose_pod_addresses(self) -> Dict[str, List[str]]:
graph_dict = {}
from jina.peapods.pods.config.docker_compose import PORT_IN
from jina.peapods.pods.config.helper import to_compatible_name
from jina.orchestrate.pods.config.docker_compose import PORT_IN
from jina.orchestrate.pods.config.helper import to_compatible_name

for node, v in self._pod_nodes.items():
if node == 'gateway':
Expand Down Expand Up @@ -1696,7 +1695,7 @@ def to_k8s_yaml(
if self._build_level.value < FlowBuildLevel.GRAPH.value:
self.build(copy_flow=False)

from jina.peapods.pods.config.k8s import K8sPodConfig
from jina.orchestrate.pods.config.k8s import K8sPodConfig

k8s_namespace = k8s_namespace or self.args.name or 'default'

Expand Down Expand Up @@ -1736,7 +1735,7 @@ def to_docker_compose_yaml(
output_path = output_path or 'docker-compose.yml'
network_name = network_name or 'jina-network'

from jina.peapods.pods.config.docker_compose import DockerComposeConfig
from jina.orchestrate.pods.config.docker_compose import DockerComposeConfig

docker_compose_dict = {
'version': '3.3',
Expand Down
2 changes: 1 addition & 1 deletion jina/flow/builder.py → jina/orchestrate/flow/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# noinspection PyUnreachableCode
if TYPE_CHECKING:
from jina.flow.base import Flow
from jina.orchestrate.flow.base import Flow
from jina.enums import FlowBuildLevel


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from abc import ABC, abstractmethod
from typing import Type, Union, Dict, Optional

from jina.peapods.runtimes.asyncio import AsyncNewLoopRuntime
from jina.serve.runtimes.asyncio import AsyncNewLoopRuntime
from jina.jaml import JAML
from jina.peapods.peas.helper import _get_event, _get_worker, ConditionalEvent
from jina.orchestrate.peas.helper import _get_event, _get_worker, ConditionalEvent
from jina import __stop_msg__, __ready_msg__, __windows__
from jina.enums import PeaRoleType, RuntimeBackendType
from jina.excepts import RuntimeFailToStart, RuntimeRunForeverEarlyError
Expand Down Expand Up @@ -382,8 +382,8 @@ def _terminate(self):
self.logger.debug(f'runtime thread properly canceled')

def _get_runtime_cls(self) -> AsyncNewLoopRuntime:
from jina.peapods.peas.helper import update_runtime_cls
from jina.peapods.runtimes import get_runtime
from jina.orchestrate.peas.helper import update_runtime_cls
from jina.serve.runtimes import get_runtime

update_runtime_cls(self.args)
return get_runtime(self.args.runtime_cls)
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@

from jina import __windows__
from jina.importer import ImportExtensions
from jina.peapods.peas import BasePea
from jina.peapods.peas.helper import _get_worker
from jina.peapods.peas.container_helper import (
from jina.orchestrate.peas import BasePea
from jina.orchestrate.peas import _get_worker
from jina.orchestrate.peas.container_helper import (
get_gpu_device_requests,
get_docker_network,
)
from jina import __docker_host__
from jina.logging.logger import JinaLogger
from jina.helper import slugify, random_name
from jina.peapods.runtimes.asyncio import AsyncNewLoopRuntime
from jina.serve.runtimes.asyncio import AsyncNewLoopRuntime

if TYPE_CHECKING:
from docker.client import DockerClient
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
from typing import TYPE_CHECKING, Type

from jina import __default_host__
from jina.peapods.peas import Pea
from jina.peapods.peas.jinad import JinaDPea
from jina.peapods.peas.container import ContainerPea
from jina.orchestrate.peas import Pea
from jina.orchestrate.peas.jinad import JinaDPea
from jina.orchestrate.peas.container import ContainerPea
from jina.enums import PeaRoleType

from jina.hubble.helper import is_valid_huburi
from jina.hubble.hubio import HubIO

if TYPE_CHECKING:
from jina.peapods.peas import BasePea
from jina.orchestrate.peas import BasePea


class PeaFactory:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from grpc import RpcError

from jina.peapods.networking import GrpcConnectionPool
from jina.serve.networking import GrpcConnectionPool
from jina.types.request.control import ControlRequest

if TYPE_CHECKING:
Expand Down
4 changes: 2 additions & 2 deletions jina/peapods/peas/jinad.py → jina/orchestrate/peas/jinad.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from pathlib import Path
from typing import TYPE_CHECKING, Dict, List, Union, Optional

from jina.peapods.peas import BasePea
from jina.peapods.peas.helper import _get_worker, is_ready
from jina.orchestrate.peas import BasePea
from jina.orchestrate.peas.helper import _get_worker, is_ready
from jina.helper import run_async
from jina.jaml.helper import complete_path
from jina.importer import ImportExtensions
Expand Down

0 comments on commit 21e5daf

Please sign in to comment.