Beispiel #1
0
 async def rolling_update(self, uses_with: Optional[Dict] = None):
     # TODO make rolling_update robust, in what state this ReplicaSet ends when this fails?
     for i in range(len(self._pods)):
         _args = self.args[i]
         old_pod = self._pods[i]
         await GrpcConnectionPool.deactivate_worker(
             worker_host=Deployment.get_worker_host(
                 _args, old_pod, self.head_pod),
             worker_port=_args.port_in,
             target_head=
             f'{self.head_pod.args.host}:{self.head_pod.args.port_in}',
             shard_id=self.shard_id,
         )
         old_pod.close()
         _args.noblock_on_start = True
         _args.uses_with = uses_with
         new_pod = PodFactory.build_pod(_args)
         new_pod.__enter__()
         await new_pod.async_wait_start_success()
         await GrpcConnectionPool.activate_worker(
             worker_host=Deployment.get_worker_host(
                 _args, new_pod, self.head_pod),
             worker_port=_args.port_in,
             target_head=
             f'{self.head_pod.args.host}:{self.head_pod.args.port_in}',
             shard_id=self.shard_id,
         )
         self.args[i] = _args
         self._pods[i] = new_pod
Beispiel #2
0
def test_pod_instantiate_start_same_context():
    arg = set_pod_parser().parse_args([])
    pod_args = [arg, arg]

    for args in pod_args:
        pod = PodFactory.build_pod(args)
        with pod:
            pass
Beispiel #3
0
def test_ping():
    a1 = set_pod_parser().parse_args([])
    a2 = set_ping_parser().parse_args(['0.0.0.0', str(a1.port)])

    a3 = set_ping_parser().parse_args(
        ['0.0.0.1', str(a1.port), '--timeout', '1000'])

    with pytest.raises(SystemExit) as cm:
        with PodFactory.build_pod(a1):
            NetworkChecker(a2)

    assert cm.value.code == 0

    # test with bad address
    with pytest.raises(SystemExit) as cm:
        with PodFactory.build_pod(a1):
            NetworkChecker(a3)

    assert cm.value.code == 1
Beispiel #4
0
def test_pod_instantiate_start_different_context():
    arg = set_pod_parser().parse_args([])
    pod_args = [arg, arg]
    pods = []
    for args in pod_args:
        pods.append(PodFactory.build_pod(args))

    for pod in pods:
        with pod:
            pass
Beispiel #5
0
def _create_gateway_pod(l_or_r, graph_description, deployments_addresses,
                        port_expose):
    args = set_gateway_parser().parse_args([])
    if l_or_r == 'remote':
        args.host = HOST
        args.port_jinad = PORT
    args.graph_description = graph_description
    args.deployments_addresses = deployments_addresses
    args.port_expose = port_expose
    args.runtime_cls = 'GRPCGatewayRuntime'
    return PodFactory.build_pod(args)
Beispiel #6
0
    def start(self) -> 'Deployment':
        """
        Start to run all :class:`Pod` in this BaseDeployment.

        :return: started deployment

        .. note::
            If one of the :class:`Pod` fails to start, make sure that all of them
            are properly closed.
        """
        if self.is_sandbox and not self._sandbox_deployed:
            self.update_sandbox_args()

        if self.pod_args['uses_before'] is not None:
            _args = self.pod_args['uses_before']
            if getattr(self.args, 'noblock_on_start', False):
                _args.noblock_on_start = True
            self.uses_before_pod = PodFactory.build_pod(_args)
            self.enter_context(self.uses_before_pod)
        if self.pod_args['uses_after'] is not None:
            _args = self.pod_args['uses_after']
            if getattr(self.args, 'noblock_on_start', False):
                _args.noblock_on_start = True
            self.uses_after_pod = PodFactory.build_pod(_args)
            self.enter_context(self.uses_after_pod)
        if self.pod_args['head'] is not None:
            _args = self.pod_args['head']
            if getattr(self.args, 'noblock_on_start', False):
                _args.noblock_on_start = True
            self.head_pod = PodFactory.build_pod(_args)
            self.enter_context(self.head_pod)
        for shard_id in self.pod_args['pods']:
            self.shards[shard_id] = self._ReplicaSet(
                self.args,
                self.pod_args['pods'][shard_id],
                self.head_pod,
            )
            self.enter_context(self.shards[shard_id])

        return self
Beispiel #7
0
def test_container_pod(mocker, monkeypatch):
    mock = mocker.Mock()

    def _mock_pull(self):
        return 'docker://jinahub/dummy_executor'

    monkeypatch.setattr(HubIO, 'pull', _mock_pull)

    args = set_pod_parser().parse_args(
        ['--uses', 'jinahub+docker://DummyExecutor'])
    pod = PodFactory.build_pod(args)
    assert pod.args.uses == 'docker://jinahub/dummy_executor'
    assert pod.name == 'ContainerPod'
Beispiel #8
0
def pod(args: 'Namespace'):
    """
    Start a Pod

    :param args: arguments coming from the CLI.
    """
    from jina.orchestrate.pods.factory import PodFactory

    try:
        with PodFactory.build_pod(args) as p:
            p.join()
    except KeyboardInterrupt:
        pass
Beispiel #9
0
def test_gateway_ready(port_expose, route, status_code):
    p = set_gateway_parser().parse_args([
        '--port-expose',
        str(port_expose),
        '--protocol',
        'http',
        '--graph-description',
        '{}',
        '--deployments-addresses',
        '{}',
    ])
    with PodFactory.build_pod(p):
        time.sleep(0.5)
        a = requests.get(f'http://localhost:{p.port_expose}{route}')
    assert a.status_code == status_code
Beispiel #10
0
        async def _scale_up(self, replicas: int):
            new_pods = []
            new_args_list = []
            for i in range(len(self._pods), replicas):
                new_args = copy.copy(self.args[0])
                new_args.noblock_on_start = True
                new_args.name = new_args.name[:-1] + f'{i}'
                new_args.port_in = helper.random_port()
                # no exception should happen at create and enter time
                new_pods.append(PodFactory.build_pod(new_args).start())
                new_args_list.append(new_args)
            exception = None
            for new_pod, new_args in zip(new_pods, new_args_list):
                try:
                    await new_pod.async_wait_start_success()
                    await GrpcConnectionPool.activate_worker(
                        worker_host=Deployment.get_worker_host(
                            new_args, new_pod, self.head_pod),
                        worker_port=new_args.port_in,
                        target_head=
                        f'{self.head_pod.args.host}:{self.head_pod.args.port_in}',
                        shard_id=self.shard_id,
                    )
                except (
                        RuntimeFailToStart,
                        TimeoutError,
                        RuntimeRunForeverEarlyError,
                ) as ex:
                    exception = ex
                    break

            if exception is not None:
                if self.deployment_args.shards > 1:
                    msg = f' Scaling fails for shard {self.deployment_args.shard_id}'
                else:
                    msg = ' Scaling fails'

                msg += f'due to executor failing to start with exception: {exception!r}'
                raise ScalingFails(msg)
            else:
                for new_pod, new_args in zip(new_pods, new_args_list):
                    self.args.append(new_args)
                    self._pods.append(new_pod)
Beispiel #11
0
def _create_head_pod(l_or_r,
                     port,
                     polling=PollingType.ANY,
                     name='',
                     uses_before=None,
                     uses_after=None):
    args = set_pod_parser().parse_args([])
    if is_remote(l_or_r):
        args.host = HOST
        args.port_jinad = PORT
    args.name = name if name else f'head-{l_or_r}'
    args.port_in = port
    args.pod_role = PodRoleType.HEAD
    args.polling = polling
    args.runtime_cls = 'HeadRuntime'
    if uses_before:
        args.uses_before_address = uses_before
    if uses_after:
        args.uses_after_address = uses_after
    return PodFactory.build_pod(args)
Beispiel #12
0
def _create_worker_pod(
    l_or_r,
    port,
    name='',
    executor=None,
    py_modules=None,
    upload_files=None,
):
    args = set_pod_parser().parse_args([])
    if is_remote(l_or_r):
        args.host = HOST
        args.port_jinad = PORT
    args.name = name if name else f'worker-{l_or_r}'
    args.port_in = port
    args.runtime_cls = 'WorkerRuntime'
    if executor:
        args.uses = executor
    if upload_files:
        args.upload_files = upload_files
    if py_modules:
        args.py_modules = [py_modules]
    return PodFactory.build_pod(args)
Beispiel #13
0
 def __enter__(self):
     for _args in self.args:
         if getattr(self.deployment_args, 'noblock_on_start', False):
             _args.noblock_on_start = True
         self._pods.append(PodFactory.build_pod(_args).start())
     return self