eclypse 0.1__tar.gz

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 (126) hide show
  1. eclypse-0.1/LICENSE +21 -0
  2. eclypse-0.1/PKG-INFO +4 -0
  3. eclypse-0.1/README.md +31 -0
  4. eclypse-0.1/eclypse/__init__.py +7 -0
  5. eclypse-0.1/eclypse/builders/__init__.py +6 -0
  6. eclypse-0.1/eclypse/builders/application/__init__.py +8 -0
  7. eclypse-0.1/eclypse/builders/application/sock_shop/__init__.py +8 -0
  8. eclypse-0.1/eclypse/builders/application/sock_shop/application.py +258 -0
  9. eclypse-0.1/eclypse/builders/application/sock_shop/mpi_services/__init__.py +19 -0
  10. eclypse-0.1/eclypse/builders/application/sock_shop/mpi_services/cart.py +50 -0
  11. eclypse-0.1/eclypse/builders/application/sock_shop/mpi_services/catalog.py +51 -0
  12. eclypse-0.1/eclypse/builders/application/sock_shop/mpi_services/frontend.py +72 -0
  13. eclypse-0.1/eclypse/builders/application/sock_shop/mpi_services/order.py +111 -0
  14. eclypse-0.1/eclypse/builders/application/sock_shop/mpi_services/payment.py +50 -0
  15. eclypse-0.1/eclypse/builders/application/sock_shop/mpi_services/shipping.py +55 -0
  16. eclypse-0.1/eclypse/builders/application/sock_shop/mpi_services/user.py +52 -0
  17. eclypse-0.1/eclypse/builders/application/sock_shop/rest_services/__init__.py +19 -0
  18. eclypse-0.1/eclypse/builders/application/sock_shop/rest_services/cart.py +37 -0
  19. eclypse-0.1/eclypse/builders/application/sock_shop/rest_services/catalog.py +40 -0
  20. eclypse-0.1/eclypse/builders/application/sock_shop/rest_services/frontend.py +52 -0
  21. eclypse-0.1/eclypse/builders/application/sock_shop/rest_services/order.py +67 -0
  22. eclypse-0.1/eclypse/builders/application/sock_shop/rest_services/payment.py +49 -0
  23. eclypse-0.1/eclypse/builders/application/sock_shop/rest_services/shipping.py +48 -0
  24. eclypse-0.1/eclypse/builders/application/sock_shop/rest_services/user.py +43 -0
  25. eclypse-0.1/eclypse/builders/infrastructure.py +340 -0
  26. eclypse-0.1/eclypse/core/__init__.py +0 -0
  27. eclypse-0.1/eclypse/core/graph/__init__.py +3 -0
  28. eclypse-0.1/eclypse/core/graph/asset_graph.py +291 -0
  29. eclypse-0.1/eclypse/core/placement/__init__.py +10 -0
  30. eclypse-0.1/eclypse/core/placement/manager.py +218 -0
  31. eclypse-0.1/eclypse/core/placement/view.py +198 -0
  32. eclypse-0.1/eclypse/core/remote/__init__.py +4 -0
  33. eclypse-0.1/eclypse/core/remote/communication/__init__.py +12 -0
  34. eclypse-0.1/eclypse/core/remote/communication/interface.py +156 -0
  35. eclypse-0.1/eclypse/core/remote/communication/mpi/__init__.py +11 -0
  36. eclypse-0.1/eclypse/core/remote/communication/mpi/interface.py +182 -0
  37. eclypse-0.1/eclypse/core/remote/communication/mpi/requests/__init__.py +12 -0
  38. eclypse-0.1/eclypse/core/remote/communication/mpi/requests/broadcast.py +54 -0
  39. eclypse-0.1/eclypse/core/remote/communication/mpi/requests/multicast.py +57 -0
  40. eclypse-0.1/eclypse/core/remote/communication/mpi/requests/unicast.py +96 -0
  41. eclypse-0.1/eclypse/core/remote/communication/mpi/response.py +43 -0
  42. eclypse-0.1/eclypse/core/remote/communication/request.py +183 -0
  43. eclypse-0.1/eclypse/core/remote/communication/rest/__init__.py +8 -0
  44. eclypse-0.1/eclypse/core/remote/communication/rest/codes.py +39 -0
  45. eclypse-0.1/eclypse/core/remote/communication/rest/http_request.py +108 -0
  46. eclypse-0.1/eclypse/core/remote/communication/rest/interface.py +208 -0
  47. eclypse-0.1/eclypse/core/remote/communication/rest/methods.py +25 -0
  48. eclypse-0.1/eclypse/core/remote/communication/route.py +108 -0
  49. eclypse-0.1/eclypse/core/remote/node/__init__.py +5 -0
  50. eclypse-0.1/eclypse/core/remote/node/node.py +180 -0
  51. eclypse-0.1/eclypse/core/remote/node/ops_thread.py +141 -0
  52. eclypse-0.1/eclypse/core/remote/service/__init__.py +7 -0
  53. eclypse-0.1/eclypse/core/remote/service/rest.py +46 -0
  54. eclypse-0.1/eclypse/core/remote/service/service.py +239 -0
  55. eclypse-0.1/eclypse/core/remote/utils/__init__.py +38 -0
  56. eclypse-0.1/eclypse/core/remote/utils/ops.py +22 -0
  57. eclypse-0.1/eclypse/core/remote/utils/response_code.py +22 -0
  58. eclypse-0.1/eclypse/core/report/__init__.py +5 -0
  59. eclypse-0.1/eclypse/core/report/metric.py +212 -0
  60. eclypse-0.1/eclypse/core/report/report.py +743 -0
  61. eclypse-0.1/eclypse/core/report/reporters/__init__.py +12 -0
  62. eclypse-0.1/eclypse/core/report/reporters/csv.py +61 -0
  63. eclypse-0.1/eclypse/core/report/reporters/gml.py +56 -0
  64. eclypse-0.1/eclypse/core/report/reporters/reporter.py +79 -0
  65. eclypse-0.1/eclypse/core/report/reporters/tensorboard.py +91 -0
  66. eclypse-0.1/eclypse/core/simulation.py +311 -0
  67. eclypse-0.1/eclypse/core/simulator/__init__.py +6 -0
  68. eclypse-0.1/eclypse/core/simulator/local.py +435 -0
  69. eclypse-0.1/eclypse/core/simulator/ops_handler.py +164 -0
  70. eclypse-0.1/eclypse/core/simulator/remote.py +171 -0
  71. eclypse-0.1/eclypse/core/simulator/reporter.py +63 -0
  72. eclypse-0.1/eclypse/core/utils/__init__.py +2 -0
  73. eclypse-0.1/eclypse/core/utils/constants.py +91 -0
  74. eclypse-0.1/eclypse/core/utils/logging.py +75 -0
  75. eclypse-0.1/eclypse/core/utils/tools.py +262 -0
  76. eclypse-0.1/eclypse/core/utils/types.py +48 -0
  77. eclypse-0.1/eclypse/core/workflow/__init__.py +6 -0
  78. eclypse-0.1/eclypse/core/workflow/callbacks/__init__.py +14 -0
  79. eclypse-0.1/eclypse/core/workflow/callbacks/callback.py +388 -0
  80. eclypse-0.1/eclypse/core/workflow/callbacks/decorator.py +104 -0
  81. eclypse-0.1/eclypse/core/workflow/callbacks/wrapper.py +42 -0
  82. eclypse-0.1/eclypse/core/workflow/events/__init__.py +9 -0
  83. eclypse-0.1/eclypse/core/workflow/events/decorator.py +82 -0
  84. eclypse-0.1/eclypse/core/workflow/events/defaults.py +60 -0
  85. eclypse-0.1/eclypse/core/workflow/events/event.py +243 -0
  86. eclypse-0.1/eclypse/core/workflow/events/wrapper.py +35 -0
  87. eclypse-0.1/eclypse/graph/__init__.py +14 -0
  88. eclypse-0.1/eclypse/graph/application.py +138 -0
  89. eclypse-0.1/eclypse/graph/assets/__init__.py +30 -0
  90. eclypse-0.1/eclypse/graph/assets/additive.py +87 -0
  91. eclypse-0.1/eclypse/graph/assets/asset.py +133 -0
  92. eclypse-0.1/eclypse/graph/assets/bucket.py +171 -0
  93. eclypse-0.1/eclypse/graph/assets/concave.py +81 -0
  94. eclypse-0.1/eclypse/graph/assets/convex.py +88 -0
  95. eclypse-0.1/eclypse/graph/assets/defaults.py +321 -0
  96. eclypse-0.1/eclypse/graph/assets/multiplicative.py +92 -0
  97. eclypse-0.1/eclypse/graph/assets/space.py +131 -0
  98. eclypse-0.1/eclypse/graph/assets/symbolic.py +71 -0
  99. eclypse-0.1/eclypse/graph/infrastructure.py +311 -0
  100. eclypse-0.1/eclypse/graph/node_group.py +82 -0
  101. eclypse-0.1/eclypse/metrics/__init__.py +24 -0
  102. eclypse-0.1/eclypse/metrics/defaults.py +524 -0
  103. eclypse-0.1/eclypse/metrics/metric.py +285 -0
  104. eclypse-0.1/eclypse/placement/__init__.py +1 -0
  105. eclypse-0.1/eclypse/placement/placement.py +230 -0
  106. eclypse-0.1/eclypse/placement/strategies/__init__.py +18 -0
  107. eclypse-0.1/eclypse/placement/strategies/best_fit.py +76 -0
  108. eclypse-0.1/eclypse/placement/strategies/first_fit.py +76 -0
  109. eclypse-0.1/eclypse/placement/strategies/placement_strategy.py +68 -0
  110. eclypse-0.1/eclypse/placement/strategies/random.py +71 -0
  111. eclypse-0.1/eclypse/placement/strategies/round_robin.py +62 -0
  112. eclypse-0.1/eclypse/placement/strategies/static.py +35 -0
  113. eclypse-0.1/eclypse/simulation/__init__.py +6 -0
  114. eclypse-0.1/eclypse/simulation/config.py +244 -0
  115. eclypse-0.1/eclypse/simulation/simulation.py +137 -0
  116. eclypse-0.1/eclypse/utils/__init__.py +27 -0
  117. eclypse-0.1/eclypse/workflow/__init__.py +4 -0
  118. eclypse-0.1/eclypse/workflow/callback.py +294 -0
  119. eclypse-0.1/eclypse/workflow/event.py +40 -0
  120. eclypse-0.1/eclypse.egg-info/PKG-INFO +4 -0
  121. eclypse-0.1/eclypse.egg-info/SOURCES.txt +124 -0
  122. eclypse-0.1/eclypse.egg-info/dependency_links.txt +1 -0
  123. eclypse-0.1/eclypse.egg-info/top_level.txt +1 -0
  124. eclypse-0.1/pyproject.toml +93 -0
  125. eclypse-0.1/setup.cfg +4 -0
  126. eclypse-0.1/setup.py +30 -0
eclypse-0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Valerio De Caro & Jacopo Massa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
eclypse-0.1/PKG-INFO ADDED
@@ -0,0 +1,4 @@
1
+ Metadata-Version: 2.1
2
+ Name: eclypse
3
+ Version: 0.1
4
+ License-File: LICENSE
eclypse-0.1/README.md ADDED
@@ -0,0 +1,31 @@
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="docs/_static/images/dark.png"><img width=450 alt="dips-logo" src="docs/_static/images/light.png"/>
4
+ </picture>
5
+ </p>
6
+
7
+ [![codecov](https://codecov.io/gh/eclypse-org/eclypse/graph/badge.svg?token=3BKF8SX0HK)](https://codecov.io/gh/eclypse-org/eclypse)
8
+ ![Python Version from PEP 621 TOML](https://img.shields.io/python/required-version-toml?tomlFilePath=https%3A%2F%2Fraw.githubusercontent.com%2Feclypse-org%2Feclypse%2Fmain%2Fpyproject.toml)
9
+ [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&)](https://github.com/pre-commit/pre-commit)
10
+ [![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
11
+ [![Checked wit pylint](https://img.shields.io/badge/pylint-10/10-green)](https://pylint.pycqa.org/en/latest/)
12
+
13
+ [![Import sorted with isort](https://img.shields.io/badge/isort-checked-brightgreen)](https://pycqa.github.io/isort/)
14
+ [![IMport cleaned with pycln](https://img.shields.io/badge/pycln-checked-brightgreen)](https://github.com/hadialqattan/pycln)
15
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-black)](https://github.com/psf/black)
16
+ [![Doc style: docformatter](https://img.shields.io/badge/doc%20style-docformatter-black)](https://github.com/PyCQA/docformatter)
17
+
18
+ **ECLYPSE** (**E**dge-**CL**oud p**Y**thon **P**latform for **S**imulated runtime **E**nvironments) is the first simulation library entirely written in Python , for experimenting with deployment strategies in varying infrastructure conditions. It provides an interface to simulate deployments of service-based applications onto life-like infrastructures, without and with an actual application implementation to be deployed.
19
+
20
+ ## Installation
21
+
22
+ To install ECLYPSE you can run the following commands:
23
+ ```bash
24
+
25
+ git clone https://github/eclypse-org/eclypse
26
+ cd eclypse
27
+ make install
28
+
29
+ ```
30
+
31
+ **N.B.** We **strongly** suggest the installation of ECLYPSE in a virtual environment.
@@ -0,0 +1,7 @@
1
+ # pylint: disable=missing-module-docstring
2
+ import os
3
+
4
+ __version__ = "0.5.1"
5
+
6
+ os.environ["RAY_DEDUP_LOGS"] = "0"
7
+ os.environ["RAY_COLOR_PREFIX"] = "1"
@@ -0,0 +1,6 @@
1
+ """Package for the application and infrastructure builders."""
2
+
3
+ from . import infrastructure
4
+ from . import application
5
+
6
+ __all__ = ["infrastructure", "application"]
@@ -0,0 +1,8 @@
1
+ """Module for the application builders. It has the following builders:
2
+
3
+ - SockShop: A microservice-based application that simulates an e-commerce platform, made of 7 microservices.
4
+ """
5
+
6
+ from .sock_shop.application import get_sock_shop
7
+
8
+ __all__ = ["get_sock_shop"]
@@ -0,0 +1,8 @@
1
+ """Module for the Sock Shop application builder. It provides a getter function to create
2
+ a Sock Shop application in 3 different configurations, by choosing the `communication
3
+ interface` in the getter:
4
+
5
+ - "None": The application graph without any remote Service configuration.
6
+ - "rest": The application graph with REST Services.
7
+ - "mpi": The application graph with MPI Services.
8
+ """
@@ -0,0 +1,258 @@
1
+ # pylint: disable=unnecessary-lambda-assignment,import-outside-toplevel
2
+ """The Sock Shop application."""
3
+
4
+ from __future__ import annotations
5
+
6
+ from typing import (
7
+ TYPE_CHECKING,
8
+ Callable,
9
+ Dict,
10
+ List,
11
+ Literal,
12
+ Optional,
13
+ Union,
14
+ )
15
+
16
+ from eclypse.graph import (
17
+ Application,
18
+ NodeGroup,
19
+ )
20
+ from eclypse.core.utils.tools import prune_assets
21
+
22
+ if TYPE_CHECKING:
23
+ from networkx.classes.reportviews import (
24
+ EdgeView,
25
+ NodeView,
26
+ )
27
+
28
+ from eclypse.graph.assets import Asset
29
+
30
+
31
+ def get_sock_shop(
32
+ application_id: str = "SockShop",
33
+ communication_interface: Optional[Literal["mpi", "rest"]] = None,
34
+ node_update_policy: Optional[Callable[[NodeView], None]] = None,
35
+ edge_update_policy: Optional[Callable[[EdgeView], None]] = None,
36
+ node_assets: Optional[Dict[str, Asset]] = None,
37
+ edge_assets: Optional[Dict[str, Asset]] = None,
38
+ include_default_assets: bool = True,
39
+ requirement_init: Literal["min", "max"] = "min",
40
+ flows: Union[Literal["default"], List[List[str]]] = "default",
41
+ seed: Optional[int] = None,
42
+ ) -> Application:
43
+ """Get the Sock Shop application.
44
+
45
+ Args:
46
+ application_id (str): The ID of the application.
47
+ communication_interface (Optional[Literal["mpi", "rest"]]): The communication interface.
48
+ node_update_policy (Optional[Callable[[NodeView], None]]): A function to update the nodes.
49
+ edge_update_policy (Optional[Callable[[EdgeView], None]]): A function to update the edges.
50
+ node_assets (Optional[Dict[str, Asset]]): The assets of the nodes.
51
+ edge_assets (Optional[Dict[str, Asset]]): The assets of the edges.
52
+ include_default_assets (bool): Whether to include the default assets.
53
+ requirement_init (Literal["min", "max"]): The initialization of the requirements.
54
+ flows (Optional[List[List[str]]): The flows of the application.
55
+ seed (Optional[int]): The seed for the random number generator.
56
+
57
+ Returns:
58
+ Application: The Sock Shop application.
59
+ """
60
+ if flows == "default":
61
+ _flows = [
62
+ ["FrontendService", "UserService", "FrontendService"], # Login
63
+ ["FrontendService", "CatalogService", "FrontendService"], # Browsing
64
+ [
65
+ "FrontendService",
66
+ "CatalogService",
67
+ "CartService",
68
+ "FrontendService",
69
+ ], # Adding to cart
70
+ [
71
+ "FrontendService",
72
+ "PaymentService",
73
+ "OrderService",
74
+ "ShippingService",
75
+ "FrontendService",
76
+ ], # Checkout
77
+ [
78
+ "FrontendService",
79
+ "OrderService",
80
+ "ShippingService",
81
+ "FrontendService",
82
+ ], # Shipping monitoring
83
+ ]
84
+ else:
85
+ _flows = flows
86
+
87
+ app = Application(
88
+ application_id=application_id,
89
+ node_update_policy=node_update_policy,
90
+ edge_update_policy=edge_update_policy,
91
+ node_assets=node_assets,
92
+ edge_assets=edge_assets,
93
+ include_default_assets=include_default_assets,
94
+ requirement_init=requirement_init,
95
+ flows=_flows,
96
+ seed=seed,
97
+ )
98
+
99
+ if communication_interface is None:
100
+ add_fn = app.add_node_by_group
101
+ id_fn = lambda service: service
102
+ elif communication_interface in ["mpi", "rest"]:
103
+ add_fn = app.add_service_by_group # type: ignore[assignment]
104
+ if communication_interface == "mpi":
105
+ from . import mpi_services as services
106
+ else:
107
+ from . import rest_services as services # type: ignore[no-redef]
108
+
109
+ classes = {
110
+ "CatalogService": services.CatalogService,
111
+ "UserService": services.UserService,
112
+ "CartService": services.CartService,
113
+ "OrderService": services.OrderService,
114
+ "PaymentService": services.PaymentService,
115
+ "ShippingService": services.ShippingService,
116
+ "FrontendService": services.FrontendService,
117
+ }
118
+ id_fn = lambda service: classes[service](service)
119
+ else:
120
+ raise ValueError(f"Unknown communication interface: {communication_interface}")
121
+
122
+ add_fn(
123
+ NodeGroup.FAR_EDGE,
124
+ id_fn("UserService"),
125
+ **prune_assets(
126
+ app.node_assets,
127
+ cpu=1,
128
+ gpu=0,
129
+ ram=0.75,
130
+ storage=0.3,
131
+ availability=0.91,
132
+ processing_time=10,
133
+ ),
134
+ )
135
+ add_fn(
136
+ NodeGroup.FAR_EDGE,
137
+ id_fn("FrontendService"),
138
+ **prune_assets(
139
+ app.node_assets,
140
+ cpu=1,
141
+ gpu=0,
142
+ ram=0.75,
143
+ storage=0.3,
144
+ availability=0.94,
145
+ processing_time=30,
146
+ ),
147
+ )
148
+ add_fn(
149
+ NodeGroup.FAR_EDGE,
150
+ id_fn("CatalogService"),
151
+ **prune_assets(
152
+ app.node_assets,
153
+ cpu=1,
154
+ gpu=0,
155
+ ram=1.5,
156
+ storage=0.75,
157
+ availability=0.91,
158
+ processing_time=12.5,
159
+ ),
160
+ )
161
+ add_fn(
162
+ NodeGroup.NEAR_EDGE,
163
+ id_fn("OrderService"),
164
+ **prune_assets(
165
+ app.node_assets,
166
+ cpu=2,
167
+ gpu=0,
168
+ ram=3.0,
169
+ storage=0.75,
170
+ availability=0.92,
171
+ processing_time=20,
172
+ ),
173
+ )
174
+ add_fn(
175
+ NodeGroup.NEAR_EDGE,
176
+ id_fn("CartService"),
177
+ **prune_assets(
178
+ app.node_assets,
179
+ cpu=1,
180
+ gpu=0,
181
+ ram=0.75,
182
+ storage=0.3,
183
+ availability=0.91,
184
+ processing_time=10,
185
+ ),
186
+ )
187
+ add_fn(
188
+ NodeGroup.NEAR_EDGE,
189
+ id_fn("PaymentService"),
190
+ **prune_assets(
191
+ app.node_assets,
192
+ cpu=1,
193
+ gpu=0,
194
+ ram=0.75,
195
+ storage=0.3,
196
+ availability=0.95,
197
+ processing_time=12.5,
198
+ ),
199
+ )
200
+ add_fn(
201
+ NodeGroup.NEAR_EDGE,
202
+ id_fn("ShippingService"),
203
+ **prune_assets(
204
+ app.node_assets,
205
+ cpu=1,
206
+ gpu=0,
207
+ ram=0.75,
208
+ storage=0.3,
209
+ availability=0.915,
210
+ processing_time=17.5,
211
+ ),
212
+ )
213
+
214
+ app.add_edge_by_group(
215
+ "FrontendService",
216
+ "CatalogService",
217
+ symmetric=True,
218
+ latency=40,
219
+ bandwidth=2,
220
+ )
221
+ app.add_edge_by_group(
222
+ "FrontendService",
223
+ "UserService",
224
+ symmetric=True,
225
+ latency=40,
226
+ bandwidth=2,
227
+ )
228
+ app.add_edge_by_group(
229
+ "FrontendService",
230
+ "CartService",
231
+ symmetric=True,
232
+ latency=40,
233
+ bandwidth=2,
234
+ )
235
+ app.add_edge_by_group(
236
+ "FrontendService",
237
+ "OrderService",
238
+ symmetric=True,
239
+ latency=50,
240
+ bandwidth=10,
241
+ )
242
+
243
+ app.add_edge_by_group(
244
+ "OrderService",
245
+ "PaymentService",
246
+ symmetric=True,
247
+ latency=50,
248
+ bandwidth=10,
249
+ )
250
+ app.add_edge_by_group(
251
+ "OrderService",
252
+ "ShippingService",
253
+ symmetric=True,
254
+ latency=70,
255
+ bandwidth=10,
256
+ )
257
+
258
+ return app
@@ -0,0 +1,19 @@
1
+ # pylint: disable=missing-module-docstring,duplicate-code
2
+
3
+ from .catalog import CatalogService
4
+ from .user import UserService
5
+ from .cart import CartService
6
+ from .order import OrderService
7
+ from .payment import PaymentService
8
+ from .shipping import ShippingService
9
+ from .frontend import FrontendService
10
+
11
+ __all__ = [
12
+ "CatalogService",
13
+ "UserService",
14
+ "CartService",
15
+ "OrderService",
16
+ "PaymentService",
17
+ "ShippingService",
18
+ "FrontendService",
19
+ ]
@@ -0,0 +1,50 @@
1
+ """The `CartService` handles the shopping cart functionality, allowing users to manage \
2
+
3
+ their desired items before making a purchase.
4
+ - Key Responsibilities:
5
+ - Manages the user’s shopping cart by adding, removing, or updating items.
6
+ - Stores cart data temporarily for guest users or long-term for registered users.
7
+ """
8
+
9
+ from eclypse.core.remote.communication import mpi
10
+ from eclypse.core.remote.service import ServiceEngine
11
+
12
+
13
+ class CartService(ServiceEngine):
14
+ """MPI workflow of the Cart service."""
15
+
16
+ async def dispatch(self):
17
+ """Example workflow of the Cart service, starting with fetching \ the user's
18
+ cart data."""
19
+ await self.frontend_request() # pylint: disable=no-value-for-parameter
20
+
21
+ @mpi.exchange(receive=True, send=True)
22
+ def frontend_request(self, sender_id, body):
23
+ """Process the frontend request and send the response to the `FrontendService`.
24
+
25
+ Args:
26
+ sender_id (str): The ID of the sender.
27
+ body (dict): The request body.
28
+
29
+ Returns:
30
+ str: The ID of the recipient.
31
+ dict: The response body.
32
+ """
33
+ self.logger.info(f"{self.id} - {body}")
34
+
35
+ # Send response to FrontendService
36
+ if body.get("request_type") == "cart_data":
37
+ frontend_response = {
38
+ "response_type": "cart_response",
39
+ "items": [
40
+ {"product_id": "1", "quantity": 2},
41
+ {"product_id": "2", "quantity": 1},
42
+ ],
43
+ }
44
+ else:
45
+ frontend_response = {
46
+ "response_type": "cart_response",
47
+ "status": "Invalid request",
48
+ }
49
+
50
+ return sender_id, frontend_response
@@ -0,0 +1,51 @@
1
+ """The `CatalogService` is responsible for managing and serving product information.
2
+
3
+ - Key Responsibilities:
4
+ -
5
+ - Supports operations such as searching for products and listing available items \
6
+ in the store.
7
+ - Interfaces with the underlying data store to fetch product data.
8
+ """
9
+
10
+ from eclypse.core.remote.communication import mpi
11
+ from eclypse.core.remote.service import ServiceEngine
12
+
13
+
14
+ class CatalogService(ServiceEngine):
15
+ """MPI workflows for the Catalog service."""
16
+
17
+ async def dispatch(self):
18
+ """The `CatalogService` workflow consists of receiving a request from the \
19
+ `FrontendService` and sending a response containing product information."""
20
+
21
+ @mpi.exchange(receive=True, send=True)
22
+ def frontend_request(self, sender_id, body):
23
+ """Process requests from the FrontendService and send responses back.
24
+
25
+ Args:
26
+ sender_id (str): The ID of the sender.
27
+ body (dict): The request body.
28
+
29
+ Returns:
30
+ str: The ID of the recipient.
31
+ dict: The response body.
32
+ """
33
+ self.logger.info(f"{self.id} - {body}")
34
+
35
+ # Send response to FrontendService
36
+ if body.get("request_type") == "catalog_data":
37
+
38
+ frontend_response = {
39
+ "response_type": "catalog_response",
40
+ "products": [
41
+ {"id": "1", "name": "Product 1", "price": 19.99},
42
+ {"id": "2", "name": "Product 2", "price": 29.99},
43
+ ],
44
+ }
45
+ else:
46
+ frontend_response = {
47
+ "response_type": "catalog_response",
48
+ "status": "Invalid request",
49
+ }
50
+
51
+ return sender_id, frontend_response
@@ -0,0 +1,72 @@
1
+ """The `FrontendService` serves as the user interface for the SockShop application, \
2
+
3
+ providing the user-facing components of the store.
4
+ - Key Responsibilities:
5
+ - Displays product catalogs, shopping carts, and order information to users.
6
+ - Interacts with backend services \
7
+ (e.g., `CatalogService`, `UserService`, `OrderService`) to display real-time data.
8
+ - Manages user input and interactions such as product searches, \
9
+ cart updates, and order placements.
10
+ """
11
+
12
+ from eclypse.core.remote.communication import mpi
13
+ from eclypse.core.remote.service import ServiceEngine
14
+
15
+
16
+ class FrontendService(ServiceEngine):
17
+ """MPI workflow of the Frontend service."""
18
+
19
+ def __init__(self, name):
20
+ super().__init__(name)
21
+ self.user_id = 12345
22
+
23
+ async def dispatch(self):
24
+ """Example workflow of the Frontend service, starting with fetching the catalog,
25
+ \ user data, and cart items, then placing an order."""
26
+ # Send request to CatalogService
27
+ await self.catalog_request()
28
+
29
+ # Receive response from CatalogService
30
+ catalog_response = await self.mpi.recv()
31
+
32
+ self.logger.info(f"{self.id} - {catalog_response}")
33
+
34
+ # Send request to UserService
35
+ user_request = {"request_type": "user_data", "user_id": self.user_id}
36
+ self.mpi.send("UserService", user_request)
37
+
38
+ # Receive response from UserService
39
+ user_response = await self.mpi.recv()
40
+ self.logger.info(f"{self.id} - {user_response}")
41
+
42
+ # Send request to CartService
43
+ cart_request = {"request_type": "cart_data", "user_id": self.user_id}
44
+ self.mpi.send("CartService", cart_request)
45
+
46
+ # Receive response from CartService
47
+ cart_response = await self.mpi.recv()
48
+ self.logger.info(f"{self.id} - {cart_response}")
49
+
50
+ cart_items = cart_response.get("items", [])
51
+
52
+ # Send request to OrderService
53
+ order_request = {
54
+ "request_type": "order_request",
55
+ "user_id": self.user_id,
56
+ "items": cart_items,
57
+ }
58
+ self.mpi.send("OrderService", order_request)
59
+
60
+ # Receive response from OrderService
61
+ order_response = await self.mpi.recv()
62
+ self.logger.info(f"{self.id} - {order_response}")
63
+
64
+ @mpi.exchange(send=True)
65
+ def catalog_request(self):
66
+ """Send a request to the CatalogService for product data.
67
+
68
+ Returns:
69
+ str: The recipient service name.
70
+ dict: The request body.
71
+ """
72
+ return "CatalogService", {"request_type": "catalog_data"}
@@ -0,0 +1,111 @@
1
+ # pylint: disable=no-value-for-parameter
2
+ """The `OrderService` processes user orders, ensuring the coordination between \
3
+
4
+ different services like payment, inventory, and shipping.
5
+ - Key Responsibilities:
6
+ - Creates, updates, and manages customer orders.
7
+ - Interacts with the `PaymentService` and `ShippingService` to complete the order transaction.
8
+ - Tracks the status of placed orders (e.g., pending, confirmed, shipped).
9
+ """
10
+
11
+ import random as rnd
12
+
13
+ from eclypse.core.remote.communication import mpi
14
+ from eclypse.core.remote.service import ServiceEngine
15
+
16
+
17
+ class OrderService(ServiceEngine):
18
+ """MPI workflow of the Order service."""
19
+
20
+ def __init__(self, name):
21
+ super().__init__(name)
22
+ self.order_id = 54321
23
+ self.transaction_id = None
24
+ self.shipping_details = {}
25
+ self.items = []
26
+
27
+ async def dispatch(self):
28
+ """Example workflow of the Order service, starting with processing the order \
29
+ request, then sending requests to the `PaymentService` and `ShippingService`."""
30
+ await self.frontend_request()
31
+ await self.payment_request()
32
+ await self.shipping_request()
33
+
34
+ @mpi.exchange(receive=True, send=True)
35
+ def frontend_request(self, _, body):
36
+ """Process the frontend request and send the response to the `PaymentService`.
37
+
38
+ Args:
39
+ body (dict): The request body.
40
+
41
+ Returns:
42
+ str: The ID of the recipient.
43
+ dict: The response body.
44
+ """
45
+
46
+ self.logger.info(f"{self.id} - {body}")
47
+
48
+ self.items = body.get("items", [])
49
+ total_amount = sum(rnd.randint(20, 100) for _ in self.items)
50
+
51
+ # Send request to PaymentService
52
+ payment_request = {
53
+ "request_type": "payment_request",
54
+ "order_id": self.order_id,
55
+ "amount": total_amount,
56
+ }
57
+
58
+ return "PaymentService", payment_request
59
+
60
+ @mpi.exchange(receive=True, send=True)
61
+ def payment_request(self, _, body):
62
+ """Process the payment request and send the response to the `ShippingService`.
63
+
64
+ Args:
65
+ body (dict): The request body.
66
+
67
+ Returns:
68
+ str: The ID of the recipient.
69
+ dict: The response body.
70
+ """
71
+ self.logger.info(f"{self.id} - {body}")
72
+
73
+ self.transaction_id = body.get("transaction_id")
74
+ # Send request to ShippingService
75
+ shipping_request = {
76
+ "request_type": "shipping_request",
77
+ "order_id": self.order_id,
78
+ }
79
+
80
+ return "ShippingService", shipping_request
81
+
82
+ @mpi.exchange(receive=True, send=True)
83
+ def shipping_request(self, _, body):
84
+ """Process the shipping request and send the response to the `FrontendService`.
85
+
86
+ Args:
87
+ body (dict): The request body.
88
+
89
+ Returns:
90
+ str: The ID of the recipient.
91
+ dict: The response body.
92
+ """
93
+ self.logger.info(f"{self.id} - {body}")
94
+
95
+ self.shipping_details = body.get("details")
96
+
97
+ # Send response to FrontendService
98
+ if self.transaction_id is not None:
99
+ order_response = {
100
+ "response_type": "order_response",
101
+ "status": "success",
102
+ "shipping_details": self.shipping_details,
103
+ "transaction_id": self.transaction_id,
104
+ }
105
+ else:
106
+ order_response = {
107
+ "response_type": "order_response",
108
+ "status": "failure",
109
+ }
110
+
111
+ return "FrontendService", order_response