Skip to content

Commit

Permalink
fix(v2client): fix retry exceeded error code description and action
Browse files Browse the repository at this point in the history
  • Loading branch information
smrutisenapati authored and pallabpain committed Sep 4, 2024
1 parent 8279b77 commit 938ed4c
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 11 deletions.
2 changes: 1 addition & 1 deletion riocli/package/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
def find_package(client: Client,
package_name: str,
package_version: str,
) -> Munch | None:
) -> Munch:

package_obj = None

Expand Down
10 changes: 5 additions & 5 deletions riocli/rosbag/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
ROSBagOnDemandUploadOptions, ROSBagTimeRange

from riocli.config import new_client
from riocli.deployment.util import name_to_guid as deployment_name_to_guid
# from riocli.deployment.util import name_to_guid as deployment_name_to_guid
from riocli.rosbag.util import ROSBagJobNotFound
from riocli.utils import inspect_with_format
from riocli.utils import tabulate_data
Expand Down Expand Up @@ -103,7 +103,7 @@ def job_inspect(job_guid: str, format_type: str) -> None:
@click.argument('deployment-name')
@click.option('--component-instance-ids', help='Filter by component instance ids ', multiple=True)
@click.option('--guids', help='Filter by job guids', multiple=True)
@deployment_name_to_guid
# @deployment_name_to_guid
def job_stop(deployment_guid: str, deployment_name: str, component_instance_ids: typing.List[str],
guids: typing.List[str]) -> None:
"""
Expand All @@ -126,7 +126,7 @@ def job_stop(deployment_guid: str, deployment_name: str, component_instance_ids:
@click.option('--guids', help='Filter by job guids ', multiple=True)
@click.option('--statuses', help='Filter by rosbag job statuses ', multiple=True, default=['Starting', 'Running'],
type=click.Choice(['Starting', 'Running', 'Error', 'Stopping', 'Stopped'], case_sensitive=True))
@deployment_name_to_guid
# @deployment_name_to_guid
def job_list(deployment_guid: str, deployment_name: str,
component_instance_ids: typing.List[str], guids: typing.List[str], statuses: typing.List[str]) -> None:
"""
Expand All @@ -153,7 +153,7 @@ def job_list(deployment_guid: str, deployment_name: str,
'format (1985-04-12T23:20:50.52Z)', required=True)
@click.option('--upload-to', help='Rosbags recorded before or at this time are uploaded. Specify time in RFC 3339 '
'format (1985-04-12T23:20:50.52Z)', required=True)
@deployment_name_to_guid
# @deployment_name_to_guid
def job_trigger_upload(deployment_guid: str, deployment_name: str, job_guid: str,
upload_from: str, upload_to: str) -> None:
"""
Expand Down Expand Up @@ -224,7 +224,7 @@ def job_trigger_upload(deployment_guid: str, deployment_name: str, job_guid: str
@click.argument('job-guid')
@click.option('--upload-mode', help='Change upload mode',
type=click.Choice([t for t in ROSBagUploadTypes]), required=True)
@deployment_name_to_guid
# @deployment_name_to_guid
def update_job(deployment_guid: str, deployment_name: str, job_guid: str, upload_mode: str) -> None:
"""
Update the Rosbag Job
Expand Down
15 changes: 10 additions & 5 deletions riocli/v2client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from riocli.v2client.enums import DeploymentPhaseConstants, DiskStatusConstants
from riocli.v2client.error import (RetriesExhausted, DeploymentNotRunning, ImagePullError,
NetworkNotFound, DeploymentNotFound)
from riocli.v2client.util import process_errors


def handle_server_errors(response: requests.Response):
Expand Down Expand Up @@ -941,8 +942,10 @@ def poll_network(
network = self.get_network(name)
status = network.status

raise RetriesExhausted('Retried {} time done with an interval of {} seconds. Network status: {}'.format(
retry_count, sleep_interval, status.phase))
msg = 'Retries exhausted: Tried {} times with {}s interval. Network: phase={} status={} \n{}'.format(
retry_count, sleep_interval, status.phase, status.status, process_errors(status.get('error_codes', [])))

raise RetriesExhausted(msg)

def list_deployments(
self,
Expand Down Expand Up @@ -1082,8 +1085,10 @@ def poll_deployment(
deployment = self.get_deployment(name)
status = deployment.status

raise RetriesExhausted('Retried {} time done with an interval of {} seconds. Deployment status: {}'.format(
retry_count, sleep_interval, status.phase))
msg = 'Retries exhausted: Tried {} times with {}s interval. Deployment: phase={} status={} \n{}'.format(
retry_count, sleep_interval, status.phase, status.status, process_errors(status.get('error_codes', [])))

raise RetriesExhausted(msg)

def stream_deployment_logs(
self,
Expand Down Expand Up @@ -1207,5 +1212,5 @@ def poll_disk(
disk = self.get_disk(name)
status = disk.status

raise RetriesExhausted('Retried {} time done with an interval of {} seconds. Disk status: {}'.format(
raise RetriesExhausted('Retries exhausted: Tried {} times with {}s interval. Disk: status={}'.format(
retry_count, sleep_interval, status.status))
File renamed without changes.
36 changes: 36 additions & 0 deletions riocli/v2client/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import typing

import click

from riocli.constants import Colors
from riocli.v2client.errors import ERRORS


def process_errors(errors: typing.List[str]) -> str:
err_fmt = '[{}] {}\nAction: {}'
support_action = ('Report the issue together with the relevant'
' details to the support team')

action, description = '', ''
msgs = []
for code in errors:
if code in ERRORS:
description = ERRORS[code]['description']
action = ERRORS[code]['action']
elif code.startswith('DEP_E2'):
description = 'Internal rapyuta.io error in the components deployed on cloud'
action = support_action
elif code.startswith('DEP_E3'):
description = 'Internal rapyuta.io error in the components deployed on a device'
action = support_action
elif code.startswith('DEP_E4'):
description = 'Internal rapyuta.io error'
action = support_action

code = click.style(code, fg=Colors.YELLOW)
description = click.style(description, fg=Colors.RED)
action = click.style(action, fg=Colors.GREEN)

msgs.append(err_fmt.format(code, description, action))

return '\n'.join(msgs)

0 comments on commit 938ed4c

Please sign in to comment.