flwr-nightly 1.8.0.dev20240315__py3-none-any.whl → 1.15.0.dev20250115__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- flwr/cli/app.py +16 -2
- flwr/cli/build.py +181 -0
- flwr/cli/cli_user_auth_interceptor.py +90 -0
- flwr/cli/config_utils.py +343 -0
- flwr/cli/example.py +4 -1
- flwr/cli/install.py +253 -0
- flwr/cli/log.py +182 -0
- flwr/{server/superlink/state → cli/login}/__init__.py +4 -10
- flwr/cli/login/login.py +88 -0
- flwr/cli/ls.py +327 -0
- flwr/cli/new/__init__.py +1 -0
- flwr/cli/new/new.py +210 -66
- flwr/cli/new/templates/app/.gitignore.tpl +163 -0
- flwr/cli/new/templates/app/LICENSE.tpl +202 -0
- flwr/cli/new/templates/app/README.baseline.md.tpl +127 -0
- flwr/cli/new/templates/app/README.flowertune.md.tpl +66 -0
- flwr/cli/new/templates/app/README.md.tpl +16 -32
- flwr/cli/new/templates/app/code/__init__.baseline.py.tpl +1 -0
- flwr/cli/new/templates/app/code/__init__.py.tpl +1 -1
- flwr/cli/new/templates/app/code/client.baseline.py.tpl +58 -0
- flwr/cli/new/templates/app/code/client.huggingface.py.tpl +55 -0
- flwr/cli/new/templates/app/code/client.jax.py.tpl +50 -0
- flwr/cli/new/templates/app/code/client.mlx.py.tpl +73 -0
- flwr/cli/new/templates/app/code/client.numpy.py.tpl +7 -7
- flwr/cli/new/templates/app/code/client.pytorch.py.tpl +30 -21
- flwr/cli/new/templates/app/code/client.sklearn.py.tpl +63 -0
- flwr/cli/new/templates/app/code/client.tensorflow.py.tpl +57 -1
- flwr/cli/new/templates/app/code/dataset.baseline.py.tpl +36 -0
- flwr/cli/new/templates/app/code/flwr_tune/__init__.py +15 -0
- flwr/cli/new/templates/app/code/flwr_tune/client_app.py.tpl +126 -0
- flwr/cli/new/templates/app/code/flwr_tune/dataset.py.tpl +87 -0
- flwr/cli/new/templates/app/code/flwr_tune/models.py.tpl +78 -0
- flwr/cli/new/templates/app/code/flwr_tune/server_app.py.tpl +94 -0
- flwr/cli/new/templates/app/code/flwr_tune/strategy.py.tpl +83 -0
- flwr/cli/new/templates/app/code/model.baseline.py.tpl +80 -0
- flwr/cli/new/templates/app/code/server.baseline.py.tpl +46 -0
- flwr/cli/new/templates/app/code/server.huggingface.py.tpl +38 -0
- flwr/cli/new/templates/app/code/server.jax.py.tpl +26 -0
- flwr/cli/new/templates/app/code/server.mlx.py.tpl +31 -0
- flwr/cli/new/templates/app/code/server.numpy.py.tpl +22 -9
- flwr/cli/new/templates/app/code/server.pytorch.py.tpl +21 -18
- flwr/cli/new/templates/app/code/server.sklearn.py.tpl +36 -0
- flwr/cli/new/templates/app/code/server.tensorflow.py.tpl +29 -1
- flwr/cli/new/templates/app/code/strategy.baseline.py.tpl +1 -0
- flwr/cli/new/templates/app/code/task.huggingface.py.tpl +102 -0
- flwr/cli/new/templates/app/code/task.jax.py.tpl +57 -0
- flwr/cli/new/templates/app/code/task.mlx.py.tpl +102 -0
- flwr/cli/new/templates/app/code/task.numpy.py.tpl +7 -0
- flwr/cli/new/templates/app/code/task.pytorch.py.tpl +29 -24
- flwr/cli/new/templates/app/code/task.sklearn.py.tpl +67 -0
- flwr/cli/new/templates/app/code/task.tensorflow.py.tpl +53 -0
- flwr/cli/new/templates/app/code/utils.baseline.py.tpl +1 -0
- flwr/cli/new/templates/app/pyproject.baseline.toml.tpl +138 -0
- flwr/cli/new/templates/app/pyproject.flowertune.toml.tpl +68 -0
- flwr/cli/new/templates/app/pyproject.huggingface.toml.tpl +46 -0
- flwr/cli/new/templates/app/pyproject.jax.toml.tpl +35 -0
- flwr/cli/new/templates/app/pyproject.mlx.toml.tpl +39 -0
- flwr/cli/new/templates/app/pyproject.numpy.toml.tpl +25 -12
- flwr/cli/new/templates/app/pyproject.pytorch.toml.tpl +29 -14
- flwr/cli/new/templates/app/pyproject.sklearn.toml.tpl +35 -0
- flwr/cli/new/templates/app/pyproject.tensorflow.toml.tpl +29 -14
- flwr/cli/run/__init__.py +1 -0
- flwr/cli/run/run.py +212 -34
- flwr/cli/stop.py +130 -0
- flwr/cli/utils.py +240 -5
- flwr/client/__init__.py +3 -2
- flwr/client/app.py +432 -255
- flwr/client/client.py +1 -11
- flwr/client/client_app.py +74 -13
- flwr/client/clientapp/__init__.py +22 -0
- flwr/client/clientapp/app.py +259 -0
- flwr/client/clientapp/clientappio_servicer.py +244 -0
- flwr/client/clientapp/utils.py +115 -0
- flwr/client/dpfedavg_numpy_client.py +7 -8
- flwr/client/grpc_adapter_client/__init__.py +15 -0
- flwr/client/grpc_adapter_client/connection.py +98 -0
- flwr/client/grpc_client/connection.py +21 -7
- flwr/client/grpc_rere_client/__init__.py +1 -1
- flwr/client/grpc_rere_client/client_interceptor.py +176 -0
- flwr/client/grpc_rere_client/connection.py +163 -56
- flwr/client/grpc_rere_client/grpc_adapter.py +167 -0
- flwr/client/heartbeat.py +74 -0
- flwr/client/message_handler/__init__.py +1 -1
- flwr/client/message_handler/message_handler.py +10 -11
- flwr/client/mod/__init__.py +5 -5
- flwr/client/mod/centraldp_mods.py +4 -2
- flwr/client/mod/comms_mods.py +5 -4
- flwr/client/mod/localdp_mod.py +10 -5
- flwr/client/mod/secure_aggregation/__init__.py +1 -1
- flwr/client/mod/secure_aggregation/secaggplus_mod.py +26 -26
- flwr/client/mod/utils.py +2 -4
- flwr/client/nodestate/__init__.py +26 -0
- flwr/client/nodestate/in_memory_nodestate.py +38 -0
- flwr/client/nodestate/nodestate.py +31 -0
- flwr/client/nodestate/nodestate_factory.py +38 -0
- flwr/client/numpy_client.py +8 -31
- flwr/client/rest_client/__init__.py +1 -1
- flwr/client/rest_client/connection.py +199 -176
- flwr/client/run_info_store.py +112 -0
- flwr/client/supernode/__init__.py +24 -0
- flwr/client/supernode/app.py +321 -0
- flwr/client/typing.py +1 -0
- flwr/common/__init__.py +17 -11
- flwr/common/address.py +47 -3
- flwr/common/args.py +153 -0
- flwr/common/auth_plugin/__init__.py +24 -0
- flwr/common/auth_plugin/auth_plugin.py +121 -0
- flwr/common/config.py +243 -0
- flwr/common/constant.py +135 -1
- flwr/common/context.py +32 -2
- flwr/common/date.py +22 -4
- flwr/common/differential_privacy.py +2 -2
- flwr/common/dp.py +2 -4
- flwr/common/exit_handlers.py +3 -3
- flwr/common/grpc.py +164 -5
- flwr/common/logger.py +230 -12
- flwr/common/message.py +191 -106
- flwr/common/object_ref.py +179 -44
- flwr/common/pyproject.py +1 -0
- flwr/common/record/__init__.py +2 -1
- flwr/common/record/configsrecord.py +58 -18
- flwr/common/record/metricsrecord.py +57 -17
- flwr/common/record/parametersrecord.py +88 -20
- flwr/common/record/recordset.py +153 -30
- flwr/common/record/typeddict.py +30 -55
- flwr/common/recordset_compat.py +31 -12
- flwr/common/retry_invoker.py +123 -30
- flwr/common/secure_aggregation/__init__.py +1 -1
- flwr/common/secure_aggregation/crypto/__init__.py +1 -1
- flwr/common/secure_aggregation/crypto/shamir.py +11 -11
- flwr/common/secure_aggregation/crypto/symmetric_encryption.py +68 -4
- flwr/common/secure_aggregation/ndarrays_arithmetic.py +17 -17
- flwr/common/secure_aggregation/quantization.py +8 -8
- flwr/common/secure_aggregation/secaggplus_constants.py +1 -1
- flwr/common/secure_aggregation/secaggplus_utils.py +10 -12
- flwr/common/serde.py +304 -23
- flwr/common/telemetry.py +65 -29
- flwr/common/typing.py +120 -19
- flwr/common/version.py +17 -3
- flwr/proto/clientappio_pb2.py +45 -0
- flwr/proto/clientappio_pb2.pyi +132 -0
- flwr/proto/clientappio_pb2_grpc.py +135 -0
- flwr/proto/clientappio_pb2_grpc.pyi +53 -0
- flwr/proto/exec_pb2.py +62 -0
- flwr/proto/exec_pb2.pyi +212 -0
- flwr/proto/exec_pb2_grpc.py +237 -0
- flwr/proto/exec_pb2_grpc.pyi +93 -0
- flwr/proto/fab_pb2.py +31 -0
- flwr/proto/fab_pb2.pyi +65 -0
- flwr/proto/fab_pb2_grpc.py +4 -0
- flwr/proto/fab_pb2_grpc.pyi +4 -0
- flwr/proto/fleet_pb2.py +42 -23
- flwr/proto/fleet_pb2.pyi +123 -1
- flwr/proto/fleet_pb2_grpc.py +170 -0
- flwr/proto/fleet_pb2_grpc.pyi +61 -0
- flwr/proto/grpcadapter_pb2.py +32 -0
- flwr/proto/grpcadapter_pb2.pyi +43 -0
- flwr/proto/grpcadapter_pb2_grpc.py +66 -0
- flwr/proto/grpcadapter_pb2_grpc.pyi +24 -0
- flwr/proto/log_pb2.py +29 -0
- flwr/proto/log_pb2.pyi +39 -0
- flwr/proto/log_pb2_grpc.py +4 -0
- flwr/proto/log_pb2_grpc.pyi +4 -0
- flwr/proto/message_pb2.py +41 -0
- flwr/proto/message_pb2.pyi +128 -0
- flwr/proto/message_pb2_grpc.py +4 -0
- flwr/proto/message_pb2_grpc.pyi +4 -0
- flwr/proto/node_pb2.py +2 -2
- flwr/proto/node_pb2.pyi +1 -4
- flwr/proto/recordset_pb2.py +35 -33
- flwr/proto/recordset_pb2.pyi +40 -14
- flwr/proto/run_pb2.py +64 -0
- flwr/proto/run_pb2.pyi +268 -0
- flwr/proto/run_pb2_grpc.py +4 -0
- flwr/proto/run_pb2_grpc.pyi +4 -0
- flwr/proto/serverappio_pb2.py +52 -0
- flwr/proto/{driver_pb2.pyi → serverappio_pb2.pyi} +62 -20
- flwr/proto/serverappio_pb2_grpc.py +410 -0
- flwr/proto/serverappio_pb2_grpc.pyi +160 -0
- flwr/proto/simulationio_pb2.py +38 -0
- flwr/proto/simulationio_pb2.pyi +65 -0
- flwr/proto/simulationio_pb2_grpc.py +239 -0
- flwr/proto/simulationio_pb2_grpc.pyi +94 -0
- flwr/proto/task_pb2.py +7 -8
- flwr/proto/task_pb2.pyi +8 -5
- flwr/proto/transport_pb2.py +8 -8
- flwr/proto/transport_pb2.pyi +9 -6
- flwr/server/__init__.py +2 -10
- flwr/server/app.py +579 -402
- flwr/server/client_manager.py +8 -6
- flwr/server/compat/app.py +6 -62
- flwr/server/compat/app_utils.py +14 -9
- flwr/server/compat/driver_client_proxy.py +25 -59
- flwr/server/compat/legacy_context.py +5 -4
- flwr/server/driver/__init__.py +2 -0
- flwr/server/driver/driver.py +36 -131
- flwr/server/driver/grpc_driver.py +220 -81
- flwr/server/driver/inmemory_driver.py +183 -0
- flwr/server/history.py +28 -29
- flwr/server/run_serverapp.py +15 -126
- flwr/server/server.py +50 -44
- flwr/server/server_app.py +59 -10
- flwr/server/serverapp/__init__.py +22 -0
- flwr/server/serverapp/app.py +256 -0
- flwr/server/serverapp_components.py +52 -0
- flwr/server/strategy/__init__.py +2 -2
- flwr/server/strategy/aggregate.py +37 -23
- flwr/server/strategy/bulyan.py +9 -9
- flwr/server/strategy/dp_adaptive_clipping.py +25 -25
- flwr/server/strategy/dp_fixed_clipping.py +23 -22
- flwr/server/strategy/dpfedavg_adaptive.py +8 -8
- flwr/server/strategy/dpfedavg_fixed.py +13 -12
- flwr/server/strategy/fault_tolerant_fedavg.py +11 -11
- flwr/server/strategy/fedadagrad.py +9 -9
- flwr/server/strategy/fedadam.py +20 -10
- flwr/server/strategy/fedavg.py +16 -16
- flwr/server/strategy/fedavg_android.py +17 -17
- flwr/server/strategy/fedavgm.py +9 -9
- flwr/server/strategy/fedmedian.py +5 -5
- flwr/server/strategy/fedopt.py +6 -6
- flwr/server/strategy/fedprox.py +7 -7
- flwr/server/strategy/fedtrimmedavg.py +8 -8
- flwr/server/strategy/fedxgb_bagging.py +12 -12
- flwr/server/strategy/fedxgb_cyclic.py +10 -10
- flwr/server/strategy/fedxgb_nn_avg.py +6 -6
- flwr/server/strategy/fedyogi.py +9 -9
- flwr/server/strategy/krum.py +9 -9
- flwr/server/strategy/qfedavg.py +16 -16
- flwr/server/strategy/strategy.py +10 -10
- flwr/server/superlink/driver/__init__.py +2 -2
- flwr/server/superlink/driver/serverappio_grpc.py +61 -0
- flwr/server/superlink/driver/serverappio_servicer.py +361 -0
- flwr/server/superlink/ffs/__init__.py +24 -0
- flwr/server/superlink/ffs/disk_ffs.py +108 -0
- flwr/server/superlink/ffs/ffs.py +79 -0
- flwr/server/superlink/ffs/ffs_factory.py +47 -0
- flwr/server/superlink/fleet/__init__.py +1 -1
- flwr/server/superlink/fleet/grpc_adapter/__init__.py +15 -0
- flwr/server/superlink/fleet/grpc_adapter/grpc_adapter_servicer.py +162 -0
- flwr/server/superlink/fleet/grpc_bidi/__init__.py +1 -1
- flwr/server/superlink/fleet/grpc_bidi/flower_service_servicer.py +4 -2
- flwr/server/superlink/fleet/grpc_bidi/grpc_bridge.py +3 -2
- flwr/server/superlink/fleet/grpc_bidi/grpc_client_proxy.py +1 -1
- flwr/server/superlink/fleet/grpc_bidi/grpc_server.py +5 -154
- flwr/server/superlink/fleet/grpc_rere/__init__.py +1 -1
- flwr/server/superlink/fleet/grpc_rere/fleet_servicer.py +120 -13
- flwr/server/superlink/fleet/grpc_rere/server_interceptor.py +228 -0
- flwr/server/superlink/fleet/message_handler/__init__.py +1 -1
- flwr/server/superlink/fleet/message_handler/message_handler.py +156 -13
- flwr/server/superlink/fleet/rest_rere/__init__.py +1 -1
- flwr/server/superlink/fleet/rest_rere/rest_api.py +119 -81
- flwr/server/superlink/fleet/vce/__init__.py +1 -0
- flwr/server/superlink/fleet/vce/backend/__init__.py +4 -4
- flwr/server/superlink/fleet/vce/backend/backend.py +8 -9
- flwr/server/superlink/fleet/vce/backend/raybackend.py +87 -68
- flwr/server/superlink/fleet/vce/vce_api.py +208 -146
- flwr/server/superlink/linkstate/__init__.py +28 -0
- flwr/server/superlink/linkstate/in_memory_linkstate.py +569 -0
- flwr/server/superlink/linkstate/linkstate.py +376 -0
- flwr/server/superlink/{state/state_factory.py → linkstate/linkstate_factory.py} +19 -10
- flwr/server/superlink/linkstate/sqlite_linkstate.py +1196 -0
- flwr/server/superlink/linkstate/utils.py +399 -0
- flwr/server/superlink/simulation/__init__.py +15 -0
- flwr/server/superlink/simulation/simulationio_grpc.py +65 -0
- flwr/server/superlink/simulation/simulationio_servicer.py +186 -0
- flwr/server/superlink/utils.py +65 -0
- flwr/server/typing.py +2 -0
- flwr/server/utils/__init__.py +1 -1
- flwr/server/utils/tensorboard.py +5 -5
- flwr/server/utils/validator.py +40 -45
- flwr/server/workflow/default_workflows.py +70 -26
- flwr/server/workflow/secure_aggregation/secagg_workflow.py +1 -0
- flwr/server/workflow/secure_aggregation/secaggplus_workflow.py +40 -27
- flwr/simulation/__init__.py +12 -5
- flwr/simulation/app.py +247 -315
- flwr/simulation/legacy_app.py +404 -0
- flwr/simulation/ray_transport/__init__.py +1 -1
- flwr/simulation/ray_transport/ray_actor.py +42 -67
- flwr/simulation/ray_transport/ray_client_proxy.py +37 -17
- flwr/simulation/ray_transport/utils.py +1 -0
- flwr/simulation/run_simulation.py +306 -163
- flwr/simulation/simulationio_connection.py +89 -0
- flwr/superexec/__init__.py +15 -0
- flwr/superexec/app.py +59 -0
- flwr/superexec/deployment.py +188 -0
- flwr/superexec/exec_grpc.py +80 -0
- flwr/superexec/exec_servicer.py +231 -0
- flwr/superexec/exec_user_auth_interceptor.py +101 -0
- flwr/superexec/executor.py +96 -0
- flwr/superexec/simulation.py +124 -0
- {flwr_nightly-1.8.0.dev20240315.dist-info → flwr_nightly-1.15.0.dev20250115.dist-info}/METADATA +33 -26
- flwr_nightly-1.15.0.dev20250115.dist-info/RECORD +328 -0
- flwr_nightly-1.15.0.dev20250115.dist-info/entry_points.txt +12 -0
- flwr/cli/flower_toml.py +0 -140
- flwr/cli/new/templates/app/flower.toml.tpl +0 -13
- flwr/cli/new/templates/app/requirements.numpy.txt.tpl +0 -2
- flwr/cli/new/templates/app/requirements.pytorch.txt.tpl +0 -4
- flwr/cli/new/templates/app/requirements.tensorflow.txt.tpl +0 -4
- flwr/client/node_state.py +0 -48
- flwr/client/node_state_tests.py +0 -65
- flwr/proto/driver_pb2.py +0 -44
- flwr/proto/driver_pb2_grpc.py +0 -169
- flwr/proto/driver_pb2_grpc.pyi +0 -66
- flwr/server/superlink/driver/driver_grpc.py +0 -54
- flwr/server/superlink/driver/driver_servicer.py +0 -129
- flwr/server/superlink/state/in_memory_state.py +0 -230
- flwr/server/superlink/state/sqlite_state.py +0 -630
- flwr/server/superlink/state/state.py +0 -154
- flwr_nightly-1.8.0.dev20240315.dist-info/RECORD +0 -211
- flwr_nightly-1.8.0.dev20240315.dist-info/entry_points.txt +0 -9
- {flwr_nightly-1.8.0.dev20240315.dist-info → flwr_nightly-1.15.0.dev20250115.dist-info}/LICENSE +0 -0
- {flwr_nightly-1.8.0.dev20240315.dist-info → flwr_nightly-1.15.0.dev20250115.dist-info}/WHEEL +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2024 Flower Labs GmbH. All Rights Reserved.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -15,68 +15,175 @@
|
|
15
15
|
"""Fleet API gRPC request-response servicer."""
|
16
16
|
|
17
17
|
|
18
|
-
from logging import INFO
|
18
|
+
from logging import DEBUG, INFO
|
19
19
|
|
20
20
|
import grpc
|
21
21
|
|
22
22
|
from flwr.common.logger import log
|
23
|
+
from flwr.common.typing import InvalidRunStatusException
|
23
24
|
from flwr.proto import fleet_pb2_grpc # pylint: disable=E0611
|
25
|
+
from flwr.proto.fab_pb2 import GetFabRequest, GetFabResponse # pylint: disable=E0611
|
24
26
|
from flwr.proto.fleet_pb2 import ( # pylint: disable=E0611
|
25
27
|
CreateNodeRequest,
|
26
28
|
CreateNodeResponse,
|
27
29
|
DeleteNodeRequest,
|
28
30
|
DeleteNodeResponse,
|
31
|
+
PingRequest,
|
32
|
+
PingResponse,
|
33
|
+
PullMessagesRequest,
|
34
|
+
PullMessagesResponse,
|
29
35
|
PullTaskInsRequest,
|
30
36
|
PullTaskInsResponse,
|
37
|
+
PushMessagesRequest,
|
38
|
+
PushMessagesResponse,
|
31
39
|
PushTaskResRequest,
|
32
40
|
PushTaskResResponse,
|
33
41
|
)
|
42
|
+
from flwr.proto.run_pb2 import GetRunRequest, GetRunResponse # pylint: disable=E0611
|
43
|
+
from flwr.server.superlink.ffs.ffs_factory import FfsFactory
|
34
44
|
from flwr.server.superlink.fleet.message_handler import message_handler
|
35
|
-
from flwr.server.superlink.
|
45
|
+
from flwr.server.superlink.linkstate import LinkStateFactory
|
46
|
+
from flwr.server.superlink.utils import abort_grpc_context
|
36
47
|
|
37
48
|
|
38
49
|
class FleetServicer(fleet_pb2_grpc.FleetServicer):
|
39
50
|
"""Fleet API servicer."""
|
40
51
|
|
41
|
-
def __init__(
|
52
|
+
def __init__(
|
53
|
+
self, state_factory: LinkStateFactory, ffs_factory: FfsFactory
|
54
|
+
) -> None:
|
42
55
|
self.state_factory = state_factory
|
56
|
+
self.ffs_factory = ffs_factory
|
43
57
|
|
44
58
|
def CreateNode(
|
45
59
|
self, request: CreateNodeRequest, context: grpc.ServicerContext
|
46
60
|
) -> CreateNodeResponse:
|
47
61
|
"""."""
|
48
|
-
log(INFO, "
|
49
|
-
|
62
|
+
log(INFO, "[Fleet.CreateNode] Request ping_interval=%s", request.ping_interval)
|
63
|
+
log(DEBUG, "[Fleet.CreateNode] Request: %s", request)
|
64
|
+
response = message_handler.create_node(
|
50
65
|
request=request,
|
51
66
|
state=self.state_factory.state(),
|
52
67
|
)
|
68
|
+
log(INFO, "[Fleet.CreateNode] Created node_id=%s", response.node.node_id)
|
69
|
+
log(DEBUG, "[Fleet.CreateNode] Response: %s", response)
|
70
|
+
return response
|
53
71
|
|
54
72
|
def DeleteNode(
|
55
73
|
self, request: DeleteNodeRequest, context: grpc.ServicerContext
|
56
74
|
) -> DeleteNodeResponse:
|
57
75
|
"""."""
|
58
|
-
log(INFO, "
|
76
|
+
log(INFO, "[Fleet.DeleteNode] Delete node_id=%s", request.node.node_id)
|
77
|
+
log(DEBUG, "[Fleet.DeleteNode] Request: %s", request)
|
59
78
|
return message_handler.delete_node(
|
60
79
|
request=request,
|
61
80
|
state=self.state_factory.state(),
|
62
81
|
)
|
63
82
|
|
83
|
+
def Ping(self, request: PingRequest, context: grpc.ServicerContext) -> PingResponse:
|
84
|
+
"""."""
|
85
|
+
log(DEBUG, "[Fleet.Ping] Request: %s", request)
|
86
|
+
return message_handler.ping(
|
87
|
+
request=request,
|
88
|
+
state=self.state_factory.state(),
|
89
|
+
)
|
90
|
+
|
64
91
|
def PullTaskIns(
|
65
92
|
self, request: PullTaskInsRequest, context: grpc.ServicerContext
|
66
93
|
) -> PullTaskInsResponse:
|
67
94
|
"""Pull TaskIns."""
|
68
|
-
log(INFO, "
|
95
|
+
log(INFO, "[Fleet.PullTaskIns] node_id=%s", request.node.node_id)
|
96
|
+
log(DEBUG, "[Fleet.PullTaskIns] Request: %s", request)
|
69
97
|
return message_handler.pull_task_ins(
|
70
98
|
request=request,
|
71
99
|
state=self.state_factory.state(),
|
72
100
|
)
|
73
101
|
|
102
|
+
def PullMessages(
|
103
|
+
self, request: PullMessagesRequest, context: grpc.ServicerContext
|
104
|
+
) -> PullMessagesResponse:
|
105
|
+
"""Pull Messages."""
|
106
|
+
log(INFO, "[Fleet.PullMessages] node_id=%s", request.node.node_id)
|
107
|
+
log(DEBUG, "[Fleet.PullMessages] Request: %s", request)
|
108
|
+
return message_handler.pull_messages(
|
109
|
+
request=request,
|
110
|
+
state=self.state_factory.state(),
|
111
|
+
)
|
112
|
+
|
74
113
|
def PushTaskRes(
|
75
114
|
self, request: PushTaskResRequest, context: grpc.ServicerContext
|
76
115
|
) -> PushTaskResResponse:
|
77
116
|
"""Push TaskRes."""
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
117
|
+
if request.task_res_list:
|
118
|
+
log(
|
119
|
+
INFO,
|
120
|
+
"[Fleet.PushTaskRes] Push results from node_id=%s",
|
121
|
+
request.task_res_list[0].task.producer.node_id,
|
122
|
+
)
|
123
|
+
else:
|
124
|
+
log(INFO, "[Fleet.PushTaskRes] No task results to push")
|
125
|
+
|
126
|
+
try:
|
127
|
+
res = message_handler.push_task_res(
|
128
|
+
request=request,
|
129
|
+
state=self.state_factory.state(),
|
130
|
+
)
|
131
|
+
except InvalidRunStatusException as e:
|
132
|
+
abort_grpc_context(e.message, context)
|
133
|
+
|
134
|
+
return res
|
135
|
+
|
136
|
+
def PushMessages(
|
137
|
+
self, request: PushMessagesRequest, context: grpc.ServicerContext
|
138
|
+
) -> PushMessagesResponse:
|
139
|
+
"""Push Messages."""
|
140
|
+
if request.messages_list:
|
141
|
+
log(
|
142
|
+
INFO,
|
143
|
+
"[Fleet.PushMessages] Push results from node_id=%s",
|
144
|
+
request.messages_list[0].metadata.src_node_id,
|
145
|
+
)
|
146
|
+
else:
|
147
|
+
log(INFO, "[Fleet.PushMessages] No task results to push")
|
148
|
+
|
149
|
+
try:
|
150
|
+
res = message_handler.push_messages(
|
151
|
+
request=request,
|
152
|
+
state=self.state_factory.state(),
|
153
|
+
)
|
154
|
+
except InvalidRunStatusException as e:
|
155
|
+
abort_grpc_context(e.message, context)
|
156
|
+
|
157
|
+
return res
|
158
|
+
|
159
|
+
def GetRun(
|
160
|
+
self, request: GetRunRequest, context: grpc.ServicerContext
|
161
|
+
) -> GetRunResponse:
|
162
|
+
"""Get run information."""
|
163
|
+
log(INFO, "[Fleet.GetRun] Requesting `Run` for run_id=%s", request.run_id)
|
164
|
+
|
165
|
+
try:
|
166
|
+
res = message_handler.get_run(
|
167
|
+
request=request,
|
168
|
+
state=self.state_factory.state(),
|
169
|
+
)
|
170
|
+
except InvalidRunStatusException as e:
|
171
|
+
abort_grpc_context(e.message, context)
|
172
|
+
|
173
|
+
return res
|
174
|
+
|
175
|
+
def GetFab(
|
176
|
+
self, request: GetFabRequest, context: grpc.ServicerContext
|
177
|
+
) -> GetFabResponse:
|
178
|
+
"""Get FAB."""
|
179
|
+
log(INFO, "[Fleet.GetFab] Requesting FAB for fab_hash=%s", request.hash_str)
|
180
|
+
try:
|
181
|
+
res = message_handler.get_fab(
|
182
|
+
request=request,
|
183
|
+
ffs=self.ffs_factory.ffs(),
|
184
|
+
state=self.state_factory.state(),
|
185
|
+
)
|
186
|
+
except InvalidRunStatusException as e:
|
187
|
+
abort_grpc_context(e.message, context)
|
188
|
+
|
189
|
+
return res
|
@@ -0,0 +1,228 @@
|
|
1
|
+
# Copyright 2024 Flower Labs GmbH. All Rights Reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
# ==============================================================================
|
15
|
+
"""Flower server interceptor."""
|
16
|
+
|
17
|
+
|
18
|
+
import base64
|
19
|
+
from collections.abc import Sequence
|
20
|
+
from logging import INFO, WARNING
|
21
|
+
from typing import Any, Callable, Optional, Union
|
22
|
+
|
23
|
+
import grpc
|
24
|
+
from cryptography.hazmat.primitives.asymmetric import ec
|
25
|
+
|
26
|
+
from flwr.common.logger import log
|
27
|
+
from flwr.common.secure_aggregation.crypto.symmetric_encryption import (
|
28
|
+
bytes_to_private_key,
|
29
|
+
bytes_to_public_key,
|
30
|
+
generate_shared_key,
|
31
|
+
verify_hmac,
|
32
|
+
)
|
33
|
+
from flwr.proto.fab_pb2 import GetFabRequest, GetFabResponse # pylint: disable=E0611
|
34
|
+
from flwr.proto.fleet_pb2 import ( # pylint: disable=E0611
|
35
|
+
CreateNodeRequest,
|
36
|
+
CreateNodeResponse,
|
37
|
+
DeleteNodeRequest,
|
38
|
+
DeleteNodeResponse,
|
39
|
+
PingRequest,
|
40
|
+
PingResponse,
|
41
|
+
PullTaskInsRequest,
|
42
|
+
PullTaskInsResponse,
|
43
|
+
PushTaskResRequest,
|
44
|
+
PushTaskResResponse,
|
45
|
+
)
|
46
|
+
from flwr.proto.node_pb2 import Node # pylint: disable=E0611
|
47
|
+
from flwr.proto.run_pb2 import GetRunRequest, GetRunResponse # pylint: disable=E0611
|
48
|
+
from flwr.server.superlink.linkstate import LinkStateFactory
|
49
|
+
|
50
|
+
_PUBLIC_KEY_HEADER = "public-key"
|
51
|
+
_AUTH_TOKEN_HEADER = "auth-token"
|
52
|
+
|
53
|
+
Request = Union[
|
54
|
+
CreateNodeRequest,
|
55
|
+
DeleteNodeRequest,
|
56
|
+
PullTaskInsRequest,
|
57
|
+
PushTaskResRequest,
|
58
|
+
GetRunRequest,
|
59
|
+
PingRequest,
|
60
|
+
GetFabRequest,
|
61
|
+
]
|
62
|
+
|
63
|
+
Response = Union[
|
64
|
+
CreateNodeResponse,
|
65
|
+
DeleteNodeResponse,
|
66
|
+
PullTaskInsResponse,
|
67
|
+
PushTaskResResponse,
|
68
|
+
GetRunResponse,
|
69
|
+
PingResponse,
|
70
|
+
GetFabResponse,
|
71
|
+
]
|
72
|
+
|
73
|
+
|
74
|
+
def _get_value_from_tuples(
|
75
|
+
key_string: str, tuples: Sequence[tuple[str, Union[str, bytes]]]
|
76
|
+
) -> bytes:
|
77
|
+
value = next((value for key, value in tuples if key == key_string), "")
|
78
|
+
if isinstance(value, str):
|
79
|
+
return value.encode()
|
80
|
+
|
81
|
+
return value
|
82
|
+
|
83
|
+
|
84
|
+
class AuthenticateServerInterceptor(grpc.ServerInterceptor): # type: ignore
|
85
|
+
"""Server interceptor for node authentication."""
|
86
|
+
|
87
|
+
def __init__(self, state_factory: LinkStateFactory):
|
88
|
+
self.state_factory = state_factory
|
89
|
+
state = self.state_factory.state()
|
90
|
+
|
91
|
+
self.node_public_keys = state.get_node_public_keys()
|
92
|
+
if len(self.node_public_keys) == 0:
|
93
|
+
log(WARNING, "Authentication enabled, but no known public keys configured")
|
94
|
+
|
95
|
+
private_key = state.get_server_private_key()
|
96
|
+
public_key = state.get_server_public_key()
|
97
|
+
|
98
|
+
if private_key is None or public_key is None:
|
99
|
+
raise ValueError("Error loading authentication keys")
|
100
|
+
|
101
|
+
self.server_private_key = bytes_to_private_key(private_key)
|
102
|
+
self.encoded_server_public_key = base64.urlsafe_b64encode(public_key)
|
103
|
+
|
104
|
+
def intercept_service(
|
105
|
+
self,
|
106
|
+
continuation: Callable[[Any], Any],
|
107
|
+
handler_call_details: grpc.HandlerCallDetails,
|
108
|
+
) -> grpc.RpcMethodHandler:
|
109
|
+
"""Flower server interceptor authentication logic.
|
110
|
+
|
111
|
+
Intercept all unary calls from nodes and authenticate nodes by validating auth
|
112
|
+
metadata sent by the node. Continue RPC call if node is authenticated, else,
|
113
|
+
terminate RPC call by setting context to abort.
|
114
|
+
"""
|
115
|
+
# One of the method handlers in
|
116
|
+
# `flwr.server.superlink.fleet.grpc_rere.fleet_server.FleetServicer`
|
117
|
+
method_handler: grpc.RpcMethodHandler = continuation(handler_call_details)
|
118
|
+
return self._generic_auth_unary_method_handler(method_handler)
|
119
|
+
|
120
|
+
def _generic_auth_unary_method_handler(
|
121
|
+
self, method_handler: grpc.RpcMethodHandler
|
122
|
+
) -> grpc.RpcMethodHandler:
|
123
|
+
def _generic_method_handler(
|
124
|
+
request: Request,
|
125
|
+
context: grpc.ServicerContext,
|
126
|
+
) -> Response:
|
127
|
+
node_public_key_bytes = base64.urlsafe_b64decode(
|
128
|
+
_get_value_from_tuples(
|
129
|
+
_PUBLIC_KEY_HEADER, context.invocation_metadata()
|
130
|
+
)
|
131
|
+
)
|
132
|
+
if node_public_key_bytes not in self.node_public_keys:
|
133
|
+
context.abort(grpc.StatusCode.UNAUTHENTICATED, "Access denied")
|
134
|
+
|
135
|
+
if isinstance(request, CreateNodeRequest):
|
136
|
+
response = self._create_authenticated_node(
|
137
|
+
node_public_key_bytes, request, context
|
138
|
+
)
|
139
|
+
log(
|
140
|
+
INFO,
|
141
|
+
"AuthenticateServerInterceptor: Created node_id=%s",
|
142
|
+
response.node.node_id,
|
143
|
+
)
|
144
|
+
return response
|
145
|
+
|
146
|
+
# Verify hmac value
|
147
|
+
hmac_value = base64.urlsafe_b64decode(
|
148
|
+
_get_value_from_tuples(
|
149
|
+
_AUTH_TOKEN_HEADER, context.invocation_metadata()
|
150
|
+
)
|
151
|
+
)
|
152
|
+
public_key = bytes_to_public_key(node_public_key_bytes)
|
153
|
+
|
154
|
+
if not self._verify_hmac(public_key, request, hmac_value):
|
155
|
+
context.abort(grpc.StatusCode.UNAUTHENTICATED, "Access denied")
|
156
|
+
|
157
|
+
# Verify node_id
|
158
|
+
node_id = self.state_factory.state().get_node_id(node_public_key_bytes)
|
159
|
+
|
160
|
+
if not self._verify_node_id(node_id, request):
|
161
|
+
context.abort(grpc.StatusCode.UNAUTHENTICATED, "Access denied")
|
162
|
+
|
163
|
+
return method_handler.unary_unary(request, context) # type: ignore
|
164
|
+
|
165
|
+
return grpc.unary_unary_rpc_method_handler(
|
166
|
+
_generic_method_handler,
|
167
|
+
request_deserializer=method_handler.request_deserializer,
|
168
|
+
response_serializer=method_handler.response_serializer,
|
169
|
+
)
|
170
|
+
|
171
|
+
def _verify_node_id(
|
172
|
+
self,
|
173
|
+
node_id: Optional[int],
|
174
|
+
request: Union[
|
175
|
+
DeleteNodeRequest,
|
176
|
+
PullTaskInsRequest,
|
177
|
+
PushTaskResRequest,
|
178
|
+
GetRunRequest,
|
179
|
+
PingRequest,
|
180
|
+
GetFabRequest,
|
181
|
+
],
|
182
|
+
) -> bool:
|
183
|
+
if node_id is None:
|
184
|
+
return False
|
185
|
+
if isinstance(request, PushTaskResRequest):
|
186
|
+
if len(request.task_res_list) == 0:
|
187
|
+
return False
|
188
|
+
return request.task_res_list[0].task.producer.node_id == node_id
|
189
|
+
if isinstance(request, GetRunRequest):
|
190
|
+
return node_id in self.state_factory.state().get_nodes(request.run_id)
|
191
|
+
return request.node.node_id == node_id
|
192
|
+
|
193
|
+
def _verify_hmac(
|
194
|
+
self, public_key: ec.EllipticCurvePublicKey, request: Request, hmac_value: bytes
|
195
|
+
) -> bool:
|
196
|
+
shared_secret = generate_shared_key(self.server_private_key, public_key)
|
197
|
+
message_bytes = request.SerializeToString(deterministic=True)
|
198
|
+
return verify_hmac(shared_secret, message_bytes, hmac_value)
|
199
|
+
|
200
|
+
def _create_authenticated_node(
|
201
|
+
self,
|
202
|
+
public_key_bytes: bytes,
|
203
|
+
request: CreateNodeRequest,
|
204
|
+
context: grpc.ServicerContext,
|
205
|
+
) -> CreateNodeResponse:
|
206
|
+
context.send_initial_metadata(
|
207
|
+
(
|
208
|
+
(
|
209
|
+
_PUBLIC_KEY_HEADER,
|
210
|
+
self.encoded_server_public_key,
|
211
|
+
),
|
212
|
+
)
|
213
|
+
)
|
214
|
+
state = self.state_factory.state()
|
215
|
+
node_id = state.get_node_id(public_key_bytes)
|
216
|
+
|
217
|
+
# Handle `CreateNode` here instead of calling the default method handler
|
218
|
+
# Return previously assigned `node_id` for the provided `public_key`
|
219
|
+
if node_id is not None:
|
220
|
+
state.acknowledge_ping(node_id, request.ping_interval)
|
221
|
+
return CreateNodeResponse(node=Node(node_id=node_id))
|
222
|
+
|
223
|
+
# No `node_id` exists for the provided `public_key`
|
224
|
+
# Handle `CreateNode` here instead of calling the default method handler
|
225
|
+
# Note: the innermost `CreateNode` method will never be called
|
226
|
+
node_id = state.create_node(request.ping_interval)
|
227
|
+
state.set_node_public_key(node_id, public_key_bytes)
|
228
|
+
return CreateNodeResponse(node=Node(node_id=node_id))
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright
|
1
|
+
# Copyright 2024 Flower Labs GmbH. All Rights Reserved.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -15,39 +15,64 @@
|
|
15
15
|
"""Fleet API message handlers."""
|
16
16
|
|
17
17
|
|
18
|
-
|
18
|
+
import time
|
19
|
+
from typing import Optional
|
19
20
|
from uuid import UUID
|
20
21
|
|
22
|
+
from flwr.common.constant import Status
|
23
|
+
from flwr.common.serde import (
|
24
|
+
fab_to_proto,
|
25
|
+
message_from_proto,
|
26
|
+
message_from_taskins,
|
27
|
+
message_to_proto,
|
28
|
+
message_to_taskres,
|
29
|
+
user_config_to_proto,
|
30
|
+
)
|
31
|
+
from flwr.common.typing import Fab, InvalidRunStatusException
|
32
|
+
from flwr.proto.fab_pb2 import GetFabRequest, GetFabResponse # pylint: disable=E0611
|
21
33
|
from flwr.proto.fleet_pb2 import ( # pylint: disable=E0611
|
22
34
|
CreateNodeRequest,
|
23
35
|
CreateNodeResponse,
|
24
36
|
DeleteNodeRequest,
|
25
37
|
DeleteNodeResponse,
|
38
|
+
PingRequest,
|
39
|
+
PingResponse,
|
40
|
+
PullMessagesRequest,
|
41
|
+
PullMessagesResponse,
|
26
42
|
PullTaskInsRequest,
|
27
43
|
PullTaskInsResponse,
|
44
|
+
PushMessagesRequest,
|
45
|
+
PushMessagesResponse,
|
28
46
|
PushTaskResRequest,
|
29
47
|
PushTaskResResponse,
|
30
48
|
Reconnect,
|
31
49
|
)
|
32
50
|
from flwr.proto.node_pb2 import Node # pylint: disable=E0611
|
51
|
+
from flwr.proto.run_pb2 import ( # pylint: disable=E0611
|
52
|
+
GetRunRequest,
|
53
|
+
GetRunResponse,
|
54
|
+
Run,
|
55
|
+
)
|
33
56
|
from flwr.proto.task_pb2 import TaskIns, TaskRes # pylint: disable=E0611
|
34
|
-
from flwr.server.superlink.
|
57
|
+
from flwr.server.superlink.ffs.ffs import Ffs
|
58
|
+
from flwr.server.superlink.linkstate import LinkState
|
59
|
+
from flwr.server.superlink.utils import check_abort
|
35
60
|
|
36
61
|
|
37
62
|
def create_node(
|
38
63
|
request: CreateNodeRequest, # pylint: disable=unused-argument
|
39
|
-
state:
|
64
|
+
state: LinkState,
|
40
65
|
) -> CreateNodeResponse:
|
41
66
|
"""."""
|
42
67
|
# Create node
|
43
|
-
node_id = state.create_node()
|
44
|
-
return CreateNodeResponse(node=Node(node_id=node_id
|
68
|
+
node_id = state.create_node(ping_interval=request.ping_interval)
|
69
|
+
return CreateNodeResponse(node=Node(node_id=node_id))
|
45
70
|
|
46
71
|
|
47
|
-
def delete_node(request: DeleteNodeRequest, state:
|
72
|
+
def delete_node(request: DeleteNodeRequest, state: LinkState) -> DeleteNodeResponse:
|
48
73
|
"""."""
|
49
74
|
# Validate node_id
|
50
|
-
if request.node.
|
75
|
+
if request.node.node_id == 0: # i.e. unset `node_id`
|
51
76
|
return DeleteNodeResponse()
|
52
77
|
|
53
78
|
# Update state
|
@@ -55,14 +80,22 @@ def delete_node(request: DeleteNodeRequest, state: State) -> DeleteNodeResponse:
|
|
55
80
|
return DeleteNodeResponse()
|
56
81
|
|
57
82
|
|
58
|
-
def
|
83
|
+
def ping(
|
84
|
+
request: PingRequest, # pylint: disable=unused-argument
|
85
|
+
state: LinkState, # pylint: disable=unused-argument
|
86
|
+
) -> PingResponse:
|
87
|
+
"""."""
|
88
|
+
res = state.acknowledge_ping(request.node.node_id, request.ping_interval)
|
89
|
+
return PingResponse(success=res)
|
90
|
+
|
91
|
+
|
92
|
+
def pull_task_ins(request: PullTaskInsRequest, state: LinkState) -> PullTaskInsResponse:
|
59
93
|
"""Pull TaskIns handler."""
|
60
|
-
# Get node_id if client node is not anonymous
|
61
94
|
node = request.node # pylint: disable=no-member
|
62
|
-
node_id:
|
95
|
+
node_id: int = node.node_id
|
63
96
|
|
64
97
|
# Retrieve TaskIns from State
|
65
|
-
task_ins_list:
|
98
|
+
task_ins_list: list[TaskIns] = state.get_task_ins(node_id=node_id, limit=1)
|
66
99
|
|
67
100
|
# Build response
|
68
101
|
response = PullTaskInsResponse(
|
@@ -71,12 +104,44 @@ def pull_task_ins(request: PullTaskInsRequest, state: State) -> PullTaskInsRespo
|
|
71
104
|
return response
|
72
105
|
|
73
106
|
|
74
|
-
def
|
107
|
+
def pull_messages(
|
108
|
+
request: PullMessagesRequest, state: LinkState
|
109
|
+
) -> PullMessagesResponse:
|
110
|
+
"""Pull Messages handler."""
|
111
|
+
# Get node_id if client node is not anonymous
|
112
|
+
node = request.node # pylint: disable=no-member
|
113
|
+
node_id: int = node.node_id
|
114
|
+
|
115
|
+
# Retrieve TaskIns from State
|
116
|
+
task_ins_list: list[TaskIns] = state.get_task_ins(node_id=node_id, limit=1)
|
117
|
+
|
118
|
+
# Convert to Messages
|
119
|
+
msg_proto = []
|
120
|
+
for task_ins in task_ins_list:
|
121
|
+
msg = message_from_taskins(task_ins)
|
122
|
+
msg_proto.append(message_to_proto(msg))
|
123
|
+
|
124
|
+
return PullMessagesResponse(messages_list=msg_proto)
|
125
|
+
|
126
|
+
|
127
|
+
def push_task_res(request: PushTaskResRequest, state: LinkState) -> PushTaskResResponse:
|
75
128
|
"""Push TaskRes handler."""
|
76
129
|
# pylint: disable=no-member
|
77
130
|
task_res: TaskRes = request.task_res_list[0]
|
78
131
|
# pylint: enable=no-member
|
79
132
|
|
133
|
+
# Abort if the run is not running
|
134
|
+
abort_msg = check_abort(
|
135
|
+
task_res.run_id,
|
136
|
+
[Status.PENDING, Status.STARTING, Status.FINISHED],
|
137
|
+
state,
|
138
|
+
)
|
139
|
+
if abort_msg:
|
140
|
+
raise InvalidRunStatusException(abort_msg)
|
141
|
+
|
142
|
+
# Set pushed_at (timestamp in seconds)
|
143
|
+
task_res.task.pushed_at = time.time()
|
144
|
+
|
80
145
|
# Store TaskRes in State
|
81
146
|
task_id: Optional[UUID] = state.store_task_res(task_res=task_res)
|
82
147
|
|
@@ -86,3 +151,81 @@ def push_task_res(request: PushTaskResRequest, state: State) -> PushTaskResRespo
|
|
86
151
|
results={str(task_id): 0},
|
87
152
|
)
|
88
153
|
return response
|
154
|
+
|
155
|
+
|
156
|
+
def push_messages(
|
157
|
+
request: PushMessagesRequest, state: LinkState
|
158
|
+
) -> PushMessagesResponse:
|
159
|
+
"""Push Messages handler."""
|
160
|
+
# Convert Message to TaskRes
|
161
|
+
msg = message_from_proto(message_proto=request.messages_list[0])
|
162
|
+
task_res = message_to_taskres(msg)
|
163
|
+
|
164
|
+
# Abort if the run is not running
|
165
|
+
abort_msg = check_abort(
|
166
|
+
task_res.run_id,
|
167
|
+
[Status.PENDING, Status.STARTING, Status.FINISHED],
|
168
|
+
state,
|
169
|
+
)
|
170
|
+
if abort_msg:
|
171
|
+
raise InvalidRunStatusException(abort_msg)
|
172
|
+
|
173
|
+
# Set pushed_at (timestamp in seconds)
|
174
|
+
task_res.task.pushed_at = time.time()
|
175
|
+
|
176
|
+
# Store TaskRes in State
|
177
|
+
message_id: Optional[UUID] = state.store_task_res(task_res=task_res)
|
178
|
+
|
179
|
+
# Build response
|
180
|
+
response = PushMessagesResponse(
|
181
|
+
reconnect=Reconnect(reconnect=5),
|
182
|
+
results={str(message_id): 0},
|
183
|
+
)
|
184
|
+
return response
|
185
|
+
|
186
|
+
|
187
|
+
def get_run(request: GetRunRequest, state: LinkState) -> GetRunResponse:
|
188
|
+
"""Get run information."""
|
189
|
+
run = state.get_run(request.run_id)
|
190
|
+
|
191
|
+
if run is None:
|
192
|
+
return GetRunResponse()
|
193
|
+
|
194
|
+
# Abort if the run is not running
|
195
|
+
abort_msg = check_abort(
|
196
|
+
request.run_id,
|
197
|
+
[Status.PENDING, Status.STARTING, Status.FINISHED],
|
198
|
+
state,
|
199
|
+
)
|
200
|
+
if abort_msg:
|
201
|
+
raise InvalidRunStatusException(abort_msg)
|
202
|
+
|
203
|
+
return GetRunResponse(
|
204
|
+
run=Run(
|
205
|
+
run_id=run.run_id,
|
206
|
+
fab_id=run.fab_id,
|
207
|
+
fab_version=run.fab_version,
|
208
|
+
override_config=user_config_to_proto(run.override_config),
|
209
|
+
fab_hash=run.fab_hash,
|
210
|
+
)
|
211
|
+
)
|
212
|
+
|
213
|
+
|
214
|
+
def get_fab(
|
215
|
+
request: GetFabRequest, ffs: Ffs, state: LinkState # pylint: disable=W0613
|
216
|
+
) -> GetFabResponse:
|
217
|
+
"""Get FAB."""
|
218
|
+
# Abort if the run is not running
|
219
|
+
abort_msg = check_abort(
|
220
|
+
request.run_id,
|
221
|
+
[Status.PENDING, Status.STARTING, Status.FINISHED],
|
222
|
+
state,
|
223
|
+
)
|
224
|
+
if abort_msg:
|
225
|
+
raise InvalidRunStatusException(abort_msg)
|
226
|
+
|
227
|
+
if result := ffs.get(request.hash_str):
|
228
|
+
fab = Fab(request.hash_str, result[0])
|
229
|
+
return GetFabResponse(fab=fab_to_proto(fab))
|
230
|
+
|
231
|
+
raise ValueError(f"Found no FAB with hash: {request.hash_str}")
|