mantatech-sdk 0.5b0.dev65__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 (54) hide show
  1. manta/__init__.light.py +22 -0
  2. manta/__init__.py +83 -0
  3. manta/__main__.py +21 -0
  4. manta/apis/__init__.py +7 -0
  5. manta/apis/async_user_api.py +6458 -0
  6. manta/apis/graph.py +498 -0
  7. manta/apis/module.py +316 -0
  8. manta/apis/results.py +251 -0
  9. manta/apis/swarm.py +206 -0
  10. manta/apis/user_api.py +1016 -0
  11. manta/cli/__init__.py +1 -0
  12. manta/cli/commands/__init__.py +1 -0
  13. manta/cli/commands/base_handler.py +229 -0
  14. manta/cli/commands/doc.py +192 -0
  15. manta/cli/commands/install.py +346 -0
  16. manta/cli/commands/sdk.py +9 -0
  17. manta/cli/commands/sdk_cluster.py +211 -0
  18. manta/cli/commands/sdk_config.py +347 -0
  19. manta/cli/commands/sdk_globals.py +280 -0
  20. manta/cli/commands/sdk_logs.py +174 -0
  21. manta/cli/commands/sdk_main.py +167 -0
  22. manta/cli/commands/sdk_module.py +516 -0
  23. manta/cli/commands/sdk_nodes.py +168 -0
  24. manta/cli/commands/sdk_original.py +3873 -0
  25. manta/cli/commands/sdk_results.py +265 -0
  26. manta/cli/commands/sdk_swarm.py +454 -0
  27. manta/cli/commands/sdk_user.py +234 -0
  28. manta/cli/commands/status.py +292 -0
  29. manta/cli/component_detector.py +112 -0
  30. manta/cli/config_manager.py +445 -0
  31. manta/cli/main.py +265 -0
  32. manta/cli/utils/__init__.py +27 -0
  33. manta/cli/utils/converters.py +140 -0
  34. manta/clients/cluster_management_client.py +486 -0
  35. manta/clients/local_client.py +149 -0
  36. manta/clients/module_management_client.py +217 -0
  37. manta/clients/swarm_management_client.py +562 -0
  38. manta/clients/user_management_client.py +395 -0
  39. manta/clients/world_client.py +195 -0
  40. manta/light/__init__.py +31 -0
  41. manta/light/globals.py +245 -0
  42. manta/light/local.py +407 -0
  43. manta/light/logging_config.py +39 -0
  44. manta/light/path.py +116 -0
  45. manta/light/results.py +236 -0
  46. manta/light/task.py +100 -0
  47. manta/light/utils.py +217 -0
  48. manta/light/world.py +177 -0
  49. mantatech_sdk-0.5b0.dev65.dist-info/METADATA +1039 -0
  50. mantatech_sdk-0.5b0.dev65.dist-info/RECORD +54 -0
  51. mantatech_sdk-0.5b0.dev65.dist-info/WHEEL +5 -0
  52. mantatech_sdk-0.5b0.dev65.dist-info/entry_points.txt +2 -0
  53. mantatech_sdk-0.5b0.dev65.dist-info/licenses/LICENSE +683 -0
  54. mantatech_sdk-0.5b0.dev65.dist-info/top_level.txt +1 -0
manta/light/world.py ADDED
@@ -0,0 +1,177 @@
1
+ import logging
2
+ import os
3
+ from typing import List, Optional
4
+
5
+ from ..clients.world_client import WorldClient
6
+ from manta_common.build.common.system import EnvId
7
+ from manta_common.build.common.tasks import TaskScheduling
8
+ from manta_common.conversions import ID
9
+ from manta_common.event_loop import EventLoopManager
10
+ from .globals import Globals
11
+ from .logging_config import configure_logging
12
+ from .results import Results
13
+
14
+ __all__ = ["World"]
15
+
16
+ configure_logging()
17
+
18
+
19
+ class World:
20
+ """
21
+ World service for accessing values with other nodes
22
+
23
+ The :code:`World` service allows the user to interact with collective values
24
+ during a :class:`Swarm <manta.swarm.Swarm>` iteration
25
+
26
+ Parameters should not be fulfill manually. Instead, it is managed during the
27
+ deployment of the task by the :code:`Node`.
28
+
29
+ Parameters
30
+ ----------
31
+ host : Optional[str]
32
+ Manager host
33
+ port : Optional[int]
34
+ Manager port
35
+ swarm_id : Optional[ID]
36
+ Swarm ID
37
+ task_id : Optional[ID]
38
+ Task ID
39
+ """
40
+
41
+ __slots__ = [
42
+ "swarm_id",
43
+ "task_id",
44
+ "logger",
45
+ "results",
46
+ "globals",
47
+ "world_client",
48
+ "loop_manager",
49
+ ]
50
+
51
+ def __init__(
52
+ self,
53
+ host: Optional[str] = None,
54
+ port: Optional[int] = None,
55
+ swarm_id: Optional[ID] = None,
56
+ task_id: Optional[ID] = None,
57
+ ):
58
+ # Retrieve environment variables for RPC host and port
59
+ host = host or os.getenv("RPC_HOST", "host.docker.internal")
60
+ port = int(port or os.getenv("RPC_PORT", 50051))
61
+ self.task_id = task_id or ID(os.getenv("TASK_ID"))
62
+ self.swarm_id = swarm_id or ID(os.getenv("SWARM_ID"))
63
+
64
+ self.logger = logging.getLogger(__name__)
65
+
66
+ self.logger.info(
67
+ f"World configured with Host: {host}, Port: {port},"
68
+ f" Task ID: {self.task_id},"
69
+ f" Swarm ID: {self.swarm_id}"
70
+ )
71
+
72
+ self.world_client = WorldClient(host=host, port=port)
73
+ self.loop_manager = EventLoopManager.get_instance()
74
+
75
+ self.results = Results(
76
+ world_client=self.world_client,
77
+ swarm_id=self.swarm_id,
78
+ task_id=self.task_id,
79
+ )
80
+ self.globals = Globals(
81
+ world_client=self.world_client, swarm_id=self.swarm_id, task_id=self.task_id
82
+ )
83
+
84
+ def schedule_next_iter(self, node_ids: List[str], task_to_schedule_alias: str):
85
+ """
86
+ Schedule the next iteration
87
+
88
+ Parameters
89
+ ----------
90
+ node_ids : List[str]
91
+ The list of node ids to schedule the next iteration for
92
+ task_to_schedule_alias : str
93
+ The task to schedule for the next iteration
94
+
95
+ Examples
96
+ --------
97
+
98
+ From :class:`Task <manta_light.task.Task>` attribute:
99
+
100
+ >>> self.world.schedule_next_iter(
101
+ ... node_ids=selected_nodes, task_to_schedule_alias="worker"
102
+ ... )
103
+ """
104
+ self.loop_manager.run_coroutine(
105
+ self.async_schedule_next_iter(node_ids, task_to_schedule_alias)
106
+ )
107
+
108
+ def stop_swarm(self):
109
+ """
110
+ Stop the swarm
111
+
112
+ Examples
113
+ --------
114
+
115
+ From :class:`Task <manta_light.task.Task>` attribute:
116
+
117
+ >>> self.world.stop_swarm()
118
+ """
119
+ self.loop_manager.run_coroutine(self.async_stop_swarm())
120
+
121
+ def __str__(self): # pragma: no cover
122
+ return f"World(host={self.world_client.host}, port={self.world_client.port}, swarm_id={self.swarm_id}, task_id={self.task_id})"
123
+
124
+ def __repr__(self): # pragma: no cover
125
+ return str(self)
126
+
127
+ # Asynchronous methods
128
+
129
+ async def async_schedule_next_iter(
130
+ self, node_ids: List[str], task_to_schedule_alias: str
131
+ ):
132
+ """
133
+ Schedule the next iteration
134
+
135
+ Parameters
136
+ ----------
137
+ node_ids : List[str]
138
+ The list of node ids to schedule the next iteration for
139
+ task_to_schedule_alias : str
140
+ The task to schedule for the next iteration
141
+
142
+ Examples
143
+ --------
144
+
145
+ Same as :meth:`schedule_next_iter <manta_light.world.World.schedule_next_iter>`
146
+ but asynchronous:
147
+
148
+ >>> await self.world.async_schedule_next_iter(
149
+ ... node_ids=selected_nodes, task_to_schedule_alias="worker"
150
+ ... )
151
+ """
152
+ await self.world_client.schedule_task(
153
+ TaskScheduling(
154
+ task_id=self.task_id.oid,
155
+ node_ids=[ID(node_id).oid for node_id in node_ids],
156
+ task_to_schedule_alias=task_to_schedule_alias,
157
+ swarm_id=self.swarm_id.oid,
158
+ )
159
+ )
160
+ self.logger.info("Schedule next iteration")
161
+
162
+ async def async_stop_swarm(self):
163
+ """
164
+ Stop the swarm
165
+
166
+ Examples
167
+ --------
168
+
169
+ Same as :meth:`stop_swarm <manta_light.world.World.stop_swarm>`
170
+ but asynchronous:
171
+
172
+ >>> await self.world.async_stop_swarm()
173
+ """
174
+ await self.world_client.stop_swarm(
175
+ EnvId(swarm_id=self.swarm_id.oid, task_id=self.task_id.oid)
176
+ )
177
+ self.logger.info("Stop swarm response")