thestage 0.6.7__py3-none-any.whl → 0.7.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. thestage/__init__.py +1 -1
  2. thestage/cli_command.py +3 -0
  3. thestage/cli_command_helper.py +2 -2
  4. thestage/config/__init__.py +1 -1
  5. thestage/{services → config/business}/app_config_service.py +3 -4
  6. thestage/{services/config_provider → config/business}/config_provider.py +6 -5
  7. thestage/config/{config_storage.py → business/config_storage.py} +1 -1
  8. thestage/{services → config/business}/validation_service.py +9 -10
  9. thestage/{controllers/config_controller.py → config/communication/config_command.py} +7 -7
  10. thestage/{services/connect → connect/business}/connect_service.py +22 -19
  11. thestage/{services → connect/business}/remote_server_service.py +4 -5
  12. thestage/connect/communication/connect_api_client.py +84 -0
  13. thestage/{services/clients/thestage_api/dtos/ssh_key_controller → connect/dto}/add_ssh_key_to_user_response.py +0 -1
  14. thestage/{services/clients/thestage_api/dtos/ssh_key_controller → connect/dto}/add_ssh_public_key_to_instance_response.py +1 -4
  15. thestage/{services/clients/thestage_api/dtos/base_controller → connect/dto}/connect_resolve_response.py +0 -1
  16. thestage/controllers/base_controller.py +2 -2
  17. thestage/debug_main.dist.py +16 -14
  18. thestage/{services/container → docker_container/business}/container_service.py +147 -22
  19. thestage/{services/container → docker_container/business}/mapper/container_mapper.py +3 -3
  20. thestage/docker_container/business/mapper/image_mapper.py +16 -0
  21. thestage/docker_container/communication/__init__.py +0 -0
  22. thestage/{controllers/container_controller.py → docker_container/communication/docker_command.py} +192 -29
  23. thestage/docker_container/communication/docker_container_api_client.py +139 -0
  24. thestage/docker_container/communication/image_command.py +40 -0
  25. thestage/docker_container/dto/__init__.py +0 -0
  26. thestage/docker_container/dto/container_action_request.py +11 -0
  27. thestage/{services/clients/thestage_api/dtos → docker_container/dto}/container_response.py +11 -4
  28. thestage/docker_container/dto/docker_container_create_request.py +28 -0
  29. thestage/docker_container/dto/docker_container_create_response.py +11 -0
  30. thestage/{services/clients/thestage_api/dtos/docker_container_controller → docker_container/dto}/docker_container_list_response.py +3 -5
  31. thestage/docker_container/dto/docker_image_list_request.py +11 -0
  32. thestage/docker_container/dto/docker_image_list_response.py +13 -0
  33. thestage/docker_container/dto/enum/__init__.py +0 -0
  34. thestage/docker_container/dto/image_entity.py +14 -0
  35. thestage/git/__init__.py +0 -0
  36. thestage/git/business/__init__.py +0 -0
  37. thestage/git/communication/__init__.py +0 -0
  38. thestage/{services/clients/git → git/communication}/git_client.py +4 -4
  39. thestage/global_dto/__init__.py +0 -0
  40. thestage/global_dto/enums/__init__.py +0 -0
  41. thestage/helpers/error_handler.py +4 -4
  42. thestage/helpers/logger/app_logger.py +1 -3
  43. thestage/i18n/en_GB/messages.po +14 -14
  44. thestage/inference_model/__init__.py +0 -0
  45. thestage/inference_model/business/__init__.py +0 -0
  46. thestage/inference_model/business/inference_model_service.py +281 -0
  47. thestage/inference_model/business/mapper/__init__.py +0 -0
  48. thestage/{services/project/mapper/project_inference_simulator_model_mapper.py → inference_model/business/mapper/inference_model_mapper.py} +5 -5
  49. thestage/inference_model/communication/__init__.py +0 -0
  50. thestage/inference_model/communication/inference_model_api_client.py +139 -0
  51. thestage/inference_model/communication/inference_model_command.py +246 -0
  52. thestage/inference_model/dto/__init__.py +0 -0
  53. thestage/{services/clients/thestage_api/dtos/inference_controller → inference_model/dto}/deploy_inference_model_to_instance_response.py +0 -1
  54. thestage/inference_model/dto/enum/__init__.py +0 -0
  55. thestage/{services/project/dto/inference_simulator_model_dto.py → inference_model/dto/inference_model.py} +1 -1
  56. thestage/{entities/project_inference_simulator_model.py → inference_model/dto/inference_model_entity.py} +1 -1
  57. thestage/{services/clients/thestage_api/dtos/inference_controller → inference_model/dto}/inference_simulator_model_list_for_project_response.py +2 -3
  58. thestage/{services/clients/thestage_api/dtos/project_controller/project_push_inference_simulator_model_request.py → inference_model/dto/push_inference_simulator_model_request.py} +1 -1
  59. thestage/{services/clients/thestage_api/dtos/project_controller/project_push_inference_simulator_model_response.py → inference_model/dto/push_inference_simulator_model_response.py} +1 -1
  60. thestage/inference_simulator/__init__.py +0 -0
  61. thestage/inference_simulator/business/__init__.py +0 -0
  62. thestage/inference_simulator/business/inference_simulator_service.py +338 -0
  63. thestage/inference_simulator/business/mapper/__init__.py +0 -0
  64. thestage/{services/project/mapper/project_inference_simulator_mapper.py → inference_simulator/business/mapper/inference_simulator_mapper.py} +5 -5
  65. thestage/inference_simulator/communication/__init__.py +0 -0
  66. thestage/inference_simulator/communication/inference_simulator_api_client.py +114 -0
  67. thestage/inference_simulator/communication/inference_simulator_command.py +347 -0
  68. thestage/inference_simulator/dto/__init__.py +0 -0
  69. thestage/inference_simulator/dto/enum/__init__.py +0 -0
  70. thestage/inference_simulator/dto/get_inference_simulator_response.py +12 -0
  71. thestage/{services/project/dto/inference_simulator_dto.py → inference_simulator/dto/inference_simulator.py} +1 -1
  72. thestage/{entities/project_inference_simulator.py → inference_simulator/dto/inference_simulator_entity.py} +1 -1
  73. thestage/{services/clients/thestage_api/dtos/inference_controller → inference_simulator/dto}/inference_simulator_list_response.py +2 -2
  74. thestage/{services/clients/thestage_api/dtos/project_controller/project_start_inference_simulator_request.py → inference_simulator/dto/start_inference_simulator_request.py} +1 -1
  75. thestage/inference_simulator/dto/start_inference_simulator_response.py +10 -0
  76. thestage/instance/__init__.py +0 -0
  77. thestage/instance/business/__init__.py +0 -0
  78. thestage/{services/instance → instance/business}/instance_service.py +26 -27
  79. thestage/instance/business/mapper/__init__.py +0 -0
  80. thestage/{services/instance/mapper/instance_mapper.py → instance/business/mapper/rented_instance_mapper.py} +3 -3
  81. thestage/{services/instance/mapper/selfhosted_mapper.py → instance/business/mapper/selfhosted_instance_mapper.py} +5 -7
  82. thestage/instance/communication/__init__.py +0 -0
  83. thestage/instance/communication/instance_api_client.py +150 -0
  84. thestage/{controllers/instance_controller.py → instance/communication/instance_command.py} +5 -5
  85. thestage/instance/dto/__init__.py +0 -0
  86. thestage/instance/dto/enum/__init__.py +0 -0
  87. thestage/{services/clients/thestage_api/dtos → instance/dto}/instance_detected_gpus.py +1 -2
  88. thestage/{services/clients/thestage_api/dtos → instance/dto}/instance_rented_response.py +2 -2
  89. thestage/{services/clients/thestage_api/dtos → instance/dto}/selfhosted_instance_response.py +2 -3
  90. thestage/logging/__init__.py +0 -0
  91. thestage/logging/business/__init__.py +0 -0
  92. thestage/{services/logging → logging/business}/logging_service.py +40 -28
  93. thestage/logging/communication/__init__.py +0 -0
  94. thestage/logging/communication/logging_api_client.py +63 -0
  95. thestage/logging/dto/__init__.py +0 -0
  96. thestage/{services/clients/thestage_api/dtos/logging_controller → logging/dto}/log_polling_response.py +2 -2
  97. thestage/{services/clients/thestage_api/dtos/logging_controller → logging/dto}/user_logs_query_response.py +2 -2
  98. thestage/main.py +54 -8
  99. thestage/project/__init__.py +0 -0
  100. thestage/project/business/__init__.py +0 -0
  101. thestage/project/business/project_service.py +480 -0
  102. thestage/project/communication/__init__.py +0 -0
  103. thestage/project/communication/project_api_client.py +46 -0
  104. thestage/project/communication/project_command.py +284 -0
  105. thestage/project/dto/__init__.py +0 -0
  106. thestage/services/clients/thestage_api/core/api_client_core.py +1 -1
  107. thestage/services/clients/thestage_api/dtos/entity_filter_request.py +1 -1
  108. thestage/services/clients/thestage_api/dtos/sftp_path_helper.py +1 -1
  109. thestage/services/filesystem_service.py +2 -2
  110. thestage/services/service_factory.py +130 -43
  111. thestage/task/__init__.py +0 -0
  112. thestage/task/business/__init__.py +0 -0
  113. thestage/task/business/mapper/__init__.py +0 -0
  114. thestage/{services/project/mapper/project_task_mapper.py → task/business/mapper/task_mapper.py} +5 -5
  115. thestage/task/business/task_service.py +307 -0
  116. thestage/task/communication/__init__.py +0 -0
  117. thestage/task/communication/task_api_client.py +122 -0
  118. thestage/task/communication/task_command.py +212 -0
  119. thestage/task/dto/__init__.py +0 -0
  120. thestage/task/dto/enum/__init__.py +0 -0
  121. thestage/{services/clients/thestage_api/dtos/task_controller/task_list_for_project_response.py → task/dto/list_for_project_response.py} +2 -2
  122. thestage/{services/clients/thestage_api/dtos/project_controller/project_run_task_request.py → task/dto/run_task_request.py} +1 -1
  123. thestage/task/dto/run_task_response.py +13 -0
  124. thestage/{services/task/dto/task_dto.py → task/dto/task.py} +1 -4
  125. thestage/{entities/project_task.py → task/dto/task_entity.py} +1 -1
  126. thestage/{services/clients/thestage_api/dtos/task_controller/task_view_response.py → task/dto/view_response.py} +2 -2
  127. {thestage-0.6.7.dist-info → thestage-0.7.0.dist-info}/METADATA +1 -1
  128. thestage-0.7.0.dist-info/RECORD +226 -0
  129. {thestage-0.6.7.dist-info → thestage-0.7.0.dist-info}/WHEEL +1 -1
  130. thestage/controllers/project_controller.py +0 -1056
  131. thestage/services/clients/thestage_api/api_client.py +0 -751
  132. thestage/services/clients/thestage_api/dtos/container_param_request.py +0 -11
  133. thestage/services/clients/thestage_api/dtos/inference_controller/get_inference_simulator_response.py +0 -13
  134. thestage/services/clients/thestage_api/dtos/project_controller/project_run_task_response.py +0 -13
  135. thestage/services/clients/thestage_api/dtos/project_controller/project_start_inference_simulator_response.py +0 -10
  136. thestage/services/clients/thestage_api/dtos/user_controller/user_profile.py +0 -12
  137. thestage/services/project/project_service.py +0 -1287
  138. thestage-0.6.7.dist-info/RECORD +0 -167
  139. /thestage/{entities → color_scheme}/__init__.py +0 -0
  140. /thestage/{entities/enums → config/business}/__init__.py +0 -0
  141. /thestage/{services/clients/git → config/communication}/__init__.py +0 -0
  142. /thestage/{services/clients/thestage_api/dtos/enums → config/dto}/__init__.py +0 -0
  143. /thestage/{services/core_files → config/dto}/config_entity.py +0 -0
  144. /thestage/{services/connect → config}/dto/remote_server_config.py +0 -0
  145. /thestage/{services/config_provider → connect}/__init__.py +0 -0
  146. /thestage/{services/container → connect/business}/__init__.py +0 -0
  147. /thestage/{services/container/mapper → connect/communication}/__init__.py +0 -0
  148. /thestage/{services/instance → connect/dto}/__init__.py +0 -0
  149. /thestage/{services/clients/thestage_api/dtos/ssh_key_controller → connect/dto}/add_ssh_key_to_user_request.py +0 -0
  150. /thestage/{services/clients/thestage_api/dtos/ssh_key_controller → connect/dto}/add_ssh_public_key_to_instance_request.py +0 -0
  151. /thestage/{services/clients/thestage_api/dtos/ssh_key_controller → connect/dto}/is_user_has_public_ssh_key_request.py +0 -0
  152. /thestage/{services/clients/thestage_api/dtos/ssh_key_controller → connect/dto}/is_user_has_public_ssh_key_response.py +0 -0
  153. /thestage/{services/instance/mapper → docker_container}/__init__.py +0 -0
  154. /thestage/{services/project → docker_container/business}/__init__.py +0 -0
  155. /thestage/{services/project → docker_container/business}/mapper/__init__.py +0 -0
  156. /thestage/{entities/container.py → docker_container/dto/container_entity.py} +0 -0
  157. /thestage/{services/clients/thestage_api/dtos/docker_container_controller → docker_container/dto}/docker_container_list_request.py +0 -0
  158. /thestage/{services/clients/thestage_api/dtos → docker_container/dto}/docker_container_mapping.py +0 -0
  159. /thestage/{services/clients/thestage_api/dtos/enums → docker_container/dto/enum}/container_pending_action.py +0 -0
  160. /thestage/{services/clients/thestage_api/dtos/enums → docker_container/dto/enum}/container_status.py +0 -0
  161. /thestage/{services/logging/exception → exceptions}/log_polling_exception.py +0 -0
  162. /thestage/git/{ProgressPrinter.py → business/ProgressPrinter.py} +0 -0
  163. /thestage/{entities → global_dto}/enums/order_direction_type.py +0 -0
  164. /thestage/{entities → global_dto}/enums/shell_type.py +0 -0
  165. /thestage/{entities → global_dto}/enums/tail_output_type.py +0 -0
  166. /thestage/{entities → global_dto}/enums/yes_no_response.py +0 -0
  167. /thestage/{entities → global_dto}/file_item.py +0 -0
  168. /thestage/{services/clients/thestage_api/dtos/inference_controller → inference_model/dto}/deploy_inference_model_to_instance_request.py +0 -0
  169. /thestage/{services/clients/thestage_api/dtos/inference_controller → inference_model/dto}/deploy_inference_model_to_sagemaker_request.py +0 -0
  170. /thestage/{services/clients/thestage_api/dtos/inference_controller → inference_model/dto}/deploy_inference_model_to_sagemaker_response.py +0 -0
  171. /thestage/{services/clients/thestage_api/dtos/enums → inference_model/dto/enum}/inference_model_status.py +0 -0
  172. /thestage/{services/clients/thestage_api/dtos/inference_controller → inference_model/dto}/inference_simulator_model_list_for_project_request.py +0 -0
  173. /thestage/{services/clients/thestage_api/dtos → inference_model/dto}/inference_simulator_model_response.py +0 -0
  174. /thestage/{services/clients/thestage_api/dtos/enums → inference_simulator/dto/enum}/inference_simulator_status.py +0 -0
  175. /thestage/{services/clients/thestage_api/dtos/inference_controller → inference_simulator/dto}/get_inference_simulator_request.py +0 -0
  176. /thestage/{services/clients/thestage_api/dtos/inference_controller → inference_simulator/dto}/inference_simulator_list_request.py +0 -0
  177. /thestage/{services/clients/thestage_api/dtos → inference_simulator/dto}/inference_simulator_response.py +0 -0
  178. /thestage/{services/clients/thestage_api/dtos/enums → instance/dto/enum}/cpu_type.py +0 -0
  179. /thestage/{services/clients/thestage_api/dtos/enums → instance/dto/enum}/gpu_name.py +0 -0
  180. /thestage/{services/clients/thestage_api/dtos/enums → instance/dto/enum}/instance_rented_status.py +0 -0
  181. /thestage/{services/clients/thestage_api/dtos/enums → instance/dto/enum}/provider_name.py +0 -0
  182. /thestage/{services/clients/thestage_api/dtos/enums → instance/dto/enum}/selfhosted_status.py +0 -0
  183. /thestage/{entities → instance/dto}/rented_instance.py +0 -0
  184. /thestage/{entities → instance/dto}/self_hosted_instance.py +0 -0
  185. /thestage/{services/logging → logging}/byte_print_style.py +0 -0
  186. /thestage/{services/clients/thestage_api/dtos/logging_controller → logging/dto}/docker_container_log_stream_request.py +0 -0
  187. /thestage/{services/logging → logging}/dto/log_message.py +0 -0
  188. /thestage/{services/clients/thestage_api/dtos/logging_controller → logging/dto}/log_polling_request.py +0 -0
  189. /thestage/{services/logging → logging}/dto/log_type.py +0 -0
  190. /thestage/{services/clients/thestage_api/dtos/logging_controller → logging/dto}/task_log_stream_request.py +0 -0
  191. /thestage/{services/clients/thestage_api/dtos/logging_controller → logging/dto}/user_logs_query_request.py +0 -0
  192. /thestage/{services/logging → logging}/logging_constants.py +0 -0
  193. /thestage/{services/clients/thestage_api/dtos/project_controller/project_get_deploy_ssh_key_request.py → project/dto/get_deploy_ssh_key_request.py} +0 -0
  194. /thestage/{services/clients/thestage_api/dtos/project_controller/project_get_deploy_ssh_key_response.py → project/dto/get_deploy_ssh_key_response.py} +0 -0
  195. /thestage/{services/project → project}/dto/project_config.py +0 -0
  196. /thestage/{services/clients/thestage_api/dtos → project/dto}/project_response.py +0 -0
  197. /thestage/{services/clients/thestage_api/dtos/enums → task/dto/enum}/task_execution_status.py +0 -0
  198. /thestage/{services/clients/thestage_api/dtos/enums → task/dto/enum}/task_status.py +0 -0
  199. /thestage/{services/clients/thestage_api/dtos/task_controller/task_list_for_project_request.py → task/dto/list_for_project_request.py} +0 -0
  200. /thestage/{services/clients/thestage_api/dtos/task_controller/task_status_localized_map_response.py → task/dto/status_localized_map_response.py} +0 -0
  201. {thestage-0.6.7.dist-info → thestage-0.7.0.dist-info}/entry_points.txt +0 -0
  202. {thestage-0.6.7.dist-info → thestage-0.7.0.dist-info}/licenses/LICENSE.txt +0 -0
@@ -1,37 +1,36 @@
1
1
  from pathlib import Path
2
- from typing import List, Optional, Dict
2
+ from typing import List, Optional
3
3
 
4
4
  import typer
5
5
 
6
- from thestage.entities.rented_instance import RentedInstanceEntity
7
- from thestage.entities.self_hosted_instance import SelfHostedInstanceEntity
6
+ from thestage.instance.communication.instance_api_client import InstanceApiClient
7
+ from thestage.instance.dto.rented_instance import RentedInstanceEntity
8
+ from thestage.instance.dto.self_hosted_instance import SelfHostedInstanceEntity
8
9
  from thestage.i18n.translation import __
9
- from thestage.services.clients.thestage_api.dtos.enums.selfhosted_status import SelfhostedBusinessStatus
10
- from thestage.services.clients.thestage_api.dtos.enums.instance_rented_status import InstanceRentedBusinessStatus
10
+ from thestage.instance.dto.enum.selfhosted_status import SelfhostedBusinessStatus
11
+ from thestage.instance.dto.enum.instance_rented_status import InstanceRentedBusinessStatus
11
12
  from thestage.services.abstract_service import AbstractService
12
13
  from thestage.helpers.error_handler import error_handler
13
- from thestage.services.clients.thestage_api.api_client import TheStageApiClient
14
- from thestage.services.clients.thestage_api.dtos.instance_rented_response import InstanceRentedDto
14
+ from thestage.instance.dto.instance_rented_response import InstanceRentedDto
15
15
  from thestage.services.clients.thestage_api.dtos.paginated_entity_list import PaginatedEntityList
16
- from thestage.services.clients.thestage_api.dtos.selfhosted_instance_response import SelfHostedInstanceDto
17
- from thestage.services.config_provider.config_provider import ConfigProvider
18
- from thestage.services.instance.mapper.instance_mapper import InstanceMapper
19
- from thestage.services.instance.mapper.selfhosted_mapper import SelfHostedMapper
20
- from thestage.services.remote_server_service import RemoteServerService
16
+ from thestage.instance.dto.selfhosted_instance_response import SelfHostedInstanceDto
17
+ from thestage.config.business.config_provider import ConfigProvider
18
+ from thestage.instance.business.mapper.rented_instance_mapper import RentedInstanceMapper
19
+ from thestage.instance.business.mapper.selfhosted_instance_mapper import SelfHostedInstanceMapper
20
+ from thestage.connect.business.remote_server_service import RemoteServerService
21
21
 
22
22
 
23
23
  class InstanceService(AbstractService):
24
-
25
- __thestage_api_client: TheStageApiClient = None
24
+ __instance_api_client: InstanceApiClient = None
26
25
  __config_provider: ConfigProvider = None
27
26
 
28
27
  def __init__(
29
28
  self,
30
- thestage_api_client: TheStageApiClient,
29
+ instance_api_client: InstanceApiClient,
31
30
  config_provider: ConfigProvider,
32
31
  remote_server_service: RemoteServerService,
33
32
  ):
34
- self.__thestage_api_client = thestage_api_client
33
+ self.__instance_api_client = instance_api_client
35
34
  self.__remote_server_service = remote_server_service
36
35
  self.__config_provider = config_provider
37
36
 
@@ -54,7 +53,7 @@ class InstanceService(AbstractService):
54
53
  InstanceRentedBusinessStatus.TERMINATING.name,
55
54
  InstanceRentedBusinessStatus.RENTAL_ERROR.name,
56
55
  ]:
57
- typer.echo(__('Cannot connect to rented server instance: renting process failed'))
56
+ typer.echo(__('Cannot connect to rented server instance: renting failed'))
58
57
  raise typer.Exit(1)
59
58
  elif instance.frontend_status.status_key in [
60
59
  InstanceRentedBusinessStatus.STOPPED.name,
@@ -105,7 +104,7 @@ class InstanceService(AbstractService):
105
104
  instance_rented_slug: Optional[str],
106
105
  input_ssh_key_path: Optional[str]
107
106
  ):
108
- instance = self.__thestage_api_client.get_rented_instance(
107
+ instance = self.__instance_api_client.get_rented_instance(
109
108
  instance_public_id=instance_rented_public_id,
110
109
  instance_slug=instance_rented_slug,
111
110
  )
@@ -119,7 +118,7 @@ class InstanceService(AbstractService):
119
118
  if not input_ssh_key_path:
120
119
  ssh_path_from_config = self.__config_provider.get_valid_private_key_path_by_ip_address(instance.ip_address)
121
120
  if ssh_path_from_config:
122
- typer.echo(f"Using configured ssh key for this instance: {ssh_path_from_config}")
121
+ typer.echo(f"Using configured SSH key for this instance: {ssh_path_from_config}")
123
122
 
124
123
  if not input_ssh_key_path and not ssh_path_from_config:
125
124
  typer.echo('Using SSH agent to connect to server instance')
@@ -149,7 +148,7 @@ class InstanceService(AbstractService):
149
148
  username = 'root'
150
149
  typer.echo(__("No remote server username provided, using 'root' as username"))
151
150
 
152
- instance = self.__thestage_api_client.get_selfhosted_instance(
151
+ instance = self.__instance_api_client.get_selfhosted_instance(
153
152
  instance_public_id=selfhosted_instance_public_id,
154
153
  instance_slug=selfhosted_instance_slug,
155
154
  )
@@ -163,7 +162,7 @@ class InstanceService(AbstractService):
163
162
  if not input_ssh_key_path:
164
163
  ssh_path_from_config = self.__config_provider.get_valid_private_key_path_by_ip_address(instance.ip_address)
165
164
  if ssh_path_from_config:
166
- typer.echo(f"Using configured ssh key for this instance: {ssh_path_from_config}")
165
+ typer.echo(f"Using configured SSH key for this instance: {ssh_path_from_config}")
167
166
 
168
167
  if not input_ssh_key_path and not ssh_path_from_config:
169
168
  typer.echo('Using SSH agent to connect to server instance')
@@ -187,7 +186,7 @@ class InstanceService(AbstractService):
187
186
  row: int = 5,
188
187
  page: int = 1,
189
188
  ) -> PaginatedEntityList[InstanceRentedDto]:
190
- data = self.__thestage_api_client.get_rented_instance_list(
189
+ data = self.__instance_api_client.get_rented_instance_list(
191
190
  statuses=statuses,
192
191
  page=page,
193
192
  limit=row,
@@ -202,7 +201,7 @@ class InstanceService(AbstractService):
202
201
  row: int = 5,
203
202
  page: int = 1,
204
203
  ) -> PaginatedEntityList[SelfHostedInstanceDto]:
205
- data = self.__thestage_api_client.get_selfhosted_instance_list(
204
+ data = self.__instance_api_client.get_selfhosted_instance_list(
206
205
  statuses=statuses,
207
206
  page=page,
208
207
  limit=row,
@@ -212,7 +211,7 @@ class InstanceService(AbstractService):
212
211
 
213
212
  @error_handler()
214
213
  def print_self_hosted_instance_list(self, statuses, row, page):
215
- selfhosted_instance_status_map = self.__thestage_api_client.get_selfhosted_business_status_map()
214
+ selfhosted_instance_status_map = self.__instance_api_client.get_selfhosted_business_status_map()
216
215
 
217
216
  if not statuses:
218
217
  statuses = ({key: selfhosted_instance_status_map[key] for key in [
@@ -245,7 +244,7 @@ class InstanceService(AbstractService):
245
244
  func_special_params={
246
245
  'statuses': backend_statuses,
247
246
  },
248
- mapper=SelfHostedMapper(),
247
+ mapper=SelfHostedInstanceMapper(),
249
248
  headers=list(map(lambda x: x.alias, SelfHostedInstanceEntity.model_fields.values())),
250
249
  row=row,
251
250
  page=page,
@@ -255,7 +254,7 @@ class InstanceService(AbstractService):
255
254
 
256
255
  @error_handler()
257
256
  def print_rented_instance_list(self, statuses, row, page):
258
- instance_rented_status_map = self.__thestage_api_client.get_rented_business_status_map()
257
+ instance_rented_status_map = self.__instance_api_client.get_rented_business_status_map()
259
258
 
260
259
  if not statuses:
261
260
  statuses = ({key: instance_rented_status_map[key] for key in [
@@ -289,7 +288,7 @@ class InstanceService(AbstractService):
289
288
  func_special_params={
290
289
  'statuses': backend_statuses,
291
290
  },
292
- mapper=InstanceMapper(),
291
+ mapper=RentedInstanceMapper(),
293
292
  headers=list(map(lambda x: x.alias, RentedInstanceEntity.model_fields.values())),
294
293
  row=row,
295
294
  page=page,
File without changes
@@ -1,11 +1,11 @@
1
1
  from typing import Optional
2
2
 
3
- from thestage.entities.rented_instance import RentedInstanceEntity
4
- from thestage.services.clients.thestage_api.dtos.instance_rented_response import InstanceRentedDto
3
+ from thestage.instance.dto.rented_instance import RentedInstanceEntity
4
+ from thestage.instance.dto.instance_rented_response import InstanceRentedDto
5
5
  from thestage.services.abstract_mapper import AbstractMapper
6
6
 
7
7
 
8
- class InstanceMapper(AbstractMapper):
8
+ class RentedInstanceMapper(AbstractMapper):
9
9
 
10
10
  def build_entity(self, item: InstanceRentedDto) -> Optional[RentedInstanceEntity]:
11
11
  if not item:
@@ -1,14 +1,12 @@
1
- from abc import ABC
2
- from typing import Optional, Any, Tuple
1
+ from typing import Optional
3
2
 
4
- from thestage.entities.rented_instance import RentedInstanceEntity
5
- from thestage.entities.self_hosted_instance import SelfHostedInstanceEntity
6
- from thestage.services.clients.thestage_api.dtos.enums.gpu_name import InstanceGpuType
7
- from thestage.services.clients.thestage_api.dtos.selfhosted_instance_response import SelfHostedInstanceDto
3
+ from thestage.instance.dto.self_hosted_instance import SelfHostedInstanceEntity
4
+ from thestage.instance.dto.enum.gpu_name import InstanceGpuType
5
+ from thestage.instance.dto.selfhosted_instance_response import SelfHostedInstanceDto
8
6
  from thestage.services.abstract_mapper import AbstractMapper
9
7
 
10
8
 
11
- class SelfHostedMapper(AbstractMapper):
9
+ class SelfHostedInstanceMapper(AbstractMapper):
12
10
 
13
11
  def build_entity(self, item: SelfHostedInstanceDto) -> Optional[SelfHostedInstanceEntity]:
14
12
  if not item:
File without changes
@@ -0,0 +1,150 @@
1
+ from typing import Optional, List, Dict
2
+
3
+ from thestage.config.business.config_provider import ConfigProvider
4
+ from thestage.services.clients.thestage_api.core.api_client_core import TheStageApiClientCore
5
+ from thestage.services.clients.thestage_api.dtos.paginated_entity_list import PaginatedEntityList
6
+
7
+ from thestage.instance.dto.instance_rented_response import (
8
+ InstanceRentedListResponse,
9
+ InstanceRentedDto,
10
+ InstanceRentedItemResponse,
11
+ InstanceRentedBusinessStatusMapperResponse
12
+ )
13
+ from thestage.instance.dto.selfhosted_instance_response import (
14
+ SelfHostedInstanceListResponse,
15
+ SelfHostedInstanceDto,
16
+ SelfHostedRentedItemResponse,
17
+ SelfHostedRentedRentedBusinessStatusMapperResponse
18
+ )
19
+
20
+
21
+ class InstanceApiClient(TheStageApiClientCore):
22
+ def __init__(self, config_provider: ConfigProvider):
23
+ super().__init__(url=config_provider.get_config().main.thestage_api_url)
24
+ self.__config_provider = config_provider
25
+
26
+ def get_rented_instance_list(
27
+ self,
28
+ statuses: List[str],
29
+ page: int = 1,
30
+ limit: int = 10,
31
+ ) -> PaginatedEntityList[InstanceRentedDto]:
32
+ data = {
33
+ #"statuses": [item.value for item in statuses],
34
+ "entityFilterRequest": {
35
+ "orderByField": "createdAt",
36
+ "orderByDirection": "DESC",
37
+ "page": page,
38
+ "limit": limit
39
+ },
40
+ }
41
+
42
+ if statuses:
43
+ data['businessStatuses'] = statuses
44
+
45
+ response = self._request(
46
+ method='POST',
47
+ url='/user-api/v3/instance-rented/list',
48
+ data=data,
49
+ token=self.__config_provider.get_config().main.thestage_auth_token,
50
+ )
51
+
52
+ result = InstanceRentedListResponse.model_validate(response) if response else None
53
+ return result.paginated_list if result and result.paginated_list else ([], None)
54
+
55
+ def get_rented_business_status_map(self) -> Optional[Dict[str, str]]:
56
+ response = self._request(
57
+ method='POST',
58
+ url='/user-api/v2/instance-rented/business-status-localized-map',
59
+ data=None,
60
+ token=self.__config_provider.get_config().main.thestage_auth_token,
61
+ )
62
+
63
+ data = InstanceRentedBusinessStatusMapperResponse.model_validate(response) if response else None
64
+
65
+ return data.instance_rented_business_status_map if data else None
66
+
67
+
68
+
69
+ def get_rented_instance(
70
+ self,
71
+ instance_public_id: Optional[str] = None,
72
+ instance_slug: Optional[str] = None,
73
+ ) -> Optional[InstanceRentedDto]:
74
+ if not instance_slug and not instance_public_id:
75
+ return None
76
+
77
+ data = {
78
+ "instanceRentedPublicId": instance_public_id,
79
+ "instanceRentedSlug": instance_slug,
80
+ }
81
+
82
+ response = self._request(
83
+ method='POST',
84
+ url='/user-api/v3/instance-rented/view',
85
+ data=data,
86
+ token=self.__config_provider.get_config().main.thestage_auth_token,
87
+ )
88
+
89
+ return InstanceRentedItemResponse.model_validate(response).instance_rented if response else None
90
+
91
+ def get_selfhosted_instance(
92
+ self,
93
+ instance_public_id: Optional[str] = None,
94
+ instance_slug: Optional[str] = None,
95
+ ) -> Optional[SelfHostedInstanceDto]:
96
+ if not instance_slug and not instance_public_id:
97
+ return None
98
+
99
+ data = {
100
+ "selfhostedInstancePublicId": instance_public_id,
101
+ "selfhostedInstanceSlug": instance_slug,
102
+ }
103
+
104
+ response = self._request(
105
+ method='POST',
106
+ url='/user-api/v3/self-hosted-instance/view',
107
+ data=data,
108
+ token=self.__config_provider.get_config().main.thestage_auth_token,
109
+ )
110
+
111
+ return SelfHostedRentedItemResponse.model_validate(response).selfhosted_instance if response else None
112
+
113
+ def get_selfhosted_instance_list(
114
+ self,
115
+ statuses: List[str],
116
+ page: int = 1,
117
+ limit: int = 10,
118
+ ) -> PaginatedEntityList[SelfHostedInstanceDto]:
119
+ data = {
120
+ "entityFilterRequest": {
121
+ "orderByField": "createdAt",
122
+ "orderByDirection": "DESC",
123
+ "page": page,
124
+ "limit": limit
125
+ }
126
+ }
127
+
128
+ if statuses:
129
+ data['businessStatuses'] = statuses
130
+
131
+ response = self._request(
132
+ method='POST',
133
+ url='/user-api/v3/self-hosted-instance/list',
134
+ data=data,
135
+ token=self.__config_provider.get_config().main.thestage_auth_token,
136
+ )
137
+
138
+ result = SelfHostedInstanceListResponse.model_validate(response) if response else None
139
+ return result.paginated_list if result and result.paginated_list else ([], None)
140
+
141
+ def get_selfhosted_business_status_map(self) -> Optional[Dict[str, str]]:
142
+ response = self._request(
143
+ method='POST',
144
+ url='/user-api/v2/self-hosted-instance/business-status-localized-map',
145
+ data=None,
146
+ token=self.__config_provider.get_config().main.thestage_auth_token,
147
+ )
148
+
149
+ data = SelfHostedRentedRentedBusinessStatusMapperResponse.model_validate(response) if response else None
150
+ return data.selfhosted_instance_business_status_map if data else None
@@ -4,7 +4,7 @@ from typing import Optional, List
4
4
  from thestage.cli_command import CliCommand
5
5
  from thestage.cli_command_helper import get_command_group_help_panel, get_command_metadata, check_command_permission
6
6
  from thestage.helpers.logger.app_logger import app_logger
7
- from thestage.services.instance.instance_service import InstanceService
7
+ from thestage.instance.business.instance_service import InstanceService
8
8
  from thestage.i18n.translation import __
9
9
  from thestage.controllers.utils_controller import \
10
10
  validate_config_and_get_service_factory, get_current_directory
@@ -91,7 +91,7 @@ def instance_connect(
91
91
  check_command_permission(command_name)
92
92
 
93
93
  if sum(v is not None for v in [public_id, slug]) != 1:
94
- typer.echo("Please provide a single identifier for rented instance - ID or name.")
94
+ typer.echo("Provide a single identifier for rented instance - ID or name.")
95
95
  raise typer.Exit(1)
96
96
 
97
97
  if private_ssh_key_path and not Path(private_ssh_key_path).is_file():
@@ -107,7 +107,7 @@ def instance_connect(
107
107
  input_ssh_key_path=private_ssh_key_path
108
108
  )
109
109
 
110
- app_logger.info(f'Stop connecting to rented server instance')
110
+ app_logger.info(f'Connection to rented instance closed')
111
111
  raise typer.Exit(0)
112
112
 
113
113
 
@@ -188,7 +188,7 @@ def self_hosted_connect(
188
188
  check_command_permission(command_name)
189
189
 
190
190
  if sum(v is not None for v in [public_id, slug]) != 1:
191
- typer.echo("Please provide a single identifier for self-hosted instance - ID or name.")
191
+ typer.echo("Provide a single identifier for self-hosted instance - ID or name.")
192
192
  raise typer.Exit(1)
193
193
 
194
194
  if private_ssh_key_path and not Path(private_ssh_key_path).is_file():
@@ -205,5 +205,5 @@ def self_hosted_connect(
205
205
  input_ssh_key_path=private_ssh_key_path
206
206
  )
207
207
 
208
- app_logger.info(f'Stop connecting to self-hosted instance')
208
+ app_logger.info(f'Connection to self-hosted instance closed')
209
209
  raise typer.Exit(0)
File without changes
File without changes
@@ -1,9 +1,8 @@
1
-
2
1
  from typing import Optional, List
3
2
 
4
3
  from pydantic import Field, BaseModel, ConfigDict
5
4
 
6
- from thestage.services.clients.thestage_api.dtos.enums.gpu_name import InstanceGpuType
5
+ from thestage.instance.dto.enum.gpu_name import InstanceGpuType
7
6
 
8
7
 
9
8
  class InstanceDaemonGpuDto(BaseModel):
@@ -5,8 +5,8 @@ from pydantic import Field, BaseModel, ConfigDict
5
5
  from thestage.services.clients.thestage_api.dtos.frontend_status import FrontendStatusDto
6
6
  from thestage.services.clients.thestage_api.dtos.base_response import TheStageBasePaginatedResponse
7
7
  from thestage.services.clients.thestage_api.dtos.paginated_entity_list import PaginatedEntityList
8
- from thestage.services.clients.thestage_api.dtos.enums.gpu_name import InstanceGpuType
9
- from thestage.services.clients.thestage_api.dtos.enums.cpu_type import InstanceCpuType
8
+ from thestage.instance.dto.enum.gpu_name import InstanceGpuType
9
+ from thestage.instance.dto.enum.cpu_type import InstanceCpuType
10
10
 
11
11
 
12
12
  class InstanceRentedDto(BaseModel):
@@ -1,4 +1,3 @@
1
- from datetime import datetime
2
1
  from typing import Optional, Dict
3
2
 
4
3
  from pydantic import Field, BaseModel, ConfigDict
@@ -6,8 +5,8 @@ from pydantic import Field, BaseModel, ConfigDict
6
5
  from thestage.services.clients.thestage_api.dtos.base_response import TheStageBasePaginatedResponse
7
6
  from thestage.services.clients.thestage_api.dtos.frontend_status import FrontendStatusDto
8
7
  from thestage.services.clients.thestage_api.dtos.paginated_entity_list import PaginatedEntityList
9
- from thestage.services.clients.thestage_api.dtos.instance_detected_gpus import InstanceDetectedGpusDto
10
- from thestage.services.clients.thestage_api.dtos.enums.cpu_type import InstanceCpuType
8
+ from thestage.instance.dto.instance_detected_gpus import InstanceDetectedGpusDto
9
+ from thestage.instance.dto.enum.cpu_type import InstanceCpuType
11
10
 
12
11
 
13
12
  class SelfHostedInstanceDto(BaseModel):
File without changes
File without changes
@@ -1,6 +1,6 @@
1
1
  import asyncio
2
2
  from _signal import SIGINT
3
- from asyncio import CancelledError, Task, StreamWriter
3
+ from asyncio import CancelledError, StreamWriter
4
4
  from datetime import datetime
5
5
  from typing import Optional, Dict
6
6
 
@@ -8,43 +8,55 @@ import aioconsole
8
8
  import typer
9
9
  from httpx import ReadTimeout, ConnectError, ConnectTimeout
10
10
 
11
+ from thestage.docker_container.communication.docker_container_api_client import DockerContainerApiClient
11
12
  from thestage.helpers.logger.app_logger import app_logger
12
- from thestage.services.clients.thestage_api.dtos.enums.container_status import DockerContainerStatus
13
- from thestage.services.clients.thestage_api.dtos.enums.inference_simulator_status import InferenceSimulatorStatus
14
- from thestage.services.clients.thestage_api.dtos.enums.task_status import TaskStatus
15
- from thestage.services.clients.thestage_api.dtos.inference_controller.get_inference_simulator_response import \
13
+ from thestage.docker_container.dto.enum.container_status import DockerContainerStatus
14
+ from thestage.inference_simulator.communication.inference_simulator_api_client import InferenceSimulatorApiClient
15
+ from thestage.inference_simulator.dto.enum.inference_simulator_status import InferenceSimulatorStatus
16
+ from thestage.logging.communication.logging_api_client import LoggingApiClient
17
+ from thestage.task.communication.task_api_client import TaskApiClient
18
+ from thestage.task.dto.enum.task_status import TaskStatus
19
+ from thestage.inference_simulator.dto.get_inference_simulator_response import \
16
20
  GetInferenceSimulatorResponse
17
- from thestage.services.clients.thestage_api.dtos.task_controller.task_view_response import TaskViewResponse
18
- from thestage.services.logging.byte_print_style import BytePrintStyle
19
- from thestage.services.logging.dto.log_message import LogMessage
20
- from thestage.services.logging.dto.log_type import LogType
21
+ from thestage.task.dto.view_response import TaskViewResponse
22
+ from thestage.logging.byte_print_style import BytePrintStyle
23
+ from thestage.logging.dto.log_message import LogMessage
24
+ from thestage.logging.dto.log_type import LogType
21
25
  from thestage.i18n.translation import __
22
- from thestage.services.abstract_service import AbstractService
23
- from thestage.services.clients.thestage_api.dtos.container_response import DockerContainerDto
26
+ from thestage.docker_container.dto.container_response import DockerContainerDto
24
27
  from thestage.helpers.error_handler import error_handler
25
- from thestage.services.clients.thestage_api.api_client import TheStageApiClient
26
28
  from rich import print
27
29
 
28
- from thestage.services.logging.exception.log_polling_exception import LogPollingException
29
- from thestage.services.logging.logging_constants import LOG_MESSAGE_CODE_TASK_FINISHED, \
30
+ from thestage.exceptions.log_polling_exception import LogPollingException
31
+ from thestage.logging.logging_constants import LOG_MESSAGE_CODE_TASK_FINISHED, \
30
32
  LOG_MESSAGE_CODE_INFERENCE_SIMULATOR_FAILED
31
33
 
32
34
  is_logs_streaming = False
33
35
 
34
36
 
35
37
  class LoggingService:
36
- __thestage_api_client: TheStageApiClient = None
38
+ __logging_api_client: LoggingApiClient = None
39
+ __task_api_client: TaskApiClient = None
40
+ __inference_simulator_api_client: InferenceSimulatorApiClient = None
41
+ __docker_container_api_client: DockerContainerApiClient = None
37
42
 
38
43
  def __init__(
39
44
  self,
40
- thestage_api_client: TheStageApiClient,
45
+ logging_api_client: LoggingApiClient,
46
+ docker_container_api_client: DockerContainerApiClient,
47
+ task_api_client: TaskApiClient,
48
+ inference_simulator_api_client: InferenceSimulatorApiClient,
49
+
41
50
  ):
42
- self.__thestage_api_client = thestage_api_client
51
+ self.__logging_api_client = logging_api_client
52
+ self.__docker_container_api_client = docker_container_api_client
53
+ self.__task_api_client = task_api_client
54
+ self.__inference_simulator_api_client = inference_simulator_api_client
43
55
 
44
56
 
45
57
  @error_handler()
46
58
  def print_last_task_logs(self, task_public_id: str, logs_number: Optional[int]):
47
- logs = self.__thestage_api_client.query_user_logs(
59
+ logs = self.__logging_api_client.query_user_logs(
48
60
  task_public_id=task_public_id,
49
61
  limit=logs_number
50
62
  )
@@ -54,7 +66,7 @@ class LoggingService:
54
66
 
55
67
  @error_handler()
56
68
  def print_last_inference_simulator_logs(self, inference_simulator_public_id: str, logs_number: Optional[int]):
57
- logs = self.__thestage_api_client.query_user_logs(
69
+ logs = self.__logging_api_client.query_user_logs(
58
70
  inference_simulator_public_id=inference_simulator_public_id,
59
71
  limit=logs_number
60
72
  )
@@ -64,7 +76,7 @@ class LoggingService:
64
76
 
65
77
  @error_handler()
66
78
  def print_last_container_logs(self, container_public_id: Optional[str], container_slug: Optional[str], logs_number: Optional[int]):
67
- container: Optional[DockerContainerDto] = self.__thestage_api_client.get_container(
79
+ container: Optional[DockerContainerDto] = self.__docker_container_api_client.get_container(
68
80
  container_public_id=container_public_id,
69
81
  container_slug=container_slug,
70
82
  )
@@ -73,7 +85,7 @@ class LoggingService:
73
85
  typer.echo("Container was not found")
74
86
  raise typer.Exit(1)
75
87
 
76
- logs = self.__thestage_api_client.query_user_logs(
88
+ logs = self.__logging_api_client.query_user_logs(
77
89
  container_public_id=container.public_id,
78
90
  limit=logs_number
79
91
  )
@@ -90,9 +102,9 @@ class LoggingService:
90
102
 
91
103
  @error_handler()
92
104
  async def __stream_task_logs_with_controls_async(self, task_public_id: str):
93
- task_view_response: Optional[TaskViewResponse] = self.__thestage_api_client.get_task(task_public_id=task_public_id,)
105
+ task_view_response: Optional[TaskViewResponse] = self.__task_api_client.get_task(task_public_id=task_public_id,)
94
106
 
95
- task_status_map: Dict[str, str] = self.__thestage_api_client.get_task_localized_status_map()
107
+ task_status_map: Dict[str, str] = self.__task_api_client.get_task_localized_status_map()
96
108
 
97
109
  task = task_view_response.task
98
110
 
@@ -128,7 +140,7 @@ class LoggingService:
128
140
  print_logs_task.cancel()
129
141
  if not input_task.result(): # result is only expected if ctrl+D triggered EOFError
130
142
  typer.echo(f"\rTask {task_public_id} will be canceled")
131
- self.__thestage_api_client.cancel_task(
143
+ self.__task_api_client.cancel_task(
132
144
  task_public_id=task.public_id,
133
145
  )
134
146
 
@@ -143,12 +155,12 @@ class LoggingService:
143
155
 
144
156
  @error_handler()
145
157
  async def __stream_inference_simulator_logs_with_controls_async(self, public_id: Optional[str], slug: Optional[str]):
146
- get_inference_simulator_response: Optional[GetInferenceSimulatorResponse] = self.__thestage_api_client.get_inference_simulator(
158
+ get_inference_simulator_response: Optional[GetInferenceSimulatorResponse] = self.__inference_simulator_api_client.get_inference_simulator(
147
159
  public_id=public_id,
148
160
  slug=slug,
149
161
  )
150
162
 
151
- inference_simulator_status_map: Dict[str, str] = self.__thestage_api_client.get_inference_simulator_business_status_map()
163
+ inference_simulator_status_map: Dict[str, str] = self.__inference_simulator_api_client.get_inference_simulator_business_status_map()
152
164
 
153
165
  inference_simulator = get_inference_simulator_response.inferenceSimulator
154
166
 
@@ -195,7 +207,7 @@ class LoggingService:
195
207
 
196
208
  @error_handler()
197
209
  async def __stream_container_logs_with_controls_async(self, container_public_id: Optional[str], container_slug: Optional[str]):
198
- container: Optional[DockerContainerDto] = self.__thestage_api_client.get_container(
210
+ container: Optional[DockerContainerDto] = self.__docker_container_api_client.get_container(
199
211
  container_public_id=container_public_id,
200
212
  container_slug=container_slug,
201
213
  )
@@ -264,7 +276,7 @@ class LoggingService:
264
276
  # stream_to_logs_diff = datetime.utcnow() - last_log_timestamp_parsed
265
277
  # print_nonblocking(f'TDIFF {stream_to_logs_diff.total_seconds()}', writer)
266
278
  try:
267
- logs_response = await self.__thestage_api_client.poll_logs_httpx(
279
+ logs_response = await self.__logging_api_client.poll_logs_httpx(
268
280
  task_public_id=task_public_id,
269
281
  inference_simulator_public_id=inference_simulator_public_id,
270
282
  docker_container_public_id=docker_container_public_id,
File without changes
@@ -0,0 +1,63 @@
1
+ from typing import Optional
2
+
3
+ import httpx
4
+
5
+ from thestage.config.business.config_provider import ConfigProvider
6
+ from thestage.services.clients.thestage_api.core.api_client_core import TheStageApiClientCore
7
+ from thestage.logging.dto.log_polling_request import LogPollingRequest
8
+ from thestage.logging.dto.log_polling_response import LogPollingResponse
9
+ from thestage.logging.dto.user_logs_query_request import UserLogsQueryRequest
10
+ from thestage.logging.dto.user_logs_query_response import UserLogsQueryResponse
11
+
12
+
13
+ class LoggingApiClient(TheStageApiClientCore):
14
+ def __init__(self, config_provider: ConfigProvider):
15
+ super().__init__(url=config_provider.get_config().main.thestage_api_url)
16
+ self.__config_provider = config_provider
17
+
18
+ async def poll_logs_httpx(self, docker_container_public_id: Optional[str], last_log_timestamp: str,
19
+ last_log_id: str, task_public_id: Optional[str] = None,
20
+ inference_simulator_public_id: Optional[str] = None) -> Optional[LogPollingResponse]:
21
+ request_headers = {'Content-Type': 'application/json'}
22
+ token = self.__config_provider.get_config().main.thestage_auth_token
23
+ if token: request_headers['Authorization'] = f"Bearer {token}"
24
+
25
+ request = LogPollingRequest(
26
+ inferenceSimulatorPublicId=inference_simulator_public_id,
27
+ taskPublicId=task_public_id,
28
+ dockerContainerPublicId=docker_container_public_id,
29
+ lastLogTimestamp=last_log_timestamp,
30
+ lastLogId=last_log_id
31
+ )
32
+
33
+ async with httpx.AsyncClient() as client:
34
+ response = await client.post(
35
+ url=f"{self._get_host()}/user-api/v2/logging/poll",
36
+ headers=request_headers,
37
+ json=request.model_dump(),
38
+ timeout=3.5
39
+ )
40
+
41
+ return LogPollingResponse.model_validate(response.json()) if response else None
42
+
43
+
44
+ def query_user_logs(self, limit: int, task_public_id: Optional[str] = None,
45
+ inference_simulator_public_id: Optional[str] = None,
46
+ container_public_id: Optional[str] = None) -> UserLogsQueryResponse:
47
+ request = UserLogsQueryRequest(
48
+ inferenceSimulatorPublicId=inference_simulator_public_id,
49
+ taskPublicId=task_public_id,
50
+ containerPublicId=container_public_id,
51
+ limit=limit,
52
+ ascendingOrder=False,
53
+ )
54
+
55
+ response = self._request(
56
+ method='POST',
57
+ url='/user-api/v2/logging/query-user-logs',
58
+ data=request.model_dump(),
59
+ token=self.__config_provider.get_config().main.thestage_auth_token,
60
+ )
61
+
62
+ result = UserLogsQueryResponse.model_validate(response) if response else None
63
+ return result