Skip to content

Commit

Permalink
[#543] Move model client creation
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillmakhonin committed Oct 16, 2018
1 parent 15a4d8f commit 388d01f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
8 changes: 1 addition & 7 deletions legion/legion/edi/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,7 @@ def inspect(model=None, version=None):
for model_service in model_services:
model_api_info = {}

model_client = legion.model.ModelClient(
model_id=model_service.id,
model_version=model_service.version,
host=model_service.url_with_ip,
timeout=3
)
LOGGER.info('Building model client: {!r}'.format(model_client))
model_client = legion.model.ModelClient.build_from_model_service(model_service)

try:
model_api_info['result'] = model_client.info()
Expand Down
18 changes: 18 additions & 0 deletions legion/legion/model/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,24 @@ def __init__(self, model_id, model_version, token=None, host=None, http_client=N

self._timeout = timeout

@staticmethod
def build_from_model_service(model_service, timeout=3):
"""
Build model client from model service information
:param model_service: model service information
:type model_service: :py:class:`legion.k8s.services.ModelService`
:param timeout: (Optional) connection timeout
:type timeout: int
:return: :py:class:`legion.model.client.ModelClient` -- model client
"""
return ModelClient(
model_id=model_service.id,
model_version=model_service.version,
host=model_service.url_with_ip,
timeout=timeout
)

def __repr__(self):
"""
Get string representation of model client
Expand Down
9 changes: 3 additions & 6 deletions legion/tests/test_edi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,11 @@
#
from __future__ import print_function

import unittest2
import unittest.mock
import json
from random import randint
import urllib.parse
from io import BytesIO
import sys
import os

import unittest2
import unittest.mock
from werkzeug.datastructures import FileMultiDict

sys.path.extend(os.path.dirname(__file__))
Expand All @@ -35,6 +31,7 @@
create_simple_summation_model_lists_with_files_info

import legion.serving.pyserve as pyserve
import legion.k8s.services


def get_models_mock_empty(model_id, model_version):
Expand Down

0 comments on commit 388d01f

Please sign in to comment.