Skip to content

Commit

Permalink
[APPLS-2081] Fixed issue with starting app when ee version is not rea…
Browse files Browse the repository at this point in the history
…dy (#28)

* [APPLS-2081] Fixed issue with starting app when ee version is not ready

* moved waiting to separate function
  • Loading branch information
demchukilya authored Apr 10, 2024
1 parent 35a0fd9 commit 71d5f6c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 3 deletions.
1 change: 0 additions & 1 deletion bin/drapps
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
#
from drapps.__main__ import drapps


if __name__ == "__main__":
drapps()
25 changes: 24 additions & 1 deletion drapps/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@
)
from .helpers.exceptions import ClientResponseError
from .helpers.execution_environments_functions import (
IMAGE_BUILD_FAILED_STATUSES,
IMAGE_BUILD_FINAL_STATUSES,
create_execution_environment,
create_execution_environment_version,
get_execution_environment_by_id,
get_execution_environment_by_name,
get_execution_environment_version_by_id,
)
from .helpers.wrappers import api_endpoint, api_token

Expand Down Expand Up @@ -171,6 +174,23 @@ def create_app_from_project(
return create_custom_app(session, endpoint, app_payload)


def wait_for_execution_environment_version_ready(
session: Session, endpoint: str, base_env_id: str, version_id: str
) -> None:
with click.progressbar(iterable=repeat(0), label='Waiting till image is ready:') as progress:
while True:
response = get_execution_environment_version_by_id(
session=session, endpoint=endpoint, base_env_id=base_env_id, version_id=version_id
)
img_status = response.get('buildStatus')
if img_status in IMAGE_BUILD_FINAL_STATUSES:
break
progress.update(1)
sleep(CHECK_STATUS_WAIT_TIME)
if img_status in IMAGE_BUILD_FAILED_STATUSES:
raise Exception("Image build failed")


def send_docker_image_with_progress(
session: Session, endpoint: str, base_env_id: str, docker_image: Path
) -> None:
Expand All @@ -188,12 +208,15 @@ def monitor_callback(monitor: MultipartEncoderMonitor):

multipart_monitor.callback = monitor_callback

create_execution_environment_version(
response = create_execution_environment_version(
session=session,
endpoint=endpoint,
base_env_id=base_env_id,
multipart_data=multipart_monitor,
)
wait_for_execution_environment_version_ready(
session=session, endpoint=endpoint, base_env_id=base_env_id, version_id=response['id']
)


def create_app_from_docker_image(
Expand Down
14 changes: 14 additions & 0 deletions drapps/helpers/execution_environments_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
from .exceptions import ClientResponseError
from .handle_dr_response import handle_dr_response

IMAGE_BUILD_SUCCESS_STATUSES = {'success'}
IMAGE_BUILD_FAILED_STATUSES = {'failed'}
IMAGE_BUILD_FINAL_STATUSES = IMAGE_BUILD_SUCCESS_STATUSES | IMAGE_BUILD_FAILED_STATUSES


def create_execution_environment(
session: Session, endpoint: str, env_name: str, description: Optional[str] = None
Expand Down Expand Up @@ -84,3 +88,13 @@ def create_execution_environment_version(
)
handle_dr_response(response)
return response.json()


def get_execution_environment_version_by_id(
session: Session, endpoint: str, base_env_id: str, version_id: str
) -> Dict[str, Any]:
"""Get a execution environment version by environment ID and version ID."""
url = posixpath.join(endpoint, f"executionEnvironments/{base_env_id}/versions/{version_id}/")
response = session.get(url)
handle_dr_response(response)
return response.json()
10 changes: 9 additions & 1 deletion tests/cli/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,18 @@ def test_create_from_docker_image(api_endpoint_env, api_token_env, wait_till_rea
)

# request for uploading docker image to execution environment version
ee_environment_version_id = str(ObjectId())
responses.post(
f'{api_endpoint_env}/executionEnvironments/{ee_environment_id}/versions/',
json={'id': str(ObjectId())},
json={'id': ee_environment_version_id},
match=[auth_matcher],
)
# requests for checking image readiness
ee_environment_version_url = f'{api_endpoint_env}/executionEnvironments/{ee_environment_id}/versions/{ee_environment_version_id}/'
responses.get(
ee_environment_version_url, json={'buildStatus': 'processing'}, match=[auth_matcher]
)
responses.get(ee_environment_version_url, json={'buildStatus': 'success'}, match=[auth_matcher])

# request for creating custom app
status_check_url = 'http://ho.st/status/status_id'
Expand All @@ -88,6 +95,7 @@ def test_create_from_docker_image(api_endpoint_env, api_token_env, wait_till_rea
expected_output = (
f'Uploading {image_name} to Data Robot.\n'
'Upload progress:\n'
'Waiting till image is ready:\n'
f'Starting {app_name} custom application.\n'
)
if wait_till_ready:
Expand Down

0 comments on commit 71d5f6c

Please sign in to comment.